import Raw Source messages from Mail

I hope to crete a script which allows me to export selected messages to separate text UTF8 files after Performing a search

It should be a a loop telling the script to

1-Crete/Select a destination folder

2-open the first selected message in the Apple Mail found messages browser window

3-Rename the mesge with subject and timestamp

4-Save it in the folder of choice as RAW Source ( ⌥⌘U) in the Apple mail View-> Message-> Raw source combination

5-Repeat with next till last message as resulting from the Selection window?



I need the RAW source format for variety of reasons not for its readablity.

Tahnks everyone who might help


I USE SNOW LEOPARD and my Keybord is terrible

Mac Pro, Mac OS X (10.6.8)

Posted on Jun 11, 2013 12:30 PM

Reply
2 replies

Jun 11, 2013 2:00 PM in response to etnad

This is what I did but id doesnt save anything .... what am I doing wrong? ( I am not very good ....)


set theOutputFolder to POSIX path of (choose folder)

tell application "Mail"

set theSelection to selection

set theMessage to item 1 of theSelection

repeat with a from 1 to length of theSelection

set MessagS to source of theMessage

set MessagID to id of theMessage

set Mess toMessagID & MessagS


try

set theSavePath to theOutputFolder



saveMessintheSavePath

end try


end repeat


end tell

Jun 11, 2013 7:48 PM in response to etnad

You won't be able to see what the error is if you enclose things in a plain try statement. Mail (at least the current versions) wants to use rich text, so instead of the standard write you can use open for access to specify the desired output type, for example:


globaloutputFolder-- this will be the destination folder for the text files

setoutputFolderto (choose folder) astext


tellapplication"Mail"-- write raw source of selected items to text files


repeatwithaMessagein (getselection)

setmessageSubjecttosubjectofaMessage

setmessageSourcetosourceofaMessage

setmessageIDto"" & idofaMessage-- coerce number to text

settheOutputtomessageID & return & messageSource

mywriteText_withFileName_(theOutput, messageSubject)


endrepeat

endtell



towriteText_withFileName_(theText, theName)


settheNametoreplaceText_inString_withText_(":", theName, space) -- replace illegal character

tell (current date) as «class isot» as string to set theDate to text 1 thru 10 -- yyyy-MM-dd


settheOutputFileto (outputFolder & theDate & " - " & theName) astext


try-- write to text file

settheFiletoopen for accesstheOutputFilewithwrite permission

writetheTexttotheFileas «classutf8»

close accesstheFile


onerrorerrmess-- just log it and try to make sure the file is closed

logerrmess

try

close accesstheFile

endtry


endtry

endwriteText_withFileName_



toreplaceText_inString_withText_(oldItem, someText, newItem)


set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}


try

set {itemList, AppleScript's text item delimiters} to {text itemsofsomeText, newItem}

set {someText, AppleScript's text item delimiters} to {itemListastext, tempTID}


onerrorerrorMessagenumbererrorNumber-- oops

setAppleScript's text item delimiterstotempTID

errorerrorMessagenumbererrorNumber-- pass it on


endtry


returnsomeText

endreplaceText_inString_withText_

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

import Raw Source messages from Mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.