Auto-resolve Apple Mail V10 accounts via Accounts4.sqlite#172
Auto-resolve Apple Mail V10 accounts via Accounts4.sqlite#172schlabrendorff wants to merge 2 commits intowesm:mainfrom
Conversation
…ectories Apple Mail V10 stores large mailboxes by splitting .emlx files across numeric partition subdirectories (0-9) nested under Data/ at arbitrary depths (e.g., Data/0/3/Messages/123.emlx). Previously, only the top-level Data/Messages/ directory was scanned, missing the majority of messages in partitioned mailboxes. Changes: - Add FileIndex map to Mailbox struct for resolving partition file paths - Add FilePath() method for transparent path resolution - Add recursive partition discovery (hasEmlxFilesInPartitions, collectPartitionFiles) with isDigitDir/isEmlxFile helpers - Handle partition-only layouts where Data/Messages/ doesn't exist - Use FilePath() in emlx importer instead of direct path join Before: 12 mailboxes, 31k files (top-level Messages/ only) After: 52 mailboxes, 39k files (all partition depths) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add auto-discovery of Apple Mail accounts by reading the GUID-to-email mapping from ~/Library/Accounts/Accounts4.sqlite. The import-emlx command now accepts optional [mail-dir] (defaults to ~/Library/Mail) and discovers accounts automatically, eliminating the need to manually specify email identifiers for V10 directory GUIDs. New flags: --accounts-db, --account (filter), --identifier (manual fallback). New package: internal/applemail with ResolveAccounts and DiscoverV10Accounts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
roborev: Combined Review (
|
Builds upon PR #166
Motivation
The previous
import-emlxcommand required users to manually specify both an email identifier and a mail directory:msgvault import-emlx me@gmail.com ~/Library/Mail/V10/AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEEEspecially for importing V10 folder (#157) this is suboptimal.
This was painful for several reasons:
AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE). There's no obvious way to know which GUID belongs to which email account without digging into Apple's internal databases.Apple already maintains this mapping in
~/Library/Accounts/Accounts4.sqlite. By reading it, we can auto-discover all accounts and import them in one shot.Summary
internal/applemailpackage that reads~/Library/Accounts/Accounts4.sqliteto map V10 directory GUIDs to email addresses, resolving child→parent account relationships (IMAP, Exchange, "On My Mac")import-emlxcommand fromimport-emlx <email> <mail-dir>toimport-emlx [mail-dir]with auto-discovery — users no longer need to manually figure out which GUID maps to which email--accounts-db,--account(repeatable filter), and--identifier(manual fallback) flagsemlx.IsUUID()for reuse across packagesNew UX
Before — one account at a time, manual GUID mapping:
After — all accounts in one command:
Example output from auto-discovery:
How it works
mail-dirforV*/directories containing UUID subdirectoriesAccounts4.sqliteread-only and resolves each GUID usingCOALESCE(child.ZUSERNAME, parent.ZUSERNAME)to handle IMAP child accounts that inherit email from their parent