Mail.app

Mail.app is Apple's built-in Mac OS X e-mail client, which defies all attempts (both good or bad) at classification. One of its worst shortcomings (of which there are many) is its inability to deal with plain UNIX mailbox formats directly via the filesystem (it will import and export them, but not use them natively).

Fiddling With The SQLite Envelope Index

This little AppleScript automates the process of compacting one of the internal index tables (the envelope index) that usually ends up full of crud:

tell application “Mail” to quit
set sizeBefore to do shell script “ls -lah ~/Library/Mail | grep -E ‘Envelope Index$’ | awk {’print $5′}”
do shell script “/usr/bin/sqlite3 ‘Envelope Index’ vacuum”
set sizeAfter to do shell script “ls -lah ~/Library/Mail | grep -E ‘Envelope Index$’ | awk {’print $5′}”
display dialog (”Mail index before: ” & sizeBefore & return & “Mail index after: ” & sizeAfter & return & return & “Enjoy the new speed!”)
tell application “Mail” to activate

Mailbox Format Notes

These were valid for pre-Leopard versions - they might not be valid still.

.emlx flags field (via jwz):

0    read                      1 << 0
 1    deleted                   1 << 1
 2    answered                  1 << 2
 3    encrypted                 1 << 3
 4    flagged                   1 << 4
 5    recent                    1 << 5
 6    draft                     1 << 6
 7    initial (no longer used)  1 << 7
 8    forwarded                 1 << 8
 9    redirected                1 << 9
10-15 attachment count         3F << 10 (6 bits)
16-22 priority level           7F << 16 (7 bits)
23    signed                    1 << 23
24    is junk                   1 << 24
25    is not junk               1 << 25
26-28 font size delta           7 << 26 (3 bits)
29    junk mail level recorded  1 << 29
30    highlight text in toc     1 << 30
31    (unused)

