Add credits for Marek
[trojita.git] / docs / masters / mobile-imap.tex
blob1895cfc2fff3e24ddbb0a1b621b3e275297d27d9
1 % vim: spelllang=en spell textwidth=120
2 \documentclass[trojita]{subfiles}
4 \begin{document}
6 \chapter{The Mobile IMAP}
7 \label{sec:mobile-imap}
9 Many of the existing IMAP extensions discussed in \secref{sec:imap-extensions} have the potential of improving the
10 client's operation tremendously. At the same time, experience has shown that there is a certain chicken-and-egg problem
11 with new proposals where server vendors are not willing to invest their time into promising extensions which no client
12 supports yet and clients are not interested in implementing extensions which they cannot test for interoperability. In
13 this chapter, I am trying to provide a concise summary of individual merit of these extensions.
15 \section{The Lemonade Profile}
16 \label{sec:lemonade-comparison}
18 The Lemonade profile, as defined in RFC 4550 \cite{rfc4550} in 2006 and later updated through RFC 5550 \cite{rfc5550}
19 during 2009, provides a list of extensions considered ``critical'' for any mobile IMAP e-mail client. The set of
20 mandatory extensions is rather big, though, and to the best of my knowledge, there is {\em no} server on the market
21 implementing all of the compulsory features. One might therefore wonder what were the reasons for this lack of general
22 availability of the Lemonade extension family.
24 \subsection{Cross-Service Requirements}
26 One unique feature of Lemonade is the possibility to {\em forward messages without their prior download}. The three
27 ESMTP~\cite{rfc5321} and IMAP extensions, often referred to as the {\em Lemonade trio}, namely the {\tt CATENATE}, {\tt
28 URLAUTH} and {\tt BURL}, allow the clients to compose a message using existing parts available from the IMAP mail store,
29 provide a way of generating single-purpose ``pawn tickets'' for making the composed messages available to the submission
30 server, and replacing the {\tt DATA} SMTP command with a way of downloading the message from the IMAP server,
31 respectively. This feature prevents having to transfer potentially huge data over the network three times --- once when
32 the users wants to read it, second time when the message is saved to the sent folder, and finally when delivering via
33 SMTP.
35 Unfortunately, a big problem with said approach is the fact that it mandates collaboration across different services ---
36 an explicit trust path between the IMAP and ESMTP servers have to be set up, which is a process prone to errors
37 \cite{qmf-fastmail-burl-bug}. This matter is also complicated by the fact that no open source MTA~\footnote{Mail
38 Transfer Agent, typically an SMTP or ESMTP server} ships with official support for {\tt BURL}.~\footnote{Unofficial
39 patches exists for Postfix dating back to 2010 \cite{apple-postfix-burl}, but they have not been integrated into the
40 mainline version as of July 2012 (the {\tt postfix-2.10-20120715.tar.gz} development snapshot.} Situation is better on
41 the IMAP server front with Cyrus supporting the {\tt URLAUTH} and {\tt CATENATE} extensions out-of-box with Dovecot's
42 support scheduled for its upcoming 2.2 release \cite{imap-server-extension-matrix}.
44 \subsection{Complicated Extensions}
46 Some of the extensions whose support is mandated by the Lemonade proposal seems to be notoriously hard for the server
47 vendors to implement.
49 A perfect example is the {\tt CONTEXT=SORT} extension \cite{rfc5267}. As a client developer, I recognize its extreme
50 usefulness and appreciate its design. Availability of such an extension would make it extremely easy to implement
51 live-updated sorting in my Trojitá (and Trojitá {\em does} make use of the sort context extension). That said, given
52 that no IMAP server which I am aware of announces its availability, clients have to deal with the status quo in the
53 meanwhile.
55 The {\tt CONVERT} extension \cite{rfc5259} belongs to a similar category --- the features it offers, like the
56 server-side downscaling of JPEG images, would be {\em very} handy on a cell phone, yet no IMAP server known to the
57 author includes that functionality.
59 Both of these RFCs were published four and five years ago, respectively, and were designed by engineers working for an
60 IMAP server vendor. One cannot therefore dismiss them altogether as a product of people not having any say in the
61 server development. My opinion is that the allocation of engineering resources required for shipping a particular
62 feature in a finished product is based on another criteria than the research activity.
64 \section{State of Other Client Implementations}
66 To obtain a better understanding on how the existing solutions available on the market today use IMAP, this section
67 takes a look at some of the most popular solutions.
69 \subsection{Apple iOS}
71 Apple's devices generally ship with a decent implementation of their IMAP stack, an evaluation shared by independent
72 researchers \cite{isode-iphone4}. The list of extensions supported by the application includes {\tt CONDSTORE} and {\tt
73 ESEARCH} for improved mailbox synchronization, {\tt COMPRESS} for transparent deflate compression and {\tt BURL} for the
74 forward-without download.
76 It is, however, surprising that their support of extensions aimed at making mailbox resynchronization more efficient
77 does not include the {\tt QRESYNC} extension \cite{rfc5162}, especially given that its implementation does not impose
78 much in terms of additional requirements on top the already-supported {\tt CONDSTORE}.
80 The iOS also notably does not use the {\tt IDLE} command at all. The reason, according to a message allegedly sent by
81 Steve Jobs \cite{jobs-ios-idle}, is that is is {\em ``a power hungry standard''}. Systematic measurements
82 \cite{wcdma-energy} \cite{cridland-fach-dch-measurements} and experience alike~\footnote{Mark Crispin's famous {\em ``I
83 have built on-demand networks which shut down until signaled back on, and then happily resumed all the active TCP
84 sessions even though the "network connection" had been powered off for days.''} \cite{crispin-no-ifup}.} shows, however,
85 that the mere act of having a TCP connection open with an occasional keep alive ``pings'' being transfered have no
86 significant impact on battery life on other platforms.
88 \subsection{Android's Native E-mail Client}
90 There is not much to be said about Android's native client's IMAP performance --- the stock client does not offer push
91 notification through {\tt IDLE} \cite{android-idle} and the list of extension identifiers referenced from the
92 application's source~\footnote{File \path{src/com/android/email/mail/store/ImapConnection.java} from Android's
93 \path{platform/packages/apps/Email} repository as of the {\tt android-4.1.1\_r3-35-g01c55fd} revision.} only references
94 the {\tt NAMESPACE}, {\tt UIDPLUS} and {\tt STARTTLS} capabilities. None of the extensions which try to improve
95 synchronization performance (the {\tt ESEARCH}, {\tt CONDSTORE} and {\tt QRESYNC}) are available. No provisions for
96 Lemonade's family are present at all. The {\tt LITERAL+}, an extension which takes literally no effort for clients to
97 support and removes one network round trip when uploading messages, is not supported.
99 Further analysis shows that the code is blocking and incapable of issuing or processing requests in parallel. These
100 observations are consistent with what users generally describe as a ``slow'' experience. This might not come surprising
101 given that Google would likely prefer its users to choose Google's own e-mail offering, the GMail, over various private
102 IMAP accounts for business reasons.
104 \subsection{Android's K-9 Mail}
106 The Android's K-9 mail~\cite{k9mail} is a fork of the original e-mail application from Google. The developers have
107 managed to add support for two extensions, namely the {\tt IDLE} and the {\tt COMPRESS=DEFLATE}. More advanced features
108 like the {\tt ESEARCH} / {\tt CONDSTORE} / {\tt QRESYNC} are however still missing.
110 Furthermore, comments like {\em ``TODO Need to start keeping track of UIDVALIDITY''}~\footnote{File
111 \path{src/com/fsck/k9/mail/store/ImapStore.java}, line 103 as of the Git revision {\tt 3.512-1249-g5ce0e19} of the K-9's
112 source code repository.} might make one feel nervous about the safety of the data being accessed.
114 \subsection{Modest / Tinymail}
116 The several years old Nokia N900 shipped with a mail client called Modest, an application based on top of the Tinymail
117 framework~\cite{tinymail}. The underlying library supports an efficient mailbox synchronization through {\tt QRESYNC}
118 and the sources contain a reference to the {\tt CONVERT} extension --- however, this functionality appears to be limited
119 and in an early state. The ``Lemonade trio'' for forwarding without download is not supported.
121 The code is written using the synchronous idioms. No support for command pipelining is present.
123 \subsection{Nokia's Qt Messaging Framework}
125 Nokia's Qt Messaging Framework~\cite{qmf} powers the e-mail functionality in the MeeGo Harmattan line of phones, the N9
126 and the N950. Support for extensions appears to be rich --- the Lemonade trio is supported in its
127 entirety,~\footnote{An interesting detail is that the {\tt BURL} extension is disabled if the account is configured to
128 use IMAP over an SSL port instead of the {\tt STARTTLS}; this is caused by a deficiency in the IMAP-URL standard
129 \cite{rfc5092}.} as well as are the {\tt COMPRESS=DEFLATE}, {\tt BINARY}, {\tt IDLE}, {\tt CHILDREN} and many others.
131 The underlying IMAP library exhibits regular ``batched synchronization'' mode of operation; connections to mailboxes are
132 typically not left alone for long, but the code makes aggressive use of the {\tt QRESYNC} extension to benefit from
133 extremely cheap mailbox synchronization. Code is written with memory-constrained devices in mind, care is taken to
134 prevent data copying if possible. The general behavior focuses on making the specified subset of messages always
135 available on device --- there is no support for server-side threading or sorting, but some form of a server-side search
136 {\em is} available. Live updates through {\tt CONTEXT=SEARCH} are not employed. Support for the {\tt LIST-STATUS} is
137 not available.
139 An interesting extension which is supported by the QMF is Google's {\tt XLIST} \cite{gmail-xlist} extension. However,
140 the code~\footnote{File \path{src/plugins/messageservices/imap/imapprotocol.cpp} as of QMF's Git revision {\tt
141 2011W26\_2-263-gec26531}.} appears to only use the {\tt \\Inbox} mailbox flag for forcing case-insensitive mailbox
142 comparison, a mechanism already mandated by the baseline IMAP protocol \cite[p. 17]{rfc3501}.
144 All in all, the Qt Messaging Framework is a promising library with support for other protocols besides IMAP. Its IMAP
145 implementation feels solid and is reasonably well covered by the unit tests.
147 \subsection{Trojitá}
149 Trojitá~\cite{trojita-website} is an advanced IMAP client which includes support for many different extensions from the
150 basic ones like {\tt IDLE}, {\tt LITERAL+} or the {\tt ID} extension to the complex ones like the Lemonade trio or the
151 {\tt ESEARCH} / {\tt CONDSTORE} / {\tt QRESYNC} triplet. Trojitá can scale up to company-wide ERP-level e-mail
152 processing (Appendix \ref{sec:xtuple}, p. \pageref{sec:xtuple}) while still using the same code base of
153 the underlying IMAP library as the desktop and cell phone version.
155 \section{Evaluating Extensions}
157 As the previous section shows, the level of support for various extensions and their real-world deployment varies
158 wildly. Many today's clients are using only a limited subset of features which are generally available, leaving
159 opportunities for new applications entering the market to offer smoother, more efficient user experience.
161 Previous efforts aimed at standardizing a set of extensions to serve as a ``mobile profile'' of IMAP have not delivered
162 a universally acceptable result. Lemonade, a specification universally considered to be {\em the} specification to go
163 when evaluating clients and servers alike \cite{isode-lemonade}, mandates a set of extensions which --- to the best of
164 my knowledge --- is not available on any single IMAP server in its entirety. Furthermore, the clients do not even
165 attempt to use these extensions, probably due to not being able to verify them for interoperability and because of
166 concerns about shipping something which could very well be considered a dead code.
168 The rest of this chapter tries to look at the available extensions through the optics of a client developer who is
169 trying to push the IMAP server developers slightly, but not too much --- pushing forward is crucial in attaining a
170 sustainable development, yet applying too much pressure often leads to the whole movement getting stuck on a first
171 obstacle. I make a few assumptions about the features which the client support; most notably, the client should have a
172 persistent cache to store already downloaded data. The client is also expected to serve a human user who will work with
173 the application for many days across a network which might fail occasionally or even very often.
175 This humble taxonomy is not an attempt to define a {\em level of support} --- entire working groups dedicated to this
176 task have failed to deliver a universally-accepted solution despite spending many years on this goal. Instead, it is
177 intended to serve as a reference suggesting client and server developers alike what extensions might be useful.
179 Further details about the mentioned extensions are available in chapters three (p. \pageref{sec:imap-extensions} and
180 four (p. \pageref{sec:proposed-extensions}).
182 \subsection{The Bare Minimum}
184 The first group of extensions lists those proposals which I consider to be a practical requirement for a well-behaving
185 client to implement. Furthermore, their implementation does not impose an overly significant burden on the servers,
186 neither in terms of complicated code and therefore increased development costs, nor in the runtime overhead.
188 \subsubsection{LITERAL+}
190 Implementing the {\tt LITERAL+} extension actually {\em reduces} the amount of special code which the client executes
191 when transmitting data using literals. As such, there is no excuse for not implementing this extension.
193 \subsubsection{IDLE}
195 Entering the {\tt IDLE} mode enables the server to issue any untagged response, including the {\tt EXPUNGE} and {\tt
196 VANISHED}, at any time. Because the IMAP clients are already required to handle any response at any time, actually
197 making use of this feature should not impose any extra requirements on their implementors. The only acceptable reason
198 for not using {\tt IDLE} is, in my opinion, a technical deficiency in the platform's TCP stack and the related layers.
199 If the total power consumption of the {\tt IDLE} command exceed periodic polling, clients shall refrain from calling
200 {\tt IDLE}.
202 \subsubsection{ID}
204 The {\tt ID} command provides useful diagnostics about the other end of the IMAP channel. Similar features exist in
205 other Internet protocols. Hiding the name of one's implementation is a weak form of security measure --- existing
206 efforts \cite{openemailsurvey} are able to recognize an IMAP server by its {\tt CAPABILITY} response, a set of standard
207 human-readable texts and through additional criteria and it is conceivable that an alternative for clients is feasible
208 as well.
210 \subsubsection{BINARY}
212 The {\tt BINARY} extension can delegate decoding of the content-transfer-encoding to the server side. Given that
213 servers compliant with the baseline IMAP protocol already have to include a full MIME decoder, support for the BINARY
214 extension is a firm candidate for the basic level of the extension taxonomy in spite of the fact that the most widely
215 deployed IMAP server does not support it in its production releases yet.
217 \subsubsection{UIDPLUS}
219 Without the {\tt UIDPLUS} extension, it is hard for clients to tell the UID of a message they have just appended to the
220 mailbox. On servers which support persistent storage of UIDs, support for this extension does not add any further
221 requirements.
223 \subsubsection{CHILDREN, LIST-EXTENDED and LIST-STATUS}
225 With the {\tt CHILDREN} {\tt LIST} extension, GUI clients do not have to explicitly issue one more {\tt LIST} command
226 for each mailbox shown in the GUI to tell whether said mailbox shall be drawn with a visual cue indicating its
227 potentially expandable state. The {\tt LIST-EXTENDED} and {\tt LIST-STATUS} allow for bundling of additional metadata
228 with the {\tt LIST} responses and invoking the {\tt STATUS} command, respectively.
230 \subsubsection{ESEARCH}
232 The {\tt ESEARCH} response does not add any requirements on the IMAP servers besides the fact that they must send the
233 whole response at once. I believe that this is a reasonable trade-off considering the benefits the compact {\tt uidset}
234 syntax can provide when working with large mailboxes.
236 \subsubsection{COMPRESS=DEFLATE}
238 Given the ubiquitous presence of the ZLib library, clients shall make sure that either the TLS compression is active or
239 the {\tt COMPRESS=DEFLATE} command is issued. IMAP is a textual protocol and as such compresses extremely well.
241 \subsection{Useful Extensions}
243 The second group of extensions consists of those which are very valuable for the increased efficiency of the protocol
244 exchange, yet their implementation imposes a set of requirements on the server vendors, CPU resources or generally
245 requires considerable effort to ``get right''.
247 \subsubsection{CONDSTORE and QRESYNC}
249 The {\tt CONDSTORE} extension enables clients to skip downloading of all flags upon each mailbox reconnect. As such, it
250 is highly desirable. It is not placed in the basic category due to its implications on the server side, though.
252 With server requirements not significantly different to the {\tt CONDSTORE}, {\tt QRESYNC} reduces the amount of data
253 transferred when resynchronizing a mailbox after new messages have arrived and others have been expunged. Because it
254 allows clients to skip the UID map rebuild, significant bandwidth savings can be obtained. As such, clients are highly
255 recommended to support this extension.
257 \subsubsection{ENABLE}
259 The {\tt ENABLE} extension is a requirement for QRESYNC. It does not add any additional requirements on clients or
260 servers, so it shall belong to the same category.
262 \subsubsection{MULTIAPPEND}
264 The {\tt MULTIAPPEND} command improves performance in clients upload many messages at once --- a scenario common in
265 applications which support batched import of existing e-mails. Clients which do not need this feature can safely ignore
266 this extension. {\tt MULTIAPPEND} also mandates that the whole operation is atomic, that is, either all of the messages
267 are appended, or none for them are. For this reason, this extension is not put into the basic level.
269 \subsubsection{SENDMAIL}
271 Servers implementing the {\tt SENDMAIL} extension as proposed in this thesis free their clients from having to speak the
272 ESMTP protocol at all, a benefit bringing along streamlined end-user configuration and reducing support calls. However,
273 due to a certain political pressure against the adoption of any extension allowing message submission via IMAP, I have
274 decided to put {\tt SENDMAIL} to the middle category.
276 \subsubsection{CATENATE}
278 If the client can make use of the {\tt CATENATE} extension, it can be leveraged for tasks like stripping out an unwanted
279 attachment from a message otherwise considered valuable. Its usefulness increases in combination with {\tt SENDMAIL} or
280 {\tt BURL} where it allows for full support for the ``forward without download'' functionality and significant bandwidth
281 reduction.
283 \subsection{The Most Advanced Extensions}
285 The last group contains those extensions which are either something {\em special}, exotic, or generally hard to
286 implement correctly. Clients can benefit from many extensions from this group, yet one cannot expect to have them
287 available on many IMAP servers due to their inherent complexity or increased amount of requirements which they put on
288 the server.
290 \subsubsection{SORT, SORT=DISPLAY and THREAD}
292 These extensions present functionality which is very desirable from a client's point of view, yet requires the server to
293 build an index of the whole mailbox contents at once. In absence of this extension, clients wishing to offer threading
294 support or those that need to present the results to their users in a particular order have no choice but to download
295 additional data for every single message in the mailbox.
297 \subsubsection{INCTHREAD, CONTEXT=SEARCH and CONTEXT=SORT}
299 This group builds upon the functionality provided by {\tt SORT} and {\tt THREAD} by enabling live updates to the results
300 the client is interested in. In their absence, clients either have to repeat the server-side operation once again
301 whenever a new message arrive, or defer to a purely client-side sorting or threading.
303 \subsubsection{SEARCH=FUZZY}
305 Adding support for ``fuzzy search'', this extension mandates servers to build an equivalent of a fulltext search index
306 for the current mailbox, placing a significant burden on the IMAP server.
308 \subsubsection{URLAUTH and BURL}
310 This subgroup of extensions is known as the ``Lemonade trio''. Together, they allow for efficient operations like
311 forward-without download, drastically reducing the amount of data to send when working with big messages. Due to the
312 requirement for an explicit trust path between the IMAP server and the ESMTP submission service, clients have to
313 anticipate problems when they try to utilize this functionality.
315 \subsubsection{SPECIAL-USE and CREATE-SPECIAL-USE}
317 A relatively new extension which allows clients to automatically obtain data about what mailbox serves a ``special
318 purpose'' --- for example, containing {\em all messages} from any other mailbox, or being designated as a ``sent
319 folder'' by the system or account configuration. This could become a very useful extension, but it is too early to
320 mandate its support now.
322 \subsubsection{CONVERT}
324 No servers that I am aware of deploy the {\tt CONVERT} extension despite the time it has been around. No matter how
325 useful I find this extension, this trait alone puts it firmly into the ``speciality'' group.
327 \subsubsection{NOTIFY and MULTISEARCH}
329 The {\tt NOTIFY} builds where {\tt IDLE} stopped, adding support for asynchronous notification about state of many
330 mailboxes without a need of keeping concurrent connections opened. The {\tt MULTISEARCH} command adds support for
331 searches spanning several mailboxes, improving the traditional model where clients are required to ``hop'' mailboxes
332 periodically. Without much support on the server side, these extensions probably cannot be relied upon in 2012.
334 \end{document}