* Now we put signatures before the original/forwarded messages (fixes
[modest] / src / modest-protocol-registry.c
1 /* Copyright (c) 2007, 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 <string.h>
31 #include <modest-account-protocol.h>
32 #include <modest-defs.h>
33 #include <modest-protocol-registry.h>
34 #include <tny-camel-pop-store-account.h>
35 #include <tny-camel-imap-store-account.h>
36 #include <tny-camel-store-account.h>
37 #include <tny-camel-transport-account.h>
38 #include <tny-simple-list.h>
39
40 #define TAG_ALL_PROTOCOLS "__MODEST_PROTOCOL_REGISTRY_ALL_PROTOCOLS"
41
42 /* These seem to be listed in 
43  * libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c 
44  */
45 #define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
46 /* This is a tinymail camel-lite specific option, 
47  * roughly equivalent to "always" in regular camel,
48  * which is appropriate for a generic "SSL" connection option: */
49 #define MODEST_ACCOUNT_OPTION_SSL_WRAPPED "wrapped"
50 /* Not used in our UI so far: */
51 #define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
52 /* This is a tinymailcamel-lite specific option that is not in regular camel. */
53 #define MODEST_ACCOUNT_OPTION_SSL_TLS "tls"
54
55 /* Posssible values for tny_account_set_secure_auth_mech().
56  * These might be camel-specific.
57  * Really, tinymail should use an enum.
58  * camel_sasl_authtype() seems to list some possible values.
59  */
60  
61 /* Note that evolution does not offer these for IMAP: */
62 #define MODEST_ACCOUNT_AUTH_PLAIN "PLAIN"
63 #define MODEST_ACCOUNT_AUTH_ANONYMOUS "ANONYMOUS"
64
65 /* Caeml's IMAP uses NULL instead for "Password".
66  * Also, not that Evolution offers "Password" for IMAP, but "Login" for SMTP.*/
67 #define MODEST_ACCOUNT_AUTH_PASSWORD "LOGIN" 
68 #define MODEST_ACCOUNT_AUTH_CRAMMD5 "CRAM-MD5"
69
70 /* These seem to be listed in 
71  * libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-provider.c 
72  */
73 #define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub" /* Show only subscribed folders */
74 #define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all" /* Check for new messages in all folders */
75
76 /* 'private'/'protected' functions */
77 static void   modest_protocol_registry_class_init (ModestProtocolRegistryClass *klass);
78 static void   modest_protocol_registry_finalize   (GObject *obj);
79 static void   modest_protocol_registry_instance_init (ModestProtocolRegistry *obj);
80 static GHashTable *   modest_protocol_registry_create_tag (ModestProtocolRegistry *obj, const gchar *tag);
81
82 /* translation handlers */
83 static gchar * translation_is_userdata (gpointer userdata, ...);
84
85 typedef struct _ModestProtocolRegistryPrivate ModestProtocolRegistryPrivate;
86 struct _ModestProtocolRegistryPrivate {
87         GHashTable *tags_table;
88         GHashTable *priorities;
89 };
90
91 #define MODEST_PROTOCOL_REGISTRY_GET_PRIVATE(o)     (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
92                                                                          MODEST_TYPE_PROTOCOL_REGISTRY, \
93                                                                          ModestProtocolRegistryPrivate))
94
95 /* globals */
96 static GObjectClass *parent_class = NULL;
97
98 static ModestProtocolType pop_protocol_type_id = -1;
99 static ModestProtocolType imap_protocol_type_id = -1;
100 static ModestProtocolType maildir_protocol_type_id = -1;
101 static ModestProtocolType mbox_protocol_type_id = -1;
102 static ModestProtocolType smtp_protocol_type_id = -1;
103 static ModestProtocolType sendmail_protocol_type_id = -1;
104 static ModestProtocolType none_connection_protocol_type_id = -1;
105 static ModestProtocolType ssl_connection_protocol_type_id = -1;
106 static ModestProtocolType tls_connection_protocol_type_id = -1;
107 static ModestProtocolType tlsop_connection_protocol_type_id = -1;
108 static ModestProtocolType none_auth_protocol_type_id = -1;
109 static ModestProtocolType password_auth_protocol_type_id = -1;
110 static ModestProtocolType crammd5_auth_protocol_type_id = -1;
111
112 GType
113 modest_protocol_registry_get_type (void)
114 {
115         static GType my_type = 0;
116
117         if (!my_type) {
118                 static const GTypeInfo my_info = {
119                         sizeof(ModestProtocolRegistryClass),
120                         NULL,   /* base init */
121                         NULL,   /* base finalize */
122                         (GClassInitFunc) modest_protocol_registry_class_init,
123                         NULL,   /* class finalize */
124                         NULL,   /* class data */
125                         sizeof(ModestProtocolRegistry),
126                         0,      /* n_preallocs */
127                         (GInstanceInitFunc) modest_protocol_registry_instance_init,
128                         NULL
129                 };
130
131                 my_type = g_type_register_static (G_TYPE_OBJECT,
132                                                   "ModestProtocolRegistry",
133                                                   &my_info, 0);
134         }
135         return my_type;
136 }
137
138 static void
139 modest_protocol_registry_class_init (ModestProtocolRegistryClass *klass)
140 {
141         GObjectClass *object_class;
142         object_class = (GObjectClass *) klass;
143
144         parent_class = g_type_class_peek_parent (klass);
145         object_class->finalize = modest_protocol_registry_finalize;
146         g_type_class_add_private (object_class,
147                                   sizeof(ModestProtocolRegistryPrivate));
148 }
149
150 static void
151 modest_protocol_registry_instance_init (ModestProtocolRegistry *obj)
152 {
153         ModestProtocolRegistryPrivate *priv;
154
155         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (obj);
156
157         priv->tags_table = g_hash_table_new (g_str_hash, g_str_equal);
158         priv->priorities = g_hash_table_new (g_direct_hash, g_direct_equal);
159         
160         modest_protocol_registry_create_tag (obj, TAG_ALL_PROTOCOLS);
161 }
162
163 static void   
164 modest_protocol_registry_finalize   (GObject *obj)
165 {
166
167         G_OBJECT_CLASS (parent_class)->finalize (obj);
168 }
169
170
171 ModestProtocolRegistry*
172 modest_protocol_registry_new ()
173 {
174         return g_object_new (MODEST_TYPE_PROTOCOL_REGISTRY, NULL);
175 }
176
177 void
178 modest_protocol_registry_add (ModestProtocolRegistry *self, ModestProtocol *protocol, gint priority, const gchar *first_tag, ...)
179 {
180         va_list list;
181         GSList *tags_list = NULL, *node = NULL;
182         const gchar *va_string;
183         GHashTable *tag_table;
184         ModestProtocolRegistryPrivate *priv;
185
186         g_return_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self));
187         g_return_if_fail (MODEST_IS_PROTOCOL (protocol));
188         g_return_if_fail (first_tag != NULL);
189         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
190
191         tag_table = g_hash_table_lookup (priv->tags_table, TAG_ALL_PROTOCOLS);
192         g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), g_object_ref (protocol));
193
194         g_hash_table_insert (priv->priorities, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), GINT_TO_POINTER (priority));
195
196         tags_list = g_slist_prepend (tags_list, (gpointer) first_tag);
197         va_start (list, first_tag);
198         while ((va_string = va_arg (list, const gchar *)) != NULL) {
199                 tags_list = g_slist_prepend (tags_list, (gpointer) va_string);
200         }
201         va_end (list);
202
203         for (node = tags_list; node != NULL; node = g_slist_next (node)) {
204
205                 tag_table = g_hash_table_lookup (priv->tags_table, node->data);
206                 if (tag_table == NULL)
207                         tag_table = modest_protocol_registry_create_tag (self, node->data);
208                 g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), protocol);
209         }
210         g_slist_free (tags_list);
211 }
212
213 GSList *
214 modest_protocol_registry_get_all (ModestProtocolRegistry *self)
215 {
216         ModestProtocolRegistryPrivate *priv;
217
218         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL);
219         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
220
221         return modest_protocol_registry_get_by_tag (self, TAG_ALL_PROTOCOLS);
222         
223 }
224
225 static void
226 add_protocol_to_list (ModestProtocolType key, ModestProtocol *protocol, GSList **list)
227 {
228         *list = g_slist_prepend (*list, protocol);
229 }
230
231 static gint
232 compare_protocols (ModestProtocol *a, ModestProtocol *b, GHashTable *priorities)
233 {
234         ModestProtocolType a_type, b_type;
235         gint result;
236
237         a_type = modest_protocol_get_type_id (a);
238         b_type = modest_protocol_get_type_id (b);
239
240         result = g_hash_table_lookup (priorities, GINT_TO_POINTER (a_type)) - g_hash_table_lookup (priorities, GINT_TO_POINTER (b_type));
241         if (result == 0) {
242                 const gchar *a_display_name;
243                 const gchar *b_display_name;
244
245                 a_display_name = modest_protocol_get_display_name (a);
246                 b_display_name = modest_protocol_get_display_name (b);
247                 result = g_utf8_collate (a_display_name, b_display_name);
248         }
249         return result;
250 }
251
252 GSList *
253 modest_protocol_registry_get_by_tag (ModestProtocolRegistry *self, const gchar *tag)
254 {
255         ModestProtocolRegistryPrivate *priv;
256         GHashTable *tag_table;
257         GSList *result;
258
259         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL);
260         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
261
262         tag_table = g_hash_table_lookup (priv->tags_table, tag);
263         if (tag_table == NULL) {
264                 return NULL;
265         }
266
267         result = NULL;
268         g_hash_table_foreach (tag_table, (GHFunc) add_protocol_to_list, &result);
269
270         result = g_slist_sort_with_data (result, (GCompareDataFunc) compare_protocols, priv->priorities);
271
272         return result;
273
274 }
275
276 static void
277 add_protocol_to_pair_list (ModestProtocolType type_id, ModestProtocol *protocol, GSList **list)
278 {
279         *list = g_slist_append (*list,
280                                 (gpointer) modest_pair_new (
281                                         (gpointer) modest_protocol_get_name (protocol),
282                                         (gpointer) modest_protocol_get_display_name (protocol),
283                                         FALSE));
284 }
285
286 ModestPairList *
287 modest_protocol_registry_get_pair_list_by_tag (ModestProtocolRegistry *self, const gchar *tag)
288 {
289         ModestProtocolRegistryPrivate *priv;
290         GHashTable *tag_table;
291         GSList *result;
292
293         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL);
294         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
295
296         tag_table = g_hash_table_lookup (priv->tags_table, tag);
297         if (tag_table == NULL) {
298                 return NULL;
299         }
300
301         g_hash_table_foreach (tag_table, (GHFunc) add_protocol_to_pair_list, &result);
302
303         return result;  
304 }
305
306 static gboolean
307 find_protocol_by_name (ModestProtocolType type_id,
308                        ModestProtocol *protocol,
309                        const gchar *name)
310 {
311         return (strcmp (name, modest_protocol_get_name (protocol)) == 0);
312 }
313
314 ModestProtocol *
315 modest_protocol_registry_get_protocol_by_name (ModestProtocolRegistry *self, const gchar *tag, const gchar *name)
316 {
317         ModestProtocolRegistryPrivate *priv;
318         GHashTable *tag_table;
319
320         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL);
321         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
322
323         tag_table = g_hash_table_lookup (priv->tags_table, tag);
324         if (tag_table == NULL) {
325                 return NULL;
326         }
327         
328         return g_hash_table_find (tag_table, (GHRFunc) find_protocol_by_name, (gpointer) name);
329 }
330
331 ModestProtocol *
332 modest_protocol_registry_get_protocol_by_type (ModestProtocolRegistry *self, ModestProtocolType type_id)
333 {
334         ModestProtocolRegistryPrivate *priv;
335         GHashTable *tag_table;
336
337         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), NULL);
338         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
339
340         tag_table = g_hash_table_lookup (priv->tags_table, TAG_ALL_PROTOCOLS);
341         if (tag_table == NULL) {
342                 return NULL;
343         }
344         
345         return g_hash_table_lookup (tag_table, GINT_TO_POINTER (type_id));
346 }
347
348 gboolean 
349 modest_protocol_registry_protocol_type_has_tag (ModestProtocolRegistry *self, ModestProtocolType type_id, const gchar *tag)
350 {
351         ModestProtocolRegistryPrivate *priv;
352         GHashTable *tag_table;
353
354         g_return_val_if_fail (MODEST_IS_PROTOCOL_REGISTRY (self), FALSE);
355         g_return_val_if_fail (tag != NULL, FALSE);
356         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
357
358         tag_table = g_hash_table_lookup (priv->tags_table, tag);
359         if (tag_table == NULL) {
360                 return FALSE;
361         }
362         
363         return (g_hash_table_lookup (tag_table, GINT_TO_POINTER (type_id))!= NULL);
364         
365 }
366
367 static GHashTable *
368 modest_protocol_registry_create_tag (ModestProtocolRegistry *self, const gchar *tag)
369 {
370         ModestProtocolRegistryPrivate *priv;
371         GHashTable *tag_table;
372
373         g_assert (tag != NULL);
374         priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self);
375         tag_table = g_hash_table_new (g_direct_hash, g_direct_equal);
376         g_hash_table_insert (priv->tags_table, g_strdup (tag), tag_table);
377
378         return tag_table;
379 }
380
381 static gchar * 
382 translation_is_userdata (gpointer userdata, ...)
383 {
384         va_list args, dest;
385         gchar *result;
386
387         va_start(args, userdata);
388         va_copy (dest, args);
389         result = g_strdup_printf (_(userdata), dest);
390         va_end (args);
391
392         return result;
393 }
394
395 static gchar * 
396 translation_is_userdata_no_param (gpointer userdata, ...)
397 {
398         gchar *result;
399
400         result = g_strdup (_(userdata));
401
402         return result;
403 }
404
405
406 void 
407 modest_protocol_registry_set_to_default (ModestProtocolRegistry *self)
408 {
409         ModestProtocol *protocol;
410         TnyList *account_options;
411         TnyPair *pair;
412
413         protocol = modest_account_protocol_new ("sendmail", N_("Sendmail"),
414                                                 0, 0,
415                                                 TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT);
416         sendmail_protocol_type_id = modest_protocol_get_type_id (protocol);
417         modest_protocol_registry_add (self, protocol, 1,
418                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
419                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
420                                       NULL);
421
422         protocol = modest_account_protocol_new ("smtp", N_("SMTP Server"),
423                                                 25, 465,
424                                                 TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT);
425         smtp_protocol_type_id = modest_protocol_get_type_id (protocol);
426         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, translation_is_userdata, "emev_ib_ui_smtp_server_invalid", NULL);
427         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_smtp_authentication_fail_error", NULL);
428         modest_protocol_registry_add (self, protocol, 2,
429                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
430                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
431                                       NULL);
432
433         protocol = modest_account_protocol_new ("pop", _("mail_fi_emailtype_pop3"),
434                                                 110, 995,
435                                                 TNY_TYPE_CAMEL_POP_STORE_ACCOUNT);
436         pop_protocol_type_id = modest_protocol_get_type_id (protocol);
437         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, translation_is_userdata, "emev_ni_ui_pop3_msg_connect_error", NULL);
438         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_pop3_msg_connect_error", NULL);
439         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, translation_is_userdata, "emev_ni_ui_pop3_msg_connect_error", NULL);
440         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, translation_is_userdata_no_param, "emev_ni_ui_pop3_msg_recv_error", NULL);
441         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_SSL_PROTO_NAME, translation_is_userdata_no_param, "mcen_fi_advsetup_other_security_securepop3s", NULL);
442         modest_protocol_registry_add (self, protocol, 3,
443                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
444                                       MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
445                                       MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS,
446                                       MODEST_PROTOCOL_REGISTRY_HAS_LEAVE_ON_SERVER_PROTOCOLS,
447                                       MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD,
448                                       NULL);
449
450         protocol = modest_account_protocol_new ("imap", _("mail_fi_emailtype_imap"),
451                                                 143, 993,
452                                                 TNY_TYPE_CAMEL_IMAP_STORE_ACCOUNT);
453         imap_protocol_type_id = modest_protocol_get_type_id (protocol);
454         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX, translation_is_userdata, "emev_nc_delete_mailboximap", NULL);
455         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, translation_is_userdata, "emev_ni_ui_imap_connect_server_error", NULL);
456         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_AUTH_ERROR, translation_is_userdata, "emev_ni_ui_imap_connect_server_error", NULL);
457         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, translation_is_userdata, "emev_ni_ui_imap_connect_server_error", NULL);
458         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, translation_is_userdata, "emev_ni_ui_imap_message_not_available_in_server", NULL);
459         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_SSL_PROTO_NAME, translation_is_userdata_no_param, "mcen_fi_advsetup_other_security_secureimap4s", NULL);
460         account_options = tny_simple_list_new ();
461         pair = tny_pair_new (MODEST_ACCOUNT_OPTION_USE_LSUB, "");
462         tny_list_append (account_options, G_OBJECT (pair));
463         g_object_unref (pair);
464         pair = tny_pair_new (MODEST_ACCOUNT_OPTION_CHECK_ALL, "");
465         tny_list_append (account_options, G_OBJECT (pair));
466         g_object_unref (pair);
467         modest_account_protocol_set_account_options (MODEST_ACCOUNT_PROTOCOL (protocol), account_options);
468         g_object_unref (account_options);
469         modest_protocol_registry_add (self, protocol, 4,
470                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
471                                       MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
472                                       MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS,
473                                       MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS,
474                                       NULL);
475
476         protocol = modest_account_protocol_new ("maildir", N_("Maildir"),
477                                                 0, 0,
478                                                 TNY_TYPE_CAMEL_STORE_ACCOUNT);
479         maildir_protocol_type_id = modest_protocol_get_type_id (protocol);
480         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, 
481                                          translation_is_userdata_no_param, "emev_nc_mailbox_notavailable", NULL);
482         modest_protocol_registry_add (self, protocol, 5, 
483                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
484                                       MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
485                                       MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS,
486                                       MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS,
487                                       NULL);
488
489         protocol = modest_account_protocol_new ("mbox", N_("MBox"),
490                                                 0, 0,
491                                                 TNY_TYPE_CAMEL_STORE_ACCOUNT);
492         mbox_protocol_type_id = modest_protocol_get_type_id (protocol);
493         modest_protocol_set_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, 
494                                          translation_is_userdata_no_param, "emev_nc_mailbox_notavailable", NULL);
495         modest_protocol_registry_add (self, protocol, 6,
496                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
497                                       MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
498                                       MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS,
499                                       MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS,
500                                       NULL);
501
502         protocol = modest_protocol_new ("none", N_("None"));
503         modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_NEVER);
504         none_connection_protocol_type_id = modest_protocol_get_type_id (protocol);
505         modest_protocol_registry_add (self, protocol, 7,
506                                       MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
507                                       NULL);
508         protocol = modest_protocol_new ("ssl", N_("SSL"));
509         modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_WRAPPED);
510         ssl_connection_protocol_type_id = modest_protocol_get_type_id (protocol);
511         modest_protocol_registry_add (self, protocol, 8,
512                                       MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
513                                       MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
514                                       MODEST_PROTOCOL_REGISTRY_USE_ALTERNATE_PORT,
515                                       NULL);
516         protocol = modest_protocol_new ("tls", N_("TLS"));
517         modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_TLS);
518         tls_connection_protocol_type_id = modest_protocol_get_type_id (protocol);
519         modest_protocol_registry_add (self, protocol, 9, 
520                                       MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
521                                       MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
522                                       NULL);
523         protocol = modest_protocol_new ("tls-op", N_("TLS when possible"));
524         modest_protocol_set (protocol, MODEST_PROTOCOL_SECURITY_ACCOUNT_OPTION, MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
525         tlsop_connection_protocol_type_id = modest_protocol_get_type_id (protocol);
526         modest_protocol_registry_add (self, protocol, 10,
527                                       MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
528                                       MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
529                                       NULL);
530         protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE, _("mcen_fi_advsetup_smtp_none"));
531         none_auth_protocol_type_id = modest_protocol_get_type_id (protocol);
532         modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_PLAIN);
533         modest_protocol_registry_add (self, protocol, 11,
534                                       MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS,
535                                       NULL);
536         protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD, _("mcen_fi_advsetup_smtp_login"));
537         password_auth_protocol_type_id = modest_protocol_get_type_id (protocol);
538         modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_PASSWORD);
539         modest_protocol_registry_add (self, protocol, 12,
540                                       MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS,
541                                       MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
542                                       NULL);
543         protocol = modest_protocol_new (MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5, _("mcen_fi_advsetup_smtp_cram_md5"));
544         crammd5_auth_protocol_type_id = modest_protocol_get_type_id (protocol);
545         modest_protocol_set (protocol, MODEST_PROTOCOL_AUTH_ACCOUNT_OPTION, MODEST_ACCOUNT_AUTH_CRAMMD5);
546         modest_protocol_registry_add (self, protocol, 13,
547                                       MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS,
548                                       MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS,
549                                       NULL);
550
551 #if 0
552         /********** WARNING: Test code ( *********/
553 #include "modest-testplugin-protocol.h"
554         protocol = (ModestProtocol *)
555                 modest_testplugin_protocol_new ("testplugin", _("mcen_va_testplugin"),
556                                                  80, 443,
557                                                  TNY_TYPE_CAMEL_IMAP_STORE_ACCOUNT);
558         modest_protocol_registry_add (self, protocol, 50,
559                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
560                                       MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS,
561                                       MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS,
562                                       MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS,
563                                       MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
564                                       NULL);
565
566         protocol =  (ModestProtocol *)
567                 modest_testplugin_protocol_new ("testplugin-transport", _("mcen_va_testplugin"),
568                                                  80, 443,
569                                                  TNY_TYPE_CAMEL_TRANSPORT_ACCOUNT);
570         modest_protocol_registry_add (self, protocol, 51,
571                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
572                                       MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS,
573                                       MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
574                                       NULL);
575
576         /********* WARNING: Test code ( *********/
577 #endif
578
579
580         /* set the custom auth mechs. We do this after creating all the protocols, because if we don't, then we
581          * won't register the auth protocol type id's properly */
582
583         /* IMAP and POP need at least a password,
584          * which camel uses if we specify NULL.
585          * Camel use a password for IMAP or POP if we specify NULL,
586          * For IMAP, at least it will report an error if we use "Password", "Login" or "Plain".
587          * (POP is know to report an error for Login too. Probably Password and Plain too.) */
588         protocol = modest_protocol_registry_get_protocol_by_type (self, MODEST_PROTOCOLS_STORE_IMAP);
589         modest_account_protocol_set_custom_secure_auth_mech (MODEST_ACCOUNT_PROTOCOL (protocol), MODEST_PROTOCOLS_AUTH_NONE, NULL);
590         modest_account_protocol_set_custom_secure_auth_mech (MODEST_ACCOUNT_PROTOCOL (protocol), MODEST_PROTOCOLS_AUTH_PASSWORD, NULL);
591         protocol = modest_protocol_registry_get_protocol_by_type (self, MODEST_PROTOCOLS_STORE_POP);
592         modest_account_protocol_set_custom_secure_auth_mech (MODEST_ACCOUNT_PROTOCOL (protocol), MODEST_PROTOCOLS_AUTH_NONE, NULL);
593         modest_account_protocol_set_custom_secure_auth_mech (MODEST_ACCOUNT_PROTOCOL (protocol), MODEST_PROTOCOLS_AUTH_PASSWORD, NULL);
594 }
595
596 ModestProtocolType
597 modest_protocol_registry_get_imap_type_id (void)
598 {
599         return imap_protocol_type_id;
600 }
601
602 ModestProtocolType 
603 modest_protocol_registry_get_pop_type_id (void)
604 {
605         return pop_protocol_type_id;
606 }
607
608 ModestProtocolType
609 modest_protocol_registry_get_maildir_type_id (void)
610 {
611         return maildir_protocol_type_id;
612 }
613
614 ModestProtocolType
615 modest_protocol_registry_get_mbox_type_id (void)
616 {
617         return mbox_protocol_type_id;
618 }
619
620 ModestProtocolType 
621 modest_protocol_registry_get_smtp_type_id (void)
622 {
623         return smtp_protocol_type_id;
624 }
625
626 ModestProtocolType 
627 modest_protocol_registry_get_sendmail_type_id (void)
628 {
629         return sendmail_protocol_type_id;
630 }
631
632 ModestProtocolType 
633 modest_protocol_registry_get_none_connection_type_id (void)
634 {
635         return none_connection_protocol_type_id;
636 }
637
638 ModestProtocolType 
639 modest_protocol_registry_get_ssl_connection_type_id (void)
640 {
641         return ssl_connection_protocol_type_id;
642 }
643
644 ModestProtocolType 
645 modest_protocol_registry_get_tls_connection_type_id (void)
646 {
647         return tls_connection_protocol_type_id;
648 }
649
650 ModestProtocolType 
651 modest_protocol_registry_get_tlsop_connection_type_id (void)
652 {
653         return tlsop_connection_protocol_type_id;
654 }
655
656 ModestProtocolType 
657 modest_protocol_registry_get_none_auth_type_id (void)
658 {
659         return none_auth_protocol_type_id;
660 }
661
662 ModestProtocolType 
663 modest_protocol_registry_get_password_auth_type_id (void)
664 {
665         return password_auth_protocol_type_id;
666 }
667
668 ModestProtocolType 
669 modest_protocol_registry_get_crammd5_auth_type_id (void)
670 {
671         return crammd5_auth_protocol_type_id;
672 }
673