Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Outlook Cleanup - Step 2
# Some initial variables
set today to (current date)
set cutoff to 2 * days
set shortCutoff to 3 * hours
tell application "Microsoft Outlook"
set myInbox to folder "Inbox" of default account
set archive to folder "Archive" of default account
set theMessages to messages of inbox
# A couple of counters used for logging changes
set countMoved to 0
set countDeleted to 0
repeat with theMessage in theMessages
try
set messageTime to time received of theMessage
set messageAge to today - messageTime
set theSender to sender of theMessage
set fromAddress to address of theSender
# Start of mail specific rules
# This deletes a CI notification if it is more than 3 hours old or has been read
if fromAddress is "semaphore+notifications@renderedtext.com" then
if messageAge > shortCutoff or (is read) of theMessage is true then
delete theMessage
set countDeleted to countDeleted + 1
end if
end if
# This archives a New Relic alert if it's more than 2 days old
if name of theSender contains "New Relic Alert" then
if messageAge > cutoff then
move theMessage to folder "Notifications" of archive
set countMoved to countMoved + 1
end if
end if
# and so on for every rule
# End of mail specific rules
on error errorMsg
log "Error: " & errorMsg
end try
end repeat
log "Outlook cleanup ran at " & today & " - " & countMoved & " moved, " & countDeleted & " deleted"
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.