Hey everyone. I’m trying to write a script that will move my listserv messages into a separate Mail.app mailbox and then delete ones that are older than ‘x’ days. I spent 6 hours yesterday trying to write the bloody thing instead of doing real work. It doesn’t really work and it’s really inefficient.
Here it is:
tell application "Mail"
set myList to {}
repeat with oneAccount in (get imap accounts)
set myMailbox to name of mailboxes of oneAccount
set myList to (myList & myMailbox)
end repeat
end tell
set TargetMailbox to {choose from list myList}
set prompt to "How long do you want to keep"
set question to display dialog prompt ¬
buttons {"Days", "Weeks", "Months"} default button 2 ¬
default answer "2"
set dNumber to text returned of question as integer
set dtext to button returned of question
set dtype to words of dtext
if dtext is "days" then set dshift to ((current date) - dNumber * days)
if dtext is "Weeks" then set dshift to ((current date) - dNumber * weeks)
if dtext is "Months" then set dshift to ((current date) - dNumber * months)
tell application "Mail"
repeat with oneAccount in (get imap accounts)
repeat with oneMailbox in mailboxes of oneAccount
if name of oneMailbox is TargetMailbox then
set theMessages to messages of oneMailbox
repeat with theEmail in theMessages
if date received of theEmail is less than dshift then
set background color of theEmail to green
delete theEmail
end if
end repeat
end if
end repeat
end repeat
end tell
I know it’s terrible, but the more I tried to tinker with it the more it broke and I had the damnedest time trying to select all messages from a specific folder/mailbox that’s not the Inbox, Outbox, Junk, or Trash.
On a side note, I’d like to know how to turn the text of a variable into inline code so that the text returned could represent a class or command or the like.
Oh and I’m working in Leopard.
Help.