This page describes a way to log email using the rule facility of apple's Mail.app . Before doing this I searched for a pre-existing rule, but couldn't find one. So I'm writing down what I did, so others can use it.
The mail rule acts on all incoming mail messages and executes an applescript called Log Mail Headers.scpt. Here is the applescript:
using terms from application "Mail" on perform mail action with messages theMessages for rule theRule tell application "Mail" repeat with eachMessage in theMessages set summary to "From: " & sender of eachMessage set summary to summary & "; Subject: " & subject of eachMessage set summary to summary & "; sent: " & date sent of eachMessage set summary to summary & "; size: " & message size of eachMessage & " bytes" do shell script "/bin/echo " & quoted form of summary & " >> ~/ReceivedMailLogs/log" end repeat end tell end perform mail action with messages end using terms fromTo set this up, go into the applescript editor, open an new window and paste in this script. Name your script Log Mail Headers.scpt and put it in /Library/Scripts/Mail Scripts/Rule Actions/. (You might prefer to put the script in your own ~/Library/Scripts/... folder instead.) Next, create a folder in your home directory called RecievedMailLogs, and create a text file inside this folder called log. Now go into Mail.app and create the new rule. Mine is called Log Headers. For the first blank that selects when the rule is to be invoked, select Messages, of type mail. For the second blank that tells what the rule does, select "run applescript" then browse to the
The script makes log records that look like this:
From: "Nature Publishing Group"; Subject: Help us to better understand authors; sent: Saturday, February 15, 2014 8:25:05 AM; size: 26330 bytes
delete before logging If you are reading your mail on a device not doing the logging, you might read a mail before it has reached the logging machine. If you delete that mail, the logging machine may never see it. Thus that email would not be logged. This is a real defect in this logging scheme. However, if you you set Mail.app to check for mail every five minutes, the number of emails thus unlogged is minimal.