Rebuild Mailbox in Mail 2.03

New to scripting and the forum has been a lifesaver, thanks to everyone!!! Wondering how to script specific mailboxes to rebuild. Recently built a Mail Archiver script and it is trying to archive mail in my http (hotmail) acount that has already been deleted. Removed the mail messages (Using finder) and rebuild manually corrects the issue. Need to incorporate the rebuild into my archive script. I archive by month so I have 3 years worth of monthy folders and mail doesn’t allow you to select multiple mailboxes to rebuild. HELP ME PLEASE. Thanks in advance

Jay

Model: Powerbook 15’’
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

The following script should demonstrate how this might be done, jayissrv.

Since I obviously have no idea how your Mail Archiver script works, I’ve kept the approach general - and haven’t attempted to suggest a complete routine. However, I hope this demo will give you some ideas…

Notes:

on idToFileList(idList)
	set tid to text item delimiters
	set text item delimiters to ".emlx" & return
	set fileList to ((idList as string) & ".emlx")'s paragraphs
	set text item delimiters to tid
	fileList
end idToFileList

to deleteFiles from fileList at mBox
	set f to POSIX file (POSIX path of (path to library folder from ¬
		user domain) & "Mail/Mailboxes/" & mBox & ".mbox/Messages/") as alias
	tell application "Finder" to delete (folder f's files whose name is in fileList)
end deleteFiles

to rebuildMailbox for mBox
	tell application "Mail" to activate
	tell application "System Events" to tell menu bar 1 of process "Mail"
		click menu item "Message Viewer" of menu "Window" of menu bar item "Window"
		tell application "Mail" to set selected mailboxes of message viewer 1 to {mailbox mBox}
		click menu item "Rebuild" of menu "Mailbox" of menu bar item "Mailbox"
	end tell
end rebuildMailbox

to updateMailbox for mBox
	tell application "Mail" to tell (mailbox mBox's messages whose deleted status is true) to if (count) > 0 then
		my (deleteFiles from my idToFileList(id) at mBox)
		my (rebuildMailbox for mBox)
	end if
end updateMailbox

updateMailbox for "AppleScript/MacScripter" (* modify as required *)

To test just the rebuilding routine, change the calling statement to: