Skip to content

Instantly share code, notes, and snippets.

@adamphillips
Last active January 22, 2020 17:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamphillips/7e72489000c88624f0921cd2e3557a7e to your computer and use it in GitHub Desktop.
Save adamphillips/7e72489000c88624f0921cd2e3557a7e to your computer and use it in GitHub Desktop.
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