Add credits for Marek
[trojita.git] / docs / masters / proposed-drafts.tex
blob0d03d110425383b1851100454c25edce50706176
1 % vim: spelllang=en spell textwidth=120
2 \documentclass[trojita]{subfiles}
4 \begin{document}
6 \chapter{Proposed Extensions}
7 \label{sec:proposed-extensions}
9 Previous chapters have shed some light on the complicated world of IMAP and showed how the protocol limitations affects
10 the users' experience. I have also introduced some of the existing extensions which aim to address many of the
11 presented shortcomings. There are still quite a few issues which make lives of the client implementors harder than
12 necessary, though. At this point, I present three separate extensions which fix race conditions, improve the
13 effectiveness of the protocol or add new features which contribute to smoother operation of the e-mail clients. This
14 broad range of changes was selected to illustrate that improving IMAP can happen on many different fronts and that even
15 after more than twenty years of ``active service'', the protocol can be actively improved to address newly emerging
16 trends.
18 Internet Drafts are usually prepared in a special system \cite{rfc-formatting} which handles the required strict
19 document formatting using plain ASCII text. This chapter is therefore purposely very short, providing only the minimal
20 descriptions of the proposed extensions. The Internet Drafts themselves are included in Appendix
21 \ref{sec:id-manuscripts} on page \pageref{sec:id-manuscripts} and are an integral part of this thesis.
23 \section{Announcing the UIDs of Newly Arriving Messages during the QRESYNC mode: the ARRIVED Extension}
24 \label{sec:draft-arrived}
26 The first extension I have implemented addresses a race condition in the {\tt QRESYNC} extension \cite{rfc5162}. In
27 {\tt QRESYNC}, the offset-based {\tt EXPUNGE} responses known from the baseline IMAP protocol are replaced by {\tt
28 VANISHED} responses which use UIDs. Unfortunately, because the {\tt EXISTS} still informs about the number of new
29 deliveries only, without including the UIDs, and due to the fact that the IMAP server is explicitly
30 allowed~\footnote{{\em``Note that a VANISHED response caused by EXPUNGE, UID EXPUNGE, or messages expunged in other
31 connections SHOULD only contain UIDs for messages expunged since the last VANISHED/EXPUNGE response sent for the
32 currently opened mailbox or since the mailbox was opened. That is, servers SHOULD NOT send UIDs for previously expunged
33 messages, unless explicitly requested to do so by the UID FETCH (VANISHED) command.''
35 ``Note that client implementors must take care to properly decrement the number of messages in the mailbox even if
36 a server violates this last SHOULD or repeats the same UID multiple times in the returned UID set. In general, this
37 means that a client using this extension should either avoid using message numbers entirely, or have a complete mapping
38 of UIDs to message sequence numbers for the selected mailbox.''}~\cite[p. 12]{rfc5162} --- in the
39 RFC language, {\em SHOULD} means that implementations are suggested to use the recommended behavior, but can deviate
40 from that as {\em ``there may exist valid reasons in particular circumstances to ignore a particular item''}
41 \cite{rfc2092}.} to include non-existing UIDs in the {\tt VANISHED} responses, a race condition exists where client does
42 not know about the full span of the sequence $\rightarrow$ UID mapping, which in turn violates RFC 5162's requirement
43 on clients having {\em ``a complete mapping of UIDs to message sequence numbers for the selected mailbox''}.
45 The proposed extension addresses this issue through the {\tt ARRIVED} response which informs the clients about the UIDs
46 of new message arrivals. At the same time, it improves the protocol efficiency by freeing the clients from a
47 requirement to explicitly ask for message UIDs when a new message is delivered.
49 This is how a typical session without the {\tt ARRIVED} extension looks like. Suppose the mailbox previously contained
50 just a single message with UID 5, the UIDNEXT is 11:
52 \begin{minted}{text}
53 S: * 3 EXISTS
54 S: * 2 FETCH (FLAGS (foo))
55 S: * 3 FETCH (FLAGS (bar))
56 S: * VANISHED 12:20
57 C: x UID SEARCH UID 11:*
58 S: * SEARCH 21
59 S: x OK Search completed
60 C: y UID FETCH 21 (FLAGS)
61 S: * 2 FETCH (UID 21 FLAGS (foo))
62 \end{minted}
64 The client had no chance but to ignore the unsolicited {\tt FETCH} responses, recover the full UID mapping through the
65 {\tt UID SEARCH} command and finally re-request the flag data once again through the {\tt UID FETCH} command.
67 In contrast to the above, the following is how the same session happens when {\tt QRESYNC} is active and enabled:
69 \begin{minted}{text}
70 S: ARRIVED 21
71 S: VANISHED 12:20
72 S: * 2 FETCH (FLAGS (foo))
73 S: * 3 FETCH (FLAGS (bar))
74 \end{minted}
76 No client activity at all is required then the {\tt ARRIVED} extension is available.
78 \subsection{Alternatives}
80 In absence of the {\tt ARRIVED} extension, clients are required to perform an explicit UID rediscovery, possibly through
81 the {\tt UID SEARCH $formerUidNext$:*}; this could pose a problem when servers send any data using the {\tt FETCH}
82 responses without the {\tt UID} field. Always including the {\tt UID} in unsolicited {\tt FETCH} responses, as
83 recommended in RFC 5162's errata document, can mitigate this particular issue. However, servers which already do not
84 send non-existing UIDs in the {\tt VANISHED} responses will still benefit from implementing the {\tt ARRIVED} extension
85 as the clients will be able to refrain from performing an explicit {\tt UID SEARCH} operations on them upon new
86 deliveries. Furthermore, due to the fact that clients have {\em no way} of finding out whether servers include the
87 non-existing UIDs in {\tt VANISHED} responses, the benefits of the proposed extension are demonstrated whenever new
88 arrivals are expunged before their UIDs become known, no matter whether the servers conform to the requirement imposed
89 by the relevant errata.
91 Full text of the proposed extension in the format of an Internet-Draft suitable for IETF submission is included in
92 section \secref{sec:draft-imap-qresync-arrived}. This extension was presented for discussion on the {\tt imap-protocol}
93 mailing list \cite{jkt-i-p-draft-qresync-arrived-01}.
95 \section{Improving Incremental Threading through Modified INTHREAD}
96 \label{sec:draft-incthread}
98 Delegating message threading to the server-side can provide clients with enormous benefits, especially when working with
99 large mailboxes. However, these benefits can be significantly reduced when clients are forced to request full thread
100 mapping over and over again.
102 Unfortunately, that is exactly the situation when new messages arrive. When clients use the server-side threading, they
103 by design do not have to keep track of the {\tt Message-Id}, {\tt References} and {\tt In-Reply-To} headers as the
104 thread tree building is all done by the IMAP server. However, that also means that newly arriving messages cannot be
105 easily ``plugged'' into the already known tree, even if full header set of the new arrival was known. Doing so reliably
106 would require knowledge of the relevant headers of all messages in mailbox, knowledge which is rather expensive to
107 obtain and avoidance of which is the whole point of server-side threading.
109 \subsection{Existing Approach}
111 Extensions exist solving this problem for both searching (the {\tt CONTEXT=SEARCH} extension from RFC~5267
112 \cite{rfc5267} which is reasonably wide-deployed) and sorting (the {\tt CONTEXT=SORT}, support of which is extremely
113 scarce despite being defined in the same RFC document), but no such proposal was ever submitted for threading. I
114 suspect that the reason is inherent in the way the threading works --- a single newly arriving message can indeed cause
115 threading updates for {\em any} other message in a mailbox, even for {\em all} of them in a pathological
116 case.~\footnote{Any new arrival could possibly join many existing threads previously considered to be individual and
117 independent of each other to a single thread having all of them as subthreads.} This is in a strong contrast to live
118 updates of search results where a pair of simple ``add item $X$ to result'' and ``remove X from the result'' is enough,
119 or even to incremental sort order communication (where the operation is complicated a little more, requiring ``add item
120 $X$ to the result at offset $Y$'').
122 One {\em could} attempt to try the incremental threading by asking for UIDs of messages with the {\tt Message-Id} header
123 matching any referenced from the new arrivals' {\tt References}, but doing so is hard in practice as some MUAs choose
124 not to use {\tt References} and set just the {\tt In-Reply-To} header. Thread building exclusively through the {\tt
125 In-Reply-To}, however, completely misses the correct thread order for threads with ``gaps'' in them, a scenario very
126 common when one's own replies are located in a dedicated {\em Sent} folder with the rest of the thread in e.g. the {\tt
127 INBOX}. Using just the basic {\tt SEARCH} command is therefore not sufficient.
129 An existing draft proposal \cite{draft-ietf-morg-inthread} extends the search query capabilities with the {\tt INTHREAD}
130 operator matching a {\em whole thread} of messages. This capability alone is not enough to fully accommodate the whole
131 incremental threading problem, but it is an improvement good enough to build upon. The only missing piece of
132 functionality is being able to tell where the new thread shall be positioned, but in absence of better tools, an
133 approximation always showing threads with ``new arrivals'' at the very end of the view might be good
134 enough.~\footnote{Displaying threads with ``new arrivals'' among the ``last messages'' is suboptimal because the newly
135 arriving message {\em could} be in fact a result of a copy operation. Having these ``older'' messages suddenly appear
136 should not interleave them with the recent content of the mailbox.}
138 \subsection{The INCTHREAD Extension}
140 The proposed extension builds on top of {\tt INTHREAD}, adding the exact positioning to each individual thread matching
141 the search criteria. In addition, the format of the response does not use the {\tt THREAD} untagged response from RFC
142 5256 \cite{rfc5256}, but instead uses the extensible {\tt ESEARCH} response from RFC 4731 \cite{rfc4731} --- the {\tt
143 ESEARCH} already contains provisions for returning multiple types of data and as an added bonus ties the response to a
144 particular command's tag, making it possible to parallelize threading operation. These reasons make the {\tt ESEARCH}
145 response better suited to accommodate the new result format.
147 The improvement, as measured in decreased bandwidth consumption, is not always as impressive as those from the CONTEXT
148 extensions. It is conceivable that more advanced forms of conveying the modified threading information (e.g. the
149 strictly incremental responses about how an update affects a particular branch in the threading tree) would result in
150 smaller overall transmitted octet counts, but on the other hand implementing such an extension would prove challenging
151 to both servers and clients. There are also circumstances under which the tree-oriented differential updates would not
152 work; the most obvious one is when a client reconnected to a mailbox, detected a couple of new arrivals and now wants to
153 ask for updates ``ex post'', long after they have physically happened in the mailbox. Finally, the client-driven mode
154 of operation through the proposed extension better fits the IMAP behavior where clients specify in what kinds of
155 information they are interested and servers optimize their operation by only transmitting what is strictly necessary.
157 Using the proposed extension, a typical communication between two compliant IMAP protocol speakers might look like the
158 following:
160 \begin{minted}{text}
161 S: * 666 EXISTS
162 C: x1 UID FETCH 665:* (FLAGS)
163 S: * 666 FETCH (UID 1666 FLAGS ())
164 S: x1 OK fetched
165 C: x2 UID THREAD RETURN (INCTHREAD) REFS utf-8
166 INTHREAD REFS 666
167 S: * ESEARCH (TAG "x2") UID INCTHREAD 400
168 (600 601 (640 666)(602 603))
169 S: x2 OK sent
170 \end{minted}
172 At first, the server informs the client about new delivery. Client responds with a request for UID and message flags of
173 the new arrivals. When both are known, the new form of the {\tt UID THREAD} command is issued, specifying that the
174 threading algorithm {\tt REFS} shall be used, searching shall be done in the {\tt utf-8} character set and that the
175 returned value shall include the relative thread position among other threads in the whole mailbox.
177 The result instructs the client that messages with UIDs of 600, 601, 602, 603 and 640 shall be removed from their
178 previous positions in the threading tree, and that they together with UID 666 form a new thread with the specified
179 shape. This new thread immediately follows a thread whose thread root has UID 400. Figure
180 \ref{fig:incthread-threading-example} shows how the new threading for this mailbox looks like.
182 \begin{figure}
183 \vspace{10mm}
184 \dirtree{%
185 .1 \ldots.
186 .2 \ldots \DTcomment{Preceding threads are skipped}.
187 .2 400 \DTcomment{No information about the rest of this thread is transmitted}.
188 .3 \ldots.
189 .2 600 \DTcomment{On the other hand, the whole of the new thread is always sent}.
190 .3 601.
191 .4 640.
192 .5 {\bf 666} \DTcomment{This is the newly arrived message}.
193 .4 602.
194 .5 603.
195 .2 \ldots \DTcomment{The following threads are also skipped}.
197 \vspace{8mm}
198 \label{fig:incthread-threading-example}
199 \caption{The incremental threading response conveyed information about one message thread in a mailbox. No data for
200 other threads have to be transmitted, leading to a significant performance improvements on slow networks or
201 bandwidth-constrained devices.}
202 \end{figure}
204 Even though the updated extended {\tt THREAD} command can still send data which are already known by the client, the
205 design is a reasonable compromise between one imposing overly complex requirements on both clients and servers on one
206 hand, and needlessly transmitting the whole mapping over and over again in absence of any extensions.
208 The full text of the proposed extension, including the formal grammar, is available from section
209 \secref{sec:draft-imap-incthread}. The extension was presented for expert review on the {\tt imapext} mailing list
210 \cite{jkt-i-p-draft-incthread}.
212 \section{Submitting Internet Mail --- the SENDMAIL Extension}
213 \label{sec:draft-sendmail}
215 Message submission is one of the controversial subjects, along the ``imap5'' and ``move messages'' discussions ---
216 whenever any of these topics is brought up on the imap-protocol mailing list, an interesting discussion is guaranteed to
217 happen. In this proposal, I have tried to accommodate criticism from many previous review rounds.
219 The baseline IMAP protocol does not offer any way of e-mail submission. Mail User Agents willing to send mail are
220 supposed to use the (E)SMTP protocol \cite{rfc5321} \cite{rfc2821}, preferably over a dedicated submission service
221 \cite{rfc6409}. This is how most of contemporary e-mail clients (at least those using the IETF standards in contrast
222 to the proprietary ones) work, but it also brings along a set of issues.
224 First of all, the clients have to be {\em properly configured}. Given that ESMTP and IMAP can be (and often are)
225 managed separately, clients have to ask their users for two sets of accounts, one for each type of service. Proposals
226 exist trying to eliminate much of this complexity, especially through the DNS system \cite{rfc6186} or via non-standard
227 mechanisms like those proposed by Mozilla \cite{mozilla-ispdb} --- but as usual, these mechanisms often cover only a
228 subset of service providers. Client programmers are required to implement and test full support for both protocols.
229 IMAP is doubtlessly the more complicated one, exceeding ESMTP both in syntax and semantic, yet adding a requirement for
230 a proper SMTP implementation causes a measurable burden on the developers.
232 Furthermore, network firewalls and other filters along the way have to be properly configured to allow for a reliable
233 pass-through for both services \cite{crocker-beep-multi-conns}. Even though the situation has much improved with a
234 dedicated ``Submission'' service \cite{rfc6409} which moved the e-mail submission to a dedicated port to not interfere
235 with the traditional SPAM-laden TCP port 25, there are still certain situations where customers cannot use both e-mail
236 services, leading to confused support calls \cite{submission-users-suck-smtp-imap} \cite{panozzo-submission-users-suck}.
238 In addition to the above, many users wants to store their outgoing e-mail in a separate IMAP mail folder. This means
239 that under typical circumstances, a message being sent has to be uploaded twice over the network, once for IMAP, the
240 second time for ESMTP delivery. In case when a message contains an attachment previously already available on the IMAP
241 server, the same data can in fact travel over the network {\em three times} -- at first when being downloaded by the
242 IMAP client only to be subsequently sent after the proper MIME encapsulation to the destined ``Sent'' folder, and
243 finally over SMTP as usual. As a last point in this quick list, even in presence of specific extensions, the time
244 required to actually {\em establish} a separate connection, setup proper TLS confidentiality and start tunnelling data
245 over it is often non-negligible.
247 All of the above suggests that there are certain benefits in choosing to deliver e-mail messages from
248 MUAs~\footnote{Mail User Agents} over IMAP.
250 \subsection{Competing Proposals}
252 Over the years, many proposals have appeared trying to accommodate this issue \cite{draft-ietf-lemonade-submit}.
254 \subsubsection{The ``Lemonade Trio''}
256 The most widely deployed mechanism aiming at bandwidth reduction is the Lemonade extension family \cite{rfc5550}.
257 Through the use of IMAP's {\tt CATENATE} \cite{rfc4469} and {\tt URLAUTH} \cite{rfc4467} along with SMTP's BURL
258 \cite{rfc4468}, conforming clients can:
260 \begin{itemize}
261 \item compose a message on the IMAP server's side, reusing any existing data,
262 \item deliver that message over SMTP without having to upload the data.
263 \end{itemize}
265 At the same time, this approach has the following disadvantages:
267 \begin{itemize}
268 \item a trust relation (at least a limited one) has to exist between the SMTP and IMAP servers,
269 \item both SMTP and IMAP servers have to be properly configured,
270 \item clients still have to maintain a separate SMTP protocol stack,
271 \item an extra connection has to be opened.
272 \end{itemize}
274 Trojitá includes full support for these extensions. However, because there is {\em no} way of discovering whether the
275 IMAP and SMTP daemons ``trust'' each other,~\footnote{The mere presence of the {\tt URLAUTH} capability on the IMAP
276 server side and the advertised {\tt BURL} extension by the ESMTP service does not imply that an eventual submission will
277 succeed.} Trojitá requires the user to explicitly enable a checkbox in the settings dialog to activate these
278 features.~\footnote{The {\tt CATENATE} extension is not subject to this limitation; it will be used whenever the server
279 announces its presence, unless the user has explicitly forbidden its usage. This is equivalent to how Trojitá handles
280 any other IMAP extension.} Using this explicit confirmation is intended to deter bugs like those which have plagued
281 other MUA implementations \cite{qmf-fastmail-burl-bug} from affecting Trojitá. This implementation might change in
282 future.
284 \subsubsection{Tunneling SMTP inside IMAP}
286 A second approach in which the IETF community and related researchers have tried to tackle down the e-mail submission
287 was via actually tunneling the real ESMTP session through the IMAP protocol \cite[p. 30]{draft-maes-lemonade-p-imap}.
288 This approach removes the burden of establishing a second connection, but retains the required complexity of having to
289 ship and test a full ESMTP client stack. This approach is {\em by definition} as flexible as any future ESMTP extension
290 and does not require any changes on the (ESMTP) server side (besides support for SMTP pipelining \cite{rfc2920}), with
291 only a limited amount of modifications for the IMAP clients. On the other hand, the requirement to tunnel a second
292 protocol through IMAP adds a lot of complexity to their interaction and it appears that either the IMAP daemon or the
293 SMTP server has to include support for BURL nonetheless. One has to wonder if the ESMTP serialization, no matter how
294 useful when speaking ESMTP, can be replaced with something terser. Consider the following example from the proposed
295 draft:
297 \begin{minted}{text}
298 C: a004 XDELIVER CAPABILITY
299 S: * XDELIVER CAPABILITY (8BITMIME EXPN HELP)
300 C: a005 XDELIVER TEXT {123+}
301 C: EHLO
302 C: MAIL FROM: john@smith.com
303 C: RCPT TO: mooch@owatagu.siam.edu
304 C: DATA
305 C: URL /Inbox;UIDVALIDITY=9999/;UID=33;Section=BODY
307 S: * XDELIVER {321}
308 S: 220 mail.metastructure.net ESMTP
309 S: 250-mail.metastructure.net
310 S: 250-AUTH LOGIN CRAM-MD5 PLAIN
311 S: 250-AUTH=LOGIN CRAM-MD5 PLAIN
312 S: 250-PIPELINING
313 S: 250 8BITMIME
314 S: 250 ok
315 S: 250 ok
316 S: 354 go ahead
317 S: 250 ok 1126337586 qp 28229
318 \end{minted}
320 This communication is indeed rather verbose. The same result is achieved in a clearer way through the {\tt UID SUBMIT}
321 command I propose later in this chapter.
323 No known deployments of these drafts exist and no further standardization process has been observed on the relevant
324 mailing lists.
326 \subsubsection{The POSTADDRESS Draft}
328 For the sake of completeness, one should also mention the {\tt POSTADDRESS} draft
329 \cite{draft-melnikov-imap-postaddress}. This extension tried to provide a way for servers to announce an Internet
330 e-mail address for each mailbox which could act as the ``Sent'' folder. The idea behind this proposal was that clients
331 should obtain this e-mail address and include it in the {\tt Bcc} field of the outgoing e-mail messages. Doing so would
332 facilitate the same result as the {\tt APPEND} command, but without having to send the data explicitly. Drawbacks of
333 this method included privacy concerns and the fact that this extension might not work with Sieve or other server-side
334 filtering \cite{postaddress-sieve}. As of July 2012, this idea appears to have been abandoned for good.
336 \subsection{The SENDMAIL Extension}
338 In mid 2011, a few requests for e-mail submission over IMAP have appeared on the {\tt imap5} mailing list
339 \cite{brong-imap5-list-of-ideas} (with the expected outcome of calling names \cite{crispin-brong-you-suck-useless}).
340 The idea presented by proponents of the ``submit mail over IMAP'' camp appeared to be that:
342 \begin{itemize}
343 \item Using two protocols ``for e-mail'' is a significant source of support requests for large service providers.
344 \item The IETF-approved approach to the ``forward-without-download'', i.e. the {\tt URLAUTH} and {\tt BURL}
345 extensions, are not widely deployed. They are also notoriously hard to implement and deploy for server vendors and
346 system integrators.
347 \item Extending IMAP to allow for message submission simplifies the number of authorization channels.
348 \item Handling the ``common case'' in an efficient manner outweighs the drawback of enabling a second e-mail
349 submission protocol.
350 \end{itemize}
352 Based on the said discussion, it appears that there is a strong demand for having ``such a feature'' in IMAP. I've
353 therefore read through various mailing list archives, studied previous iterations of the discussion and tried to address
354 many issues which were previously considered to be a blocking issue (like the apparent need to rewrite message bodies
355 when dealing with blind-carbon-copies (the {\tt Bcc} headers), having to scan message contents unconditionally, or a
356 lack of delivery status notification (DSN) control). The extension which I propose as a part of this thesis has the
357 following advantages:
359 \begin{itemize}
360 \item It removes the need for clients to speak both ESMTP and IMAP protocols.
361 \item It reduces the amount of account details to ask users for.
362 \item Whole communication is performed over a single connection, eliminating a significant cause of support requests.
363 \item All features can be implemented as a thin wrapper over a {\tt sendmail}-compatible binary which is nowadays
364 shipped by most MTAs.
365 \item Messages can be submitted using a single round trip once stored on the server.
366 \item The extension plays well with {\tt CATENATE}.
367 \item Further ESMTP extensions can be trivially integrated through IMAP capabilities.
368 \end{itemize}
370 The extension proposes a single IMAP command, the {\tt UID SENDMAIL}. This commands accepts a reference to an already
371 existing message to be sent along with a complimentary list of submission options. This list is intended to serve as a
372 substitute to the missing ESMTP envelope; in the initial version, clients can use it to specify senders and receivers or
373 for control of the DSN options. The command is also ready for future extensibility; other options can be easily added
374 to the specification when further ESMTP extensions are defined.
376 A typical conversation with a {\tt SENDMAIL}-capable IMAP server can therefore look similar to the following (note that
377 white space has been added to the {\tt UID SENDMAIL} command for clarity):
379 \begin{minted}{text}
380 C: x UID SENDMAIL 123 (FROM "foo@example.org"
381 RECIPIENT "a@example.org"
382 RECIPIENT "b@example.org"
383 DSN (delay failure)
385 S: * 10 FETCH (UID 123 FLAGS (\$Submitted))
386 S: x OK Message passed to the sendmail binary
387 \end{minted}
389 Changing Trojitá to support e-mail delivery via the proposed extension was just a matter of plugging another
390 implementation of its abstract MSA~\footnote{Mail Submission Agent} interface.
392 Full text of this specification is available in section \secref{sec:draft-imap-sendmail}. An interesting discussion
393 followed \cite{jkt-i-p-draft-sendmail} after I posted my initial draft to the {\tt imapext} IETF mailing list.
395 \end{document}