Whitespace cleanups.
[platform/upstream/evolution-data-server.git] / camel / providers / imapx / camel-imapx-provider.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-pop3-provider.c: pop3 provider registration code */
3 /*
4  * Authors :
5  *   Dan Winship <danw@ximian.com>
6  *   Michael Zucchi <notzed@ximian.com>
7  *
8  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU Lesser General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <string.h>
30 #include <camel/camel.h>
31 #include <glib/gi18n-lib.h>
32
33 static guint imapx_url_hash (gconstpointer key);
34 static gint  imapx_url_equal (gconstpointer a, gconstpointer b);
35
36 CamelProviderConfEntry imapx_conf_entries[] = {
37         { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
38           N_("Checking for New Mail") },
39         { CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL,
40           N_("C_heck for new messages in all folders"), "1" },
41         { CAMEL_PROVIDER_CONF_CHECKBOX, "check-subscribed", NULL,
42           N_("Ch_eck for new messages in subscribed folders"), "0" },
43         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-qresync", NULL,
44           N_("Use _Quick Resync if the server supports it"), "1" },
45         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-idle", NULL,
46           N_("_Listen for server change notifications"), "1" },
47         { CAMEL_PROVIDER_CONF_SECTION_END },
48 #ifndef G_OS_WIN32
49         { CAMEL_PROVIDER_CONF_SECTION_START, "cmdsection", NULL,
50           N_("Connection to Server") },
51         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-shell-command", NULL,
52           N_("_Use custom command to connect to server"), "0" },
53         { CAMEL_PROVIDER_CONF_ENTRY, "shell-command", "use-shell-command",
54           N_("Command:"), "ssh -C -l %u %h exec /usr/sbin/dovecot --exec-mail imap" },
55         { CAMEL_PROVIDER_CONF_CHECKSPIN, "concurrent-connections", NULL,
56           N_("Numbe_r of cached connections to use"), "y:1:5:7" },
57         { CAMEL_PROVIDER_CONF_SECTION_END },
58 #endif
59         { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
60           N_("Folders") },
61         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-subscriptions", NULL,
62           N_("_Show only subscribed folders"), "1" },
63 #if 0
64         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-namespace", NULL,
65           N_("O_verride server-supplied folder namespace"), "0" },
66         { CAMEL_PROVIDER_CONF_ENTRY, "namespace", "use-namespace",
67           N_("Namespace:") },
68 #endif
69         { CAMEL_PROVIDER_CONF_SECTION_END },
70         { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
71         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-all", NULL,
72           N_("Apply _filters to new messages in all folders"), "0" },
73         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", "!filter-all",
74           N_("_Apply filters to new messages in Inbox on this server"), "1" },
75         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
76           N_("Check new messages for _Junk contents"), "0" },
77         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk",
78           N_("Only check for Junk messages in the IN_BOX folder"), "0" },
79         { CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL,
80           N_("Automatically synchroni_ze remote mail locally"), "0" },
81         { CAMEL_PROVIDER_CONF_SECTION_END },
82         { CAMEL_PROVIDER_CONF_END }
83 };
84
85 CamelProviderPortEntry imapx_port_entries[] = {
86         { 143, N_("Default IMAP port"), FALSE },
87         { 993, N_("IMAP over SSL"), TRUE },
88         { 0, NULL, 0 }
89 };
90
91 static CamelProvider imapx_provider = {
92         "imapx",
93
94         N_("IMAP+"),
95
96         N_("For reading and storing mail on IMAP servers."),
97
98         "mail",
99
100         CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
101         CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL|
102         CAMEL_PROVIDER_SUPPORTS_MOBILE_DEVICES |
103         CAMEL_PROVIDER_SUPPORTS_BATCH_FETCH |
104         CAMEL_PROVIDER_SUPPORTS_PURGE_MESSAGE_CACHE,
105
106         CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
107
108         imapx_conf_entries,
109
110         imapx_port_entries,
111
112         /* ... */
113 };
114
115 extern CamelServiceAuthType camel_imapx_password_authtype;
116
117 void camel_imapx_module_init (void);
118
119 void
120 camel_imapx_module_init (void)
121 {
122         imapx_provider.object_types[CAMEL_PROVIDER_STORE] = camel_imapx_store_get_type ();
123         imapx_provider.url_hash = imapx_url_hash;
124         imapx_provider.url_equal = imapx_url_equal;
125         imapx_provider.authtypes = camel_sasl_authtype_list (FALSE);
126         imapx_provider.authtypes = g_list_prepend (imapx_provider.authtypes, &camel_imapx_password_authtype);
127         imapx_provider.translation_domain = GETTEXT_PACKAGE;
128
129         /* TEMPORARY */
130         imapx_utils_init ();
131
132         camel_provider_register (&imapx_provider);
133 }
134
135 void
136 camel_provider_module_init (void)
137 {
138         camel_imapx_module_init ();
139 }
140
141 static void
142 imapx_add_hash (guint *hash,
143                 gchar *s)
144 {
145         if (s)
146                 *hash ^= g_str_hash(s);
147 }
148
149 static guint
150 imapx_url_hash (gconstpointer key)
151 {
152         const CamelURL *u = (CamelURL *) key;
153         guint hash = 0;
154
155         imapx_add_hash (&hash, u->user);
156         imapx_add_hash (&hash, u->host);
157         hash ^= u->port;
158
159         return hash;
160 }
161
162 static gint
163 imapx_check_equal (gchar *s1,
164                    gchar *s2)
165 {
166         if (s1 == NULL) {
167                 if (s2 == NULL)
168                         return TRUE;
169                 else
170                         return FALSE;
171         }
172
173         if (s2 == NULL)
174                 return FALSE;
175
176         return strcmp (s1, s2) == 0;
177 }
178
179 static gint
180 imapx_url_equal (gconstpointer a,
181                  gconstpointer b)
182 {
183         const CamelURL *u1 = a, *u2 = b;
184
185         return imapx_check_equal (u1->protocol, u2->protocol)
186                 && imapx_check_equal (u1->user, u2->user)
187                 && imapx_check_equal (u1->host, u2->host)
188                 && u1->port == u2->port;
189 }