15 Commits

Author SHA1 Message Date
df78397870 fix stale IMAP connection: clean up old connection on reconnect, robust disconnect
- connect() now cleans up any stale connection/event loop group before
  creating a new one, preventing leaked resources after failed syncs
- disconnect() uses try? for both channel close and group shutdown so
  "Already closed" errors don't prevent cleanup

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 12:10:53 +01:00
ff91e397e8 fix sync: INSERT OR IGNORE for duplicate messages, fix leaked IMAP continuations
- insertMessages uses INSERT OR IGNORE on (mailboxId, uid) conflict instead of
  crashing on UNIQUE constraint when messages are re-fetched after restart
- IMAPResponseHandler.sendCommand resumes any leaked previous continuation before
  registering a new one, preventing DuplicateCommandTag errors
- add channelInactive handler to resume pending continuations on connection drop
- add error type to sync failure log for better diagnostics

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 11:58:29 +01:00
1e39a2bd43 fix offline: remove deadlocking syncShutdownGracefully from deinit, limit flag sync range
- remove deinit from IMAPConnection, SMTPConnection — syncShutdownGracefully
  blocks and deadlocks if called on NIO event loop thread
- limit reconcileFlags to last 500 UIDs to avoid overwhelming the connection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 11:44:45 +01:00
8c33d4d4a6 fix raw MIME body display, re-parse stale cached bodies, fix minor review items
- detect and re-fetch bodies containing unparsed MIME content (boundary markers,
  Content-Transfer-Encoding headers) from pre-MIMEParser code path
- fix MIMEParser section numbering: pass cumulative sectionPrefix in nested multiparts
  instead of resetting to empty string
- generate snippet from parsed body text when envelope snippet is missing
- add pendingAction(id:) direct lookup to MailStore, avoid re-fetching all actions
- add updateSnippet method to MailStore
- fix IMAPIdleClient.selectInbox: use incrementing tag counter instead of hardcoded tag
- use static nonisolated(unsafe) ISO8601DateFormatter in ActionQueue (avoid repeated alloc)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 10:33:08 +01:00
10b7cb2fd2 fix code review issues: deferral date format, storeFlags SELECT, event loop leaks, GTD selection tracking
- fix deferral resurfacing using VTODOParser.formatDateOnly instead of ISO8601 (date format mismatch)
- add SELECT mailbox before UID STORE in storeFlags (IMAP protocol requirement)
- pass credentials to SyncCoordinator so IDLE monitoring activates
- add selectedItem tracking to MailViewModel, wire List selection in GTD views
- fix startPeriodicSync to sleep-first, preventing duplicate sync on launch
- add deinit cleanup for EventLoopGroup in IMAPConnection, SMTPConnection
- use separate IMAP client for attachment downloads, avoid shared connection interference
- remove [weak self] from IMAPIdleClient actor Task to prevent orphaned connections
- fix isGTDPerspective to check selectedMailbox instead of items.isEmpty
- fix fetchBody to use complete RFC822 fetch instead of BODY[TEXT]
- reuse single IMAP connection per ActionQueue.flush() batch
- add requiresIMAP to ActionPayload for connection batching
- load task categories from label store instead of hardcoded empty array
- suppress NIOSSLHandler Sendable warnings via Package.swift unsafeFlags
- fix unused variable warnings across codebase

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 23:13:46 +01:00
3b82e6cd95 fix IMAPIdleHandler thread safety: pass idleTag via init, clean up event loop group on reconnect 2026-03-14 14:20:53 +01:00
004d1ad027 remove inline body fetch from fetchEnvelopes, bodies now come from MIME-aware prefetchBodies
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:41:33 +01:00
1cbe09c443 add IMAPIdleClient actor with IDLE loop, reconnect backoff, re-IDLE timer
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:38:39 +01:00
3ea88f6402 add IMAPIdleHandler: NIO channel handler for IDLE event streaming
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:37:16 +01:00
968dd91f80 add fetchFullMessage, fetchSection to IMAPClient for MIME attachment retrieval 2026-03-14 13:31:38 +01:00
427f197bb3 add IMAP write operations, special folder role detection
Extend IMAPClientProtocol with storeFlags, moveMessage, copyMessage,
expunge, appendMessage, capabilities methods. Implement all six in
IMAPClient actor using NIOIMAPCore typed commands. Add multi-part
command support to IMAPConnection/IMAPCommandRunner for APPEND.
MockIMAPClient tracks all write calls for testing. SyncCoordinator
detects mailbox roles from LIST attributes with name-based fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 05:13:39 +01:00
21227b3c78 add real IMAPClient actor with NIO connection, command pipeline, envelope parsing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 21:12:39 +01:00
ec820b2785 add nio connection layer: tls bootstrap, response handler, command runner
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 21:05:44 +01:00
ce5c985272 add imap client protocol, types, mock for testing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:27:20 +01:00
9c3d02ae45 scaffold MagnumOpusCore swift package with four modules
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 18:05:02 +01:00