1

As I am about to drop a server, I thought, I should clean up my Maildir directory, just in case. It may contain some emails with password and such so I do not want those to be readable by others. I used the following command line:

find Maildir/ -type f -exec shred -u {} \;

To my surprise, that command line did not return even after a few minutes. So I ran another command to see how many files I had under Maildir:

find Maildir/ -type f | wc
  14736   17737 1394113

And yes. That's 14,736 files.

What is going on with postfix?

I'm using thunderbird as a client, but that should not affect how the server works. So why would all those files be created and kept there?

As an example, I have a Folder named "Blogs" with a sub-folder named "Warriors" in Thunderbird. When I look at Thunderbird, that folder is definitely empty. When looking at my Maildir folder, I see two files. I have the real impression that postfix does not delete emails that I delete in Thunderbird. Could that be it? The two files below were deleted a while back and yet they are still there on my mail server nearly 3 months later...

Maildir/.Blogs.Warriors/cur:
total 16
drwx------ 2 alexis alexis 4096 Feb  8 00:10 .
drwx------ 6 alexis alexis 4096 Feb  8 00:03 ..
-rw-r--r-- 1 alexis alexis 2727 Feb  5 00:02 1486252970.M453258P14727V0000000000000800I00000000001E4FDE_9.m2osw.com,S=2727:2,ST
-rw-r--r-- 1 alexis alexis 2646 Feb  8 00:02 1486512185.M350097P2621V0000000000000800I00000000001E4F7B_84.m2osw.com,S=2646:2,ST
Alexis Wilke
  • 2,057
  • 1
  • 18
  • 33

1 Answers1

1

First of all, Postfix has nothing to do with this as it is a mail transport agent, and messages already delivered to Maildir are retrieved and handled by mail user agent (e.g. Thunderbird) most likely (and hopefully) via IMAP server (e.g. Dovecot).

Deleting a message on an IMAP account only sets a flag that marks it for deletion and hides it from view. The file is not deleted immediately from the Maildir, but it now has flag 2.T in its filename:

info starting with 2,: Each character after the comma is an independent flag.

  • Flag P (passed): the user has resent/forwarded/bounced this message to someone else.
  • Flag R (replied): the user has replied to this message.
  • Flag S (seen): the user has viewed this message, though perhaps he didn't read all the way through it.
  • Flag T (trashed): the user has moved this message to the trash; the trash will be emptied by a later user action.
  • Flag D (draft): the user considers this message a draft; toggled at user discretion. Flag "F" (flagged): user-defined flag; toggled at user discretion.

Both your example files have flags :2,ST in their name meaning they have been seen and trashed.

You may find it rather confusing, but a "deleted" message is actually copied to the Trash folder. On technical level you'll end up having two copies of the file on the server, while GUI tells the opposite. This is more useful in mbox format as it takes less disk I/O to save just the metadata rather than to immediately remove one message in the middle of a possibly huge file containing the whole mailbox.


Normally you should purge messages from the folder with your IMAP client, but it doesn't make any difference in this situation, when they are all to be removed (or overwritten with shred) anyway.

Thunderbird calls this purging as compacting, but it has nothing to do with compression.

  • Right click on a single folder and select Compact in order to purge it.

  • You can compact all folders at once from File > Compact Folders.

  • You can automate purging from Options > Advanced > Network & Disk Space > [x] Compact all folders when it will save over [20] MB in total.

Now that you know how Maildir flagging works, you could easily purge automatically on server side, too. Just find and remove all messages having 2,ST, possibly only when older than n days.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122