For some time with the help of in particular Craig I have been developing a script that will transfer email messages and attachements to folders in my document files. the script is nearly working but something I had left until last has me stumped and that is how to sort the lst of mailboxes that I choose from. At present they come up inthe order they are in mail and as a number of the boxes have sub boxes the entire list is not in order. Would greatly appreciate any help.
The script so far is as follows.
set folder_path to (choose folder with prompt "Select the Destination Folder") --Select Document file to put emails in
set Des_Folder to info for folder_path
set Des_Folder to the name of Des_Folder --Returns tha name of the Folder not the Path
global desk_path1
set desk_path to folder_path as string
set desk_path1 to folder_path
global desk_path
global r2
set r2 to 1
tell application "Mail"
set m_boxes to the name of every mailbox
set this_box to choose from list m_boxes with prompt "Select Source"
if Des_Folder as string ≠this_box as string then --Checks if folders are the same clicking OK accepts the difference or clicking cancel exits the scrip
display dialog (("Target Selected is " & Des_Folder) & return & "Mail box is " & this_box) & return & " is this correct"
end if
repeat with a_mess in (every message in mailbox (item 1 of this_box))
--Built to check if get names of file attachments
set fn to (a_mess's subject) --Gets email Subject line
repeat with attach from 1 to count every mail attachment of a_mess --Cycles through every attachment
try
set fn2 to fn & " " & the name of mail attachment attach of a_mess as string --Adds Attachment Name to email Subject
save mail attachment attach of a_mess in desk_path & fn2 --Saves attachment
end try
end repeat
my MakeTextDoc((a_mess's content), (my TestFixSubject((a_mess's subject))), ((a_mess's date received) as string))
--my MakeWordDoc((a_mess's content), (my TestFixSubject((a_mess's subject))), ((a_mess's date received) as string))
end repeat
--delete every message in mailbox (item 1 of this_box)
end tell
on MakeTextDoc(con, sub, dat)
set file_nm to (desk_path & sub & ".rtf")
tell application "TextEdit"
try
open file_nm
--set OldText to every paragraph in front document as string
close front document
--make new document at front
--set name of window 1 to file_nm
--set text of front document to OldText & return & con
--save front document in file_nm
--display dialog OldText as string
on error
make new document at front
set name of window 1 to file_nm
--set text of front document to con
--save front document in file_nm
end try
close every document
delay 2
end tell
end MakeTextDoc
on MakeWordDoc(con, sub, dat)
set file_nm to (desk_path & sub)
tell application "Microsoft Word"
try --Trys to save file with Subject Name for eMail if file name exists adds text to existing file
set newDoc to open file name file_nm --If file already exists it is opened
insert text " " at end of text object of newDoc --Then adds space to existing file
on error --File name does not exist it creates a file with name of Subject from email
set newDoc to make new document
end try
insert text con at end of text object of newDoc --Adds Message text
insert text " " at end of text object of newDoc --Adds a space
insert text dat at end of text object of newDoc --Adds the date of the message
save as newDoc file name file_nm --Saves Document with file name of the subject in email message
close every document
end tell
delay 5
end MakeWordDoc
-------------------------------------------------
on TestFixSubject(str)
set fixed_string to {}
set bad_char to {":", "/"}
repeat with c from 1 to (count every character in str)
if bad_char contains (character c of str) then
set end of fixed_string to "-"
else
set end of fixed_string to (character c of str)
end if
end repeat
fixed_string as string
end TestFixSubject
Thanks
Peter