* set advanced setup dialog to position "center on parent"
[modest] / docs / design / modest-design.tex
1 %
2 % modest-design.tex
3 % Time-stamp: <2006-05-12 18:47:13 (djcb)>
4 %
5 \documentclass{book}
6 \usepackage{graphics}
7
8 % macros
9 \newcommand{\modest}{{\tt modest} } 
10 \newcommand{\tinymail}{{\tt tinymail} }
11 \newcommand{\camel}{{\tt libcamel} }
12
13 \newcommand{\djcbemail}{$<$dirk-jan.binnema@nokia.com$>$ }
14 \newcommand{\smtp}{{\sc SMTP} }
15 \newcommand{\pop}{{\sc POP3} }
16 \newcommand{\imap}{{\sc IMAP} }
17 \newcommand{\gtk}{{\sc GTK+} }
18 \newcommand{\gconf}{{\sc GConf} }
19
20 \author{Dirk-Jan C. Binnema\\\djcbemail}
21 \title{{\huge \modest}\\
22 an e-mail program for small devices\\
23 architecture \& design}
24 \setlength{\parskip}{8pt}
25 \setlength{\parindent}{0pt}
26 \begin{document}
27 \maketitle
28 \tableofcontents
29 \chapter*{Introduction}
30 \modest is a mail user agent (MUA) targetting small devices, in particular
31 Nokia's {\em Nokia 770 Internet Tablet}. This document describes the design
32 and implementation of this software.
33
34 \modest lives at the top of a extensive stack of software. It is built on
35 top of {\tt libtinymail}, and uses its libcamel backend. It strives to the be
36 a simple yet powerful program, geared towards small devices, for example (but
37 not limited to) Nokia's 770 internet tablet. An important goal is to minimize
38 memory usage while still being able to handle significant amounts of email
39 quickly; much of that is achieved simply by using \tinymail, which
40 uses a number of clever tricks for that, such as the proxy design pattern for
41 listing email headers, and not needing memory for headers which are not
42 currently visible.
43
44 \modest, in turn, also tries to be efficient, fast and {\em scalable}. That
45 means that the MUA should support multiple user-interfaces, perhaps making it
46 even possible to switch between them during runtime. 
47
48 To summarize the goals for \modest:
49 \begin{itemize}
50 \item target devices with limited amounts of memory ("limited" in 2006 terms means
51   less than 64Mb, and of which only part can be used for e-mail);
52 \item target Linux/Unix-like environments with GLib/GTK+-based support;
53 \item support multiple user-interface (UIs) with as
54   much code sharing as possible between the different UIs.
55 \end{itemize}
56
57 Like {\tt libtinymail} and {\tt libcamel}, \modest is programmed in C, using the
58 GObject-system for object-oriented (OO) features. For now, it specifically
59 targets \gtk based UIs (and derivatives like "Hildon"). 
60
61 \chapter{Architecture}
62 \modest tries to be quite flexible in its design. However, it's always
63 important not to make things {\em too} generic. Both for reasons of time
64 limitations and keeping the software understandable and ``modest'', it's
65 important to limit the scope.
66
67 For \modest, the following:
68 \begin{itemize}
69   \item \modest is a e-mail program using the \tinymail and \camel libraries;
70   \item \modest targets \gtk and \gconf-based user-interfaces, including the Hildon
71     environment;
72   \item \modest main use-case is in small, mobile device such as Nokia's {\em 770
73     Internet Tablet};
74   \item However, effort is made also to make \modest usable as a
75     general-purpose e-mail client on normal desktop computer.
76 \end{itemize}
77
78
79 \chapter{Design}
80 In this chapter, we'll discuss the design of various parts of \modest. We'll
81 not go into the details of various APIs. Please consult the documentation
82 generated from the source code ({\tt gtk-doc}) for that.
83
84 There are {\tt \#define}-definitions for many account keys in {\tt
85   modest-account-keys.h}. 
86
87 \section {Configuration}
88 Configuration is the part of \modest that deals with storing all
89 settings. While the design allows for alternative implementations, currently
90 only {\tt gconf} is supported as a backend.
91
92 All dealing with configuration is done with the {\tt ModestConf} GObject. This
93 object is declared in {\tt modest-conf.h}, and the GConf-based implementation in
94 {\tt modest-conf-gconf.c}. As said, there could be different implementations
95 {\tt modest-conf-myconf.c}, but we use the GConf-backed system. However,
96 nothing GConf-specific is visible in the ModestConf API.
97
98 \section{Account Management}
99 Account Management is the part of \modest that deals with the setting related
100 to sending and receiving of e-mail. We will follow the libcamel-convention of
101 using the term {\em store} for a e-mail storage/retrieval server, and a {\em
102   transport} for a server that transports mail to its destination.
103
104 In practice, the following types are available:
105 \begin{itemize}
106   \item {\bf stores}: \pop and \imap;
107   \item {\bf transports}: {\tt sendmail} and \smtp.
108 \end{itemize}
109
110 \subsection{Definitions}
111 \begin{itemize}
112     \item An {\bf account} is a named entity consisting of a {\bf store} and a
113     {\bf transport}.\footnote{For our mobile use-cases, the {\em transport}
114       cannot be a static entity, but may depend on the network
115       connection. That is however not part of Account Management, so not
116       discussed here}
117     \item  A {\bf server account} is account describing the connection with a
118       specific server. Server accounts come in two type:
119       \begin{itemize}
120       \item A {\bf transport} describes the connection information (servername,
121         username, password etc.) for a transport server;
122       \item A {\bf store} describes the connection information for a store server;
123       \end{itemize}
124 \end{itemize}
125
126 \subsection{Code}
127 The functions to deal with account and server accounts are located in {\tt
128   ModestAccountMgr}, ie. in {\tt modest-account-mgr.[ch]}. There function to
129 add specific values for both, to list the available ones, etc. Please refer to
130 the source code documentation for details.
131
132 \subsection{Location in configuration database}
133 {\em Accounts} can be found in {\tt /apps/modest/accounts}, while {\em server
134   accounts} can be found in {\tt /app/modest/server\_accounts}.
135
136 The following image show an account {\em accountstest} with server accounts
137 {\tt mystore} and {\tt mytransport}.
138
139 \includegraphics{modest-account-mgr.png}
140
141 For each of the stores, there are number of parameters specified:
142 \begin{itemize}
143 \item {\tt hostname} - the place where the server resides;
144 \item {\tt username} - the username;
145 \item {\tt password} - the password;
146 \item {\tt proto} - the protocal for communication with this server - for
147   now these are the following valid values (literal strings):
148   \begin{itemize}
149   \item {\tt sendmail};
150   \item {\tt smtp};
151   \item {\tt pop}
152   \item {\tt imap}.
153   \end{itemize}
154 \end{itemize}
155
156 In the {\tt modest-proto.[ch]} there are various functions to check whether
157 something is a valid protocol, and whether it is a transport of a store. 
158
159 Note that server accounts and accounts are relatively independent. While
160 accounts refer to two server accounts, these server accounts can be
161 used by other accounts as well.
162
163 The reason two keep accounts and server accounts separately, is a bit of
164 flexibility. In mobile use-cases, quite often it's desirable to use a
165 network-specific smtp-server. The chosen structure makes it easy to iterate
166 over all smtp-servers and find the right one.
167
168 \chapter{Finding the Transport}
169 One of the interesting topics in designing a mobile e-mail client is to deal
170 with transports (in particular, \smtp). The reason for that is that the
171 majority of \smtp-servers only allow e-mail from the same network. That means
172 that for example {\tt smtp.some-isp.com} will only accept mail from ({\tt MAIL
173   FROM:}) {\tt user@some-isp.com}, and refuse mail from {\tt
174   user@some-other-isp.com}, unless the recipient {\tt RCPT TO:} is on the same
175 network. 
176
177 To summarize:
178
179 \footnote{Some smtp-servers {\bf will} accept mail
180   from} 
181
182
183
184 \chapter*{Coding guidelines}
185 When hacking on \modest, please honour these time-tested coding guidelines.
186 First, please follow the {\em Linux CodingStyle guidelines}:\\
187        {\tt /usr/src/linux/Documentation/CodingStyle}\\
188 Then, read the {\em OSSO Coding Style Guidelines}:\\
189         {\tt http://foo}
190 Here are only some additional notes.
191
192 Your editor may help you with this, for example for {\tt emacs}:
193 \begin{verbatim}
194   (c-set-style "K&R")
195   (setq tab-width 8)
196   (setq indent-tabs-mode t)
197   (setq c-basic-offset 8)
198 \end{verbatim}
199
200 Or the equivalent in your favourite editor.
201
202 Lines should not exceed 100 characters.
203
204 Global functions (the ones in {\tt .h}-files) should be commented using 
205 doxygen-style comments.
206
207 Furthermore, please follow 'conventional wisdom' for programming with 
208 GLib/GTK+/GObject. Some things to remember:
209 \begin{itemize}
210 \item {\tt g\_new}, {\tt g\_malloc} and friends {\bf never} return {\tt NULL}. They terminate
211   the application if it happens (normally). No need to check for {\tt NULL} returns.
212 \item {\tt g\_return\_if\_fail} and friends may be 'turned off', ie. they are
213   to be used for error checking, but {\bf not} for your programming logic
214 \end{itemize}
215
216 To test for the validity of function parameters,
217 %   g_return_if_fail / g_return_val_if_fail
218
219 ie.
220 \begin{verbatim}
221 double
222 one_divided_by_x (double x)
223 {
224         g_return_val_if_fail ((x != 0), -1);
225         return 1/x;     
226 }
227 \end{verbatim}
228 This will give us a warning (and a wrong answer) in case we do
229 %     one_divided_by_x (0);
230
231 This is good for testing, but it's important to keep in mind that in
232 production code the check may be turned off. The caller should make
233 sure that the parameter is correct (ie. != 0 in this case).
234
235 Now, if a similar check is actually part of the logic of a function,
236 then {\tt g\_return\_if\_fail} should not be used, but instead, e.g.:
237 \begin{verbatim}
238 int
239 stack_item_num (Stack *stack)
240 {
241         if (!stack)
242                 return 0;
243
244         /* calculate item count */
245 }
246 \end{verbatim}
247 \end{document}