1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-imap-provider.c: imap provider registration code */
5 * Authors: Jeffrey Stedfast <fejj@ximian.com>
7 * Copyright 2000 Ximian, Inc. (www.ximian.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU Lesser General Public
11 * License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
29 #include <glib/gi18n-lib.h>
31 #include "camel-imap-store.h"
32 #include "camel-provider.h"
33 #include "camel-sasl.h"
34 #include "camel-session.h"
35 #include "camel-url.h"
37 static void add_hash (guint *hash, char *s);
38 static guint imap_url_hash (gconstpointer key);
39 static gint check_equal (char *s1, char *s2);
40 static gint imap_url_equal (gconstpointer a, gconstpointer b);
42 CamelProviderConfEntry imap_conf_entries[] = {
43 { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
44 N_("Checking for New Mail") },
45 { CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
46 N_("C_heck for new messages in all folders"), "1" },
47 { CAMEL_PROVIDER_CONF_SECTION_END },
49 { CAMEL_PROVIDER_CONF_SECTION_START, "cmdsection", NULL,
50 N_("Connection to Server") },
51 { CAMEL_PROVIDER_CONF_CHECKBOX, "use_command", NULL,
52 N_("_Use custom command to connect to server"), "0" },
53 { CAMEL_PROVIDER_CONF_ENTRY, "command", "use_command",
54 N_("Command:"), "ssh -C -l %u %h exec /usr/sbin/imapd" },
55 { CAMEL_PROVIDER_CONF_SECTION_END },
57 { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
59 { CAMEL_PROVIDER_CONF_CHECKBOX, "use_lsub", NULL,
60 N_("_Show only subscribed folders"), "1" },
61 { CAMEL_PROVIDER_CONF_CHECKBOX, "override_namespace", NULL,
62 N_("O_verride server-supplied folder namespace"), "0" },
63 { CAMEL_PROVIDER_CONF_ENTRY, "namespace", "override_namespace",
65 { CAMEL_PROVIDER_CONF_SECTION_END },
66 { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
67 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter", NULL,
68 N_("_Apply filters to new messages in INBOX on this server"), "0" },
69 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk", NULL,
70 N_("Check new messages for Jun_k contents"), "0" },
71 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk_inbox", "filter_junk",
72 N_("Only check for Junk messages in the IN_BOX folder"), "0" },
73 { CAMEL_PROVIDER_CONF_CHECKBOX, "offline_sync", NULL,
74 N_("Automatically synchroni_ze remote mail locally"), "0" },
75 { CAMEL_PROVIDER_CONF_SECTION_END },
76 { CAMEL_PROVIDER_CONF_END }
79 static CamelProvider imap_provider = {
83 N_("For reading and storing mail on IMAP servers."),
87 CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
88 CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL,
90 CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
97 CamelServiceAuthType camel_imap_password_authtype = {
100 N_("This option will connect to the IMAP server using a "
101 "plaintext password."),
108 camel_provider_module_init(void)
110 imap_provider.object_types[CAMEL_PROVIDER_STORE] = camel_imap_store_get_type ();
111 imap_provider.url_hash = imap_url_hash;
112 imap_provider.url_equal = imap_url_equal;
113 imap_provider.authtypes = camel_sasl_authtype_list (FALSE);
114 imap_provider.authtypes = g_list_prepend (imap_provider.authtypes, &camel_imap_password_authtype);
115 imap_provider.translation_domain = GETTEXT_PACKAGE;
117 camel_provider_register(&imap_provider);
121 add_hash (guint *hash, char *s)
124 *hash ^= g_str_hash(s);
128 imap_url_hash (gconstpointer key)
130 const CamelURL *u = (CamelURL *)key;
133 add_hash (&hash, u->user);
134 add_hash (&hash, u->authmech);
135 add_hash (&hash, u->host);
142 check_equal (char *s1, char *s2)
154 return strcmp (s1, s2) == 0;
158 imap_url_equal (gconstpointer a, gconstpointer b)
160 const CamelURL *u1 = a, *u2 = b;
162 return check_equal (u1->protocol, u2->protocol)
163 && check_equal (u1->user, u2->user)
164 && check_equal (u1->authmech, u2->authmech)
165 && check_equal (u1->host, u2->host)
166 && u1->port == u2->port;