Mail - exporting raw message source

I want to export each message in Mail to a file but I need the raw message source which includes attachments.
I tried scripting Mail without any luck.
The following almost works but it doesn’t actually save the file; its like the enter key never gets hit.


tell application "Mail"
	activate
	tell application "System Events"
		keystroke "s" using {command down, shift down}
		keystroke "1.msg"
		keystroke return
	end tell
end tell

Any help would be greatly appreciated.

Hi FP,

try this:

activate application "Mail"
tell application "System Events"
	tell process "Mail"
		keystroke "s" using {command down, shift down}
		keystroke "1.msg"
		click button "Save" of sheet 1 of window 1
	end tell
end tell

Thanks Stefan, unfortunately your solution didn’t work; I kept getting an error.
By dumb luck I got the following code to work:


activate application "Mail"
tell application "System Events"
	tell process "Mail"
		keystroke "s" using {command down, shift down}
		keystroke "1.msg"
		delay 1
	end tell
	keystroke return
end tell

I guess when Mail has the save dialog up it stops responding to apple script but System Events can still press the enter key. Hope this saves someone else a few hours of aggravation.