Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to move/delete old Entourage emails Apps
I have Entourage set up with multiple folders for the various people I receive email from. There are some people for whom I want to keep their emails for a certain number of days before I delete them, while others I don't care about keeping. So, I wrote the following AppleScript which looks through my folders (excluding some) and finds emails older than 60 days. The script then moves those emails to Deleted Items.
tell application "Microsoft Entourage"
  repeat with theFolder in every folder
    set theCurrentFolder to theFolder
    set folderName to the name of theCurrentFolder
    if folderName is not equal to "Keep" and folderName 
    is not equal to "Deleted Items" and folderName is not equal to 
    "Archive" and folderName is not equal to "Sent Items" then
      display dialog "Processing folder " & folderName
      repeat with theMessage in every message in the folder folderName
        set theCurrentMessage to theMessage
        try
          set theDate to time received of theMessage
          set difference to ((current date) - theDate) div days
          if difference is greater than 60 then
            move theMessage to folder "Deleted Items"
          end if
        end try
      end repeat
    end if
  end repeat
  display dialog "Done!"
end tell
The lines in the script you'd want to modify are:
  • if folderName is not equal to "Keep" and folderName is not equal to "Deleted Items" and folderName is not equal to "Archive" and folderName is not equal to "Sent Items" then
    This line controls which folders not to check. There's probably a better way of writing this line, but, being new to AppleScript, I'm not sure what it would be.

  • if difference is greater than 60 then
      move theMessage to folder "Deleted Items"
    end if

    This line controls the age of the email and where to move it.
You may also want to delete display dialog "Processing folder " & folderName. I have that in there so I know which folder is currently being processed.
    •    
  • Currently 1.33 / 5
  You rated: 1 / 5 (3 votes cast)
 
[11,047 views]  

An AppleScript to move/delete old Entourage emails | 4 comments | Create New Account
Click here to return to the 'An AppleScript to move/delete old Entourage emails' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to move/delete old Entourage emails
Authored by: fresler on Aug 19, '04 11:35:23AM

I discovered how to write the line that excludes folders in a better way. The better was is:
[code]if folderName is not in {"Keep", "Deleted Items", "Archive", "Sent Items"} then[/code]



[ Reply to This | # ]
An AppleScript to move/delete old Entourage emails
Authored by: lukec on Aug 19, '04 11:58:53AM

The problem with this is that it only goes 2 folders deep. Many of us have folder that go 5 levels deep or more. You need some proper recursion in here, my friend. A good start. I'm sure someone will eventually pipe up with some real code, but here's what it looks like.

<code>
on process_folder(myfolder)
repeat with my folder in every folder
process_folder(myfolder)
end repeat
--do process folder stuff here like copying messages
--checking date and folder names
end process_folder

on run
repeat with myfolder in every folder
process_folder(myfolder)
end repeat
end run
</code>

This is just intended as a starting point.

Luke



[ Reply to This | # ]
An AppleScript to move/delete old Entourage emails
Authored by: PeteVerdon on Aug 19, '04 02:14:25PM

Deleting your (non-spam) email? What an odd idea.

Pete



[ Reply to This | # ]
An AppleScript to move/delete old Entourage emails
Authored by: exHintsUser1 on Aug 20, '04 09:35:30PM

I hate to be the one to tell you that you made this script for nothing :-) But, well, you did. All one needs to do in E-Rage X or 2004 is go to Tools-> Run Schedule-> Schedules->New

Give it a name
Tell it to run once every x times
Add as many actions as you want to "Delete Mail" From "Folder" older than X days



[ Reply to This | # ]