MBOX-Line: From mrc+imap at panda.com  Mon May  2 15:36:41 2011
To: imap-protocol@u.washington.edu
From: Mark Crispin <mrc+imap@panda.com>
Date: Fri Jun  8 12:34:45 2018
Subject: [Imap-protocol] Looking for help implementing an IMAP-to-HTTP
	gateway for web app developers
In-Reply-To: <7D2A9AA5-CC8F-4C8A-A917-4E242E7BCE12@gmail.com>
References: <7D2A9AA5-CC8F-4C8A-A917-4E242E7BCE12@gmail.com>
Message-ID: <alpine.OSX.2.00.1105021449030.870@hsinghsing.panda.com>

Hi Brian -

There is a fundamental problem in your design: IMAP is stateful whereas
HTTP is stateless.  It is therefore quite difficult to layer IMAP on top
of HTTP.

The opposite (HTTP on top of IMAP) is quite a bit easier; but in general
will perform rather poorly unless you have some sort of state-keeper at
the HTTP/IMAP boundary so that you don't re-establish IMAP state per HTTP
operation.

Here's the problem:

Once IMAP has announced something about a mailbox, that something may not
change on the server unless an update is announced via IMAP.  This
specifically refers to: messages being added to the mailbox, messages
being removed from the mailbox, and the state of flags of any message in
the mailbox.

Somehow, you must keep all the state that IMAP needs, and ensure that the
proper state updates are passed at the IMAP-HTTP gateway to IMAP.

This is not an impossible task; it is just a quite difficult one.  The
first part of it will make your programmer bang his head relentlessly
against a wall and tell you that he hates you.

We have layered IMAP on top of a (different) stateless protocol.  The only
practical solution was a secret command argument in the stateless protocol
that makes it stateful; that is, the protocol is stateless to everybody
except for IMAP.  The secret argument makes the TCP/IP connection immortal
and binds the thread and underlying stream to that connection.
Fortunately, we are also the only consumers of that protocol, thus we
don't have to worry about the secret being abused.

That solution won't work too well with HTTP, especially as you probably
don't have the HTTP server under your control.  But, you have to make
essentially the same thing happen at your IMAP-HTTP gateway.  That will be
the head-against-wall banger, since the HTTP server will see no reason to
tell the HTTP consumer (your IMAP-HTTP gateway) of changes that must be
transmitted in IMAP state.  So your IMAP-HTTP gateway not only has to keep
state, it has to pull the necessary updates from the HTTP server.

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.

