I’m trying to write a script to save a Mail message as an eml file, such as an
eml file I obtain dragging a message from within Mail application to the Finder (a new feature of new OS Leopard).
The script:
tell application “Mail”
set theFile to open for access file (“Macintosh HD:Msg:M39461038.eml”) with write permission
set TheMsg to my getMessage(messageid)
set TheSource to source of TheMsg
write TheSource to theFile starting at eof
close access theFile
end tell
if you change a few properties with Systen Events, you got it
set theFile to "Macintosh HD:Msg:M39461038.eml"
set mailApp to path to application "Mail"
set ff to open for access file theFile with write permission
set TheMsg to getMessage(messageid)
tell application "Mail" to set TheSource to source of TheMsg
write TheSource to ff starting at eof
close access ff
tell application "System Events"
tell file theFile
set creator type to missing value
set file type to missing value
set default application to mailApp
end tell
end tell