This script saves the raw source of an email from Mail.app:
set tmpPath to (path to home folder) as string
tell application "Mail"
set theSel to selection
set theMsg to (item 1 of theSel)
set theSource to source of theMsg
set rawF to (open for access file (tmpPath & "foo.txt") with write permission)
set eof rawF to 0 --empty anything previously in the file
write theSource as string to rawF
close access rawF
end tell
The problem is, the file is different from the one you would get if you choose “File|save as” in Mail.app and choose to save the raw message source in the options of Save dialog.
(especially emails with non-western encodings)
What should I do to get the absolute RAW source saved as a file using AppleScript? Thanks!