Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / providers / imap / camel-imap-provider.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-imap-provider.c: imap provider registration code */
3
4 /*
5  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
6  *
7  *  Copyright 2000 Ximian, Inc. (www.ximian.com)
8  *
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.
12  *
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.
17  *
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.
22  *
23  */
24
25 #include <config.h>
26
27 #include <string.h>
28
29 #include <glib/gi18n-lib.h>
30
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"
36
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);
41
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 },
48 #ifndef G_OS_WIN32
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 },
56 #endif
57         { CAMEL_PROVIDER_CONF_SECTION_START, "folders", NULL,
58           N_("Folders") },
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",
64           N_("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 }
77 };
78
79 static CamelProvider imap_provider = {
80         "imap",
81         N_("IMAP"),
82
83         N_("For reading and storing mail on IMAP servers."),
84
85         "mail",
86
87         CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
88         CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL,
89
90         CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
91
92         imap_conf_entries,
93
94         /* ... */
95 };
96
97 CamelServiceAuthType camel_imap_password_authtype = {
98         N_("Password"),
99         
100         N_("This option will connect to the IMAP server using a "
101            "plaintext password."),
102         
103         "",
104         TRUE
105 };
106
107 void
108 camel_provider_module_init(void)
109 {
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;
116
117         camel_provider_register(&imap_provider);
118 }
119
120 static void
121 add_hash (guint *hash, char *s)
122 {
123         if (s)
124                 *hash ^= g_str_hash(s);
125 }
126
127 static guint
128 imap_url_hash (gconstpointer key)
129 {
130         const CamelURL *u = (CamelURL *)key;
131         guint hash = 0;
132
133         add_hash (&hash, u->user);
134         add_hash (&hash, u->authmech);
135         add_hash (&hash, u->host);
136         hash ^= u->port;
137         
138         return hash;
139 }
140
141 static int
142 check_equal (char *s1, char *s2)
143 {
144         if (s1 == NULL) {
145                 if (s2 == NULL)
146                         return TRUE;
147                 else
148                         return FALSE;
149         }
150         
151         if (s2 == NULL)
152                 return FALSE;
153         
154         return strcmp (s1, s2) == 0;
155 }
156
157 static int
158 imap_url_equal (gconstpointer a, gconstpointer b)
159 {
160         const CamelURL *u1 = a, *u2 = b;
161         
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;
167 }