* cosmetics
[modest] / docs / reference / modest-docs.sgml
1 <?xml version="1.0"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
3                "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
5
6   <copyright>
7   <year>2006</year>
8   <holder>Nokia Corporation</holder>
9   </copyright>
10
11   <bookinfo>
12     <title>modest technical documentation</title>
13   </bookinfo>
14
15   <preface>
16     <title>Introduction</title>
17     <para><application>modest</application> is a mail user agent
18       (<abbrev>MUA</abbrev>) targetting small devices, in particular Nokia's
19       <productname>Nokia 770 Internet Tablet</productname>. This document
20       describes the design and implementation of this software.
21     </para>
22     
23     <para><application>modest</application> lives at the top of a extensive
24       stack of software. It is built on top
25       of <application>tinymail</application>, and uses its libcamel
26       backend. It strives to the be a simple yet powerful program, geared
27       towards small devices, for example (but not limited
28       to) <productname>Nokia's 770 internet tablet</productname>. An important
29       goal is to minimize memory usage while still being able to handle
30       significant amounts of email quickly; much of that is achieved simply by
31       using <application>tinymail</application>, which uses a number of clever
32       tricks for that, such as the proxy design pattern for listing email
33       headers, and not needing memory for headers which are not currently
34       visible.
35     </para>
36     
37     <para>
38       <application>modest</application>, in turn, also tries to be efficient,
39       fast and scalable. That means that the <abbrev>MUA</abbrev> should
40       support multiple user-interfaces, perhaps making it even possible to
41       switch between them during runtime.
42     </para>
43     
44     <para>To summarize the goals for <application>modest</application>:
45     <itemizedlist>
46       <listitem>target devices with limited amounts of memory ('limited' in 2006
47         terms means less than 64Mb, and of which only part can be used for
48         e-mail);</listitem>
49       <listitem>target Linux/Unix-like environments with GLib/GTK+-based
50       support;</listitem>
51       <listitem>support multiple user-interface (UIs) with as much code
52         sharing as possible between the different UIs.</listitem>
53     </itemizedlist></para>
54     
55     <para>Like <application>tinymail</application>
56     and <application>libcamel</application>, <application>modest</application>
57     is programmed in C, using the <package>GObject</package>-system for
58     object-oriented (OO) features. For now, it specifically targets \gtk based
59     UIs (and derivatives like 'Hildon').</para>
60
61   </preface>
62
63   <part>
64     <title>Architecture</title>
65     <partintro>
66       <para><application>modest</application> tries to be quite flexible in its
67         design. However, it's always important not to make things too
68         generic. Both for reasons of time limitations and keeping the software
69         understandable and 'modest', it's important to limit the scope.
70       </para>
71       
72       <para>
73         For <application>modest</application>, the following:
74         <itemizedlist>
75           <listitem><application>modest</application> is a e-mail program
76           using the <package>tinymail</package> and <package>camel</package>
77           libraries;</listitem>
78           <listitem><application>modest</application> targets gtk and
79             gconf-based user-interfaces, including the Hildon
80             environment;</listitem>
81           <listitem><application>modest</application> main use-case is in
82             small, mobile device such as the <productname>Nokia 770 Internet
83             Tablet</productname>;</listitem>
84           <listitem>However, effort is made also to
85             make <application>modest</application> usable as a general-purpose
86             e-mail client on normal desktop computer.</listitem>
87         </itemizedlist>
88       </para>
89     </partintro>
90   </part>
91       
92   <part>
93     <title>Design</title>
94     <partintro>
95       <para>In this part, we'll discuss the design of various parts of
96         <application>modest</application>. We'll not go into the details of
97         various APIs in this chapter.  Please consul the documentation generated
98         from the source code (<systemitem>gtk-doc</systemitem>) for that.</para>
99     </partintro>
100     
101     <chapter>
102       <title>Configuration</title>
103       <para>Configuration is the part of <application>modest</application>
104         that deals with storing all settings. While the design allows for
105         alternative implementations, currently
106         only <systemitem>GConf</systemitem> is supported as a backend.
107       </para>
108       
109       <para>
110         All dealing with configuration is done with
111         the <classname>ModestConf</classname>-class. It is declared
112         in <filename> modest-conf.h</filename>, and
113         the <systemitem>GConf</systemitem>-based implementation in 
114         <filename>modest-conf.c</filename>. As said, there could be
115         different implementations --
116         nothing <systemitem>GConf</systemitem>-specific is visible in the
117         <classname>ModestConf</classname>-<abbrev>API</abbrev>.
118       </para>
119     </chapter>
120     
121     <chapter>
122       <title>Account Management</title>
123       <para>
124         Account Management is the part of <application>modest</application>
125         that deals with the setting related to sending and receiving of
126         e-mail. We will follow the libcamel-convention of using the
127         term <emphasis>store</emphasis> for an e-mail storage/retrieval
128         server, and a <emphasis>transport</emphasis> for a server that
129         transports mail to its destination.
130       </para>
131       
132       <para>
133         In practice, the following types are available:
134         <itemizedlist>
135           <listitem><emphasis>stores</emphasis>: <abbrev>POP</abbrev>
136             and <abbrev>IMAP</abbrev>; </listitem>
137           <listitem> <emphasis>transports</emphasis>: <systemitem>sendmail</systemitem>
138             and <abbrev>SMTP</abbrev>.</listitem>
139         </itemizedlist>
140       </para>
141       
142       <sect1>
143         <title>Definitions</title>
144         <itemizedlist>
145           <listitem>An <emphasis>account</emphasis> is a named entity
146             consisting of a <emphasis>store</emphasis> and
147             a <emphasis>transport</emphasis>. Note: For our mobile use-cases,
148               the <emphasis>transport</emphasis> cannot be a static entity, but
149               may depend on the network connection. That is however not part of
150               Account Management, so not discussed here</listitem>
151           <listitem>A <emphasis>server account</emphasis> is account
152             describing the connection with a specific server. Server accounts
153             come in two type:
154             <itemizedlist>
155               <listitem>A <emphasis>transport</emphasis> describes the connection information
156                 (servername, username, password etc.) for a transport
157                 server;</listitem>
158               <listitem>A <emphasis>store</emphasis> describes the connection information for
159                 a store server;</listitem>
160             </itemizedlist>
161           </listitem>
162         </itemizedlist>
163       </sect1>
164               
165       <sect1>
166         <title>Code</title>
167         <para>The functions to deal with account and server accounts are
168           located in <classname>ModestAccountMgr</classname>, ie. in 
169           <filename>modest-account-mgr.[ch]</filename>. There function to add
170           specific values for both, to list the available ones, etc. Please
171           refer to the source code documentation for details.
172         </para>
173       </sect1>
174       
175       <sect1>
176         <title>Location in configuration database</title>
177         <para>
178           <emphasis>Accounts</emphasis> can be found
179           in <systemitem>/apps/modest/accounts</systemitem>,
180           while <emphasis>server accounts</emphasis> can be found
181           in <systemitem>/app/modest/server_accounts</systemitem>.
182         </para>
183         
184         <para>
185           The following image show an
186           account <systemitem>accountstest</systemitem> with server accounts
187           <systemitem>mystore</systemitem>
188           and <systemitem>mytransport</systemitem>.
189           <imagedata fileref="modest-account-mgr.png"/>
190         </para>
191
192         <para>
193           For each of the stores, there are number of parameters specified:
194           <itemizedlist>
195             <listitem><emphasis>hostname</emphasis> - the place where the server resides;</listitem>
196             <listitem><emphasis>username</emphasis> - the username;</listitem>
197             <listitem><emphasis>password</emphasis> - the password;</listitem>
198             <listitem><emphasis>proto</emphasis> - the protocal for communication with this server - for
199               now these are the following valid values (literal strings):
200               <itemizedlist>
201                 <listitem><emphasis>sendmail</emphasis>;</listitem>
202                 <listitem><emphasis>smtp</emphasis>;</listitem>
203                 <listitem><emphasis>pop</emphasis></listitem>
204                 <listitem><emphasis>imap</emphasis>.</listitem>
205               </itemizedlist>
206             </listitem>
207           </itemizedlist>
208         </para>
209         
210         <para>In <filename>modest-proto.[ch]</filename> there are various
211           functions to check whether something is a valid protocol, and
212           whether it is a transport of a store.
213         </para>
214         
215         <para>Note that server accounts and accounts are relatively independent. While
216           accounts refer to two server accounts, these server accounts can be
217           used by other accounts as well.
218         </para>
219         
220         <para>The reason two keep accounts and server accounts separately, is a bit of
221           flexibility. In mobile use-cases, quite often it's desirable to use a
222           network-specific smtp-server. The chosen structure makes it easy to iterate
223           over all smtp-servers and find the right one.
224         </para>
225       </sect1>
226     </chapter>
227
228     <sec1>
229       <title>Account Management and Tinymail</title>
230       <para>
231         Tinymail needs the information about all configured accounts - and the
232         mechanism that it uses for that
233         is <interface>TnyAccountStoreIface</interface>. We don't want to use
234         the tinymail-provided <classname>TnyAccountStore</classname>, but
235         provide our own implementation
236         instead: <classname>ModestTnyAccountStore</classname>. This class
237         implements the <interface>TnyAccountStoreIface</interface>-interace in
238         terms of the aforementioned <classname>ModestAccountMgr</classname>.
239       </para>
240       
241       <para>
242         One unexpected function
243         that  <classname>ModestTnyAccountStore</classname> needs to implement
244         is <symbol>tny account_store get_session</symbol> (to get the
245         Camel-session). This function must be provided as a public function,
246         with that exact name.
247       </para>
248     </sec1>
249   </chapter>
250   
251   
252   
253
254   <chapter>
255     <title>Finding the right transport</title>
256     <para>
257       One of the interesting topics in designing a mobile e-mail client is
258       to deal with transports (in
259       particular, <acronym>SMTP</acronym>). The reason for that is that
260       the majority of <acronym>SMTP</acronym>-servers only allow e-mail
261       from the same network. That means that for example <systemitem>
262         smtp.some-isp.com</systemitem> will only accept mail from
263       (<command>MAIL FROM:</command>) <systemitem>
264         user@some-isp.com</systemitem>, and refuse mail
265       from <systemitem>user@some-other-isp.com</systemitem>, unless the
266       recipient (<command>RCPT TO:</command>) is on the same network.
267     </para>
268   </chapter>
269   </part>
270   
271
272
273   <chapter>
274     <title>Coding guidelines</title>
275     <para>
276       When hacking on modest, please honour these time-tested coding guidelines.
277       First, please follow the <emphasis>Linux CodingStyle guidelines</emphasis>
278       (<filename>/usr/src/linux/Documentation/CodingStyle</filename>).
279     </para>
280     
281     <para>
282       Here are only some additional notes.
283     </para>
284
285     <para>
286       Your editor may help you with this, for example for <application>emacs</application>:
287       <programlisting>
288       (c-set-style "K&amp;R")
289       (setq tab-width 8)
290       (setq indent-tabs-mode t)
291       (setq c-basic-offset 8)
292       </programlisting>
293       
294       Or the equivalent in your favourite editor.
295     </para>
296     
297     <para>
298       Lines must not exceed 100 characters.
299     </para>
300
301     <para>
302       Functions should do one thing, and do it well. In general, functions
303       should not be much longer than 20-30 lines (except for, say, handling
304       many different cases in a 'switch'-statement). Files should not get to
305       big either; if there's more than, say, 800 lines, it probably shows the
306       codes needs to be refactored a bit.
307     </para>
308       
309     <para>
310       Code should compile cleanly
311       with <command>gcc</command>'s <symbol>-Wall</symbol> compile option. Of
312       course this might not always be possible due to problems in dependent
313       libraries and/or compiler version. Therefore, do not
314       include <symbol>-Werror</symbol> in the standard compile options.
315     </para>
316
317     <para>Global functions (the ones in <filename>.h</filename>-files) should
318       be commented using
319       <systemitem>gtk-doc</systemitem>.
320     </para>
321     
322     
323     
324
325     <para>
326         Furthermore, please follow 'conventional wisdom' for programming with 
327         GLib/GTK+/GObject. Some things to remember:
328         <itemizedlist>
329           <listitem> <function>g_new</function>, <function>g_malloc</function> and
330             friends <emphasis>never</emphasis> return <function>NULL</function>. They terminate
331             the application if it happens (normally).  No need to check
332             for <function>NULL</function> returns;</listitem>
333           <listitem> <function>g_return_if_fail</function> and friends may be
334             'turned off', ie. they are to be used for error checking,
335             but <emphasis>not</emphasis> for your programming logic
336           </listitem>
337         </itemizedlist>
338     </para>
339   </chapter>
340   
341   <chapter>
342     <title>Object Index</title>
343   </chapter>
344         
345   <chapter>
346     <title>API Reference</title>
347     <xi:include href="xml/modest-ui.xml"/>
348     <xi:include href="xml/modest-tny-header-tree-view.xml"/>
349     <xi:include href="xml/modest-tny-msg-view.xml"/>
350     <xi:include href="xml/modest-account-mgr.xml"/>
351     <xi:include href="xml/modest-conf.xml"/>
352     <xi:include href="xml/modest-window-mgr.xml"/>
353     <xi:include href="xml/modest-tny-folder-tree-view.xml"/>
354     <xi:include href="xml/modest-tny-account-store.xml"/>
355     <xi:include href="xml/modest-tny-transport-actions.xml"/>
356     <xi:include href="xml/modest-main-window.xml"/>
357     <xi:include href="xml/modest-editor-window.xml"/>
358     <xi:include href="xml/modest-viewer-window.xml"/>
359     <xi:include href="xml/modest-proto.xml"/>
360     <xi:include href="xml/modest-account-keys.xml"/>
361     <xi:include href="xml/modest-conf-keys.xml"/>
362   </chapter>
363 </book>