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

How to Switch to the MacGetting things done - Part IIRegarding AppleScript on Mail.app and RSS ItemsDovecot patch for Mail.app IMAP Stupidity
IMAP Backup Script.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
LeopardSo, this is a better Mail.app?Mail.appWidescreenMailPlugin
Settling InHear The Leopard Spots RoarLetterbox for Leopard - it's comingMicrosoft Exchange Server
Radar Bugs I'd Like To SeeHow to install Mail.app on the iPod TouchMy Five Wishes for LeopardA Bank That "Gets" Online
Post-Keynote NotesPalmWiki Editing, Mind Maps and UsenetGTD
AppleScriptThe Switcher's Application GuideZero Sum GameThe New Portuguese ID Card - and Macs
Re-surfacedThe IMAP ProtocolThe iPhone, At Long LastThe StealthBook
Look Ma, No MiceRandom RemaindersTaming my RSS feeds, the Bayesian wayTNEF
Tim GadenDimmedAppleScript/News Flush.Mac - And Round And Round We Go...
MailArchive.pyIMAP to mbox Backup ScriptOdds and EndsThe Little Python IMAP Archiver That Couldn't
All Hail Michael RothwellBullets in Mail.app without Shooting It?Interesting TimesRe-Plumbing Mail
A Spotty Take On Leopard's FeaturesBacklogBuzzing BackPreparing for Launch
Leisurely LinkageCasual DebunkingMac OS XMonday, Oddly Enough
.Mac's Missed OpportunitiesLetterboxDetoxTopical
Yojimbo on the CheapApple Jam RecipesWebKitFive Drops Of Orange Juice
EmailchemyTriple SixOn Mark's un-Switching, and LemmingsThree Panes - The Right Way, At Last!
Random UpdatesHaving a Cow of a WeekMinor EarthquakesMailTags
Link ModeSide-SwitchingAppleUNIX
Fun in PerspexKinky GTDBoostedMore Mail.app Gripes
HousekeepingFinally, a Reason to Look at VistaMinor Photography UpdateMacBooks and Other Happenings - The Sequel
10.4.4 First ImpressionsMacBooks and Other HappeningsMaking the Mouse RedundantAppleScript/Mail Archive
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?
SMTPAnd I Wanted a Quiet Vacation...OnlifeMore Mail.app/Exchange Oddities
Oh Come On, Apple, THIS IS JUST STUPID!And Now, The Real News: iPod nanoBack to WorkSOCKS
Take TwoIs Mac OS X Becoming Crufty?More BacklogFive Random Annoying Things That I've Had To Put Up With This Week
Real NewsAh, Monday, How I Loathe Thee...A Few Other Tiger NotesMail.app 0.2
Ruby Shower EpiphaniesStripe ThreeNeeding a ChangeMonday Mode
Lap TigerTaming TigerThe Pint-Sized TigerTiger Teasers
Ouch...Catching UpWhat if Mail.app were like iTunes?The Bayesian Thing, Again
Things That Go Dump In The NightMinimal News UpdateThree Little Mac AnnoyancesSlight Overload
Birds Of A FeatherIntensive RestingThat Bird, by Thunder!Odd Happenings of an Otherwise Unremarkable Monday
Little GripesGetting Things DoneProgress Along a Lopsided RoadThe Widest Desktop On Earth
Geeking OutInbox LintBit TwiddlingGarfield Mode
Mail.appetizerNeat IdeasThe Top Five Mac OS X Applications I Can't Live WithoutRSS and Mail, Revisited
The Quest, RevisitedPulp FictionThe Mail ThingThe Mouse, Done Right
Nothing To ReportMailPrioritySlew of Apple UpdatesSqueeze That Box
Panther in the OfficePanther First ImpressionsPanther MadnessBigger, Faster, Stronger
Palm LaunchesLost In a Sea of Coasters, Found In a Bunch Of EnvelopesVertical Preview Pane in NetNewsWire... And in Mail.appBayesian Whatsits
PackagingMailPicturesThe SSL Way, and Why Mozilla Needs a PushThink Different
Switching back to WindowsSeries 60 TriviaJaguar