My application Mail Archiver allows to delete emails from Mail.
I do a simple script to get the headers to fish out the date of the emails.
Von: xxxx<xxx@xxx>
Content-Type: multipart/alternative; boundary="Apple-Mail=_75CA2569-48CA-45BA-BED4-53271AF06DD1"
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
Datum: 11. Juli 2019 um 11:59:07 MESZ
Betreff: xxx
X-Universally-Unique-Identifier: 4EA1B025-D200-4E52-91DC-19EB053B610B
Message-Id: <ADBFD282-BC79-420B-A08A-9A5B4F26C6AE@xxx>
An: xxx
Blindkopie: "xxx" <xxxx>
The script is simple:
property Mailbox0 : "xxx"
property Mailbox1 : "xxx"
property Mailbox2 : "xxx"
property currentMessageListStr : "1"
with timeout of 10000 seconds
set currentMessage to currentMessageListStr as integer
tell application id "com.apple.mail"
return all headers of message currentMessage of mailbox (Mailbox2) of mailbox (Mailbox1) of account (Mailbox0)
end tell
end timeout
The localisation wouldn’t be that bad if the headers contained the received data. So far nobody else has complained about such a problem so I’m really confused how the user managed to get such data. When I test the script I always get the received data.
Of course, I can do a second script to get the received or the sent date.
The user is on macOS Monterey. So how did the user get such data?
I stopped using Mail’s headers long ago due to localization issues (Sierra or before) and then Apple actually broke the command – so I haven’t even looked at them for years…
Typically I grab them raw if I want them:
--------------------------------------------------------
property LF : linefeed
--------------------------------------------------------
tell application "Mail"
set selectedMessageList to selection
if selectedMessageList ≠ {} then
set selectedMessage to item 1 of selectedMessageList
tell selectedMessage
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {LF & LF}}
set msgHeaders to text item 1 of (get its source)
set AppleScript's text item delimiters to oldTIDS
end tell
else
error "Zero messages were selected!"
end if
end tell
return msgHeaders
Does the correct received data show up in the raw source?
Headers have always been localised in Outlook. But never in Mail.
Using the source in Mojave and newer is terribly slow. I’ll dig around in my old code to find the script version that used message id, date sent and date received. I switched to the headers because getting the headers and parsing it was faster than getting specific header fields.