aa99fd901d5d044878bce9ac8034cbed45214719
[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 #include "camel-imapx-store.h"
34
35 static guint imapx_url_hash (gconstpointer key);
36 static gint  imapx_url_equal (gconstpointer a, gconstpointer b);
37
38 CamelProviderConfEntry imapx_conf_entries[] = {
39         { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
40           N_("Checking for New Mail") },
41         { CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL,
42           N_("C_heck for new messages in all folders"), "1" },
43         { CAMEL_PROVIDER_CONF_CHECKBOX, "check-subscribed", NULL,
44           N_("Ch_eck for new messages in subscribed folders"), "0" },
45         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-qresync", NULL,
46           N_("Use _Quick Resync if the server supports it"), "1" },
47         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-idle", NULL,
48           N_("_Listen for server change notifications"), "1" },
49         { CAMEL_PROVIDER_CONF_SECTION_END },
50 #ifndef G_OS_WIN32
51         { CAMEL_PROVIDER_CONF_SECTION_START, "cmdsection", NULL,
52           N_("Connection to Server") },
53         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-shell-command", NULL,
54           N_("_Use custom command to connect to server"), "0" },
55         { CAMEL_PROVIDER_CONF_ENTRY, "shell-command", "use-shell-command",
56           N_("Command:"), "ssh -C -l %u %h exec /usr/sbin/dovecot --exec-mail imap" },
57         { CAMEL_PROVIDER_CONF_CHECKSPIN, "concurrent-connections", NULL,
58           N_("Numbe_r of cached connections to use"), "y:1:5:7" },
59         { CAMEL_PROVIDER_CONF_SECTION_END },
60 #endif
61         { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
62           N_("Folders") },
63         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-subscriptions", NULL,
64           N_("_Show only subscribed folders"), "1" },
65 #if 0
66         { CAMEL_PROVIDER_CONF_CHECKBOX, "use-namespace", NULL,
67           N_("O_verride server-supplied folder namespace"), "0" },
68         { CAMEL_PROVIDER_CONF_ENTRY, "namespace", "use-namespace",
69           N_("Namespace:") },
70 #endif
71         { CAMEL_PROVIDER_CONF_SECTION_END },
72         { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
73         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-all", NULL,
74           N_("Apply _filters to new messages in all folders"), "0" },
75         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", "!filter-all",
76           N_("_Apply filters to new messages in Inbox on this server"), "1" },
77         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
78           N_("Check new messages for _Junk contents"), "0" },
79         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk",
80           N_("Only check for Junk messages in the IN_BOX folder"), "0" },
81         { CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL,
82           N_("Automatically synchroni_ze remote mail locally"), "0" },
83         { CAMEL_PROVIDER_CONF_SECTION_END },
84         { CAMEL_PROVIDER_CONF_END }
85 };
86
87 CamelProviderPortEntry imapx_port_entries[] = {
88         { 143, N_("Default IMAP port"), FALSE },
89         { 993, N_("IMAP over SSL"), TRUE },
90         { 0, NULL, 0 }
91 };
92
93 static CamelProvider imapx_provider = {
94         "imapx",
95
96         N_("IMAP+"),
97
98         N_("For reading and storing mail on IMAP servers."),
99
100         "mail",
101
102         CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
103         CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL|
104         CAMEL_PROVIDER_SUPPORTS_MOBILE_DEVICES |
105         CAMEL_PROVIDER_SUPPORTS_BATCH_FETCH |
106         CAMEL_PROVIDER_SUPPORTS_PURGE_MESSAGE_CACHE,
107
108         CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
109
110         imapx_conf_entries,
111
112         imapx_port_entries,
113
114         /* ... */
115 };
116
117 CamelServiceAuthType camel_imapx_password_authtype = {
118         N_("Password"),
119
120         N_("This option will connect to the IMAP server using a "
121            "plaintext password."),
122
123         "",
124         TRUE
125 };
126
127 void camel_imapx_module_init (void);
128
129 void
130 camel_imapx_module_init (void)
131 {
132         imapx_provider.object_types[CAMEL_PROVIDER_STORE] = camel_imapx_store_get_type ();
133         imapx_provider.url_hash = imapx_url_hash;
134         imapx_provider.url_equal = imapx_url_equal;
135         imapx_provider.authtypes = camel_sasl_authtype_list (FALSE);
136         imapx_provider.authtypes = g_list_prepend (imapx_provider.authtypes, &camel_imapx_password_authtype);
137         imapx_provider.translation_domain = GETTEXT_PACKAGE;
138
139         /* TEMPORARY */
140         imapx_utils_init ();
141
142         camel_provider_register (&imapx_provider);
143 }
144
145 void
146 camel_provider_module_init (void)
147 {
148         camel_imapx_module_init ();
149 }
150
151 static void
152 imapx_add_hash (guint *hash,
153                 gchar *s)
154 {
155         if (s)
156                 *hash ^= g_str_hash(s);
157 }
158
159 static guint
160 imapx_url_hash (gconstpointer key)
161 {
162         const CamelURL *u = (CamelURL *) key;
163         guint hash = 0;
164
165         imapx_add_hash (&hash, u->user);
166         imapx_add_hash (&hash, u->host);
167         hash ^= u->port;
168
169         return hash;
170 }
171
172 static gint
173 imapx_check_equal (gchar *s1,
174                    gchar *s2)
175 {
176         if (s1 == NULL) {
177                 if (s2 == NULL)
178                         return TRUE;
179                 else
180                         return FALSE;
181         }
182
183         if (s2 == NULL)
184                 return FALSE;
185
186         return strcmp (s1, s2) == 0;
187 }
188
189 static gint
190 imapx_url_equal (gconstpointer a,
191                  gconstpointer b)
192 {
193         const CamelURL *u1 = a, *u2 = b;
194
195         return imapx_check_equal (u1->protocol, u2->protocol)
196                 && imapx_check_equal (u1->user, u2->user)
197                 && imapx_check_equal (u1->host, u2->host)
198                 && u1->port == u2->port;
199 }