Save a message like dragging from Mail (Leopard).

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

create a normal text file, not a file like above.

TIA

Kasketto

Hi,

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

Hi Stefan,
thanks for your trick that works fine!

Now we have another small problem:

if we try to substitute the local path

set theFile to “Macintosh HD:Msg:M39461038.eml”

with a network path, a lot of problems rise…

We got an exception such as:

“Mail has encountered an error: the document is not opened with write permission”

Any ideas ?

k.

I guess, you haven’t write permission in the destination folder,
maybe it works, that you create the file locally and move it to the server volume