Dealing with the iCloud Junk Mailbox

Dealing with the iCloud Junk Mailbox

One of iCloud’s annoying features is its server-side spam filtering. Besides the utterly opaque side of the filtering, where it may simply refuse to deliver a message to a recipient based on the content, there’s the side that delivers other messages it judges to be spam to your Junk mailbox.

Mind you, this is different than Mail’s client-side filtering. What makes this annoying is that it happens whether or not Mail’s filtering is enabled and—unlike with Mail—there’s no way to tell iCloud that false positives are not spam.

I can’t do anything about the messages that iCloud doesn’t deliver at all, but those messages in the Junk mailbox—which get deleted after thirty days if I forget about them—are dealt with easily enough.

on run
    tell application "Mail"
        if mailbox "Junk" of account "iCloud" exists then
            if (count of messages of mailbox "Junk" of account "iCloud") > 0 then
                set flagged status of every message of mailbox "Junk" of account "iCloud" to true
                move every message of mailbox "Junk" of account "iCloud" to mailbox "INBOX" of account "iCloud"
            end if
            delete mailbox "Junk" of account "iCloud"
        end if
    end tell
end run

Quite simply, this AppleScript moves any messages it finds in the Junk mailbox (if it exists) into the iCloud Inbox, flagging them to get my attention, then deletes the Junk mailbox. Although the Junk mailbox will be recreated when iCloud finds more spam, until then my mailbox hierarchy is kept clean.

Ideally, I’d have SpamSieve check these messages before moving them, but I’ll save that exercise for another day.