Exporting/archiving email from Mail.app #

Michael Tsai has hosted a long-running discussion on data loss in Mail.app starting in Catalina and continuing unabated through Big Sur and Monterey (I have settled on only moving messages from IMAP servers to local storage via Thunderbird).

Further, Mail's built-in export (and import) methods suffer from various limitations and bugs; the following tests were run under macOS 12.4 and Mail 16.0 (3696.100.31):

1. Mailbox → Export Mailbox...

  1. Creates a single MBOX file containing all messages (actually a slightly nonstandard folder with the mbox file named "mbox" and another file named "table_of_contents").

  2. Pro: Successfully exported all messages.

  3. Con: Attempting to import such MBOX files (containing any significant number of messages) back into Mail generally fails with the following error: Some messages could not be imported. The partially imported mailboxes are located in the mailbox named "Import" in the mailboxes list.

  4. While Mail displayed a count of 4611 messages for the mailbox, 4618 were shown in Claws Mail and Thunderbird after import.

2. Click and drag multiple messages from Mail to Finder

  1. Creates a single EML file per message (converting from Mail's native EMLX format, which stores attachments separately) as opposed to MBOX's monolithic single file format.

  2. Pro: Works on even large numbers of messages (tested on a selection of over 10,000 - see below).

  3. Con: Silently fails to export messages with subject lines 252 characters or longer.

  4. When performed on the aforementioned mailbox (which Mail showed as containing 4611 messages while the exported MBOX file was reported to hold 4618), only 4600 messages were exported. The missing messages all had subject lines over 251 characters in length. This was verified by getting a list of all subjects in the mailbox via AppleScript (which also returned 4618 instead of 4611):

    tell application "Mail" to get the subject of every message of mailbox "foo"
    set subjectList to result
    set AppleScript's text item delimiters to "\n"
    set subject1PerLine to subjectList as string
    get subject1PerLine

    then locating those containing 252 or more characters: grep '.\{252\}' subjects.txt. Sure enough, the difference was exactly 18.

  5. Mail reported 10,663 messages in another mailbox; however, clicking and dragging them to a folder in Finder resulted in 10,672 EML files, indicating once again that Mail has a hard time keeping track of messages.

3. AppleScript

  1. Tom Floeren's 2017 "Export Selected Mail Messages" AppleScript still runs under Monterey, exporting highlighted messages to EML files.

  2. Pro: Truncates subjects/filenames over 180 characters to avoid the con described in 2c.

  3. Con: 31 messages were missing from the export after the script terminated with Script Error: AppleEvent timed out. Happily, this was easily rectified by adding with timeout of 3600 seconds above repeat with i from 1 to count of msgSubjects and end timeout below end repeat; afterwards, all messages exported successfully.

  4. As in 1d and 2d above, 4618 messages were exported from the mailbox which Mail had reported as containing 4611 messages. As a final test, ran this simple AppleScript oneliner to get the number of messages in the mailbox: tell application "Mail" to get the count of messages of mailbox "foo"; the result was 4618.

  5. Updated script:

4. partial-emlx-converter

  1. Open source script that "converts .emlx and .partial.emlx files written by Apple's Mail.app into fully self-contained, 'stand alone' .eml files."

  2. The author, Philipp Katz, relates that "one of my IMAP mailboxes went out of service and I was not able to copy all the messages to a different account with Mail.app, even though all mails and attachments were there (see here for the story). That’s why I created this script."

  3. Pro: Successfully converted all 4618 messages in test mailbox to EML format.

  4. Con: Not native.

/mac | Jun 14, 2022


Subscribe or visit the archives.