Refractoring Stage 3 Completed the mail-service refactoring stage and started IPC hardening

This commit is contained in:
2026-10-16 16:57:07 +03:00
parent e398bc4e1a
commit da543d5059
18 changed files with 1344 additions and 520 deletions
+17 -11
View File
@@ -65,27 +65,30 @@ This is a gradual destination, not a requirement to move everything at once. IPC
**Result:** persistence adapters and legacy migration are covered independently; `npm test` passes 54 tests.
### 4. Split mail services — in progress
### 4. Split mail services — complete
- [x] Extract SMTP submission and Sent-copy handling (`desktop/mail/send-service.cjs`).
- [x] Extract IMAP special-folder discovery and folder-path resolution (`desktop/mail/folders.cjs`).
- [x] Extract mailbox page/search reads (`desktop/mail/read-service.cjs`).
- [x] Extract message actions (`desktop/mail/action-service.cjs`).
- [ ] Extract background sync, IDLE watchers, retries, and snooze processing.
- [ ] Extract offline outbox processing.
- [ ] Extract attachment parsing, saving, and preview workflows.
- [x] Extract mailbox reconciliation and rule application (`desktop/mail/sync-service.cjs`).
- [x] Extract background scheduling, per-account backoff, and request coalescing (`desktop/mail/sync-coordinator.cjs`).
- [x] Extract IMAP IDLE watcher lifecycle (`desktop/mail/idle-watcher-manager.cjs`).
- [x] Extract snooze reminder processing (`desktop/mail/snooze-reminder-service.cjs`).
- [x] Extract offline outbox processing and optimistic cache updates (`desktop/mail/outbox-service.cjs`).
- [x] Extract attachment saving and preview workflows (`desktop/mail/attachment-service.cjs`).
**Acceptance:** mail services can be tested with fake clients/stores; generation invalidation, connection cleanup, and no-plaintext PGP queueing remain covered.
**Progress:** SMTP submission/Sent-copy behavior, IMAP folder discovery, mailbox reads, and message actions now have fake-client tests, including transport cleanup, duplicate-send prevention, special-use lookup, custom-folder validation, paging/search, snooze exclusions, flag/move/delete behavior, and connection cleanup. Background sync, outbox, and attachment workflows remain to be extracted.
**Result:** mail protocol, outbox, attachment, scheduling, IDLE, and snooze workflows are isolated behind injected dependencies; `npm test` passes 92 tests.
### 5. Harden and modularize IPC
- Register handlers by feature and keep `preload.cjs` as the narrow renderer API.
- Validate argument shape, type, size, and authority-sensitive values at the IPC boundary.
- Verify the sender is the expected application document before privileged actions.
- Review navigation handling so only the intended app document can load; do not allow arbitrary `file:` navigation.
- Return deliberate DTOs rather than internal store objects.
- [x] Verify the IPC sender is the expected top-level application document (`desktop/security/ipc-sender.cjs`).
- [x] Restrict navigation to the exact app document URL; reject arbitrary `file:` navigation.
- [ ] Validate argument shape, type, size, and authority-sensitive values at the IPC boundary.
- [ ] Register handlers by feature and keep `preload.cjs` as the narrow renderer API.
- [ ] Return deliberate DTOs rather than internal store objects.
**Acceptance:** IPC tests cover malformed inputs and rejected senders; privileged behavior remains in trusted code.
@@ -119,5 +122,8 @@ This is a gradual destination, not a requirement to move everything at once. IPC
- Step 1 added a generated-web-asset parity test; the full suite passed 38 tests.
- Step 2 extracted pure account, folder, mail-content, filtering, and DAV codec helpers; the full suite passed 47 tests.
- Step 3 extracted encrypted JSON persistence and account migration; the full suite passed 54 tests.
- Step 4 extracted injected SMTP, IMAP folder/read, and message-action services; the full suite passed 69 tests.
- Step 4 extracted injected SMTP, IMAP folder/read/action, outbox, attachment, mailbox-sync, and scheduling services; the full suite passed 86 tests.
- Step 4 completed with extracted IDLE and snooze services; the full suite passed 92 tests.
- Step 5 added a trusted top-level sender check to all 54 registered IPC handlers; sender boundary tests pass.
- Step 5 also aligned `will-navigate` with the same exact-document policy; `npm test` passes 96 tests.
- While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved.