Mail.app scripting is very unreliable....
Mail.app scripting is very unreliable....
- Subject: Mail.app scripting is very unreliable....
- From: Robert Nicholson <email@hidden>
- Date: Sun, 17 Dec 2006 22:50:36 -0600
It seems that mail locks up frequently when you attempt to do
anything with stored mail.
in the script below mail works for a while but eventually it will
lock up during a move operation
this is quite disappointing as it makes processing email very difficult
this script goes thru mailboxes in order to locate duplicate messages
and move them to a duplicates folder. There's just something about
Mail and it's management of threads etc that causes it to frequently
lock up when shift mail around. I've noticed this on occasion when
just doing things manually but it seems to be the case also with the
scripting too.
If anybody's got any hints as to what can cause Mail to hang
eventually in the "move" step I'm all ears.
tell application "Mail"
--set everyAccount to every account
--set everyMailbox to every mailbox of everyAccount
set everyMailbox to every mailbox
set filter to "Archive/lists/mac/apple/xcode-users/2005"
repeat with eachMailbox in everyMailbox
set msg_ids to {}
set theContainer to container of eachMailbox
set mailBoxName to name of eachMailbox
set theContainerPath to my containerPath(eachMailbox) & "/" &
mailBoxName
if theContainerPath contains filter then
if mailBoxName does not end with "_duplicates" then
set theContainerPath to my containerPath(eachMailbox) & "/" &
mailBoxName
set msgs to every message of eachMailbox
repeat with eachMessage in msgs
set mid to (message id of eachMessage)
if (mid is not "") then
set k to mid & "/" & (date sent of eachMessage)
else
set k to (sender of eachMessage) & "/" & (subject of
eachMessage) & "/" & (date sent of eachMessage)
end if
if msg_ids contains k then
-- create mailbox to hold duplicates
if not (exists mailbox (theContainerPath & "_duplicates")) then
make new mailbox with properties {name:(theContainerPath &
"_duplicates")}
end if
beep
set dupe to (theContainerPath & "_duplicates")
with timeout of 900 seconds
move eachMessage to mailbox dupe
end timeout
else
copy k to end of msg_ids
end if
end repeat
end if
end if
end repeat
end tell
on containerPath(mb)
tell application "Mail"
set retVal to ""
repeat
try
set retVal to (name of container of mb) & "/" & retVal
set mb to container of mb
on error
try
return text 1 thru -2 of retVal
on error
return ""
end try
end try
end repeat
end tell
end containerPath
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden