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):
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").
Pro: Successfully exported all messages.
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.
While Mail displayed a count of 4611 messages for the mailbox, 4618 were shown in Claws Mail and Thunderbird after import.
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.
Pro: Works on even large numbers of messages (tested on a selection of over 10,000 - see below).
Con: Silently fails to export messages with subject lines 252 characters or longer.
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.
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.
Tom Floeren's 2017 "Export Selected Mail Messages" AppleScript still runs under Monterey, exporting highlighted messages to EML files.
Pro: Truncates subjects/filenames over 180 characters to avoid the con described in 2c.
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. (UPDATE: See Michael Tsai's post for another potential issue affecting non-ASCII characters under some circumstances.)
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.
Open source script that "converts .emlx and .partial.emlx files written by Apple's Mail.app into fully self-contained, 'stand alone' .eml files."
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."
Pro: Successfully converted all 4618 messages in test mailbox to EML format.
Con: Not native.
Mail Exporter Pro, mentioned back in 2017, offers fast, robust exporting to a number of destination formats, including Entourage/Outlook, PST, Apple Mail Mailbox (Archive), Thunderbird/Postbox, MBOX, and EML.
Import EML files into Mail.app (tested in version 16 under macOS 14 Sonoma):
/mac | Jun 14, 2022