
Sort emails by year, using AppleScript
tell application “Mail”
— Specify the parent mailbox where the year folders are located
set yearsMailbox to mailbox “Years” of account “iCloud” — Adjust if the path is different
— List of sub-mailboxes under ‘Years’, each named with a four-digit year
set yearFolders to every mailbox of yearsMailbox
— Specify the source folder where emails are currently located
set sourceFolder to mailbox “Recovered” — Replace “SourceFolder” with the name of your folder
repeat with eachMessage in (get messages of sourceFolder)
set messageDate to date received of eachMessage
set messageYear to year of messageDate as string
— Check if a folder for the year exists and move the message
repeat with eachYearFolder in yearFolders
if name of eachYearFolder is messageYear then
move eachMessage to eachYearFolder
exit repeat
end if
end repeat
end repeat
end tell
Please leave comments below.
*** This is a Security Bloggers Network syndicated blog from Joel Esler authored by Joel Esler. Read the original post at: http://blog.joelesler.net/2023/12/sort-emails-by-year-using-applescript.html