Bugs:

  • Mail.app 2.0.5 loses messages if your default SMTP server is unavailable and you reflexively click OK when prompted to accept the next alternative SMTP server without waiting for the message to be re-rendered. This causes Mail.app to send an empty message and lose your original e-mail (filed as #4460682 on 2005-02-28).
  • Mail.app 2.0 will not display meeting requests, cancellations or read receipts when used against an Exchange server (which means they will simply pile up in your account, and that Mail.app is totally useless for backing up/archiving Exchange mail via IMAP because it won't archive those - it won't even list them). To be filed on Radar when I understand this better.
  • Mail.app 2.1 does not seem to be able to use SOCKS for SMTP (or gets thoroughly confused by it when you have multiple SMTP servers defined). Filed as #4678812 on 2006-08-13, marked as a "known issue" on 2006-08-30.

IMAP and AppleScript Support

There seems to be some odd change in Leopard where a script such as:

tell application "Mail"
    set theMessages to (every message in mailbox "INBOX" of account "News" whose read status = true and flagged status = false and deleted status = false)
    try
      tell application "Mail"
        delete theMessages
      end tell
    end try
  end tell

...no longer seems to truly delete the messages. They vanish from the message list, but return afterwards upon the next folder refresh. A workaround could be:

tell application "Mail"
    set theMessages to (every message in mailbox "INBOX" of account "News" whose read status = true and flagged status = false and deleted status = false)
    try
      tell application "Mail"
        move theMessages to mailbox "Deleted Messages" of account "News"
      end tell
    end try
  end tell

...which produces the desired effect.


See Also

Microsoft Exchange ServerThe Switcher's Application GuideHow to Switch to the Macvim keybindings for Lion Mail.app
Making your mail sit up and begJavaScriptSnow LeopardOpening and Converting Corrupted PDF Files
Outlook lock-in could vanish with new open source projectsRelatedMailIMAP Backup ScriptMy Snow Leopard experience so far
Microsoft's Outlook Opens Up To an Uncertain FutureAppleScriptMail Archiving Service for Snow LeopardOnlife
LeopardXUL Extensions and Add-OnsEntouragePostbox on WINE
Random Rant On E-Mail SlashingPretty Good PrivacyBackup ToolsOn Apple, Netbooks, and My Line of Work
Gmail Advanced IMAP ControlsSMTPImmobile dot Where?Regarding AppleScript on Mail.app and RSS Items
Dovecot patch for Mail.app IMAP Stupidity.Mac Doesn't Trust YouPatching .emlx filesEntourage 2008 Review
An update on my RSS setupNew Year CrashesDear Google Mail DevelopersAnxiety
The Utter Asinine Stupidity Of Mail.app's Sudden Bouts Of Password AmnesiaMac OS X Leopard: A perfect 10A Month Of Seeing SpotsWideMail
So, this is a better Mail.app?Mail.appWidescreenMailPluginSettling In
Hear The Leopard Spots RoarLetterbox for Leopard - it's comingRadar Bugs I'd Like To SeeMy Five Wishes for Leopard
A Bank That "Gets" OnlinePost-Keynote NotesPalmWiki Editing, Mind Maps and Usenet
GTDZero Sum GameThe New Portuguese ID Card - and MacsRe-surfaced
The IMAP ProtocolThe iPhone, At Long LastThe StealthBookLook Ma, No Mice
Random RemaindersTaming my RSS feeds, the Bayesian wayTNEFTim Gaden
DimmedNews Flush.Mac - And Round And Round We Go...MailArchive.py
IMAP to mbox Backup ScriptOdds and EndsThe Little Python IMAP Archiver That Couldn'tAll Hail Michael Rothwell
Bullets in Mail.app without Shooting It?Interesting TimesRe-Plumbing MailA Spotty Take On Leopard's Features
BacklogBuzzing BackPreparing for LaunchLeisurely Linkage
Casual DebunkingMac OS XMonday, Oddly Enough.Mac's Missed Opportunities
LetterboxDetoxTopicalYojimbo on the Cheap
Apple Jam RecipesFive Drops Of Orange JuiceEmailchemyTriple Six
On Mark's un-Switching, and LemmingsThree Panes - The Right Way, At Last!Random UpdatesHaving a Cow of a Week
Minor EarthquakesMailTagsLink ModeSide-Switching
AppleUNIXFun in PerspexKinky GTD
BoostedMore Mail.app GripesHousekeepingFinally, a Reason to Look at Vista
Minor Photography UpdateMacBooks and Other Happenings - The Sequel10.4.4 First ImpressionsMacBooks and Other Happenings
Making the Mouse RedundantTen Things I'm Looking Forward To In 200610.4.4, Come On Down!E-Mail GTD-fu
Restlessness10.4.3 Odds and EndsBack To Our Scheduled ProgrammingMiscellaneous Geekery
Post-10.4.3One Day To GoBackup 3.0Re-Thinking my Backup Strategy
Hyperlinked PDF Generation?And I Wanted a Quiet Vacation...More Mail.app/Exchange OdditiesOh Come On, Apple, THIS IS JUST STUPID!
And Now, The Real News: iPod nanoBack to WorkSOCKSTake Two
Is Mac OS X Becoming Crufty?More BacklogFive Random Annoying Things That I've Had To Put Up With This WeekReal News
Ah, Monday, How I Loathe Thee...A Few Other Tiger NotesMail.app 0.2Ruby Shower Epiphanies
Stripe ThreeNeeding a ChangeMonday ModeLap Tiger
Taming TigerThe Pint-Sized TigerTiger TeasersOuch...
Catching UpWhat if Mail.app were like iTunes?The Bayesian Thing, AgainThings That Go Dump In The Night
Minimal News UpdateThree Little Mac AnnoyancesSlight OverloadBirds Of A Feather
Intensive RestingThat Bird, by Thunder!Odd Happenings of an Otherwise Unremarkable MondayLittle Gripes
Getting Things DoneProgress Along a Lopsided RoadThe Widest Desktop On EarthGeeking Out
Inbox LintBit TwiddlingGarfield ModeMail.appetizer
Neat IdeasThe Top Five Mac OS X Applications I Can't Live WithoutRSS and Mail, RevisitedThe Quest, Revisited
Pulp FictionThe Mail ThingThe Mouse, Done RightNothing To Report
MailPrioritySlew of Apple UpdatesSqueeze That BoxPanther in the Office
Panther First ImpressionsPanther MadnessBigger, Faster, StrongerPalm Launches
Lost In a Sea of Coasters, Found In a Bunch Of EnvelopesVertical Preview Pane in NetNewsWire... And in Mail.appBayesian WhatsitsPackaging
MailPicturesThe SSL Way, and Why Mozilla Needs a PushThink DifferentSwitching back to Windows
Series 60 TriviaJaguar