BACHELOR THESIS Jan Kundrát IMAP E-Mail Client
Total Page:16
File Type:pdf, Size:1020Kb
Charles University in Prague Faculty of Mathematics and Physics BACHELOR THESIS Jan Kundr´at IMAP E-mail Client Department of Software Engineering Supervisor: Mgr. Vlastimil Babka Study Program: Computer Science, Programming 2009 I’d like to thank my supervisor, Mgr. Vlastimil Babka, for his numerous advices during the writing of this thesis, Ms. Anna Adamcov´a for her great patience and support, and my parents for supporting my studies. I hereby declare that I wrote this thesis myself using the referenced sources only. I also agree with lending and publishing of this thesis. Prague, May 29, 2009 Jan Kundr´at 2 Contents 1 Introduction 7 1.1 Motivation............................ 7 1.2 Structureofthethesis ..................... 8 2 IMAP and Related Technologies 9 2.1 BasicConcepts ......................... 9 2.2 IMAP-specificAttributes. 10 2.3 MIME .............................. 12 2.3.1 MessageasaContainer. 12 2.3.2 International Characters in Messages . 13 2.3.3 MIMESupportinIMAP. 13 2.4 IMAPProtocolFlow ...................... 14 2.4.1 Commandsandresponses . 14 2.4.2 Mailbox Synchronization . 15 2.4.3 ChangestoMailbox . 16 2.4.4 Fetching and Manipulating Messages . 17 2.4.5 Queries Against Other Mailboxes . 18 2.4.6 Searching, Sorting and Threading . 18 2.4.7 Manipulating Mailboxes . 18 2.4.8 Sessiontermination. 19 2.4.9 IMAPExtensions. 19 2.5 OtherMethodsofMailStoreAccess . 20 2.5.1 POP3 .......................... 20 2.5.2 MAPI .......................... 20 2.5.3 Webmail......................... 20 2.5.4 IMAPCriticism..................... 21 3 3 Trojita Design 23 3.1 Overview............................. 23 3.2 Model-ViewArchitecture. 25 3.3 Parser .............................. 26 3.3.1 Low-levelParser . .. .. 26 3.3.2 Parser .......................... 27 3.4 Cache .............................. 28 3.5 Streams ............................. 28 3.6 ModelinDetail ......................... 29 3.6.1 TheTree......................... 29 3.6.2 ProxyModels ...................... 32 3.6.3 Offline and Expensive Network Mode . 33 3.7 MessageView .......................... 33 3.7.1 NetworkManager. 34 3.7.2 WidgetFactory ..................... 35 3.7.3 HTMLMail....................... 36 3.8 GUI ............................... 36 4 Other IMAP Implementations 38 4.1 Alpine2.0 ............................ 38 4.2 Mutt1.5.19 ........................... 39 4.3 KMail3.5 ............................ 39 4.4 MozillaThunderbird2.0 . 40 4.5 Mailody ............................. 41 4.6 OutlookExpress ........................ 42 4.7 WindowsLiveMail ....................... 43 4.8 Trojita.............................. 43 5 User’s Guide 45 5.1 AboutTrojita.......................... 45 5.2 Installation ........................... 45 5.2.1 Prerequisites. .. .. 45 5.2.2 Obtainingsourcecode . 46 5.2.3 Installing ........................ 46 5.3 UsingTrojita .......................... 47 5.3.1 Configuration ...................... 47 5.3.2 Basicusage ....................... 48 5.3.3 Managing Messages and Mailboxes . 49 4 5.3.4 MessageComposition. 50 5.3.5 CheckingMail...................... 50 5.4 Advancedusage......................... 50 5.4.1 PartialMessageFetching . 50 5.4.2 OfflineMode ...................... 50 5.4.3 ExpensiveNetwork . 50 5.4.4 OnlineMode ...................... 51 5.4.5 LocalCache....................... 51 5.4.6 FullTreeView ..................... 52 6 Conclusion 53 Bibliography 55 A Contents of the CD 59 5 N´azev pr´ace: IMAP E-mail Client Autor: Jan Kundr´at Katedra (´ustav): Katedra softwarov´eho inˇzen´yrstv´ı Vedouc´ıbakal´aˇrsk´epr´ace: Mgr. Vlastimil Babka E-mail vedouc´ıho: Vlastimil.Babka@mff.cuni.cz Abstrakt: Pˇredloˇzen´apr´ace popisuje implementaci pokroˇcil´eho klienta pro pr´aci s poˇstou pomoc´ı protokolu IMAP. Hlavn´ım zamˇeˇren´ım je podpora relevantn´ıch standard˚us d˚urazem na efektivn´ı implementaci; vyuˇz´ıv´ase pokroˇcil´ych vlastnost´ı IMAPu, jako napˇr´ıklad IDLE notifikac´ı, parsov´an´ı zpr´av na stranˇeserveru ˇci lok´aln´ıho ukl´ad´an´ıe-mail˚us moˇznost´ıpr´ace of- fline. Spojen´ıs IMAP serverem je realizov´ano protokolem TCP s volitelnou moˇznost´ıTLS ˇsifrov´an´ıˇci pˇres lok´alnˇebeˇz´ıc´ı proces. Projekt umoˇzˇnuje psan´ı a odes´ıl´an´ıjednoduch´ych mail˚u, podporov´ano je odes´ıl´an´ıpomoc´ıprotokolu SMTP a sendmailem. C´ılov´aplatforma je framework Qt na Linuxu, avˇsak aplikace je portovateln´ai na jin´eplatformy. Kl´ıˇcov´aslova: IMAP, e-mail, MIME, Qt, SMTP Title: IMAP E-mail Client Author: Jan Kundr´at Department: Department of Software Engineering Supervisor: Mgr. Vlastimil Babka Supervisor’s e-mail address: Vlastimil.Babka@mff.cuni.cz Abstract: This thesis describes the implementation of an advanced IMAP e-mail client, Trojita. Focusing on standards compliance, the client sup- ports a wide range of IMAP features crucial for an efficient implementation such as IDLE notifications, server-side message parsing and caching of re- trieved body data for offline operation. Connecting to the IMAP server is supported over TCP sockets, optionally secured via the TLS encryption, as well as through a local process. Basic message composition and sending via both SMTP and a local sendmail instance is supported. The target platform is the Qt framework on Linux, but the application is reasonably portable. Keywords: IMAP, e-mail, MIME, Qt, SMTP 6 Chapter 1 Introduction Although being surpassed in popularity by other technologies like the World Wide Web and peer-to-peer applications, the electronic mail is still one of the few services that an average user can name when talking about the Internet. There are many ways how to send and receive e-mail, some of them being more popular than the others. In this thesis, we try to resurrect the older approach to reading e-mail, that is, using an standalone application. In the recent years, the improvements in the field of web browsers and related technologies allowed rapid development of new features that were not conceivable just five years ago. Using these new functions, the popular- ity of web-based e-mail readers grew accordingly. However, using a proper standalone application has numerous benefits from being able to work when not connected to the Internet to providing a truly instant feedback, a feature that is still somewhat missing from most of the web applications. Managing e-mail over a standardized protocol also avoids vendor lock-in, a highly dan- gerous phenomenon associated with using proprietary messaging solutions. To date, the Internet Message Access Protocol [1] (or IMAP) is the only such protocol. 1.1 Motivation Implementing an IMAP client is far from trivial. While there are certainly numerous stable and widely-used Mail User Agents on the market, none of them fulfills all the expectations of reasonable performance and efficiency. Indeed, most of these applications started as MUAs speaking the POP3 protocol only, adding support for IMAP later on. Typically, this support 7 was implemented long since the initial design phase of the product was completed, resulting in suboptimal design choices [2]. Therefore, we believe there is still a place on the market for a stable, highly performing IMAP e-mail application. 1.2 Structure of the thesis In the following chapter, we provide a gentle introduction to the world of IMAP and related standards such as MIME. Chapter 3 explains some of the design choices made during the development process of Trojita, as well as elaborates on the internal application architecture and structure. An overview of other IMAP implementations on the market is provided in chap- ter 4, including a comparison about how well they operate when compared to Trojita. The User’s Guide is available in chapter 5. Finally, the whole thesis is concluded by a wrap-up providing an overview of what we implemented and how the result is usable. 8 Chapter 2 IMAP and Related Technologies Electronic mail, or a SMTP-mail, is a public service suitable for automated message exchange among connected entities. Interoperability is guaranteed by several Internet standards, usually codified in the form of RFC docu- ments. Subject to these standards are various protocols specifying the rules of what entities can communicate to each other as well as definition of the format of all transmitted messages. In this section, we provide a gentle in- troduction to the numerous standards which deal with this highly complex topic. 2.1 Basic Concepts An email message, or a RFC-8221 message, consists of three parts: Envelope, Header and Body. The envelope is the only relevant part for mail exchange among Internet hosts; it includes basic information like addresses of the sender and recipient. A header provides more detailed metadata about the message, from human-readable sender addresses and message route traces to user-defined fields. Some pieces of this information are used when the original delivery fails for some reason, like the Return-Path header. The header also serves as a basis for an IMAP envelope data which is explained later in chapter 2.2. Finally, a message body is what an average user typically 1As defined by the RFC 822 standard and subsequently modified by RFC 2822 [3] and others 9 refers to as “the e-mail”. It might contain just a plain US-ASCII text, an HTML message with embedded images or it could be a recursively defined entity with rich tree structure. An IMAP server is a host in the Internet which provides access to local mail store via the standard protocol, IMAP4rev1 in this case. The IMAP server might be located in an employer’s data center or on the user’s laptop, for example. An MTA2 or an SMTP Server is an Internet host whose purpose is de- livery of the RFC 2822 mail. MTAs in the Internet communicate with each other, determining routing information from MX-records3 in the DNS. As a common practice nowadays, these servers also accept outgoing e-mail from their own users, provided the connection is properly authenticated, either by simple fact that it originates from a trusted network or that the user has provided her credentials, typically as a user name and password combination or in the form of an X.509 certificate. A Mailbox or a Mail Folder is a place on the IMAP server where the messages are logically stored.