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

JavaScriptBurn, RSS, Burn!The Switcher's Application GuideHow to Switch to the Mac
IMAP Backup ScriptMountain LionMantra of the dayMicrosoft Exchange Server
vim keybindings for Lion Mail.appMaking your mail sit up and begSnow LeopardOpening and Converting Corrupted PDF Files
Outlook lock-in could vanish with new open source projectsRelatedMailMy Snow Leopard experience so farMicrosoft's Outlook Opens Up To an Uncertain Future
AppleScriptMail Archiving Service for Snow LeopardOnlifeLeopard
XUL Extensions and Add-OnsEntouragePostbox on WINERandom Rant On E-Mail Slashing
Pretty Good PrivacyBackup ToolsOn Apple, Netbooks, and My Line of WorkGmail Advanced IMAP Controls
SMTPImmobile dot Where?Regarding AppleScript on Mail.app and RSS ItemsDovecot patch for Mail.app IMAP Stupidity
.Mac Doesn't Trust YouPatching .emlx filesEntourage 2008 ReviewAn update on my RSS setup
New Year CrashesDear Google Mail DevelopersAnxietyThe Utter Asinine Stupidity Of Mail.app's Sudden Bouts Of Password Amnesia
Mac OS X Leopard: A perfect 10A Month Of Seeing SpotsWideMailSo, this is a better Mail.app?
Mail.appWidescreenMailPluginSettling InHear The Leopard Spots Roar
Letterbox for Leopard - it's comingRadar Bugs I'd Like To SeeMy Five Wishes for LeopardA Bank That "Gets" Online
Post-Keynote NotesPalmWiki Editing, Mind Maps and UsenetGTD
Zero Sum GameThe New Portuguese ID Card - and MacsRe-surfacedThe IMAP Protocol
The iPhone, At Long LastThe StealthBookLook Ma, No MiceRandom Remainders
Taming my RSS feeds, the Bayesian wayTNEFTim GadenDimmed
News Flush.Mac - And Round And Round We Go...MailArchive.pyIMAP to mbox Backup Script
Odds and EndsThe Little Python IMAP Archiver That Couldn'tAll Hail Michael RothwellBullets in Mail.app without Shooting It?
Interesting TimesRe-Plumbing MailA Spotty Take On Leopard's FeaturesBacklog
Buzzing BackPreparing for LaunchLeisurely LinkageCasual Debunking
Mac OS XMonday, Oddly Enough.Mac's Missed OpportunitiesLetterbox
DetoxTopicalYojimbo on the CheapApple Jam Recipes
Five Drops Of Orange JuiceEmailchemyTriple SixOn Mark's un-Switching, and Lemmings
Three Panes - The Right Way, At Last!Random UpdatesHaving a Cow of a WeekMinor Earthquakes
MailTagsLink ModeSide-SwitchingApple
UNIXFun in PerspexKinky GTDBoosted
More Mail.app GripesHousekeepingFinally, a Reason to Look at VistaMinor Photography Update
MacBooks and Other Happenings - The Sequel10.4.4 First ImpressionsMacBooks and Other HappeningsMaking the Mouse Redundant
Ten Things I'm Looking Forward To In 200610.4.4, Come On Down!E-Mail GTD-fuRestlessness
10.4.3 Odds and EndsBack To Our Scheduled ProgrammingMiscellaneous GeekeryPost-10.4.3
One Day To GoBackup 3.0Re-Thinking my Backup StrategyHyperlinked 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 nano
Back to WorkSOCKSTake TwoIs Mac OS X Becoming Crufty?
More BacklogFive Random Annoying Things That I've Had To Put Up With This WeekReal NewsAh, Monday, How I Loathe Thee...
A Few Other Tiger NotesMail.app 0.2Ruby Shower EpiphaniesStripe Three
Needing a ChangeMonday ModeLap TigerTaming Tiger
The Pint-Sized TigerTiger TeasersOuch...Catching Up
What if Mail.app were like iTunes?The Bayesian Thing, AgainThings That Go Dump In The NightMinimal News Update
Three Little Mac AnnoyancesSlight OverloadBirds Of A FeatherIntensive Resting
That Bird, by Thunder!Odd Happenings of an Otherwise Unremarkable MondayLittle GripesGetting Things Done
Progress Along a Lopsided RoadThe Widest Desktop On EarthGeeking OutInbox Lint
Bit TwiddlingGarfield ModeMail.appetizerNeat Ideas
The Top Five Mac OS X Applications I Can't Live WithoutRSS and Mail, RevisitedThe Quest, RevisitedPulp Fiction
The Mail ThingThe Mouse, Done RightNothing To ReportMailPriority
Slew of Apple UpdatesSqueeze That BoxPanther in the OfficePanther First Impressions
Panther MadnessBigger, Faster, StrongerPalm LaunchesLost In a Sea of Coasters, Found In a Bunch Of Envelopes
Vertical Preview Pane in NetNewsWire... And in Mail.appBayesian WhatsitsPackagingMailPictures
The SSL Way, and Why Mozilla Needs a PushThink DifferentSwitching back to WindowsSeries 60 Trivia
Jaguar