# mailbox or ~./maildir

## DumbAss

Hi, I've got a question about the mail-format to use.

I'm setting up an IMAP mailserver, well at least I'm trying to.

I've read a lot of quetion about mailboxes and everyone has a marked opinion about weither to use mbox or ./maildir. But why should the one be better than the other? What are the advantages of both?

And I've got another question: what's the best way to authenticate with postfix? I've read you can use mysql for that or ldap or....?

Is there one that has a serious speed-advantage over another? I know you can use webmin to add records to the mysql database. Is there another way to add (virtual) users to postfix?

And what is / does sasl do?

Thanks in advance!Last edited by DumbAss on Tue Feb 03, 2004 12:49 pm; edited 2 times in total

----------

## jbrazio

The mbox format is a plain text file, .maildir is the new format arranged by subdirectories. If you want to use the mail command you have to convert the .maildir format to mbox with the maildir2mbox (qmail distro) but if you plan to use IMAP you dont need any of this, just stick to the .maildir style.

(Im not sure if an mbox style mailbox works with IMAP.)

----------

## skunkworx

Unless you have a specific need for the mbox format, such as your favorite email client or IMAP server not offering maildir support, I highly recommend sticking with maildir.  As jbrazio pointed out, mbox is a single, flat text file.  This means that only one process can modify a user's mailbox at any given time, which can (and often does) lead to messy file locking issues, or worse, file corruption when the locking process doesn't work like it's supposed to.  maildir, on the other hand, puts each message in its own file, and also employs a variety of checks and balances to make sure no file has the chance of overwriting any other file, even when more than one process is accessing the same user's mailbox.  This makes maildir practically essential for something like IMAP, where it is common for clients to open more than one connection to the same mailbox.

I haven't used postfix, so I can't answer that part.  qmail is my poison of choice.

SASL stands for Simple Authentication and Security Layer.  Basically it allows multiple protocols to use the same set of authentication tools on a server, provided each protocol adds support for SASL commands.  You can see all the nitty gritty details in the RFC.

----------

## DumbAss

OK, maybe if someone would comment on this:

I think I'm going to use for my email-server:

fetchmail, procmail, postfix, courier-imap, spamassasin and for authentication: ldap

I chose ldap but because (I think) I can use it for the centralised address book too. Someone said it was faster than mySQL and I believe him.

----------

## buzzin

http://advosys.ca/papers/postfix-filtering.html

A great paper which might help on setting up postfix with spamassasin and Anomy.

----------

## axxackall

One more argument for maildir:

it's much easier to right scripts that would scan on of maildir folders, do something with messages and moe already process messages to another folder.

Tha tway I teach SpamAssassin to recognize spam that it's still missing.

----------

## kashani

A few more reasons maildir is a better solution.

Say you come in Monday morning and find that your email server has recieved 140k messages due to a problematic customer's email server. 

1. Pine can actually open this many emails if you wait long enough.

2. It's easy to write a script to delete the emails you don't want instead of trying to manually edit a mbox file to delete mails to you can get the ones you do want to read.

Not that this happened to me this morning... no no this isn't the voice of experience. 

kashani

----------

## axxackall

By the way, mbox or maildir are not the only two options. 

There is a project called dbmail that stores all email in the databases. It promises a real high and scalable speed fo searchin and manipulating on your mailarchives. I am going to look closer at that project.

The other option is implemented by Cyrus - it keeps email messages in maildir-like way, in addition to message headers in dbmail-like database.

Well, neither dbmail or cyrus are for novices.

----------

## asilva

One thing that everybody seems to forget are the security implications of using mbox. having one single file means that reading other users email becomes childplay.

with the Maildir format the email is stored in the user's ~/.maildir/ directory making a whole lot more secure (and flexible)!

----------

## kashani

 *asilva wrote:*   

> One thing that everybody seems to forget are the security implications of using mbox. having one single file means that reading other users email becomes childplay.
> 
> with the Maildir format the email is stored in the user's ~/.maildir/ directory making a whole lot more secure (and flexible)!

 

That's not true, unless you've purposely broken the permissions on /var/mail/spool/

kashani

----------

## axxackall

 *asilva wrote:*   

> One thing that everybody seems to forget are the security implications of using mbox. having one single file means that reading other users email becomes childplay.
> 
> with the Maildir format the email is stored in the user's ~/.maildir/ directory making a whole lot more secure (and flexible)!

 

One file, many files... What's the difference? Based on your logic users should be completely isolated from their mail files (otherwise they may change permissions) and access their mail only through IMAP. But that is exactly the way of dbmail. I wonder if it is possible to do with courier-imap or qmail.

----------

## asilva

 *axxackall wrote:*   

> One file, many files... What's the difference? Based on your logic users should be completely isolated from their mail files (otherwise they may change permissions) and access their mail only through IMAP.

 

Working in a school does make me a bit paranoid about security, especially since the teachers started handling sensitive matters by email.

----------

## skunkworx

 *axxackall wrote:*   

> I wonder if it is possible to do [dbmail] with courier-imap or qmail.

 

If there is a command-line program that will read an email message from standard input and insert it into the database, then qmail can support dbmail.  Courier IMAP is a different story; it's basically hardwired for maildir support.

----------

## DumbAss

OK, 

It works (a part of it). But this is really weird. When I sent a message to a vmail virtual user. It gets the message. But It doesn't create .maildir as a directory. It creates a file called .maildir. That file contains the messages I sent. Weird not?

When I remove the file .maildir and do "maildirmake .maildir" and then I sent a message, maildrop complains it cannot "open mailbox"

Does anyone know what te problem is? Please?

----------

## fleed

Hey DumbAss (he he he  :Twisted Evil:  , sorry, had to do it), 

You set it up so it writes in mbox format to a file called .maildir. Hence why it doesn't work if you create the maildir yourself with maildirmake. You have to configure it to use maildirs, not mbox.

----------

## DumbAss

Thanks, but that's part of the problem. I don't know how to make it use the maildir format.

----------

## kashani

It'll usually do that if you've forgotten the tailing slash on .maildir/

In /etc/postfix/main.cf you should have:

home_mailbox = .maildir/

if you're using the Virtual Guide your maildir path needs to end in / as in:

/home/vmain/domain.com/user/.maildir/

You also probably let this thread die. If you have problems with your MTA it'd be easier for someone to look at without having to wade through mbox vs maildir stuff. 

kashani

----------

## eNTi

i come to think that this whole mbox/maildir stuff is completly crap. what if i want (like in my case) to use e.g. mutt for console and sylpheed for X to read my emails. i don't want to convert or copy around any emails. i want them only ONCE on my system. is it so hard to make this a little more flexible and customizable?

----------

## Jaxom

Well, thanks to having worked for this ISP (I now own it) for the past 4 years.  I can tell you flat out maildir is the way to go.  Our "old" mail server was using NTMail (yes, on NT *crindge*) and uses an mbox format.  I can't tell you how many times I would have to go and flat out remove a users mail simply because of corruption.  Atleast once a week a box would get destroyed and that was for about 3000 mail boxes.

I always hated the format (that and all of our services on NT/2k) and was eager to get that changes.  With the help of the guys here, and the virt mail guide I've been able to remove the constant loss of e-mail, headaches, and everything else involved with mbox/NT crap.  Granted part of it is simply NT/NTMail being the problem, but mbox wasn't helping matters in the least.  It's probably fine for a low usage instance, but these days with the spam problems....I wouldn't use it if you have more than 50 users on your box.

----------

## kwiqsilver

There are a few other good reason to use maildir that nobody mentioned:

Since it's directory based, not file based, when you have tens of thousands of emails in your sentbox hitting "c<" in mutt doesn't lock mutt for twenty seconds while it reads the single mammoth file (it just reads the file names listed in a readdir() call).

Also since it's directory based, you can gzip or delete individual files in an archive directory based on age, size, etc., instead of having to cut them out of the mammoth file.

@eNTi:

Why can't you use maildir for that? I use mutt for 99% of my mail, but when I get an html email that I actually want/need to read, I open it in balsa. As long as both programs support maildir, there's no problem. Mutt has an option for the ~/.mutt/mutt.rc file and the gui ones should have a checkbox or something under preferences.

Even when I used mbox, I didn't have a problem doing that.

You just have to set both mail apps up to understand ~/.maildir/inbox is the inbox, etc. Back up your maildir before fiddling. I destroyed my inbox when setting up balsa.

----------

## eNTi

i use sylpheed and it uses a "MH" format, whatever this means. i don't know the difference between .maildir and mh, i do not even know if it's the same "level of operation". i'll try to find some information elsewhere.

----------

## kwiqsilver

MH is a different format, which explains why the two don't play well together. You could see if mutt supports mh format, or try a new gui mail app: they're all pretty much the same anyway. If you do your filtering and delivery through an outside app, all the mail client is doing is displaying the mailboxes and calling the mailserver to send emails.

----------

