Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Extracting email headers from Apple Mail

Hello friends...


I have hundreds of email received / sent to various people whose accounts are in the same email server, for example @xyz.gov.in

( sony@xyz.gov.in , tony@xyz.gov.in etc.)


I need to search and extract the following header information from all email sent to / received from email server, for example, @xyz.gov.in, in the following format:


From:

To:

Cc:

Bcc:

Date & Time:

Subject:


Is there any script that can do this for me and create a text or .csv or any other file?


All messages are stored in Apple mail, imap, pop and offline folders.


My OS: Mac OS 10.8.3

Apple Mail Version: 6.3


many thanks in advance


Amit

MacBook Pro (15-inch 2.4/2.2 GHz), OS X Mountain Lion (10.8.3)

Posted on Apr 28, 2013 6:58 AM

Reply
39 replies

Apr 30, 2013 9:09 PM in response to twtwtw

Dear TwTwTw,


Thanks for the taking the pain to redo the script. It is running and I am waiting for the results.


It beeps intermittently. Does that mean anything?


Also, the smart mailbox filter criteria does not apply to Bcc field it seems, and therefore messages that have been Bcc to @sebi.gov.in do not show up in Smart Mailbox. Is there any work around?


Thanks so much for being so patient with me.


best


Amit

Apr 30, 2013 11:00 PM in response to twtwtw

Unfortunately, yes, a lot of times..., in order to keep officials at this organisation in loop.


Unfortunately, now this organisation has turned hostile against its mandate (or say that some of its officials are allegedly corrupt and have concealed / destroyed my emails), and therefore the exercise in larger public interest. I basically have to tell a commission what these people have been concealing.


Anyhow, as a work around, I have added a criteria in the Smart Mail Box, "Entire message that ends with @sebi.gov.in". Now the Bcc mails are showing, but even those without "@sebi.gov.in"


Crazy Apple Mail searches in versions beyond OS 10.6...


I ran the script on a few messages, and it works awesomely.


BUT, if I was to apply rule "Entire message that ends with @sebi.gov.in", for the smart mailbox, every to, cc, bcc, email addresses would have to show seperatey in different fields in the final output, for the purpose of filtering them in MS Excel.


Something like, to 1 = to field 1, to 2 = to field 2 and so on...

Apr 30, 2013 11:23 PM in response to auromira

one more (somewhat esoteric) thing to try. copy the following line into the search field and hit return:


bcc recipient:@sebi.gov.in OR to recipient:@sebi.gov.in OR cc recipient:@sebi.gov.in OR sender:@sebi.gov.in


or alternately, construct your smart mailbox like so (same difference):


User uploaded file


this format (keyword:searchterm) tokenizes the search criteria, and may get more focused results. You can use the same script to extract the info from the front window.


I'm not sure what your last bolded paragraph means exactly, and I think it may not apply to what I just suggested, so I'll wait on that.

May 1, 2013 1:13 AM in response to twtwtw

Dear twtwtw,


Both the suggested search methods reduce the number of messages and give an inaccurate search result. Something weird with Apple Mail version in OS 10.7 & above. I am on OS 10.8.3, Apple Mail v6.3. Quite possibly, the transfer of mail upon up-gradation did something wrong and the index is bad. No idea.


Anyhow... I will explain the bold part from my last message in the given situation.


If, I was to apply rule "Entire message that ends with @sebi.gov.in", for the smart mailbox, every to, cc, bcc, email addresses would have to show separately in different fields in the final output, for the purpose of filtering them in MS Excel.


Explanation:


Now we are looking at an output that would have some messages that has no "@sebi.gov.in", recipient or sender.


Therefore, in order to filter out the output in MS Excel, every email address would have to be in a separate field.


For example, header output a message sent "to: 5 email address, cc to: 10 email addresses, and bcc to: 20 email addresses, would have be in the following output format:


to: 1 = output field to: 1

to: 2 = output field to: 2

to: 3 = output field to: 3


and so on


similarly


cc: 1 = output field cc: 1

cc: 2 = output field cc: 2

cc: 3 = output field cc: 3


and so on...


Sorry, this is getting more messy that it sounded earlier. Maybe apple needs to be told to look into inaccurate searches in apple mail. Up to 10.6 was so much accurate


May 1, 2013 2:38 PM in response to auromira

Well, I figured out why Mail is having trouble with bcc:. apparently mail immediately forgets bcc entries (probably as a security measure); the only place to find them is by digging through the 'received' header in the sent email for the 'for' keyword.


So, there's only two more approaches I can recommend here. First the easy one: do it in two waves. first wave gets the to:, cc:, and sender:, fields using the script as above. second wave starts by modifying the Mail rules do a little tricky modification in the Rules preference pane. create a new rule, and from the first popup choose the Edit Header List... option at the very bottom. in the panel that pops up add the word Received on a new line, and close the panel. now you'll have a new option in the popup which searches the Received header. select it, add the sebi phrase, and flag the result with a color you're not using. looks like this:

User uploaded file

Now, run that rule on your SENT mailboxes, open the Flagged mailbox of the correct color, then run the script on that window (as above). Make sure you change the name of the file first, or you'll overwrite the other data. you can merge them after.


Yes, that was the easy way.


The hardcore approach is to forget about using Mail.app. Download TextWrangler and open the app. go to ~/Library/Mail/ and drag the top-level folder (should be V2) to the textwrangler icon in the dock. This will open a disk browser in TW. Once that's done, click Ok on the 'Abandon All Hope Ye Who Enter Here' alert if it pops up, then run an appropriate regular expressions search on all the emlx files in the folder. emlx files are standardized xml files, so an appropriate regular expression does exist. However, figuring it out may result in premature balding.

May 2, 2013 2:27 AM in response to twtwtw

Dear twtwtw,



The rule for the sent mailboxes as you described does not work for some reason. These are gmail imap sent mailboxes...



In fact, after running the rule on sent mailboxes, the number of messages in the Smart Mailbox reduced by 5. Hope something did not disappear. Gmail imap folders are known for disappearance of messages...


With time running out, I think the only way left now is to run the script on individual mailboxes, with the search phrase "@sebi.gov.in". If you can separate the time and date fields in the output, alongwith other fields, it would help in filtering duplicates at a later stage.



best


Amit

Extracting email headers from Apple Mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.