How can I access emails in Apple Mail programmatically?

Solution 1:

One can do this. The following shows what I've found...

Individual Apple Mail emails reside in a directory, typically something like the following:

/Users/UserName/Library/Mail/[email protected]@pop.secureserver.net/INBOX.mbox/Messages

as ".emix" files readable by any text editor.

".emix" files have a sequential numbering by mails received by one's Apple Mail itself rather than the particular mailbox, something like:

18373.emix
18376.emix
18378.emix

The ".emix" files have clearly marked identifiers of their content. An abridged ".emix" file follows::

Received: (somemailprovider ...); 16 Jul 2012 00:04:00 -0000
Received: from unknown ...; 16 Jul 2012 00:04:00 -0000
X-IronPort-Anti-Spam-Result: AuEPABVXA1DR...
Received: from ....isp.com ...; 15 Jul 2012 17:03:59 -0700
Received: by qcsg1 ...; Sun, 15 Jul 2012 17:03:59 -0700 (PDT)

DKIM-Signature: ...
Received: ...; Sun, 15 Jul 2012 17:03:59 -0700 (PDT)

Return-Path: <[email protected]>
Received: from iMac-6.local ....

Date: Sun, 15 Jul 2012 20:03:54 -0400 (EDT)
From: [email protected]
To: [email protected]
Message-ID: <50035a6e.02d0e00a.1fef.....com>
Subject: TEST
MIME-Version: 1.0
Content-Type: multipart/mixed;boundary="----=_Part_0_1792110529.1342397034510"
X-Nonspam: None

------=_Part_0_...
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit 

------=_Part_0_...
Content-Type: image/gif; name=0001.gif
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=0001.gif

So, given all of this one needs to:

  • Identify which email one wants to read (I can use date and a specific email directory) ;
  • Import the text of the email into Mathematica;
  • Parse the required information using the appropriate identifiers in the ".emix" file.

A little cumbersome, but workable.