Warning, /pim/trojita/docs/masters/mobile-imap.tex is written in an unsupported language. File is not indexed.
0001 % vim: spelllang=en spell textwidth=120 0002 \documentclass[trojita]{subfiles} 0003 0004 \begin{document} 0005 0006 \chapter{The Mobile IMAP} 0007 \label{sec:mobile-imap} 0008 0009 Many of the existing IMAP extensions discussed in \secref{sec:imap-extensions} have the potential of improving the 0010 client's operation tremendously. At the same time, experience has shown that there is a certain chicken-and-egg problem 0011 with new proposals where server vendors are not willing to invest their time into promising extensions which no client 0012 supports yet and clients are not interested in implementing extensions which they cannot test for interoperability. In 0013 this chapter, I am trying to provide a concise summary of individual merit of these extensions. 0014 0015 \section{The Lemonade Profile} 0016 \label{sec:lemonade-comparison} 0017 0018 The Lemonade profile, as defined in RFC 4550 \cite{rfc4550} in 2006 and later updated through RFC 5550 \cite{rfc5550} 0019 during 2009, provides a list of extensions considered ``critical'' for any mobile IMAP e-mail client. The set of 0020 mandatory extensions is rather big, though, and to the best of my knowledge, there is {\em no} server on the market 0021 implementing all of the compulsory features. One might therefore wonder what were the reasons for this lack of general 0022 availability of the Lemonade extension family. 0023 0024 \subsection{Cross-Service Requirements} 0025 0026 One unique feature of Lemonade is the possibility to {\em forward messages without their prior download}. The three 0027 ESMTP~\cite{rfc5321} and IMAP extensions, often referred to as the {\em Lemonade trio}, namely the {\tt CATENATE}, {\tt 0028 URLAUTH} and {\tt BURL}, allow the clients to compose a message using existing parts available from the IMAP mail store, 0029 provide a way of generating single-purpose ``pawn tickets'' for making the composed messages available to the submission 0030 server, and replacing the {\tt DATA} SMTP command with a way of downloading the message from the IMAP server, 0031 respectively. This feature prevents having to transfer potentially huge data over the network three times --- once when 0032 the users wants to read it, second time when the message is saved to the sent folder, and finally when delivering via 0033 SMTP. 0034 0035 Unfortunately, a big problem with said approach is the fact that it mandates collaboration across different services --- 0036 an explicit trust path between the IMAP and ESMTP servers have to be set up, which is a process prone to errors 0037 \cite{qmf-fastmail-burl-bug}. This matter is also complicated by the fact that no open source MTA~\footnote{Mail 0038 Transfer Agent, typically an SMTP or ESMTP server} ships with official support for {\tt BURL}.~\footnote{Unofficial 0039 patches exists for Postfix dating back to 2010 \cite{apple-postfix-burl}, but they have not been integrated into the 0040 mainline version as of July 2012 (the {\tt postfix-2.10-20120715.tar.gz} development snapshot.} Situation is better on 0041 the IMAP server front with Cyrus supporting the {\tt URLAUTH} and {\tt CATENATE} extensions out-of-box with Dovecot's 0042 support scheduled for its upcoming 2.2 release \cite{imap-server-extension-matrix}. 0043 0044 \subsection{Complicated Extensions} 0045 0046 Some of the extensions whose support is mandated by the Lemonade proposal seems to be notoriously hard for the server 0047 vendors to implement. 0048 0049 A perfect example is the {\tt CONTEXT=SORT} extension \cite{rfc5267}. As a client developer, I recognize its extreme 0050 usefulness and appreciate its design. Availability of such an extension would make it extremely easy to implement 0051 live-updated sorting in my Trojitá (and Trojitá {\em does} make use of the sort context extension). That said, given 0052 that no IMAP server which I am aware of announces its availability, clients have to deal with the status quo in the 0053 meanwhile. 0054 0055 The {\tt CONVERT} extension \cite{rfc5259} belongs to a similar category --- the features it offers, like the 0056 server-side downscaling of JPEG images, would be {\em very} handy on a cell phone, yet no IMAP server known to the 0057 author includes that functionality. 0058 0059 Both of these RFCs were published four and five years ago, respectively, and were designed by engineers working for an 0060 IMAP server vendor. One cannot therefore dismiss them altogether as a product of people not having any say in the 0061 server development. My opinion is that the allocation of engineering resources required for shipping a particular 0062 feature in a finished product is based on another criteria than the research activity. 0063 0064 \section{State of Other Client Implementations} 0065 0066 To obtain a better understanding on how the existing solutions available on the market today use IMAP, this section 0067 takes a look at some of the most popular solutions. 0068 0069 \subsection{Apple iOS} 0070 0071 Apple's devices generally ship with a decent implementation of their IMAP stack, an evaluation shared by independent 0072 researchers \cite{isode-iphone4}. The list of extensions supported by the application includes {\tt CONDSTORE} and {\tt 0073 ESEARCH} for improved mailbox synchronization, {\tt COMPRESS} for transparent deflate compression and {\tt BURL} for the 0074 forward-without download. 0075 0076 It is, however, surprising that their support of extensions aimed at making mailbox resynchronization more efficient 0077 does not include the {\tt QRESYNC} extension \cite{rfc5162}, especially given that its implementation does not impose 0078 much in terms of additional requirements on top the already-supported {\tt CONDSTORE}. 0079 0080 The iOS also notably does not use the {\tt IDLE} command at all. The reason, according to a message allegedly sent by 0081 Steve Jobs \cite{jobs-ios-idle}, is that is is {\em ``a power hungry standard''}. Systematic measurements 0082 \cite{wcdma-energy} \cite{cridland-fach-dch-measurements} and experience alike~\footnote{Mark Crispin's famous {\em ``I 0083 have built on-demand networks which shut down until signaled back on, and then happily resumed all the active TCP 0084 sessions even though the "network connection" had been powered off for days.''} \cite{crispin-no-ifup}.} shows, however, 0085 that the mere act of having a TCP connection open with an occasional keep alive ``pings'' being transfered have no 0086 significant impact on battery life on other platforms. 0087 0088 \subsection{Android's Native E-mail Client} 0089 0090 There is not much to be said about Android's native client's IMAP performance --- the stock client does not offer push 0091 notification through {\tt IDLE} \cite{android-idle} and the list of extension identifiers referenced from the 0092 application's source~\footnote{File \path{src/com/android/email/mail/store/ImapConnection.java} from Android's 0093 \path{platform/packages/apps/Email} repository as of the {\tt android-4.1.1\_r3-35-g01c55fd} revision.} only references 0094 the {\tt NAMESPACE}, {\tt UIDPLUS} and {\tt STARTTLS} capabilities. None of the extensions which try to improve 0095 synchronization performance (the {\tt ESEARCH}, {\tt CONDSTORE} and {\tt QRESYNC}) are available. No provisions for 0096 Lemonade's family are present at all. The {\tt LITERAL+}, an extension which takes literally no effort for clients to 0097 support and removes one network round trip when uploading messages, is not supported. 0098 0099 Further analysis shows that the code is blocking and incapable of issuing or processing requests in parallel. These 0100 observations are consistent with what users generally describe as a ``slow'' experience. This might not come surprising 0101 given that Google would likely prefer its users to choose Google's own e-mail offering, the GMail, over various private 0102 IMAP accounts for business reasons. 0103 0104 \subsection{Android's K-9 Mail} 0105 0106 The Android's K-9 mail~\cite{k9mail} is a fork of the original e-mail application from Google. The developers have 0107 managed to add support for two extensions, namely the {\tt IDLE} and the {\tt COMPRESS=DEFLATE}. More advanced features 0108 like the {\tt ESEARCH} / {\tt CONDSTORE} / {\tt QRESYNC} are however still missing. 0109 0110 Furthermore, comments like {\em ``TODO Need to start keeping track of UIDVALIDITY''}~\footnote{File 0111 \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 0112 source code repository.} might make one feel nervous about the safety of the data being accessed. 0113 0114 \subsection{Modest / Tinymail} 0115 0116 The several years old Nokia N900 shipped with a mail client called Modest, an application based on top of the Tinymail 0117 framework~\cite{tinymail}. The underlying library supports an efficient mailbox synchronization through {\tt QRESYNC} 0118 and the sources contain a reference to the {\tt CONVERT} extension --- however, this functionality appears to be limited 0119 and in an early state. The ``Lemonade trio'' for forwarding without download is not supported. 0120 0121 The code is written using the synchronous idioms. No support for command pipelining is present. 0122 0123 \subsection{Nokia's Qt Messaging Framework} 0124 0125 Nokia's Qt Messaging Framework~\cite{qmf} powers the e-mail functionality in the MeeGo Harmattan line of phones, the N9 0126 and the N950. Support for extensions appears to be rich --- the Lemonade trio is supported in its 0127 entirety,~\footnote{An interesting detail is that the {\tt BURL} extension is disabled if the account is configured to 0128 use IMAP over an SSL port instead of the {\tt STARTTLS}; this is caused by a deficiency in the IMAP-URL standard 0129 \cite{rfc5092}.} as well as are the {\tt COMPRESS=DEFLATE}, {\tt BINARY}, {\tt IDLE}, {\tt CHILDREN} and many others. 0130 0131 The underlying IMAP library exhibits regular ``batched synchronization'' mode of operation; connections to mailboxes are 0132 typically not left alone for long, but the code makes aggressive use of the {\tt QRESYNC} extension to benefit from 0133 extremely cheap mailbox synchronization. Code is written with memory-constrained devices in mind, care is taken to 0134 prevent data copying if possible. The general behavior focuses on making the specified subset of messages always 0135 available on device --- there is no support for server-side threading or sorting, but some form of a server-side search 0136 {\em is} available. Live updates through {\tt CONTEXT=SEARCH} are not employed. Support for the {\tt LIST-STATUS} is 0137 not available. 0138 0139 An interesting extension which is supported by the QMF is Google's {\tt XLIST} \cite{gmail-xlist} extension. However, 0140 the code~\footnote{File \path{src/plugins/messageservices/imap/imapprotocol.cpp} as of QMF's Git revision {\tt 0141 2011W26\_2-263-gec26531}.} appears to only use the {\tt \\Inbox} mailbox flag for forcing case-insensitive mailbox 0142 comparison, a mechanism already mandated by the baseline IMAP protocol \cite[p. 17]{rfc3501}. 0143 0144 All in all, the Qt Messaging Framework is a promising library with support for other protocols besides IMAP. Its IMAP 0145 implementation feels solid and is reasonably well covered by the unit tests. 0146 0147 \subsection{Trojitá} 0148 0149 Trojitá~\cite{trojita-website} is an advanced IMAP client which includes support for many different extensions from the 0150 basic ones like {\tt IDLE}, {\tt LITERAL+} or the {\tt ID} extension to the complex ones like the Lemonade trio or the 0151 {\tt ESEARCH} / {\tt CONDSTORE} / {\tt QRESYNC} triplet. Trojitá can scale up to company-wide ERP-level e-mail 0152 processing (Appendix \ref{sec:xtuple}, p. \pageref{sec:xtuple}) while still using the same code base of 0153 the underlying IMAP library as the desktop and cell phone version. 0154 0155 \section{Evaluating Extensions} 0156 0157 As the previous section shows, the level of support for various extensions and their real-world deployment varies 0158 wildly. Many today's clients are using only a limited subset of features which are generally available, leaving 0159 opportunities for new applications entering the market to offer smoother, more efficient user experience. 0160 0161 Previous efforts aimed at standardizing a set of extensions to serve as a ``mobile profile'' of IMAP have not delivered 0162 a universally acceptable result. Lemonade, a specification universally considered to be {\em the} specification to go 0163 when evaluating clients and servers alike \cite{isode-lemonade}, mandates a set of extensions which --- to the best of 0164 my knowledge --- is not available on any single IMAP server in its entirety. Furthermore, the clients do not even 0165 attempt to use these extensions, probably due to not being able to verify them for interoperability and because of 0166 concerns about shipping something which could very well be considered a dead code. 0167 0168 The rest of this chapter tries to look at the available extensions through the optics of a client developer who is 0169 trying to push the IMAP server developers slightly, but not too much --- pushing forward is crucial in attaining a 0170 sustainable development, yet applying too much pressure often leads to the whole movement getting stuck on a first 0171 obstacle. I make a few assumptions about the features which the client support; most notably, the client should have a 0172 persistent cache to store already downloaded data. The client is also expected to serve a human user who will work with 0173 the application for many days across a network which might fail occasionally or even very often. 0174 0175 This humble taxonomy is not an attempt to define a {\em level of support} --- entire working groups dedicated to this 0176 task have failed to deliver a universally-accepted solution despite spending many years on this goal. Instead, it is 0177 intended to serve as a reference suggesting client and server developers alike what extensions might be useful. 0178 0179 Further details about the mentioned extensions are available in chapters three (p. \pageref{sec:imap-extensions} and 0180 four (p. \pageref{sec:proposed-extensions}). 0181 0182 \subsection{The Bare Minimum} 0183 0184 The first group of extensions lists those proposals which I consider to be a practical requirement for a well-behaving 0185 client to implement. Furthermore, their implementation does not impose an overly significant burden on the servers, 0186 neither in terms of complicated code and therefore increased development costs, nor in the runtime overhead. 0187 0188 \subsubsection{LITERAL+} 0189 0190 Implementing the {\tt LITERAL+} extension actually {\em reduces} the amount of special code which the client executes 0191 when transmitting data using literals. As such, there is no excuse for not implementing this extension. 0192 0193 \subsubsection{IDLE} 0194 0195 Entering the {\tt IDLE} mode enables the server to issue any untagged response, including the {\tt EXPUNGE} and {\tt 0196 VANISHED}, at any time. Because the IMAP clients are already required to handle any response at any time, actually 0197 making use of this feature should not impose any extra requirements on their implementors. The only acceptable reason 0198 for not using {\tt IDLE} is, in my opinion, a technical deficiency in the platform's TCP stack and the related layers. 0199 If the total power consumption of the {\tt IDLE} command exceed periodic polling, clients shall refrain from calling 0200 {\tt IDLE}. 0201 0202 \subsubsection{ID} 0203 0204 The {\tt ID} command provides useful diagnostics about the other end of the IMAP channel. Similar features exist in 0205 other Internet protocols. Hiding the name of one's implementation is a weak form of security measure --- existing 0206 efforts \cite{openemailsurvey} are able to recognize an IMAP server by its {\tt CAPABILITY} response, a set of standard 0207 human-readable texts and through additional criteria and it is conceivable that an alternative for clients is feasible 0208 as well. 0209 0210 \subsubsection{BINARY} 0211 0212 The {\tt BINARY} extension can delegate decoding of the content-transfer-encoding to the server side. Given that 0213 servers compliant with the baseline IMAP protocol already have to include a full MIME decoder, support for the BINARY 0214 extension is a firm candidate for the basic level of the extension taxonomy in spite of the fact that the most widely 0215 deployed IMAP server does not support it in its production releases yet. 0216 0217 \subsubsection{UIDPLUS} 0218 0219 Without the {\tt UIDPLUS} extension, it is hard for clients to tell the UID of a message they have just appended to the 0220 mailbox. On servers which support persistent storage of UIDs, support for this extension does not add any further 0221 requirements. 0222 0223 \subsubsection{CHILDREN, LIST-EXTENDED and LIST-STATUS} 0224 0225 With the {\tt CHILDREN} {\tt LIST} extension, GUI clients do not have to explicitly issue one more {\tt LIST} command 0226 for each mailbox shown in the GUI to tell whether said mailbox shall be drawn with a visual cue indicating its 0227 potentially expandable state. The {\tt LIST-EXTENDED} and {\tt LIST-STATUS} allow for bundling of additional metadata 0228 with the {\tt LIST} responses and invoking the {\tt STATUS} command, respectively. 0229 0230 \subsubsection{ESEARCH} 0231 0232 The {\tt ESEARCH} response does not add any requirements on the IMAP servers besides the fact that they must send the 0233 whole response at once. I believe that this is a reasonable trade-off considering the benefits the compact {\tt uidset} 0234 syntax can provide when working with large mailboxes. 0235 0236 \subsubsection{COMPRESS=DEFLATE} 0237 0238 Given the ubiquitous presence of the ZLib library, clients shall make sure that either the TLS compression is active or 0239 the {\tt COMPRESS=DEFLATE} command is issued. IMAP is a textual protocol and as such compresses extremely well. 0240 0241 \subsection{Useful Extensions} 0242 0243 The second group of extensions consists of those which are very valuable for the increased efficiency of the protocol 0244 exchange, yet their implementation imposes a set of requirements on the server vendors, CPU resources or generally 0245 requires considerable effort to ``get right''. 0246 0247 \subsubsection{CONDSTORE and QRESYNC} 0248 0249 The {\tt CONDSTORE} extension enables clients to skip downloading of all flags upon each mailbox reconnect. As such, it 0250 is highly desirable. It is not placed in the basic category due to its implications on the server side, though. 0251 0252 With server requirements not significantly different to the {\tt CONDSTORE}, {\tt QRESYNC} reduces the amount of data 0253 transferred when resynchronizing a mailbox after new messages have arrived and others have been expunged. Because it 0254 allows clients to skip the UID map rebuild, significant bandwidth savings can be obtained. As such, clients are highly 0255 recommended to support this extension. 0256 0257 \subsubsection{ENABLE} 0258 0259 The {\tt ENABLE} extension is a requirement for QRESYNC. It does not add any additional requirements on clients or 0260 servers, so it shall belong to the same category. 0261 0262 \subsubsection{MULTIAPPEND} 0263 0264 The {\tt MULTIAPPEND} command improves performance in clients upload many messages at once --- a scenario common in 0265 applications which support batched import of existing e-mails. Clients which do not need this feature can safely ignore 0266 this extension. {\tt MULTIAPPEND} also mandates that the whole operation is atomic, that is, either all of the messages 0267 are appended, or none for them are. For this reason, this extension is not put into the basic level. 0268 0269 \subsubsection{SENDMAIL} 0270 0271 Servers implementing the {\tt SENDMAIL} extension as proposed in this thesis free their clients from having to speak the 0272 ESMTP protocol at all, a benefit bringing along streamlined end-user configuration and reducing support calls. However, 0273 due to a certain political pressure against the adoption of any extension allowing message submission via IMAP, I have 0274 decided to put {\tt SENDMAIL} to the middle category. 0275 0276 \subsubsection{CATENATE} 0277 0278 If the client can make use of the {\tt CATENATE} extension, it can be leveraged for tasks like stripping out an unwanted 0279 attachment from a message otherwise considered valuable. Its usefulness increases in combination with {\tt SENDMAIL} or 0280 {\tt BURL} where it allows for full support for the ``forward without download'' functionality and significant bandwidth 0281 reduction. 0282 0283 \subsection{The Most Advanced Extensions} 0284 0285 The last group contains those extensions which are either something {\em special}, exotic, or generally hard to 0286 implement correctly. Clients can benefit from many extensions from this group, yet one cannot expect to have them 0287 available on many IMAP servers due to their inherent complexity or increased amount of requirements which they put on 0288 the server. 0289 0290 \subsubsection{SORT, SORT=DISPLAY and THREAD} 0291 0292 These extensions present functionality which is very desirable from a client's point of view, yet requires the server to 0293 build an index of the whole mailbox contents at once. In absence of this extension, clients wishing to offer threading 0294 support or those that need to present the results to their users in a particular order have no choice but to download 0295 additional data for every single message in the mailbox. 0296 0297 \subsubsection{INCTHREAD, CONTEXT=SEARCH and CONTEXT=SORT} 0298 0299 This group builds upon the functionality provided by {\tt SORT} and {\tt THREAD} by enabling live updates to the results 0300 the client is interested in. In their absence, clients either have to repeat the server-side operation once again 0301 whenever a new message arrive, or defer to a purely client-side sorting or threading. 0302 0303 \subsubsection{SEARCH=FUZZY} 0304 0305 Adding support for ``fuzzy search'', this extension mandates servers to build an equivalent of a fulltext search index 0306 for the current mailbox, placing a significant burden on the IMAP server. 0307 0308 \subsubsection{URLAUTH and BURL} 0309 0310 This subgroup of extensions is known as the ``Lemonade trio''. Together, they allow for efficient operations like 0311 forward-without download, drastically reducing the amount of data to send when working with big messages. Due to the 0312 requirement for an explicit trust path between the IMAP server and the ESMTP submission service, clients have to 0313 anticipate problems when they try to utilize this functionality. 0314 0315 \subsubsection{SPECIAL-USE and CREATE-SPECIAL-USE} 0316 0317 A relatively new extension which allows clients to automatically obtain data about what mailbox serves a ``special 0318 purpose'' --- for example, containing {\em all messages} from any other mailbox, or being designated as a ``sent 0319 folder'' by the system or account configuration. This could become a very useful extension, but it is too early to 0320 mandate its support now. 0321 0322 \subsubsection{CONVERT} 0323 0324 No servers that I am aware of deploy the {\tt CONVERT} extension despite the time it has been around. No matter how 0325 useful I find this extension, this trait alone puts it firmly into the ``speciality'' group. 0326 0327 \subsubsection{NOTIFY and MULTISEARCH} 0328 0329 The {\tt NOTIFY} builds where {\tt IDLE} stopped, adding support for asynchronous notification about state of many 0330 mailboxes without a need of keeping concurrent connections opened. The {\tt MULTISEARCH} command adds support for 0331 searches spanning several mailboxes, improving the traditional model where clients are required to ``hop'' mailboxes 0332 periodically. Without much support on the server side, these extensions probably cannot be relied upon in 2012. 0333 0334 \end{document}