AppleScript - Get information of .eml file
I write an AppleScript to backup all my emails. A lot of emails I have already saved as .eml files on my local hard drive and deleted them from the server. Is there a wa开发者_JAVA百科y to load the .eml files with AppleScript as message to get the date sent, subject etc. of them?
How about something like this :
set fromField to text 7 thru -1 of (do shell script "cat /test.eml | grep From:")
set dateField to text 7 thru -1 of (do shell script "cat test.eml | grep Date:")
set toField to text 5 thru -1 of (do shell script "cat /test.eml | grep To:")
set subjectField to text 10 thru -1 of (do shell script "cat /test.eml | grep Subject:")
The body is a little harder since you need to decide if you only want the emails body or also all the previous emails that are embedded into the body. The following gets the body of my test email.
set temp to do shell script "cat /test.eml"
set text item delimiters to "--"
set temp2 to (text item 3 of temp)
set text item delimiters to "
"
set messageField to paragraphs 6 thru -1 of temp2 as text
Make sure you watch out for the encoding of the file if you use other characters.
精彩评论