Created
April 14, 2022 00:39
-
-
Save jmdelafe/1e3df86d04817107cf95fd99bc5b0346 to your computer and use it in GitHub Desktop.
Script to sort mails in my Exchange account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if application "Microsoft Outlook" is running then | |
tell application "Microsoft Outlook" | |
set caseMessages to messages in mail folder "Cases" | |
repeat with theMessage in caseMessages | |
set msgSubject to subject of theMessage as Unicode text | |
if (msgSubject contains "Support Survey") then | |
set theContent to content of theMessage | |
set theLines to paragraphs of theContent | |
repeat with aLine in theLines | |
set isMatch to do shell script "echo " & quoted form of aLine & " | grep -E '^[0-9]{8}$' > /dev/null; printf $?" | |
if isMatch = "0" then | |
set caseNumber to aLine | |
end if | |
end repeat | |
else | |
set caseNumber to do shell script "echo " & quoted form of msgSubject & " | sed s/[a-zA-Z[:punct:]\\]//g | awk '{ print $1 }'" | |
end if | |
set msgFolder to (every mail folder whose name contains caseNumber) | |
if (msgFolder is {}) then | |
set msgFolder to make new mail folder at mail folder "Cases" with properties {name:caseNumber} | |
end if | |
move theMessage to msgFolder | |
end repeat | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment