Hey Folks,
I used Eudora for more than 10 years, and I'm used to being able to push a little 'Pencil' button and edit the extraneous junk out of received messages. The fact that I can't do this with Mail.app annoys me greatly.
It is possible to edit received messages in Mail by moving them to the Drafts folder and editing as normal. The rub with this method is that Mail destroys the header content and converts the message to an outgoing message from you (which is not especially acceptable - to me anyway).
I keep many of the posts from the Applescript Users List and others, and I'm really tired of having to store all the bottom quoted junk along with the worthwhile stuff.
So. I finally got ticked enough to tackle the problem, and after experimenting for a while I discovered how to edit messages for Mail with reasonable ease.
If the first line of the message is a number then the message contains meta-data. That number is the byte-offset of the first character of the meta-data, and you may need to change it depending upon how you edit the message - otherwise the meta-data may be partly or wholly displayed in the message. (Both BBEdit and TextWranger have a handy info dialog for text/selected-text which makes it easy to change that number to reflect your edits.)
NOTE: This is a first draft and has only general error-checking.
set userLibFolder to path to library folder from user domain set mailFolder to POSIX path of ("" & userLibFolder & "Mail:")
try tell application "Mail" tell (some message viewer whose index is 1) set sel to item 1 of (get selected messages) end tell tell sel to set msgID to id end tell
set msgID to "" & msgID & "*" set shellCMD to "find " & mailFolder & " -name " & msgID set msgPath to do shell script shellCMD
# Should work in TextWrangler if you don't have BBEdit tell application "BBEdit" open msgPath opening in new_window activate end tell on error errMsg number errNum beep display dialog "Error: " & errMsg & return & "Error Number: " & errNum end try
I tried 'mdfind' while testing, but on my system (to my surprise) 'find' was quite a lot faster.
Mail seems to keep recently viewed messages in memory, so you have to quit/restart it or rebuild the mailbox in order to view your mods to the message [in Mail].
Under some circumstances (which I have yet to figure out) Mail will create a new message with the edits and leave the old one untouched when you rebuild the mailbox.
At the moment I'm only editing copies that I've moved to a mailbox that has nothing else in it for safety in both edit and mailbox-rebuild processes. I think I'll probably write a module to backup the message to be edited just in case I fiubr.
I REALLY wish Apple would allow live-editing of received message in Mail and improve its Applescript dictionary - in particular to allow Applescript to act on the selection; to know if the front window is a message viewer, a received message, or an outgoing message; to create a new message (from scratch, reply, or forward) and be able to change its properties after it's created.
|