I have a requirement to save messages out as rich text when they come in via apple’s mail program.
I see “save” in the mail dictionary, but I can’t seem to get it to work. Does anyone have any clues on how to do this?
here is an edited version of what I’m trying. I am selecting the message from a menu or from a rule, that part works. it’s just the save command that’s killing me…
on processMail(theMsgs)
tell application "Mail"
repeat with aMsg in theMsgs
set myAddy to extract address from x
set myPath to my buildMyPath(subject of aMsg, date sent of aMsg, myAddy)
save aMsg in myPath as rich text
end repeat
end tell
end processMail
on buildMyPath(mySubj, myDate, mySender)
-- this creates the entire file path as a string and returns it as text
-- for example, something like the following line
tell application "Finder" to set myPath to (path to the "docs" from user domain)
set retVal to myPath & "someFolder:" & mySubj & "-" & (myDate as text) as text
return retVal
end buildMyPath
any ideas on what I’m doing incorrectly?
Hi,
your script got some problems:
¢ path to the “docs” from user domain results an alias, so you get three items back from the handler instead of one string.
Better is: path to the “docs” from user domain as Unicode text
¢ If the subject contains any colon like AW: or Re:, the colon will be taken als folder separator, so you should remove the colons
¢ a message cannot be saved directly into a file, you have to compose a text, which contains sender, date, subject and body or what you need.
good catch on the colon thing, thanks!
So what I’m understanding is that I’ll have to build a file in applescript and save that file. There’s no way via the script to invoke the “save as rich text” command in the file menu? That’s a shame, because that command keeps up with the attachments and everything in one rich text file.
Any suggestions on how to embed the attachments in the file I’m creating before I save it?
Hi,
there is no direct way to save messages with attachments as rich text.
But take a look at Andreas Ammann’s mail scripts collection
In his Archive Mail Script the complete RTF-code ist composed “manually”. The source (an Xcode project) is also downloadable from his site
sweet! thanks! I’ll check em out…