Thursday, February 14, 2008

Fun of implementing a IMAP server (part 1)

IMAP is beautiful. Long time ago I don't like IMAP, I think it is bulky and slow. However after a couple of HD reformats (when I was young that comes often), the advantage of IMAP is obvious. All mails are on the server, no need to restore email after a reformat.

So after we moved our wonderful linux server to windows (well, the only reason is to run sqlserver on it so I don't need to let wife start her computer when I need the sql server),
I am having a hard time to find a simple IMAP server.
There are a lot on linux (I like dovcot) that works very well, but on windows is a different story.
The default windows IMAP server is Exchange, which is bulky and needs Active Directory?!! Forget that.

I am using cygwin with uwimap and exim. They are OK, the only problem is my wife keep complaining about some of her deleted mails coming back. And I don't like the mail stores, it is mbox format, big and hard to maintain.

So I wanted to implement my own IMAP server for sometime now (only need a easy to use one), haven't started on it till recently.

The first thing to do is find out the IMAP protocol. Plenty on the internet.
Then implement the easy ones, login, select... No problem.
Then comes the UID ones (FETCH/STORE), that was some job. It took me a while to figure out what you are supposed to return on RFC822.HEADER. I used to return everything.
Up till then it is always using a mock store. I decided to use my own mail store format. Files! I don't want to involve a database server.
My mail formats are: each email is in the format of eml_[uid].eml. And tags stored as eml_[uid].eml.[tag$]+.tag, for example eml_112.eml.Seen$Deleted.tag
This way the emails are easy to backup, and save me a lot of extra indexing work.

A simple SmtpServer is also needed. I wanted to use Microsoft's default one, but that one is not suitable, sometimes it locks the files in directories and I can't move them.

There are quit some bumps doing this, I will add them in when remembered.

No comments: