I had a play with installing the RoundCube webmail system on my server yesterday and was pretty impressed. It does seem to do what it says on the tin and act as a AJAX-y web front end to an IMAP server.
This encouraged me to place my web developer hat[0] upon my head and have a ponder. “Surely JavaScript » Some XML-y RPC » PHP » IMAP » My Mail and the associated return path is somehow sub-optimal, requiring, as it does, two separate servers on my email hosting box”, says I to myself. “Not to mention the overhead of said box talking IMAP to itself!” I added.
Astonished that such a sentence could emerge from my mouth, abusing, as it does, a French punctuation symbol, I started Googling around for an IMAP-like protocol which was more RESTful. Perhaps I should explain at this point that RESTful is the Web 2.0 buzzword du jour for ’sensible API for accessing stuff over the web, innit’. The Big Idea I had was making the mail reader truly just a hunk of HTML + JavaScript which could access the mail directly.
I failed to find such a (public) API. Do please link in comments if my Googling was insufficient.
Then I stumbled upon a description of the Maildir on-disk mailbox format which my IMAP server was getting all the mail from and it struck me that, actually, the Maildir format itself is RESTful. It certainly ticks many REST boxes:
- Authentication is devolved to some higher power. In REST APIs this is generally some HMAC sent with the request or using the Auth mechanism built into HTTP. With Maildir, any authentication/permissions/etc are handled by the filesystem/OS.
- Data are organised as resources. Each email is a file with an unique ID located by a semantically valid resource locater (i.e. a folder subdirectory in Maildir++ boxes).
- It is stateless. Maildirs were designed to allow stateless, lock-free[1] concurrent access. Just what a RESTful API craves.
This set me wondering. Assuming I have some appropriately cunning Apache config which lets me access my Maildir via WebDAV under something like http://example.com/~user/mail/…, would this be sufficient to write a mail reader[2] entirely in HTML + JavaScript? I am far to busy to actually investigate this myself but the idea is almost irresistible to my mind.
[0] A funky little beret naturally!
[1] Well, locking handled by the file system anyhow. It has been pointed out that there are some conditions where Maildirs are not the panacea they appear in this regard but for the purposes of this discussion I’ll stick my fingers in my ears about it.
[2] Reading. i.e. without the actual sending mail part.
Update: So it appears that one of the protocols Exchange and Outlook speak for exchanging emails is WebDAV. Great minds…