Empty Mail.app Outbox

Posted on

Tagged as os x, applescript and computing

Background

Users can extend the func­tion­al­i­ty of Mail.app for OS X by installing software packages called "Mail Bundles". I use three such bundes of joy on a daily basis:

Each of these is essential to my workflow, and not having one of them severely imapcts my pro­duc­tiv­i­ty.

The Problem

One of them is broken, and none of them will admit it. The problem began after applying the OS X 10.9.3 update.

At irregular intervals, Mail.app will stop servicing the Outbox. That is, messages to be sent will be placed into the Outbox folder, and then remain there. I have my suspicions, but I'm not able to trace Mail.app's execution deeply enough to figure out who is rep­son­si­ble. The problem is not related to the system's network location, or the actual mail payload itself (that I can tell). Restarting Mail (usually) doesn't help.

Apple Support is es­sen­tial­ly useless if there is a problem that's not a short between the keyboard and chair. Despite the fact that the problem had never once occurred previously and started literally minutes after updating to OS X 10.9.3, they washed their hands of it after de­ter­min­ing that I could sometimes access my iCloud account. This is completly reasonable since no Apple programmer has ever made a coding error in recorded history.

While annoying, this did provide a clue: If the Mail Bundles are unin­stalled the outbox im­me­di­ate­ly empties when Mail is restarted.

Okay, so the update broke something on which one of the bundles depends! I'll just contact the authors and submit a bug report!

Yeah... Not to easy.

I know it's not GPG Tools, because when that is the only bundle the problem never happens -- it has to be the Clip-O-Tron or Mail Act-On. Both of these are made by great companies, so I submit problems to both of them... and they both es­sen­tial­ly say, "We're happy to help once you prove it's our Bundle."

Thanks, guys. If I had the tools to do that (like your source code), I would have just sent you a patch. How about you at least tell me how to run your junk in debug mode?

Solution

So failing any meaningful help or direction, what's left to do? Script it! Below is an Ap­ple­Script that:

  • Stops Mail.app
  • Moves the Bundles out of the way so Mail.app doesn't load them
  • Empties the Outbox folder
    • Starts Mail.app
    • Waits until the Outbox has no messages
    • Stops Mail.app
  • Moves the Bundles back into place
  • Starts Mail.app

Restart Mail.app Ap­ple­Script

set mailDir to "Macintosh HD:Users:ulmer:Library:Mail" as alias

tell application "Mail"
    quit
end tell

waitForExit("Mail")

tell application "Finder"
    set the name of folder "Bundles" of mailDir to "Bundles.not"
end tell

tell application "Mail"
    activate
    repeat until not (exists messages in mailbox "Outbox")
        delay 1
    end repeat
    quit
end tell

waitForExit("Mail")

tell application "Finder"
    set the name of folder "Bundles.not" of mailDir to "Bundles"
end tell

tell application "Mail"
    activate
end tell


-- Wait until the process named as parameter is not running
on waitForExit(appName)
    tell application "System Events"
        repeat
            if not (exists application process appName) then exit repeat
            delay 1
        end repeat
    end tell
end waitForExit
FairTax OS X TSA acrylamid applescript computing food frugal government hazel js music woodworking