Newbie mail script

I’ve just started looking at Applescript and am getting a bit confused…

My script seems a very simple task. Take the currently selected mail message, get it’s full source, save it in a file.

I’ve nicked bits from the Get Full message source script.

I found the ‘save’ item in the mail dictionary and that would appear to be axactly what I need.

save theFile in thePath as plain text

Where I set up theFile and thepath earlier on in the script. I get no errors but no file either.

Help?

Hi,

The iapps are confusing and you need to experiment, but I don’t think you can use the ‘save’ command to save a message unless maybe it was previously saved. Here’s one that uses the ‘source’ property of a message:

set desk_path to (path to desktop) as string
set file_spec to (desk_path & “New Mail Source”) as file specification

tell application “Mail”
activate
set sel_messages to (selection)
set message_ref to (item 1 of sel_messages)
set mail_source to (source of message_ref) as string
end tell

set ref_num to (open for access file_spec with write permission)
try
set eof_byte to (get eof ref_num)
write (mail_source & return) to ref_num starting at (eof_byte + 1)
close access ref_num
on error
close access ref_num
beep 2
end try
beep 3
tell application “Finder” to activate – just to update the Finder and show the file

I’m running Jaguar.

gl,

Thats great, many thanks…

I’ll have to get a book or two, i think.