Mail.app

is 's built-in e-mail client, which defies all attempts (both good or bad) at classification. One of its worst shortcomings (of which there are ) is its inability to deal with plain 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  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):

00    read                      1 << 0
01    deleted                   1 << 1
02    answered                  1 << 2
03    encrypted                 1 << 3
04    flagged                   1 << 4
05    recent                    1 << 5
06    draft                     1 << 6
07    initial (no longer used)  1 << 7
08    forwarded                 1 << 8
09    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:

  • 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 to send an empty message and lose your original e-mail (filed as #4460682 on 2005-02-28).
  • 2.0 will not display meeting requests, cancellations or read receipts when used against an server (which means they will simply pile up in your account, and that is totally useless for backing up/archiving 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.
  • 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 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.

This page is referenced in: