Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Unix Operating Systems Software

Improving Unix Mail Storage? 615

At first, there was mbox, then there was Maildir, and Bill begat Outlook and .mbx. CaraCalla wonders if there is a better way to store mail than the way we currently store it today. I admit, with the changes that email has undergone over the past 5 years (changes in what is being sent, not necessarily in how it is sent), it may be time to reinvent the mail format. Read on for CaraCalla's analysis of the current mail options, and his thoughts on where we may go in the future. If you were to design your own MUA, how would you design its mail storage?
CaraCalla asks: "Does anybody know a good, free solution for storing mail on unix hosts? The reason that I ask this question is my discontent with available techniques:
  • mbox: There are problems with locking, corruption, access-times, and bloat.
  • Maildir: Do you really want to clutter your system with millions of small files? That's waste of inodes, space (unless perhaps you use Linux/ReiserFS or SGi) and just try to open a Maildir with 1000+ mails and see how long it takes your favorite Mailprogram to only display the subjects.
  • Cyrus: Basically the same as Maildir with database features.
  • UW-Imap mbx: That's classical mbox with extensions allowing multiple access.
  • Evolution: Basically mbox with database features.
  • Windows clients: Typically some proprietary db-format. Pathetic.

But the thing that bugs me most is disk space. Typical inboxes are made of 5% to 10% of Text including Headers and HTML. The rest are BASE64- (or UU-) encoded pictures, word documents, zip archives and so on. The problem here is the encoding which wastes considerable amounts of space (at least one third).

Some ideas about the ideal mail-storage:

  • One file per Mailbox-folder, allowing multiple folders per user. Should those files reside in one central location or in users Homedirs?
  • Compression: Should messages be broken into pieces and the MIME-attachments stored separately (thus searching of the text parts would still be possible without decompressing the whole file)?
  • File format: gdbm, Sleepycat db? Something new?
  • Should the security model allow users to directly access their files, grep them, copy them around?
  • Shared folders, virtual domains?
  • Unicode support in folder names? Imap message-IDs, flags, useragent specific state-information?
  • How would MTAs deliver mail? How would clients access? File-locking (NFS)?
  • What about backwards-compatibility? Writing libmailstore (anyone)? adopting UW c-client?

Does my ideal mailstorage exist somewhere? Is somebody working on a project addressing this? Does anybody have some other hints? And please no mbox/Maildir flamewar!"

This discussion has been archived. No new comments can be posted.

Improving Unix Mail Storage?

Comments Filter:
  • by Pig Hogger ( 10379 ) <(moc.liamg) (ta) (reggoh.gip)> on Tuesday May 28, 2002 @11:22PM (#3599830) Journal
    Stuff the mail in one folder, one to rule them all.

    But put multiple indexes (by sender, subject, date, whatever key-classes you want to assign messages) and the possibility to restrict the range displayed. With careful programming, you can manage many users who won't be able to read each other's mail, except as required.

    This way, you can arrange your mail as you please.

    No more message duplication. Send a memo to 250 people? Just send it once, but tag it as readable by the 250 sendees.

    Of course, this calls for an SQL database... :) :) :)

    • by TheBracket ( 307388 ) on Tuesday May 28, 2002 @11:33PM (#3599891) Homepage
      You do realise that you just described MS Exchange (albeit in a chronically simplified form), right? :-)

      Exchange is actually a pretty decent mail server, although only using it for mail is pretty dumb - its groupware features are the killer app. It exposes both benefits (in particular, single storage of messages with multiple recipients) and flaws (if your db goes boom, it affects all your users - or at least all your users in a given mail partition) of database-based mail storage.

      I remember seeing a project to combine mail storage with PostgreSQL a while ago. Anyone know what happened to it?

      • James [apache.org] from the apache group can use an SQL datastore.
      • by Anonymous Coward on Wednesday May 29, 2002 @01:20AM (#3600315)

        Exchange is actually a pretty decent mail server

        As part of my job, I've written software to send out HTML mails to people (no, it's not spam). When these messages pass through an Exchange server, Exchange does us the "service" of creating a text version of the mail from the HTML. I guess this is so that people without HTML-capable mailers can have a readable version...

        The problem is, we include our own text/plain version alongside the HTML (ain't multipart/alternative great?). Nicely formatted and everything. Instead of leaving our mail alone, Exchange rips out the text version and creates a new one from the HTML. The result is an ugly mess of URLs because we use some graphics in the HTML version. Our nicely formatted text version ends up in the bit bucket so that Exchange can dump it's url-barf on people.

        This is really stupid behaviour for an MTA. And for some reason, it's always CEOs of important clients who use text-based MUAs while sitting behind an MS Exchange server. They call us up asking which URL to click on.

        This, combined with other mail-rewriting bogons, has lead me to the conclusion that Exchange has no respect for the messages passing through it.

        • And for some reason, it's always CEOs of important clients who use text-based MUAs while sitting behind an MS Exchange server. They call us up asking which URL to click on.

          Easy solution: Build a list of "VIP" users who will get a text-only version. Or who will get the text and the HTML version in 2 separate mails.

          • That's not easy and it's not a solution.

            I have no idea on the specifics of the original problem, but in my experience every user does not complain about a problem. Depending on the system the mailing list is sourced from, adding a "prefers text/html mail option" could be non-trivial or just not possible, so as to require implementing a "parasite" database from scratch to keep track of such preferences, which would be quite difficult.
        • by ortholattice ( 175065 ) on Wednesday May 29, 2002 @04:30AM (#3600783)
          Mod parent up. More people need to know about this blatant RFC 2046 violation that corrupts carefully composed multipart/alternative emails. Sometimes it makes me want to scream that Microsoft gets away with this stuff and no one seems to care. Or maybe they don't realize their correspondents are receiving a corrupted version on the other side, and the correspondents just assume the sender is sloppy and lazy.

          BTW a good way to get nicely formatted text/plain content is:

          links -dump abc.html > abc.txt
          with neatly formatted tables and everything. Unfortunately only your non-Exchange recipients will see it.

          Now if Exchange automatically put in a text/plain for attached Word documents, I might buy that... :)

          • by Anonymous Coward on Wednesday May 29, 2002 @11:18AM (#3602079)
            Sometimes it makes me want to scream that Microsoft gets away with this stuff and no one seems to care.

            One thing to keep in mind about Exchange is that it's really a X.400 mail system, with some proprietary routing features kludged on top, lots of back-compat MS Mail features kludege on top of that, and then (as the last afterthought) SMTP kludged on top of all that. Next time you are at a computer book store, gander at the architecture diagram for Exchange -- it's so complex that it _should_ make you queasy. The thing just reeks of early-90s incorrect design assumptions.

            So it shouldn't be a shock that it can't handle a large number of SMTP edge cases. Frankly, nobody would buy a product like Exchange if it didn't have the Microsoft logo on it and a nice client which gets installed with Word and Excel.

            Microsoft, in their heart of hearts knows that it's a piece of shit, but it's _their_ piece of shit. And it happens to sell well, and any product that profitable can't be all that bad.

            I wouldn't be shocked if numerous skunkwork project have come and gone at MS to replace their Big X.400 Jet DB Kludge with a real Internet-saavy mail server, but the poltics of the place probably dictate that that they lumber on with what's working (that also explains products like Windows ME).
      • Exchange is actually a pretty decent mail server

        The problem is, mail is a critical app, and in some ways exchange *really* misses the point.

        I think the most frustrating situation I've ever seen as a system administrator was when we were doing a scheduled reboot of the exchange server. After about 20 minutes waiting for it to resync itself & shutdown, my boss, one of those "smart enough to be dangerous types", decided it was a typical NT hang & to go ahead and hit the reset button (he did it in a single motion without a word, there was nothing anyone could do).

        It took almost 2 weeks to get things straightend out. We had backups, but it turned out there was a 2048 meg bug with NT restores that had been re-introduced by a recent server upgrade, and we had problems getting the patch rolled into the new code (legato tech support- need I say more?).

        350 people *screaming* for 2 weeks. I was very glad I was not the mail administrator.. but very sad to be sitting next to him.
        • by H310iSe ( 249662 ) on Wednesday May 29, 2002 @02:23AM (#3600496)
          ditto. Either exchange is impossible to administer well or just very, very hard. Until recently you couldn't restore single users mailboxes (there was brick backup but eventually even MS admitted it didn't work) you have to restore the entire server to get back one corrupted data store.

          At one firm I was at exchange went down and it took 3 days of 24 hour work to get it back up (I guess we were 'lucky') - the solution? a $50,000 backup server that does absolutely nothing but wait for the main exchange server to go down. First time we had to use it, we were down for a day, it didn't come up.

          I'm currently looking for a mail server, any server, that does mail well for 50 - 500 users (I'd settle for 50-100). I've played w/ xMail, it's tough to config. Heard good things about WorldMail (qualcomm?) but not used it. Heard free BSD's qmail (?) is good as well. I'm very interested in anyone who has info about free or cheap mail servers that can be configured in a day or two of work. If that exists.

    • Actually, this quite similar IIRC to how Exchange is set up (provided you leave all of the mail on the server).

      For moderators who are rabid anti-MS, just skip me, for those of you that live in the real wolrd read on.

      One would not need to have an SQL DB as the backend. The ideal would a very fast embedded db, be it and SQL offering or not. Not just fast in lookups and such, but a fast interface. Build the server around the db, clients connect to server, server sends messages to client based on user id. Really a quite simple idea.

      MS used a good idea, I just don't like their implimentation of it. It is just too cumbersome.

      What I would like to see would be the following:

      1 DB backend
      2 Single message store (One message + 250 addressees = One message record)
      3 POP3 (and IMAP?) accessability
      4 Calendar/meeting planner
      5 Global/Private address book (one address book does both)
      6 'easy to use' CLI (I don't give a rats ass if it is for Linux, Windows or both, CLI is paramount. I know CLI ease is a relative term esp. for and MCSE, but GUI admin should be an extra, no the only way.
      7 Easy to set up and admin (Again ease being elative
      7a Set up and forget about it. An admin should not have to look at the server and 'fix' it daily, it should take care of itself.
      8. Likely many more.

      For once, let someone innovate on Microsoft's idea.

      (Don't flame is project X is doin this, because I don;t really care, and have not looked around lately. This is general laundry list. If anyone wants to start a project, I will help though)
      • " If anyone wants to start a project, I will help though"

        OK. I'm game. I have done some research into the subject and here is what I have thought of.

        No matter what you write eventually you will want things like database independence, flexable authorization (LDAP etc), ACL lists etc. I also thought it might be more productive to use a higher level language and to see if you can leverage other people's code (why re-invent the wheel). So what do do?

        1) Work and adding IMAP and mCal support to Apache James. They have written a mail server in Java which includes POP3, database back end, TLS support LDAP etc. It probably needs a nice admin interface too. Since there are several calendar servers written in java it ought be easy to graft something on.

        2) Add on to ZOPE. Zope provides for flexable user management and database abstraction as well as a built in object oriented datastore which can be distributed. There are already several python based email servers out there so it ought to be fairly easy to graft them on to Zope. As a bonus you also get a web server, FTP server, and a WebDav server so access to your mail could be provided by many methods.

        3) Use Delphi/kylix. There are at least three projects which have been started. Delphi has awsome database capabilities and a great GUI development anvironment.

        So there you have it. Which one do you want to tackle.
    • I also think a database solution is the way to go. ( me too :)

      The attachments could be unencoded, and stored as binary data. The metadata of the message ( to, from date, subject, complete headers etc ) could be indexed for fast searches. Seperating out binary from text data would speed up searches and previewing.

      It would be pretty simple to convert from a database-stored format to any other storage format (mbox, maildir), so if later on, you wanted to change back to another format it would be no problem.

      perl or php with a mysql database would do this stuff easily.

    • Of course, this calls for an SQL database... :) :) :)

      God forbid mySQL. Heh, if we could afford it, Oracle would be the way to go, but we'd all need a ton of ram!

      I hear Microsoft is making their "next generation" filesystem based on SQLServer... any word on the truth of this?
    • As others have mentioned, that's a description for Exchange. From what I've read there's an ex-HP product called OpenMail [openmail.com] that supposedly is an Exchange replacement for UNIX. That was my understanding when I read the half of a related slashdot post a while back.

      Of course, when someone says "Exchange" replacement I assume that they mean a single instance store, since everything else can be done on UNIX... but the single instance store is really the deal breaker...

      Actually, my Sendmail config is a sort of single instance store... since my user account is the only one who gets mail, my MBOX is, technically... ;)

      While the various UNIX office suites are doing a fantastic job, it seems to me that effort needs to be put towards building an Exchange replacement... as a lot of companies use exchange for the groupware features. Of course this is a way to lock them into the Microsoft cage forever. Having a UNIX/Windows/Mac (cross platform) office suite and a stable single instance store mail server with groupware features (preferrably as a module) would kick Billy Boy where it hurts. Samba's already bested Microsoft... only two more to go (and the office suites are getting close for 90% of the users).

      • HP licensed the code to SamsungSDS. If you want to purchase a copy you have to go to: http://www.samsungcontact.com.

        They seem to be a fair bit cheaper than exchange for even a small number of users.

    • Cool, then you could do:

      DELETE FROM inbox WHERE subject LIKE '%Penis Enlargement%'

      This would save a lot of time. :)

    • by leandrod ( 17766 ) <l@dutras . o rg> on Wednesday May 29, 2002 @03:51AM (#3600701) Homepage Journal

      > this calls for an SQL database

      God forbid using SQL, this half-baked relational standard that is never properly complied with!

      Seriously, while SQL – be it FireBird [firebird.sf.net], InterBase [interbase.com.], PostgreSQL [postgresql.org.], SAPdb [sapdb.org.] but never MySQL [dbdebunk.com.], which isn’t even a proper DBMS, much less SQL entry-level compliant – is our only alternative to any immediate implementation, such a basic piece of software such as a MUA, or even more an IMAP server, calls for a proper relational DBMS, preferrably one which would be based on Chris J Date [dbdebunk.com.]’s The Third Manifesto [dbdebunk.com.]’s Tutorial D [tutoriald.sf.net], whose only implementation up to this day is unfortunately a proprietary one, namely Alphora [alphora.com.]’s Dataphor [alphora.com].

  • Well. My solution for storing ALOT of BIG email but still browsing fast is to use MySQL. My mail client is Pronto! [muhri.net] (written by Muhri, in perl, gtk, etc).. I have several 10's of thousands emails in about 10 different folders. Reaction time is immediate and searching is pretty damn quick aswell.
    The mysql server is at work, and I can view my mail from anywhere simply by pointing my client at my IP. Presto.

    I'm also slowly writing a MySQL-based IMAP server which will hopefully be compatible with Pronto!... But as with so many projects, itl probably take some time to complete...

    David
  • by Glytch ( 4881 )
    If you're so worried about encoded binaries, why not try yEnc instead of base64 or uuencoding? It works well in newsgroups. It might work well for email storage as well.
    • yEnc isn't all that great. See http://www.exit109.com/~jeremy/news/yenc.html [exit109.com].

    • Re:yEnc (Score:2, Informative)

      by fejjie ( 192392 )
      *sigh*

      yEnc is a complete waste of time. Had the author of yEnc actually gone out and read some pre-existing MIME specifications before going out and re-inventing (a square) wheel, he would have found that MIME already defines an encoding that gets even better compresion than yEnc. It's called "binary". Yes, MIME can handle binary content.

      Content-Transfer-Encoding: binary

      it's as simple as that.

      Btw, I've implemented the yEnc specification in my library GMime [sourceforge.net]

      My favourite part of the yEnc authors defense for why he implemented yEnc is "but most news clients don't implement MIME". Hah, join the real world where NO news reader implemented yEnc. (yes, I know there are clients that implement it now, in fact my code is used in a few of them).

      Believe me as someone who spends time hacking on news and mail readers, yEnc is nothing but a headache.
  • I like MS Exchange (Score:5, Informative)

    by alen ( 225700 ) on Tuesday May 28, 2002 @11:29PM (#3599875)
    A single database to hold of the user's email. Single instance storage ensures that only one copy of any attachment is in the database at once, no matter in how many email messages it was sent in. API's for back up let you back up the whole database or individual mailboxes. And depending on your backup solution you can restore mailboxes and individual emails. Anti-virus software that integrates into the server side of the software. In Exchange 2000 if you accidently delete a mailbox you can easily bring it back with all emails without restoring from tape. Only files to worry about on the user end is a personal address book and archived email. Unless you use POP3 or it's archived in personal folders the email always stays on the server preventing problems like accidentaly downloading important emails you need at the office being on a home PC. And it's stable. Not as stable as UNIX I admit, but it stays up for months without a reboot. And in my experience most problems are solved by a simple reboot. In 4 yeas of exposure to exchange, the only non-admin related problems I've seen were 1 database corruption where I needed to run a utility and wait 45 minutes for it to work again. And a corrupted MTA that needed a reboot to get it working right again.
    • We do the same thing, 1 Large multi-TB oracle database, ldap front ends. Of course this is for Voice Mail(encoded), SMS and Email. Not cheap, but its pretty standard, all the vendors seems to offer the same configuration.

      I think the sweetest thing is how 1 object(voicemail/etc) can go be tagged for a select group of people. Theres Garbage Collection, extra storage, all kinds of handy features. Just a well thought out, easy to manage, solution. Thou it costs :)

      Oh by the way, its Unix baby, ya ya. (-;
    • And I forgot to add. Deleted item retention. You set the number of days. The user deletes an email and empties the trash. The email is still in the database for that number of days and can be restored without back up software.
    • by afidel ( 530433 )
      I liked this until the server (well cluster actually) that served our EMEA operation fell over. EMC, Compaq and Microsoft fought over who was at fault and in the end 22 hours later the thing had been rebuilt and restored from tape. This was a solution put together by a Microsoft Premier Support partner that was supposed to have 5 9's availability and fell over in its first couple months! Instead of 0 lost email we had all emails that hadn't been in the last tape cycle lost along with any emails that timed out waiting for the server to come back up, not only that but noone could read their email for an entire day (2 business days actually).
    • Single instance storage is only good for intranets except that there there one should use file sharing to collaborate on documents rather than sending virii^H^H^H^H^Hattachments.
      Alen, your experiences with MS-Exchanges are so many worlds of difference away from mine that I nearly suspect that you've written a troll. Rebooting a mission critical service like a mail server during working hours is unsatisfactory. If other mission critical services like file and print sharing are also disabled during that reboot, then it's time to look for a more robust product.

      I have worked closely with three shops in the previous three years that used Microsoft Exchange. Each had at least 3 full time equivalents of MSCEs to babysit their Exchange servers, probably more if you count overtime. This is not counting the occasional high priced consultant. None of these shops could keep Exchange running for a full week. Nor could they keep it from losing mail (When I measured it was 10-15%, ). Nor could they get it to communicate well with other mail servers. Nor could they keep it from getting wiped out once every three months by MSTDs (especially worms and virii).

      In contrast, Novell servers run years at a time unattended (nearly every consultant has at least two such anecdotes of their own) and many UNIX-based MTA's need only a few hours of non-hardware maintenance per year, when set up tight. I guess running MS-Exchange is a new status thing to flaunt resources, like having a tuburcular wife was during the Vicrotian era.

      Needless to say the managment's support was/is a real PITA for anyone doing work via e-mail with people outside of the house's MS-Intranet. In one case it even delayed a publishing a book by several weeks. In house use of Exchange was fine -- when it was down for you, it was down for everyone else so it was a nice time out and a chance to go have coffee with the others. When put to the test, file sharing couldn't, wouldn't, didn't function often enough to be useful either. For file sharing, those without access to a Novell or Unix file server, used sneaker net or mailed attachments. Yes, Exchange does look good in the 4-color glossy marketing brochure, but that's were it ends and reality sets in.

      Puh.

      Back to mail databases. RFC 2822, Internet Message Format [faqs.org] specifies the general structure of a message. This can be over simplified as a header with its standard and non-standard fields and one or more message bodies. RFC2049 specifies multipart bodies. These structures do seem very well suited to a relational database.

  • by Dr. Awktagon ( 233360 ) on Tuesday May 28, 2002 @11:35PM (#3599900) Homepage

    Something like Maildir .. if the FS is slow and can't handle that kind of application, then we need to improve our filesystems!

    Lots of applications need lightweight databases with indexes, locking, and atomic operations. Why not bake this into the filesystem, and it won't have to be just for email, it will have many uses.

    I was thinking about this the other day as I was working on a logging system for a large in-house email filtering system.. similar problem, except instead of storing emails, I'm storing small XML fragments describing the structure of each email and what was done to each. So far the easiest solution was large monolithic XML files, and an external index pointing in the large file (i.e., like mbox + a DB index). As it grows we'll probably have to move it to a "real" database.

    There is a need for something like sleepycat DB + ReiserFS on steriods..

    • This, as several other threads note, is the approach that Hans Reiser is taking with his filesystem. That is, if the filesystem is not good enough for storing our (large-grained) data, that we are resorting to what basically amounts to indexed archive files or databases full of BLOB objects to store our data, then our filesystems are broken. A directory with 1,000,000 files in it shouldn't take any longer to return a sorted directory listing than one with say, 10 files - because it all should be indexed behind the scenes. Same for the problems of inode starvation, fsck, etc. A program such as mail clients and servers (for most people anyway) -- or any other apps that need simple storage should use the filesystem as the storage mechanism.
  • by SwellJoe ( 100612 ) on Tuesday May 28, 2002 @11:37PM (#3599909) Homepage
    I've followed ReiserFS development for years now, shipping our first servers with it some two years ago (and every box we've shipped since then), and I believe they have the best long-term plan for this kind of thing. Hans has written some excellent white-papers on making small files extremely cheap.

    The eventual goal of Reiser is a filesystem that is indistinguishable from a powerful database (if a special purpose database). The plan is to make small files so cheap that every extension of a file, directory, etc. is just another file. Another interesting turn is that files would no longer be, necessarily, of the form '/big/long/path/to/some/file'...because the filesystem is a database, one could also access it by a category, so that one file read pulls in all of the data of that category (from any number of files). Directories become just one view of the data available, with any number of other views possible depending on the application.

    As was mentioned in the parent, this would lead to things like 250 email recipients and only one actual file. But of course, this leaves out the copy-on-write functionality needed to make this seamless.

    So I think the solution is probably to fix the filesystem--not to fix the email storage mechanism. A number of very smart people have 'fixed' email storage in the past, leading to all of the options we have today, none of which works extremely well on really large mailboxes. Yes, many are good enough, and many work fabulously for small to mid-sized applications. But the day will come when they do not work so well, due to the higher volume and growing average size of emails.

    A good place to start for information about these ideas (which are primarily a consolidation of the most interesting research in the field of filesystems and databases):

    http://www.namesys.com/whitepaper.html

    ReiserFS is good stuff. Give Hans' papers a read sometime.

    BTW-Don't gripe at me about ReiserFS instability, etc. I know better. As I mentioned I've been shipping servers with it for 2 years, and we've never had a single ReiserFS-caused corruption. Not one.

    • I've been studying WebDAV, and have been excited about how it presents a network storage that seems much more general than a typical filesystem-based metaphor -- kind of making the dynamicism of web applications available at a lower level to the OS.

      What is intriguing here, is that the level of granularity that you talk about with ReiserFS would map well with WebDAV. Running mod_dav for Apache is fine, but unexciting -- the underlying filesystem storage that Apache is so closely tied to is awkward and lacks good granularity and flexibility. But with a more powerful filesystem, it could go much further.

      In a lot of monolithic client-server architectures, I see systems created where the OS is insignificant -- just a dumb layer of hardware compatibility. You dump all the data in one file, with internal structure you define yourself. You almost always do your own permission structure -- traditional Unix permissions are worthless in most new domains (IMHO). All you need is a socket interface and a disk interface, everything else you write yourself.

      This is a shame, really, because you are reimplementing things the OS should be doing... but OS design is stagnant. Maybe that's fine, but I don't even see much ambition among Linux kernel programmers (or BSD or other Unices)... they're working off an old model that is fine at what it does, but not helpful for new systems. They don't seem to mind that they are being made more and more insignificant... maybe that's good, they aren't holding onto power or being territorial, but it really is true that there isn't much innovation there. (There is innovation in non-kernel applications, mind you, just not much in the kernel or most basic libraries like libc)

      It's nice to hear ReiserFS people are thinking about real progress, not just little tweaks.

  • Portability (Score:2, Insightful)

    by Pretzalzz ( 577309 )
    The great advantage of the current system is that it is very easy to move your e-mail from one program or computer to another with little hassle and/or risk. With any type of database system, you introduce a level of complexity that virtually assures that only one e-mail program will be able to read your e-mail. I think the best solution as far as I am concerned is to just stick with current mbox format, but allowing attachments to be deleted independently though that is just personal preference. But I think we should be wary of adding any complexity that endangers the portability of mail. Also, the other thing to be said for the mbox format is that worst come to worse you can still access your e-mail with a text editor and/or grep.
  • by cwinters ( 879 ) on Tuesday May 28, 2002 @11:43PM (#3599941) Homepage

    /. punchingbag jwz has some strong [jwz.org] opinions [jwz.org] about using databases (etc.) for mail storage. I tend to agree: everything can read from and write to files, there no versioning issues, they can be easily transported among different operating and file systems, they can be backed up easily. But it's another wheel to reinvent, so everyone hop to it at once and then lose interest in two or three weeks!

  • by cybermage ( 112274 ) on Tuesday May 28, 2002 @11:43PM (#3599945) Homepage Journal
    I've been joking for years about getting two shell accounts on opposite sides of the planet and setting each up with procmail to bounce all my mail between the two (always rewriting the header so as to avoid a loop.) I figure at any given time, my mail would be in both places and neither simultaneously.

    If I want to read some, I'd just chmod .procmailrc for a few seconds and change it back. Plenty of mail storage without chewing-up precious file-system quota.
    • by akh ( 240886 )
      A similar idea has already been implemented. Some
      Canadian researchers used an existing 8000km fiber
      optic network as a storage device. Basicly, the network
      is configured as a loop and the
      data to be stored is simply sent onto the network.
      Packets of data are placed onto the network and can be
      pulled from it as they pass a node on the network.
      It's kind of like a cross between a token ring network [techtarget.com]
      and a mercury delay line [ed-thelen.org]. You can find a few more
      details from this link [canarie.ca].
  • Eudora mbox (Score:4, Informative)

    by 1u3hr ( 530656 ) on Tuesday May 28, 2002 @11:47PM (#3599965)
    Eudora (Win and Mac)handles encoded attachments by decoding them and storing them in an attachments folder, replacing the encoded text in the mesage with a line like

    Attachment Converted: "C:\EUDORA\ATTACH\NEW YORK.pps"

    Click on that in Eudora and the attachment opens.


    This keeps the actual text in the mbox file lean. I've got almost a decade of correspondence that totals about 20 MB, if it included all the attachments it'd be much more.

    Also it allows you to edit messages after receipt, (this might trouble some people, but it just simplifies what I used to do by opening the mbx file in a text editor). I can select all the text, then paste it back in. This has the effect of removing all the HTML coding that is especially crufty from Word generated mail -- a 20k message reduces to 1k.

    • Eudora (Win and Mac)handles encoded attachments by decoding them and storing them in an attachments folder, replacing the encoded text in the mesage with a line like

      Attachment Converted: "C:\EUDORA\ATTACH\NEW YORK.pps"

      Click on that in Eudora and the attachment opens.


      For the sake of portability I turn features like that off, that and it makes it harder for me to loose my attachments and manual maintenance easier.
  • The next generation of mail storage should definitely work on taking optimal advantage of compression technologies. Preferably in a way that compresses the data from end to end, not just in the recieving mailbox. As to managing the kind of data sent, I'd suggest using a twofold approach. Save binary attachments in the natural state in a subfolder linked to the message itself, which would be kept in a compressed database format.

    As to the database format itself, I'd like to see a form of redundancy in the structure of it. Give the design some self-healing ability in case flaws develop as the information gets shuffled around. Media isn't perfect, but mail stability should try and be as good as it can get.

    If you want to speed searches, index the data in a seperate file and use that. Just keep the actual data storage as simple and reliable as possible, anything like searching or sorting is just a bonus.
    • You can go a step further - don't bother with setting up a new compression layer, just encrypt it with existing tools. Most encryption routines compress it first, to make cryptanalysis more difficult (and for performance, since there's less data to encrypt), but this is partially offset by the continuing need for 7-bit safe transport layers.
    • Shredding and compressing mail messages is almost always a bad idea. Essentially *nobody* does it correctly, and you can't reconstruct messages in their original byte-for-byte formats, which trashes digital signatures. You won't save much disk space, because real text doesn't take up enough space for anybody except a big ISP mailsystem to worry about, and binary attachments usually only compress well if they've been encoded in some non-8-bit-transparency format like base64 or uucode. About the only time it wins is when one person on your keep-mail-on-server mailsystem is sending an attachment to a bunch of people who can then all use the original, which is to say they should probably have stored the file on the web and mailed a URL. If you're going to do things like this, get yourself a compression-equipped filesystem and just store your raw mail messages there.
  • Well.... (Score:2, Interesting)

    by BJH ( 11355 )
    One file per Mailbox-folder, allowing multiple folders per user. Should those files reside in one central location or in users Homedirs?

    Depends on how the user accesses their mail. If they read their mail only on the local machine, it should be in their home dir. If the server allows multiple forms of access (like local + IMAP), central storage makes sense. There's a lot of other issues here, like backup methods.

    Compression: Should messages be broken into pieces and the MIME-attachments stored separately (thus searching of the text parts would still be possible without decompressing the whole file)?

    No. Separating a single mail into its component parts is just asking for trouble (not to mention that it massively increases your locking problems).

    File format: gdbm, Sleepycat db? Something new?

    Personally, I like Maildir, since it lets me use standard tools like grep to find particular mails. I admit that a more efficient method is probably required these days.

    Should the security model allow users to directly access their files, grep them, copy them around?

    Yes, of course. It's their mail - let them do what they want with it. The mail app must be able to deal with that.

    Shared folders, virtual domains?

    Shared folders would be nice - IMAP can do that now, although it's overengineered and not necessarily fully implemented in any particular IMAP server. Virtual domains I've never had any use for myself...

    Unicode support in folder names?

    Why not?

    Imap message-IDs, flags, useragent specific state-information?

    As you say, IMAP does that already...

    File-locking (NFS)?

    More the fault of NFS than the mail software (and I believe NFS4 handles locking better).

  • by g4dget ( 579145 ) on Tuesday May 28, 2002 @11:56PM (#3600018)
    One file per mail message is the right thing to do. That lets you use standard UNIX tools for manipulating mail and it gives you convenient locking semantics. And the hierarchical UNIX file system structure, together with links, matches mail semantics nearly perfectly.

    Of course, with traditional UNIX file systems, this is a bit slow. The thing to do is to fix the file system, not to kludge ever more complex mail formats on top of it. ReiserFS goes much of the way; we now also need some system calls to open and read multiple files with a single call.

    Until file systems catch up, one kludge is as good as another. UNIX mbox format is at least simple, so I stick with that.

  • People have been arguing about the balance between standard formats that are easy to parse and move between systems and complex formats that make searching easier.

    What we need is a standard DTD or schema for mail data that all well written email systems can understand. If everything can import and export XML representations of email, the internals aren't so important.
  • Maildirs (Score:4, Informative)

    by mrsam ( 12205 ) on Tuesday May 28, 2002 @11:57PM (#3600026) Homepage
    Maildir : Do you really want to clutter your system with millions of small files? That's waste of inodes, space (unless perhaps you use Linux/ReiserFS or SGi) ...

    In case you haven't noticed, the default settings for the Linux ext[23] filesystems is to allocate one inode per 4096 or 8192 bytes of disk space. Which happens to be pretty much the size of an average E-mail message. So, in other words, you are unlikely to run out of inodes before you run out of disk space, since both are going to be used up pretty much at the same clip.

    It may come as a shocking surprise to some, but the average large filesystem is just littered with small files here, and small files there, all over the place. Here's my workstation -- a fairly large box with all sorts of crap loaded:

    Filesystem 1k-blocks ...
    /dev/sdb5 8159388 ...

    Filesystem Inodes ...
    /dev/sdb5 1036288 ...

    I'm using up almost exactly 8192 bytes per inode.

    and just try to open a Maildir with 1000+ mails and see how long it takes your favorite Mailprogram to only display the subjects.

    How about instantly? Most GUI E-mail clients cache mail headers, so they don't have to go and wait for the server to reply each time you click on the folder index window to re-sort, or scroll the folder index.

    ...

    Some ideas about the ideal mail-storage:
    * One file per Mailbox-folder, allowing multiple folders per user.


    Using one file per folder essentially forces you to use some form of locking each time folder access is necessary. Locking of any sort has been problematic for years whenever NFS (or pretty much any other network filesystem) is involved. A single circuit will now take out your entire network spool, as all clients are now spinning on lock requests out on the unreachable server.

    Compression: Should messages be broken into pieces and the MIME-attachments stored separately (thus searching of the text parts would still be possible without decompressing the whole file)?

    I thought you wanted to save everything in a single file per folder, and using multiple files for messages is supposed to waste inodes, remember?

    File format: gdbm, Sleepycat db? Something new?

    Ask an Exchange admin about joys of a corrupted Exchange database. If mail are stored in simple, plain, files, a single instance of corruption will affect at most one mailbox, instead of taking out the entire monolithic database.

    Unicode support in folder names? Imap message-IDs, flags, useragent specific state-information?

    IMAP already uses Unicode to encode folder names. Not sure what "useragent specific state-information" means...
    • Re:Maildirs (Score:2, Troll)

      by Ian Bicking ( 980 )
      In case you haven't noticed, the default settings for the Linux ext[23] filesystems is to allocate one inode per 4096 or 8192 bytes of disk space. Which happens to be pretty much the size of an average E-mail message. So, in other words, you are unlikely to run out of inodes before you run out of disk space, since both are going to be used up pretty much at the same clip.
      This doesn't make sense to me, at least not as presented. You are going to run out of inodes at exactly the same time you run out of disk space, because they are one and the same thing. In fact, I believe all the inodes are created when you create your filesystem, all space is mapped to an inode (though of course one file can use multiple inodes).

      The issue is not the waste of inodes, but the waste of diskspace because the smallest file chunk is one inode worth of space. It's usually said that if you have 4k inodes, you'll lost 2k (on average) per file. This is not really correct, because inodes themselves take up space -- I remember reading a paper somewhere many years ago where they estimated that most users would find 4k inodes better than smaller values, because in normal file distributions the space you save with the smaller inode is less than the space of the increased number of inodes themselves. However, this would lead one to believe you should have really big inodes and really big files, and then you'll be very efficient.

      But really, none of this should be given much weight until someone does a statistical analysis of just how inefficient a one-mail-per-file system is. It might not be significant, or it might be insignificant compared to storing base64 messages, or it may be insignificant compared to the benefits of compression. It's bad form to optimize before profiling, and the many-file inefficiency concerns feel like they are more based on intuition and less on fact. But then, someone must have studied it, so maybe not.

  • by zsmooth ( 12005 )
    I believe that UW-IMAP .mbx also includes indexing in the mail file, along with the concurrent access stuff. It's definitely WAY faster than mbox.
  • Oh great (Score:3, Funny)

    by elefantstn ( 195873 ) on Wednesday May 29, 2002 @12:03AM (#3600046)
    If you were to design your own MUA, how would you design its mail storage?


    Now I'll never get to sleep tonight.
  • Check out the Citadel [citadel.org] system. (Disclaimer: I am one of the developers, so my opinion on this is kind of strong.) We use Berkeley DB [sleepycat.com] from Sleepycat Software for the data store. Yes, this is the same Berkeley DB that Sendmail uses to store its alias tables, access tables, etc. But it's capable of so much more than that. It's a robust, non-relational database that is hugely scalable and even has transactions/logging support!

    We store all messages in the database.

    Works like a charm. No pounding through ugly directory hierarchies or insanely long flat files. No need to escape out the word "From" when it appears at the start of a line. None of the cruft.

    Ok, so it's a black box. But it's an open source server that uses an open source database backend, and since it supports SMTP/POP/IMAP plus webmail all by itself, you can still plug your favorite utilities into it (Pine, elm, fetchmail, etc.) and you don't have to graft together Sendmail+IMAP+whatever to make your mail system work.

    The traditional Unix mail utilities are getting a little long in the tooth. I'm going to get flamed for saying this but look at what's happened to the email world: Lotus and Microsoft have run away with most of the market because Unix traditionalists won't give up their flat files. It's time for us to evolve, folks.
  • by Hollins ( 83264 ) on Wednesday May 29, 2002 @12:40AM (#3600175) Homepage
    You're newfangled system better have DRM built in. I don't have any data, but it must be obvious that artists are losing billions in revenues every week due to mp3s being sent as attachments. This criminal behavior must be stopped or the practice of free expression will come to a screeching halt.
  • by buss_error ( 142273 ) on Wednesday May 29, 2002 @12:40AM (#3600176) Homepage Journal

    We have to have the remote hammer to pop out of the monitor to whack the end user. This is a must for any admin that works with more than 300 people. Hammer trigger from e-mail, pager, SMS, or telephone number.

    Power mains must be connected to the user's chair, see above for trigger.

    The MUA must forward all p0rn to the admin account. Likewise with credit card info.

    The MUA must know when the user is about to do something to tick off the admin, like sending a "me too" to everyone in the office, or replying to a confidential e-mail to the whole office and prevent the user from reproducing. X-rays are fine for impromptu sterlizations. The side effect of loosing all your body hair is no problem, as it alerts others to a stupid co-worker.

    The MUA must alert the admin when a coworker he has got the hots for changes her home phone number. Just to be fair, if the the admin is female, the reverse applies.

    The MUA must analyze the admins e-mail and throw a bucket of cold water if (s)he attempts to send a really stupid e-mail.

    Also, the MUA must be able to launch nuclear missles at spammers automatically. After that, it should refer the e-mail to the admin to see if a stronger response is warranted. Better yet, the MUA should employ a time machine to go back and choke the spamming creep when the spammer is still a baby, then use X-rays on the parents as above.

    The MUA should have a hypnotic effect on the object of the Admins desire and cause that person to preform disgusting oral acts on the Admins body each time a new e-mail arrives. (HOORAY FOR KELZ!)

    For the PHB, he should (by the same hypnotic effect) do a "Full Monty" when the big cheese walks in. Twice.

    The MUA should be able to cause back dated confirmation messages from HR approving a 51 week paid vacation upon pressing a special key combination, unless it's the PHB pressing the keys, then it should cause an e-mail to be sent to HR from the PHB's account turning in notice.

    Sorry, if you had a day like mine, you'd need a laugh about now...

  • Maildir? (Score:2, Insightful)

    by Dionysus ( 12737 )
    What is the problem with Maildir? I mean if you're going to store email, might as well use reisterfs. I don't have any problems with big mail boxes, and the extra integrity of the email messages, are worth the (non-noticable) dealy.

    Used to get the mbox corrupted once in a while. Never had problems with Maildir.

  • Databases Ptewey. (Score:3, Insightful)

    by Jason Pollock ( 45537 ) on Wednesday May 29, 2002 @12:46AM (#3600196) Homepage

    The problem with using database formats is that you can't access them with vi. How many times has your mail client crashed attempting to read an email, but you still _need_ to get access to it? If it's in a database (proprietary or not), you're up the creek. If it's stored in a flat file, you at least have the option of using vi/emacs/grep to find and read the email, and then excise it.

    This has happened to me in Netscape, Kmail, Outlook, Evolution, Eudora, etc. Every single one has had problems at one point or another. The best programs are the ones that are _truly_ open, and let you get at the mail from other directions.

    Don't doubt the power of the text utilities in Unix. :)

    Jason Pollock

  • If you store your messages in an usenet server you get all kinds of neat features like auto expiration and tools that can put the binaries together and let the server deal with the file format.

    Back when C-news was new, there was a systems called "Notes" that keep usenet posts in a database. From what I can tell that became the ancestor of lotus notes at some point.
  • by Doktor Memory ( 237313 ) on Wednesday May 29, 2002 @01:37AM (#3600378) Journal
    Maildir: Do you really want to clutter your system with millions of small files? That's waste of inodes, space (unless perhaps you use Linux/ReiserFS or SGi)
    Psssst. It's not 1978 any more. Inodes are cheap. So is disk space. Stop spreading FUD.
    and just try to open a Maildir with 1000+ mails and see how long it takes your favorite Mailprogram to only display the subjects.
    Quite right. Just try it. You might be a bit surprised by the results. [courier-mta.org]
    • An interesting comparison, but its a comparison of Courier-IMAP vs UW IMAP, and not just Maildir vs mbox.

      I once tried benchmarking Maildir vs mbox for my mail archives (mailboxes with ~3000 messages). On ext2 Maildir was a loss:

      • Mutt took twice as long to open a Maildir than mbox from cold cache.
      • Mutt still took a bit longer to open Maildir than mbox from hot cache.
      • On ext2 with 4K blocks mbox ate 13 MB of space, Maildir ate 21 MB.
      • Small UI degradation: Mutt wouldn't show the number of lines in a message from a Maildir, and it wouldn't show percent progress indicator while reading the Maildir.
      Basically for my situation (read-only mail archives with large numbers of messages, which are rarely in filesystem cache, ext2 and constant disk space shortage) mbox was better. But my situation (personal mosty static mail archives) is remarkably different from running IMAP server.

      I did this test in 2000. I should probably try again some day with Reiserfs, but I heard various people telling me it doesn't improve Maildir performance. Can't say anything until I try myself.

      I therefore recommend you to try it yourself and see if Maildirs really help in your situation.

  • by fejjie ( 192392 ) on Wednesday May 29, 2002 @01:44AM (#3600389)
    A couple things:

    1. Evolution is NOT "Basically mbox with database features". It can use Maildir or MH as the backend (and you can write your own plugin to extend this if you like).

    2. Evolution's body indexing and summary files are extremely fast and efficient, about the best you'll get. I hear MySQL has text indexing capabilities that are extremely fast, but I'm not sure if they are faster than Evolution's indexer or not. Might be interesting to check this out.

    3.

    > But the thing that bugs me most is disk space. Typical inboxes are
    > made of 5% to 10% of Text including Headers and HTML. The rest are
    > BASE64- (or UU-) encoded pictures, word documents, zip archives and so
    > on. The problem here is the encoding which wastes considerable amounts
    > of space (at least one third).

    It's theoretically possible, if you wrote your own Evolution storage plugin, to change the Content-Transfer-Encoding header value of binary attachments to "binary" (and text attachments to "8bit") before writing the message out to disk (or wherever) thus magically making it so that you no longer save the encoded text of the attachments but rather in-line binary data content. (Yes, it's as easy as setting an enum value in the CamelMimePart structure).

    However, you have to be aware of the consequences of this. Most importantly, you will not be able to validate any of your PGP/MIME or S/MIME signed messages as according to the RFCs for these types, the signed MIME parts MUST be treated as opaque (meaning that you may not modify them in any way).

    Now on to your ideas...

    > One file per Mailbox-folder, allowing multiple folders per user.
    > Should those files reside in one central location or in users
    > Homedirs?

    How is this different from mbox? (btw, CVS Evolution can handle mbox files and directory trees in external locations - ie, not within the
    ~/evolution directory).

    > Compression: Should messages be broken into pieces and the
    > MIME-attachments stored separately (thus searching of the text parts
    > would still be possible without decompressing the whole file)?

    If you break apart the MIME parts, you run into the same problem I described above about not being able to verify signatures.

    However... if you took a normal mbox and gzipped it, you would certainly save space (at the expense of speed). I've been thinking about writing a CamelMimeFilterGzip class for gzip compresing/decompressing streams which would allow Evolution to read and write to gzipped mbox files for example.

    Once the class is written (which should be fairly simple), allowing Evolution to read gzipped mboxes should be as simple as doing:

    camel_stream_filter_add (MboxStream, GzipFilter);

    ...before feeding 'MboxStream' to the MIME parser.

    > File format: gdbm, Sleepycat db? Something new?

    Please not Sleepycat. If you are so sure that a generic database backend will be better than what Evolution's got, at least have the sense to use MySQL or PostgreSQL.

    I'm personally against using a generic database as a storage and heres why:

    1. The average user does not have an SQL database installed on their desktop systems, and so this is a completely rediculous dependency for them. If you think library dependencies are bad, just wait till you have to go installing, configuring, and maintaining a multi-user database running on your system. This may be fine for a company solution, but not the average end-user.

    2. I'm not too familiar with MySQL or PostgreSQL, but I recall there being problems with mailers that use SQL database backends that tried to store the content of the messages as part of the table (due to them making the size of the table too small or whatever). If you can set the size to be "infinite", then I guess that's not a problem.

    If your plan is just to have the database index the folder and actually store the contents as separate files, then you've instantly gained nothing over Maildir except that now you have a hefty database that you have to maintain and very little to no speed improvements (especially if you have a well designed/implemented summary index like Evolution does).

    The only improvements you might gain here is body indexing? As I said earlier, MySQL supposedly has a REALLY good text indexer and so it might be a little faster than Evolution's. I'm really not sure on the comparison here.

    > Should the security model allow users to directly access their
    > files, grep them, copy them around?

    Is there a reason NOT to? I don't see one. It's their mail.

    > Shared folders, virtual domains?

    This doesn't really have anything to do with folder formats and everything to do with features of the client itself.

    (Evolution can do this).

    > Unicode support in folder names? Imap message-IDs, flags, useragent
    > specific state-information?

    Unicode support in folder names I'd say is a pretty important feature. I'm not sure what you mean by "Imap message-IDs". Do you mean UIDs? Evolution, for example, has a UID assigned for each message whether it be in an mbox folder, Maildir folder, MH folder, or IMAP folder. So this isn't necessarily dependant on folder format (though it could be if you used a database backend for example, you might want a UID in the table).

    I don't feel that UIDs are a must though, but I would suggest them. They are definetely useful especially for folders that can be accessed by multiple clients at once.

    Flags are good. I'd go so far as to say a MUST have.

    As far as user-agent specific state-information, it'd be nice to not need it. But if the client needs to keep it's own info, it'd be nice to be able to map the info to UIDs and keep it's own state file somewhere else (not necessarily alongside of the mail storage).

    For example, IMAP doesn't have any means for the client to store state information on it, but that's perfectly fine. If a client chooses to
    have it's own state, then it can save it locally.

    It would be nice if the storage could handle user-defined flags/tags though. This would allow the client to extend the native features of the format (Flag-for-Followup, message colouring, etc).

    > How would MTAs deliver mail? How would clients access? File-locking
    > (NFS)?

    This is one reason to just stick with what's available :-)

    File locking is a MUST have (or a scheme to make it not needed, such as Maildir).

    --
    You know, I have one simple request...and that is to have messages with freakin' laser beams attached to their headers. Now evidently my MIME specification informs me that that can't be done. Uh, can you remind me what I pay you people for? Honestly, throw me a bone here. What do we have?
  • by jukal ( 523582 )
    I have in some times used a custom made MTA and indexed the incoming mails, headers and first message body part, into MySQL database. Attachments are compressed and stored within "regular filesystem". The whole kludge is then interfaced to IMAP. User authentication is also done via MySQL, thus making it unnecessary to create "real users". The solution has lasted without problems for years now already. MySQL in general, works like a dream, I have never had any problems with it.

    It is good (and fast) for some purposes, which I am not going to discuss here, everyone is probably very well equipped to figure out the plusses and minuses of this way of doing it.
  • by strredwolf ( 532 ) on Wednesday May 29, 2002 @02:03AM (#3600443) Homepage Journal
    Plain and simple. Switch from mail to Usenet. Maildir-like structure, but with a .overview (XOVER) file to help out with indexing.

    Storage is another problem, though... but Usenet messages can be sidetracked a bit with the encoding.
  • Problems & Ideas (Score:4, Informative)

    by Twylite ( 234238 ) <twylite&crypt,co,za> on Wednesday May 29, 2002 @02:53AM (#3600587) Homepage

    Oh dear, another file format debate. I'm glad there was a library suggestion though ... that allows us to change our mind when we do it wrong the first time ;)

    First, you need to consider the possibilitiy of moving the mailbox. To a different computer, or a different platform. This means it must be easy to access in any environment, and the tools must be portable.

    This doesn't completely rule out a database solution (like mySQL), but it certainly makes it less-than-ideal.

    Second, having used many mailers which separate out attachments ... Please Don't Do It! You can't easily move your mailbox, because there are a host of associated attachment files. There is ALWAYS a synchronisation issue between attachments and messages, so you end up scanning and cleaning out the attachment folder every so often to prevent dead files from accumulating.

    Compression is nifty, but isn't really important. Disk space is seldom a concern these days, and the really big stuff (binaries) is often already compressed or don't compress well.

    The real issue with most mailbox formats is how do you deal with the problem of removing dead space from the mailbox? Some program just leave it there until you hit "compact", which is wasteful and confuses users. Others rewrite the entire mailbox every time, which causes the software to "hang" for a while on shutdown.

    The best suggestion I can come up with off the top of my head is this: One file per mailbox folder, and that file is its own filesystem. The "root node" contains a group of summaries (from, to, subject, date, etc) and node links. Other nodes are chained to contain the message and attachments.

    Handling attachments: attachments are separated out and stored as binary in the mailbox. This conserves space but keeps the attachment with the message.

    Compacting: is avoided. When a mail is deleted, it is merely flagged in the root node (index). So each mailbox has its own deleted items folder, so to speak. When the deleted items folder is empties, the index is rewritten and nodes freed - every node not at the end of the file is overwritten with a node from the end of the file (and appropriate reindexing done), so the file is automatically compacted.

    Ideally the file needs some sort of transation logging area to ensure its integrity at all times.

    Shared access to files is best handled through a library or a service. File locking is notoriously prone to bugs and security issues, and avoiding multiple implementations in different mail clients would be beneficial.

  • by martinflack ( 107386 ) on Wednesday May 29, 2002 @03:00AM (#3600602)
    For Pete's sake, leave mail alone. If I can't fix it in less than 20 minutes with grep and perl, I don't want to know about it.

    Divide mail into 20-30 logical "folders" (files), use procmail to help sort/scan/unspam, do IMAP to get to it from Win machines, archive mail out of your working files once it gets a year old, and you're all set. Strive to keep your inbox empty (you need a proper "action" orientation with your mail folders to accommodate this). No big deal.
  • by NotZed ( 19455 ) on Wednesday May 29, 2002 @04:12AM (#3600752)
    I lost the plot half way through this, but here's some food for thought anyway. Now I should get back to work ...

    Z

    I think that this is looking for the solution to a problem that doesn't really exist in the first place. Although I guess it depends somewhat on what you define as 'Unix mail'.

    I'm a developer on Evolution, and primarily on Camel, evolution's email library. I'm not sure i'd rave about it (although I think Camel is a mostly beautiful piece of code ;), but it works reasonably well, and we've had a chance to try and deal with users with lots of email.

    What IS 'Unix mail'?

    I would define Unix mail as mail (rfc822 format) downloaded and stored locally on a per-user basis. IMAP, Exchange, and other remote protocols are very different beasts.

    Why are DBMS's not suitable for 'Unix mail'?

    Once you have a remote server you have to do things differently than if you have local access. Using a DBMS, and having a trained administrator to manage it are practical considerations, as are the benefits you might get from this configuration. These solutions dont really make sense for standalone users. They shouldn't need to install and manage databases, complex backup prodedures, and so forth, just to read their email.

    i.e. rdbms's are:
    hard to setup
    hard to maintain
    another major point of failure

    If however, I was to design a multi-user groupware server, then a DBMS would come into serious consideration - at the backend at least. It allows you do to things like easily consolidate authentication outside of the operating system (the idea of having a 'shell account' to access mail is somewhat outdated), it allows you to save space by storing common data, like attachments and email content in a single place, and redirecting it to multiple recipients (which is a common practice within organisations). It may be practical to use a mixture, a RDBMS to store textual parts or indices to data stored in a more conventional filesystem.

    But even with a RDBMS backend, I would personally probably still stick to IMAP to serve it to actual clients. The IMAP protocol is a bit heavy, but not really that bad, and it serves email, I dont think there's really any need to reinvent the wheel here.

    So ...

    If you define unix mail as I have, and separate it from a *mail server*, then you rule out full blown RDBMS's, and are left with:

    single file database
    multiple file database

    I'm not even going to mention XML because I think it is the single most stupid idea anyone's come up with. It is completely unsuitable for this purpose.

    And well, there's really no reason not to use MIME to store the messages. MIME already does everything you can possibly do with email (since, uh, it is how the email *will* be sent), any client will already have to deal with it, and mime decoding is for the most part really quite simple and fast anyway. Translating the mime format into some other storage format really doesn't make sense.

    single file databases

    mbox

    Mbox is a single file database. Its just that everyone that uses it generally writes their own access code. This is where problems with 'locking' come about, either because the underlying filesystem doesn't support it properly (e.g. some nfs implementations), or everyones clients don't use the same locking mechanism. This really just an implementation issue anyway. There would be nothing to stop someone writing a common 'mbox.db' library that stored everything in completely compatible mbox files, which took all the work out of it, and then you'd have an mbox DBMS ...

    mbox scales ok, without any caching of header information it handles in the order of 2K messages in an interactive timescale, and quite a lot more if you dont mind some short delays (i.e. in the order of the time it takes mozilla to start up).

    Appending and reading is quick, and reliable - assuming the filesystem works, which is a pretty safe assumption to make. This is assuming the mailbox is first summarised at first opening, otherwise looking up messages can be slow, because you have to scan the whole file first.

    The only operation that is slow is expunging messages, and at worst case isn't really any slower than copying a whole file across to another file.

    The only other issue is agreement on the 'standard' for what constitutes an mbox file. For example. Solaris uses and honours the 'Content-Length' header, and thus it does not translate any lines beggining with "From " into the conventional ">From ". Some mail clients translate "(>*)From " into ">\1From " (using sed syntax) and visa versa, others do not. There is no standard, just some conventions, some of which aren't easy to determine either.

    Because you need to keep the whole index in memory at once, this can become expensive, but you could use a secondary database as an index into the real file. But eventually you hit a point where the cost of expunging does get too expensive. You could just archive the mail regularly, or use a format like maildir instead.

    gdbm/db/etc

    db files wrap the single file in a common api that handles all of the locking issues and access issues for you. Some have different features, e.g. querying capability, logging and transactions, etc.

    We've never tried to use db for this purpose, more just because we didn't think it was worth it. All you really get with a minimal implementation is the ability to store and retrieve a blob of data using a single key. Writing is fairly slow because the database has to manage more details for you (locking, allocating blocks, unlocking, etc). You could use multiple db files as indices to perform multiple-key searches, but they are quite slow at creating them (we tried using db for the content indices and it was way too slow).

    i.e. even if you store the data in a db file, which gives you a slight benefit of inbuilt referential integrity, you still need to provide additional indices to actually be able to use it in any useful way. Evolution suffers this problem with the addressbook which stores vCards in db records.

    Most db libraries (all?) also dont provide any mechanism to stream data. You either get the whole lot into memory, or you get none of it. So for large messages you're limited by memory (well, evolution is anyway, but it doesn't have to be). Yes, memory is cheap, but it is still a consideration, and it would certainly rule out a simple database in a multi-user environment.

    db files are also slower than native files, especially for large objects. You're mapping an arbitrarily sized chunk of data to some 'database blocks', which are then stored in an arbitrarily sized 'database file' which the operating system is then mapping to its 'filesystem blocks'.

    multifile solutions

    Well I guess this comes down to mh and maildir. mh isn't really suitable for anything, because of its just plain bad design and lack of defined semantics. There's no way to guarantee anything about its operation.

    maildir - i like. It moves the scourge of trying to implement a reliably, scalable, multiple access database almost entirely into the operating system layer. Operating systems already do this very well - they manage hundreds of thousands of files randomly written across your disks, without skipping a beat.

    No operation requires more than a single message size of data, and the operating system already indexes the message, via its filename. Sure, ext2 doesn't do such a swell job with long directories, but that can be addressed (and the same problem can be addressed on just about any platform). For 'free' you get concurrent multiple-reader, multiple-writer database access, without any of the considerable problems you have to solve to implement it otherwise.

    The maildir 'protocol' is simple, reliable, and it works.

    Again, it can easily be augmented by a client with additional indices, but for things like delivery agents who dont care about existing email, they dont need to suffer that overhead at all.

    Some other comments specific to the question:

    Compression. Personally I dont see the point. But a maildir-like structure would fit well with compression. Flat files would be the worst (e.g. mbox), and block-file formats (like db files) would also work well with compression. The good thing about email is it is 'write once', you don't edit or change the messages in the mailbox.

    External attachments. I guess its possible, but again, it isn't really worth it in most cases. Parsing MIME is *fast*. It is much faster than parsing xml, and besides, people rarely look at an email more than once or twice. There isn't much use going off and storing the attachment in a high-performance reading format if it isn't going to be accessed often, and it just places a greater burden on your server.

    base64, etc. Well, its entirely possible simply to store the messages as 'binary' format. Assuming the boundary markers are checked properly, Camel can work with binary encoded mail messages, and probably at least some other mail clients can too. There are some problems with some of the extremely broken openpgp/pgp/mime specs which suddenly say that mail transports aren't allowed to alter the *transport* encodings of some parts, but well, these specs are just braindead, and can be worked around.

    Security model. Well, talking about Unix mail, not server mail, the filesystem is adequate.

    Shared folders - is not an issue for unix mail.

    Unicode. Well you can write unicode filenames to most unix filesystems, evne if 'ls' doesn't show it right.

    MTA. Nothing could be simpler or safer than maildir as a delivery format. The mta doesn't have to care about any client-side indices, the mua will simply update them when it incorporates the new messages, etc.

    Writing libmailstore? Mate, its called Camel, and its already written. Camel already does mbox, maildir, mh, it can read spool files directly (it doesn't create a summary file or build any indexes), it can talk imap, pop, and partial support for nntp. If someone gave me a decent RDBMS table schema and a carton of pale, I could probably write a MySQL backend in a couple of days, well, assuming the MySQL api is mt-safe.

    Finally, some comments on evolution.

    Evolution isn't reinventing any wheel. We use standard mbox format (if such a thing really exists anyway). We use standard maildir format, etc. Yes we may optionally create body indices, and we do usually create on-disk binary/compressed 'summaries' of the data, but these are really just on-disk caches of in-memory data structures, rather than anything to do with the mail storage format.

    We put mail in another location, but everyone else has done that too, elm:Mail, pine:mail (or is it the other way around?), netscape:ns_mail, etc. At least we now offer the option to read most of this 'in place'.

    The main problems evolution has with scalability is:

    indexing.

    Indexing is quite costly. The original index code was written somewhat like a database, it handled all internal data structures, used blocks of data, etc. It was slow, it scaled poorly. Definetly some of the algorithm choices and the implementation wasn't that hot, but it shows that such a solution isn't as simple as at first thought. Using libdb was impossibly slow (like several orders of magnitude slower).

    The new stuff is a lot better, but can still use a lot of resources while indexing, and copies the whole file (well 2 files) across when performing expunges, but they are only performed occasionally, and the indices are smaller than the original indices, so in practice it scales much much better.

    the summaries

    The summaries are indices of a sort anyway. They are an in-memory tree of a subset of the information on each message. Enough information to display a list of messages, and perform vfoldering operations. Even though we do some tricks, like sharing common strings, the summary can get very large.

    But, its a tradeoff I thought was worth it, rather than using on-disk summaries. The api's are much easier to use, and the problem gets pushed to the user - if they want to have folders with 100K messages, they should expect it to use a bit of memory. The on-disk size of the summaries is very small too, although I guess it could be made even smaller if we consolidated common strings.

    per-message memory use

    Currently, a lot of data gets copied around in memory. Every time you read a message, at least 1 whole copy of the (decoded) message is in memory at a given time (yes, including attachments). For IMAP this can get even worse (2-3 copies of a given attachment at a given time), because it doesn't stream enough. Most of this could use a disk-backing without changing any api's though, and well, i'm rewriting IMAP.

    Wrapping up ...

    And yeah, we're talking 100K messages here, not 1400. My 500Mhz celeron laptop has about 35K messages stored over about 10 mbox files, and it starts up in under 10 seconds, and that includes all of the bonobo/activation overhead (which is very significant). Yeah it uses a bit of memory, but memory is cheap on a personal workstation.

    In short. The current mailbox formats we have suffice for "Unix mail". Add some archiving abilities to your mail client (even RDBMS backed mail clients need archiving), and you'll never have to delete a message again, and still get work done and still use mbox.

    If you want to talk about writing a server - well who cares, you can do whatever you want, because everyone has to go through your interface anyway (you DO NOT want clients accessing data under you, thats what DBMS's are all about in the first place ... and you dont want 1-tier applications), so it doesn't matter what format you use under the belt - you can choose the format which best suits what you're trying to do.

    It seems some people think using 1-tier applications (client code talking directly to a database) are the way to go for multi-user environments. They're not, they dont scale and are impossible to maintain. Nobody writes any real software like that anymore, unless you're writing dodgey vb toy apps.

  • Some thoughts (Score:3, Interesting)

    by ChrisJones ( 23624 ) <`cmsj-slashdot' `at' `tenshu.net'> on Wednesday May 29, 2002 @04:33AM (#3600790) Homepage Journal
    There seem to be two discussions going on in the comments today, one about mail storage for an MUA and one for storing mail on servers.
    As far as the client end is concerned, from the point of view of writing an MUA, having an SQL backend is a complete godsend because you have to write virtually no IO code, you can put all the logic in the queries. However, there are some tricks you need to use to keep up the speed, most importantly to use two tables, one for metadata and one for the mails themselves. This keeps the speed up by keeping the metadata table small (maybe on a better RDBMS than MySQL this wouldn't make a difference, but I found that >10,000 mails all in a single table in MySQL got quite slow until I moved the metadata into a seperate table).
    The obvious downside of using a DB for client end storage is that you have to have a centreal DB server, or one on each client and you need to admin one more set of authentication/permission details, plus you can't move the mail very easily to other MUAs. IMO a much better solution would be to keep the use of SQL/RDBMS, but move the DB into the filesystem so you can just have a bunch of files with metadata stored in the fs. Need to make an mbox? "cat ~/mail/* >>/tmp/my_new_mbox".
    From the server point of view, many people have been mentioning Exchange/Domino etc. Personally I can't stand Exchange, I've had to admin it on several occasions and it's generally done everything it can to stop me from having an easy life (just thought I'd air my predjudice against Exchange in the spirit of fairness and honesty ;) I've never used OpenMail/Domino/Notes/whatever, but I guess they do roughly the same thing, which is a pretty good idea. However, these things all have the distinct disadvantage that they use propritary protocols and aren't particularly cheap. There's always IMAP, which many people really like, but I feel is too complex a protocol (compare with the infant levels of complexity in POP3).

    With a colleague of mine, I'm working on a set of POP3 extensions that give some IMAP like features, but is really designed to keep multiple mail clients in sync with each other by way of a transaction log. There are still some limitations, but I think I know what they are and how to fix them (e.g. not enough metadata can be associated with each mail yet). It adds about 6 or 7 commands to POP3 and currently lacks any decent client support, but I have written a fairly usable library and patch to gnu-pop3d for it. I've just submitted it as my University final year project, so I'll try and get the protocol description documentation online soon. In the mean time, if you're interested, it's on SourceForge [sf.net]
  • by speedenator ( 83485 ) on Wednesday May 29, 2002 @04:43AM (#3600808)
    So NNTP solved this IMHO a rather elegant way...

    You have directories corresponding to newsgroups or mail folders or whatnot. i.e. alt.swedish.chef.bork.bork.bork is really alt/swedish/chef/bork/bork/bork

    Articles are numeric, i.e. \d+ for Perl types. The raw message is stored in each file.

    In each directory, there's a file called .overview, which is just the summary information for all the files.

    Thus, you can have zillions of small files, and happily grep and copy them to your heart's content. But you never do a 'ls' on a huge directory, you always just look through the .overview file. Or grep through it, if you like.

    So, in that sense, it's very much the best of both worlds. And, on the same box, you can specify rules on who can access the folders, so one file can be read by multiple people. Ooh.

    GNUS, an Emacs based mail/news reader, uses a variant of this called nnml, which rocks.

    Of course, when you get down to it, JWZ arguments aside, databases start to really look like what you want, especially on a corporate level when you're tossing the same piece of mail around to tons of different folks.

    -e
  • by ellem ( 147712 ) <ellem52.gmail@com> on Wednesday May 29, 2002 @05:46AM (#3600902) Homepage Journal
    Are you trying to tell me that a 5MB empty mailbox is asking too much? A text message that says "Hi!" costing 1.2MB is somehow wasteful?

    Lotus Notes Uber Alles!
  • the plan 9 approach (Score:5, Interesting)

    by rpeppe ( 198035 ) on Wednesday May 29, 2002 @07:23AM (#3601060)
    as a basis for an approach i like what plan 9 [bell-labs.com] does. the mail is made available to clients as a filesystem (provided by a user level program). each mail message gets its own directory; each mime attachment gets its own subdirectory within that message (and recursively, as MIME is recursive).

    here's a little transcript:

    % cd /mail/fs/mbox
    % lc
    Directories:
    1 113 128 142 157 171 186 20 214 229 243 258 272 287 300 315 33 344 359 373 388 401 416 430 445 46 474 56 70 85
    [...]
    % cd 318
    % lc
    Files:
    bcc date filename info messageid rawbody sender type body digest from inreplyto mimeheader rawheader subject unixheader cc disposition header lines raw replyto to

    Directories:
    1 2 3
    % head raw
    Return-Path:
    Received: from punt-1.mail.demon.net by mailstore for rog@vitanuova.com
    id 1021665470:10:17045:138; Fri, 17 May 2002 19:57:50 GMT
    Received: from psuvax1.cse.psu.edu ([130.203.4.6]) by punt-1.mail.demon.net
    id aa1016828; 17 May 2002 19:57 GMT
    Received: from psuvax1.cse.psu.edu (psuvax1.cse.psu.edu [130.203.6.6])
    by mail.cse.psu.edu (CSE Mail Server) with ESMTP
    id 27DA4199BE; Fri, 17 May 2002 15:57:13 -0400 (EDT)
    Delivered-To: 9fans@cse.psu.edu
    Received: from acl.lanl.gov (plan9.acl.lanl.gov [128.165.147.177])
    % head body
    This is a multi-part message in MIME format.
    --upas-mbyuptynpdsmbjuyeermihdgur
    Content-Disposition: inline
    Content-Type: text/plain; charset="US-ASCII"
    Content-Transfer-Encoding: 7bit

    Hi,

    If you seek excitement and thrills you need to look no further than
    Plan9 -- it gives you everything and then some, but in a good way (or
    % cd 2
    % lc
    Files:
    bcc date filename info messageid rawbody sender type
    body digest from inreplyto mimeheader rawheader subject unixheader
    cc disposition header lines raw replyto to
    % cat mimeheader
    Content-Type: image/jpeg
    Content-Disposition: attachment; filename=iostats.jpg
    Content-Transfer-Encoding: base64
    % page body
    reading through graphics...
    %
    "raw" contains the raw data that makes up the message. "body" contains the data after the encoding formats have been applied (hence in that case /mail/fs/mbox/318/2/body is a jpeg file, viewable directly by any usual jpeg viewer).

    the beauty of this scheme is that it hides the underlying storage scheme from the mail clients. if i wish to change things so that the underlying storage format is many files [currently it uses a traditional mbox format], none of the mail client programs have to change.

    plus i can use grep, diff, shell scripts, etc directly on the messages in my mailbox. procmail eat your heart out.

    • by glv ( 31611 ) on Wednesday May 29, 2002 @08:06AM (#3601151) Homepage
      You alluded to this, but I know slashdot, and it's worth being explicit about it to avoid all the flames:

      This is not how mail is actually stored on disk in Plan 9. The "real" mail storage is just mbox files. What rpeppe has described is the view that the mail storage system provides to clients.

      I agree it's very sweet, but the question is primarily dealing with the actual storage format.

  • by mellon ( 7048 ) on Wednesday May 29, 2002 @02:01PM (#3603223) Homepage
    I don't think it makes sense to store email in dbm files. It's too sketchy - what happens when the dbm file gets corrupted? The nice thing about flat files is that if something goes wrong, you can fix it with vi.

    I think the right solution to the problem is to key off the message ID, which is supposed to be unique. Then define a mail folder as simply a list of message IDs. Messages can appear in more than one folder, but hopefully not in no folders.

    To make this efficient, I'd hash the message ID, and use a hierarchy of directories, because Unix doesn't do well with large flat directories. The hierarchy could auto-extend, so that as one subdirectory fills up, you do a sub-hash and split it into more directories.

    The problem of tiny files is a real one. The solution is probably to make the bottom of a hash a file rather than a directory, and store more than one message in each such file. You don't have to store a lot of messages in these files to win - even ten messages would produce a big win, and would be pretty efficient.

    The format of the individual files should probably be indexed sequential access - that is, a TOC at the front, and then the contents as plain text, nothing fancy. The TOC should be in ASCII, not binary, and you should be able to rebuild the TOC by looking at the file.

    Babyl used to use a control character as a delimiter, which worked pretty nicely - much better than using "^From ". Ever seen >From in an email message? That's because Unix mail uses "^From " as an inter-message delimiter, so it has to quote it, and it does so stupidly. So use ^_ as a delimiter, and if ^_ appears in the email message, just double it. Take a doubled ^_ out when reading a message.

    As for compression, I don't think it's worth doing at first. Disk space is cheap. Yes, my email folder is pretty huge, but it's really not a major problem. Making the storage system extra-complicated by uncompressing MIME is something to add on after you've got something more basic that works - you don't have to solve every problem all at once.

    As for folder scan performance, you can make a cache, and have the mail program scan the cache from time to time when it's idle to clean up errors. This is much better than trying to come up with a format that's optimized toward folders - if you try to optimize toward folders, you wind up creating all kinds of problems, IMHO.

For God's sake, stop researching for a while and begin to think!

Working...