* big commit, mainly cleanups:
[modest] / src / modest-runtime.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <config.h>
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <glib/gstdio.h>
34 #include <modest-runtime.h>
35 #include <modest-defs.h>
36 #include <modest-singletons.h>
37 #include <widgets/modest-header-view.h>
38 #include <widgets/modest-folder-view.h>
39 #include <modest-tny-platform-factory.h>
40 #include <modest-platform.h>
41 #include <modest-widget-memory.h>
42 #include <modest-widget-memory-priv.h>
43 #include <modest-local-folder-info.h>
44 #include <modest-account-mgr.h>
45 #include <modest-account-mgr-helpers.h>
46 #include <modest-icon-names.h>
47
48 static gboolean init_header_columns (ModestConf *conf, gboolean overwrite);
49 static gboolean init_local_folders  (void);
50 static gboolean init_default_account_maybe  (ModestAccountMgr *acc_mgr);
51 static void     init_i18n (void);
52 static void     init_stock_icons (void);
53 static void     init_debug_g_type (void);
54 static void     init_debug_logging (void);
55 static void     init_test_accounts (ModestAccountMgr *acc_mgr);
56
57
58 static ModestSingletons *_singletons = NULL;
59
60
61 /*
62  * defaults for the column headers
63  */
64 typedef struct {
65         ModestHeaderViewColumn col;
66         guint                  width;
67 } FolderCols;
68
69 static const FolderCols INBOX_COLUMNS_DETAILS[] = {
70         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
71         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
72         {MODEST_HEADER_VIEW_COLUMN_FROM,    80},
73         {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
74         {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
75         {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
76 };
77 static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
78         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
79         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
80         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 200}
81 };
82
83 static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
84          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
85          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
86          {MODEST_HEADER_VIEW_COLUMN_TO,    80},
87          {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
88          {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
89          {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
90 };
91 static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
92          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
93          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  40},
94          {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200},
95 };
96          
97 static const TnyFolderType LOCAL_FOLDERS[] = {
98         TNY_FOLDER_TYPE_OUTBOX,
99         TNY_FOLDER_TYPE_DRAFTS,
100         TNY_FOLDER_TYPE_SENT,
101         TNY_FOLDER_TYPE_TRASH,
102         TNY_FOLDER_TYPE_ARCHIVE 
103 };
104
105
106 gboolean
107 modest_runtime_init (void)
108 {
109         ModestSingletons *my_singletons;
110         gboolean reset;
111         
112         if (_singletons) {
113                 g_printerr ("modest: modest_runtime_init can only be called once\n");
114                 return FALSE;
115         }
116         
117         init_i18n();
118         init_debug_g_type();
119         init_debug_logging();
120
121         g_thread_init(NULL);
122         gdk_threads_init ();
123
124         my_singletons = modest_singletons_new ();
125         if (!my_singletons) {
126                 g_printerr ("modest: failed to initialize singletons\n");
127                 return FALSE;
128         }
129         
130         if (!modest_platform_init()) {
131                 modest_runtime_uninit ();
132                 g_printerr ("modest: failed to run platform-specific initialization\n");
133                 return FALSE;
134         }
135
136         /* based on the debug settings, we decide whether to overwrite old settings */
137         reset = modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS;
138         if (!init_header_columns(modest_singletons_get_conf (my_singletons), reset)) {
139                 modest_runtime_uninit ();
140                 g_printerr ("modest: failed to init header columns\n");
141                 return FALSE;
142         }
143         
144         if (!init_local_folders()) {
145                 modest_runtime_uninit ();
146                 g_printerr ("modest: failed to init local folders\n");
147                 return FALSE;
148         }
149         
150         if (!init_default_account_maybe(modest_singletons_get_account_mgr (my_singletons))) {
151                 modest_runtime_uninit ();
152                 g_printerr ("modest: failed to init default account\n");
153                 return FALSE;
154         }
155
156         /* create the test accounts if the debug flag for that is set */
157         if (modest_runtime_get_debug_flags () & MODEST_RUNTIME_DEBUG_TINY_TEST_ACCOUNTS)
158                 init_test_accounts (modest_singletons_get_account_mgr (my_singletons)); 
159         
160         /* don't initialize _singletons before all the other init stuff
161          * is done; thus, using any of the singleton stuff before
162          * runtime is fully init'ed  is avoided
163          */
164         _singletons = my_singletons;
165         
166         return TRUE;
167 }
168
169
170 gboolean
171 modest_runtime_init_ui (gint argc, gchar** argv)
172 {
173         if (!gtk_init_check(&argc, &argv)) {
174                 g_printerr ("modest: failed to initialize graphical ui\n");
175                 return FALSE;
176         }
177
178         init_stock_icons ();
179         return TRUE;
180 }
181
182
183 gboolean
184 modest_runtime_uninit (void)
185 {
186         if (_singletons) {
187                 g_object_unref (G_OBJECT(_singletons));
188                 _singletons = NULL;
189         }
190         modest_runtime_verify_object_death (_singletons, "_singletons");
191         
192         return TRUE;
193 }
194
195
196 ModestAccountMgr*
197 modest_runtime_get_account_mgr   (void)
198 {
199         g_return_val_if_fail (_singletons, NULL);
200         return modest_singletons_get_account_mgr (_singletons);
201 }
202
203 ModestTnyAccountStore*
204 modest_runtime_get_account_store   (void)
205 {
206         g_return_val_if_fail (_singletons, NULL);
207         return modest_singletons_get_account_store (_singletons);
208
209 }
210
211 ModestConf*
212 modest_runtime_get_conf (void)
213 {
214         g_return_val_if_fail (_singletons, NULL);
215         return modest_singletons_get_conf (_singletons);
216 }
217
218
219 ModestCacheMgr*
220 modest_runtime_get_cache_mgr (void)
221 {
222         g_return_val_if_fail (_singletons, NULL);
223         return modest_singletons_get_cache_mgr (_singletons);
224 }
225
226
227 ModestMailOperationQueue*
228 modest_runtime_get_mail_operation_queue (void)
229 {
230         g_return_val_if_fail (_singletons, NULL);
231         return modest_singletons_get_mail_operation_queue (_singletons);
232 }
233
234
235
236 TnyDevice*
237 modest_runtime_get_device (void)
238 {
239         g_return_val_if_fail (_singletons, NULL);
240         return modest_singletons_get_device (_singletons);
241 }
242
243
244 TnyPlatformFactory*
245 modest_runtime_get_platform_factory  (void)
246 {
247         g_return_val_if_fail (_singletons, NULL);
248         return modest_singletons_get_platform_factory (_singletons);
249 }
250
251
252
253
254 ModestTnySendQueue*
255 modest_runtime_get_send_queue  (TnyTransportAccount *account)
256 {
257         ModestCacheMgr *cache_mgr;
258         GHashTable     *send_queue_cache;
259         gpointer       orig_key, send_queue;
260         
261         g_return_val_if_fail (_singletons, NULL);
262         g_return_val_if_fail (TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
263
264         cache_mgr = modest_singletons_get_cache_mgr (_singletons);
265         send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
266                                                        MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
267
268         if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
269                 send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
270                 g_hash_table_insert (send_queue_cache, account, send_queue);
271         }
272
273         return MODEST_TNY_SEND_QUEUE(send_queue);
274 }
275
276
277
278
279 /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
280 ModestRuntimeDebugFlags
281 modest_runtime_get_debug_flags ()
282 {
283         static const GDebugKey debug_keys[] = {
284                 { "abort-on-warning",   MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
285                 { "log-actions",        MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
286                 { "debug-objects",      MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
287                 { "debug-signals",      MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS },
288                 { "factory-settings",   MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS},
289                 { "tiny-test-accounts", MODEST_RUNTIME_DEBUG_TINY_TEST_ACCOUNTS}
290         };
291         const gchar *str;
292         static ModestRuntimeDebugFlags debug_flags = -1;
293
294         if (debug_flags != -1)
295                 return debug_flags;
296         
297         str = g_getenv (MODEST_DEBUG);
298         
299         if (str != NULL)
300                 debug_flags = g_parse_debug_string (str, debug_keys, G_N_ELEMENTS (debug_keys));
301         else
302                 debug_flags = 0;
303         
304         return debug_flags;
305 }
306
307
308
309
310
311 /* NOTE: the exact details of this format are important, as they
312  * are also used in modest-widget-memory. FIXME: make a shared function
313  * for this with widget-memory
314  */
315 static gboolean
316 save_header_settings (ModestConf *conf, TnyFolderType type,
317                       ModestHeaderViewStyle style,  const FolderCols* cols,
318                       guint col_num, gboolean overwrite)
319 {
320         int i;
321         gchar *key;
322         GString *str;
323
324         g_return_val_if_fail (cols, FALSE);
325
326         key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
327                                                                   type, style,
328                                                                   MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
329         /* if we're not in overwrite mode, only write stuff it
330          * there was nothing before */
331         if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
332                 g_free (key);
333                 return TRUE;
334         }
335
336         /* the format is necessarily the same as the one in modest-widget-memory */
337         str = g_string_new (NULL);
338         for (i = 0; i != col_num; ++i) 
339                 g_string_append_printf (str, "%d:%d ",
340                                         cols[i].col, cols[i].width); 
341
342         modest_conf_set_string (conf, key, str->str, NULL);
343         g_free (key);
344         g_string_free (str, TRUE);
345         
346         return TRUE;
347 }
348
349 /**
350  * modest_init_header_columns:
351  * @overwrite: write the setting, even if it already exists
352  * 
353  * will set defaults for the columns to show for folder,
354  * if there are no such settings yet (in ModestWidgetMemory)
355  * 
356  * Returns: TRUE if succeeded, FALSE in case of error
357  */
358 static gboolean
359 init_header_columns (ModestConf *conf, gboolean overwrite)
360 {
361         int folder_type;
362         
363         for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
364              folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
365                 
366                 switch (folder_type) {
367                 case TNY_FOLDER_TYPE_OUTBOX:
368                 case TNY_FOLDER_TYPE_SENT:
369                 case TNY_FOLDER_TYPE_DRAFTS:
370                 save_header_settings (conf, folder_type,
371                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
372                                       OUTBOX_COLUMNS_DETAILS,
373                                       G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
374                                       overwrite);
375                 save_header_settings (conf, folder_type,
376                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
377                                       OUTBOX_COLUMNS_TWOLINES,
378                                       G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
379                                       overwrite);
380                 break;
381
382                 default:
383                 save_header_settings (conf, folder_type,
384                                       MODEST_HEADER_VIEW_STYLE_DETAILS,
385                                       INBOX_COLUMNS_DETAILS,
386                                       G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
387                                       overwrite);
388                 save_header_settings (conf, folder_type,
389                                       MODEST_HEADER_VIEW_STYLE_TWOLINES,
390                                       INBOX_COLUMNS_TWOLINES,
391                                       G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
392                                       overwrite);
393                 };
394         }
395         return TRUE;
396 }
397
398 /**
399  * init_local_folders:
400  * 
401  * create the Local Folders folder under cache, if they
402  * do not exist yet.
403  * 
404  * Returns: TRUE if the folder were already there, or
405  * they were created, FALSE otherwise
406  */
407 static gboolean
408 init_local_folders  (void)
409 {
410         int i;
411         gchar *maildir_path;
412         static const gchar* maildirs[] = {
413                 "cur", "new", "tmp"
414         };
415         
416         maildir_path = modest_local_folder_info_get_maildir_path ();
417
418         for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
419                 int j;
420                 for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
421                         gchar *dir;
422                         dir = g_build_filename (maildir_path,
423                                                 modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
424                                                 maildirs[j],
425                                                 NULL);
426                         if (g_mkdir_with_parents (dir, 0755) < 0) {
427                                 g_printerr ("modest: failed to create %s\n", dir);
428                                 g_free (dir);
429                                 g_free (maildir_path);
430                                 return FALSE;
431                         }
432                         g_free(dir);
433                 }
434         }
435         
436         g_free (maildir_path);
437         return TRUE;
438 }
439
440
441
442 static void
443 free_element (gpointer data, gpointer user_data)
444 {
445         g_free (data);
446 }
447
448
449
450 /**
451  * init_default_account_maybe:
452  *
453  * if there are accounts defined, but there is no default account,
454  * it will be defined.
455  * 
456  * Returns: TRUE if there was a default account already,
457  *  or one has been created or there are no accounts yet,
458  *  returns FALSE in case of error
459  */
460 static gboolean
461 init_default_account_maybe  (ModestAccountMgr *acc_mgr)
462 {
463         GSList *all_accounts = NULL;
464         gchar *default_account;
465         gboolean retval = TRUE;
466         
467         all_accounts = modest_account_mgr_account_names (acc_mgr);
468         if (all_accounts) { /* if there are any accounts, there should be a default one */
469                 default_account = 
470                         modest_account_mgr_get_default_account (acc_mgr);
471                 if (!default_account) {
472                         gchar *first_account;
473                         g_printerr ("modest: no default account defined\n");
474                         first_account = (gchar*)all_accounts->data;
475                         if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
476                                 g_printerr ("modest: set '%s' as the default account\n",
477                                             first_account);
478                         else
479                                 g_printerr ("modest: failed to set '%s' as the default account\n",
480                                             first_account);
481                         g_free (default_account);
482                 }
483                 g_slist_foreach (all_accounts, free_element, NULL);
484                 g_slist_free    (all_accounts);
485         }
486         return retval;
487 }
488
489
490
491 static void
492 init_debug_g_type (void)
493 {
494         GTypeDebugFlags gflags;
495         ModestRuntimeDebugFlags mflags;
496         
497         gflags = 0;
498         mflags = modest_runtime_get_debug_flags ();
499
500         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)
501                 gflags |= G_TYPE_DEBUG_OBJECTS;
502         if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
503                 gflags |= G_TYPE_DEBUG_SIGNALS;
504
505         g_type_init_with_debug_flags (gflags);
506 }
507
508 static void
509 init_debug_logging (void)
510 {
511         ModestRuntimeDebugFlags mflags;
512         mflags = modest_runtime_get_debug_flags ();
513         
514         if (mflags & MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING)
515                 g_log_set_always_fatal (G_LOG_LEVEL_ERROR |
516                                         G_LOG_LEVEL_CRITICAL |
517                                         G_LOG_LEVEL_WARNING);
518 }
519
520
521 static void
522 init_i18n (void)
523 {
524         bindtextdomain (GETTEXT_PACKAGE, MODEST_LOCALEDIR);
525         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
526         textdomain (GETTEXT_PACKAGE);
527
528 }
529
530
531 /* 
532  *  This function registers our custom toolbar icons, so they can be
533  *  themed. The idea of this function was taken from the gtk-demo
534  */
535 static void
536 init_stock_icons (void)
537 {
538         static gboolean registered = FALSE;
539   
540         if (!registered) {
541                 GdkPixbuf *pixbuf;
542                 GtkIconFactory *factory;
543                 gint i;
544
545                 static GtkStockItem items[] = {
546                         { MODEST_STOCK_MAIL_SEND, "send mail", 0, 0, NULL },
547                         { MODEST_STOCK_NEW_MAIL, "new mail", 0, 0, NULL },
548 /*                      { MODEST_STOCK_SEND_RECEIVE, "send receive", 0, 0, NULL },  */
549                         { MODEST_STOCK_REPLY, "reply", 0, 0, NULL },
550                         { MODEST_STOCK_REPLY_ALL, "reply all", 0, 0, NULL },
551                         { MODEST_STOCK_FORWARD, "forward", 0, 0, NULL },
552                         { MODEST_STOCK_DELETE, "delete", 0, 0, NULL }, 
553 /*                      { MODEST_STOCK_NEXT, "next", 0, 0, NULL }, */
554 /*                      { MODEST_STOCK_PREV, "prev", 0, 0, NULL }, */
555 /*                      { MODEST_STOCK_STOP, "stop", 0, 0, NULL } */
556                 };
557       
558                 static gchar *items_names [] = {
559                         MODEST_TOOLBAR_ICON_MAIL_SEND,
560                         MODEST_TOOLBAR_ICON_NEW_MAIL,
561 /*                      MODEST_TOOLBAR_ICON_SEND_RECEIVE,  */
562                         MODEST_TOOLBAR_ICON_REPLY,      
563                         MODEST_TOOLBAR_ICON_REPLY_ALL,
564                         MODEST_TOOLBAR_ICON_FORWARD,
565                         MODEST_TOOLBAR_ICON_DELETE, 
566 /*                      MODEST_TOOLBAR_ICON_NEXT, */
567 /*                      MODEST_TOOLBAR_ICON_PREV, */
568 /*                      MODEST_TOOLBAR_ICON_STOP */
569                 };
570
571                 registered = TRUE;
572
573                 /* Register our stock items */
574                 gtk_stock_add (items, G_N_ELEMENTS (items));
575       
576                 /* Add our custom icon factory to the list of defaults */
577                 factory = gtk_icon_factory_new ();
578                 gtk_icon_factory_add_default (factory);
579
580                 /* Register icons to accompany stock items */
581                 for (i = 0; i < G_N_ELEMENTS (items); i++) {
582                         pixbuf = NULL;
583                         pixbuf = gdk_pixbuf_new_from_file (items_names[i], NULL);
584
585                         if (pixbuf != NULL) {
586                                 GtkIconSet *icon_set;
587                                 GdkPixbuf *transparent;
588
589                                 transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
590
591                                 icon_set = gtk_icon_set_new_from_pixbuf (transparent);
592                                 gtk_icon_factory_add (factory, items[i].stock_id, icon_set);
593                                 gtk_icon_set_unref (icon_set);
594                                 g_object_unref (pixbuf);
595                                 g_object_unref (transparent);
596                         }
597                         else
598                                 g_warning ("failed to load %s icon", items_names[i]);
599                 }
600                 /* Drop our reference to the factory, GTK will hold a reference. */
601                 g_object_unref (factory);
602         }
603 }
604
605
606 static void
607 init_test_accounts (ModestAccountMgr *acc_mgr)
608 {
609         const gchar *imap_test = "TnyImapTest";
610         const gchar *pop_test  = "TnyPopTest";
611         const gchar *smtp_test = "TnySmtpTest";
612
613         if (!modest_account_mgr_account_exists (acc_mgr, imap_test, FALSE)) 
614                 modest_account_mgr_add_server_account (acc_mgr,
615                                                        imap_test,
616                                                        "imap2.tinymail.org",
617                                                        "tnytest", "tnytest",
618                                                        MODEST_PROTOCOL_STORE_IMAP,
619                                                        MODEST_PROTOCOL_SECURITY_NONE,
620                                                        MODEST_PROTOCOL_AUTH_NONE);
621         if (!modest_account_mgr_account_exists (acc_mgr, pop_test, FALSE)) 
622                 modest_account_mgr_add_server_account (acc_mgr,
623                                                        pop_test,
624                                                        "imap2.tinymail.org",
625                                                        "tnytest", "tnytest",
626                                                        MODEST_PROTOCOL_STORE_POP,
627                                                        MODEST_PROTOCOL_SECURITY_NONE,
628                                                        MODEST_PROTOCOL_AUTH_NONE);
629         if (!modest_account_mgr_account_exists (acc_mgr, smtp_test, FALSE)) 
630                 modest_account_mgr_add_server_account (acc_mgr,
631                                                        smtp_test,
632                                                        "127.0.0.1",
633                                                        NULL,NULL,
634                                                        MODEST_PROTOCOL_TRANSPORT_SMTP,
635                                                        MODEST_PROTOCOL_SECURITY_NONE,
636                                                        MODEST_PROTOCOL_AUTH_NONE);
637         
638         modest_account_mgr_add_account (acc_mgr, imap_test, imap_test, smtp_test);
639         modest_account_mgr_add_account (acc_mgr,  pop_test, pop_test,  smtp_test);
640 }