1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4 *
5 * This library is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Michael Zucchi <notzed@ximian.com>
18 */
19
20 #include "evolution-data-server-config.h"
21
22 #include <stdio.h>
23 #include <string.h>
24
25 #include <glib/gi18n-lib.h>
26
27 #include "camel-maildir-store.h"
28 #include "camel-mbox-store.h"
29 #include "camel-mh-store.h"
30 #include "camel-spool-store.h"
31
32 #define d(x)
33
34 #ifndef G_OS_WIN32
35
36 static CamelProviderConfEntry mh_conf_entries[] = {
37 { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
38 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-all", NULL,
39 N_("Apply _filters to new messages in all folders"), "1" },
40 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
41 N_("Check new messages for _Junk contents"), "1" },
42 { CAMEL_PROVIDER_CONF_CHECKBOX, "use-dot-folders", NULL,
43 N_("_Use the “.folders” folder summary file (exmh)"), "0" },
44 { CAMEL_PROVIDER_CONF_SECTION_END },
45 { CAMEL_PROVIDER_CONF_END }
46 };
47
48 static CamelProvider mh_provider = {
49 "mh",
50 N_("MH-format mail directories"),
51 N_("For storing local mail in MH-like mail directories."),
52 "mail",
53 CAMEL_PROVIDER_IS_SOURCE | CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_IS_LOCAL,
54 CAMEL_URL_NEED_PATH | CAMEL_URL_NEED_PATH_DIR | CAMEL_URL_PATH_IS_ABSOLUTE | CAMEL_URL_FRAGMENT_IS_PATH,
55 mh_conf_entries,
56 NULL,
57 /* ... */
58 };
59
60 #endif
61
62 static CamelProviderConfEntry mbox_conf_entries[] = {
63 { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
64 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-all", NULL,
65 N_("Apply _filters to new messages"), "1" },
66 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
67 N_("Check new messages for _Junk contents"), "1" },
68 { CAMEL_PROVIDER_CONF_END }
69 };
70
71 static CamelProvider mbox_provider = {
72 "mbox",
73 N_("Local delivery"),
74 N_("For retrieving (moving) local mail from standard mbox-formatted spools into folders managed by Evolution."),
75 "mail",
76 CAMEL_PROVIDER_IS_SOURCE | CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_IS_LOCAL,
77 CAMEL_URL_NEED_PATH | CAMEL_URL_PATH_IS_ABSOLUTE | CAMEL_URL_FRAGMENT_IS_PATH,
78 mbox_conf_entries, /* semi-empty entries, thus evolution will show "Receiving Options" page */
79 NULL,
80 /* ... */
81 };
82
83 static CamelProviderConfEntry maildir_conf_entries[] = {
84 { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
85 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
86 N_("_Apply filters to new messages in Inbox"), "0" },
87 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
88 N_("Check new messages for _Junk contents"), "1" },
89 { CAMEL_PROVIDER_CONF_SECTION_END },
90 { CAMEL_PROVIDER_CONF_END }
91 };
92
93 static CamelProvider maildir_provider = {
94 "maildir",
95 N_("Maildir-format mail directories"),
96 N_("For storing local mail in maildir directories."),
97 "mail",
98 CAMEL_PROVIDER_IS_SOURCE | CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_IS_LOCAL,
99 CAMEL_URL_NEED_PATH | CAMEL_URL_NEED_PATH_DIR | CAMEL_URL_PATH_IS_ABSOLUTE | CAMEL_URL_FRAGMENT_IS_PATH,
100 maildir_conf_entries,
101 NULL,
102 /* ... */
103 };
104
105 #ifndef G_OS_WIN32
106
107 static CamelProviderConfEntry spool_conf_entries[] = {
108 { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
109 { CAMEL_PROVIDER_CONF_CHECKBOX, "listen-notifications", NULL,
110 N_("_Listen for change notifications"), "1" },
111 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
112 N_("_Apply filters to new messages in Inbox"), "0" },
113 { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
114 N_("Check new messages for _Junk contents"), "1" },
115 { CAMEL_PROVIDER_CONF_CHECKBOX, "use-xstatus-headers", NULL, N_("_Store status headers in Elm/Pine/Mutt format"), "0" },
116 { CAMEL_PROVIDER_CONF_SECTION_END },
117 { CAMEL_PROVIDER_CONF_END }
118 };
119
120 static CamelProvider spool_file_provider = {
121 "spool",
122 N_("Standard Unix mbox spool file"),
123 N_("For reading and storing local mail in external standard mbox "
124 "spool files.\nMay also be used to read a tree of Elm, Pine, or Mutt "
125 "style folders."),
126 "mail",
127 CAMEL_PROVIDER_IS_SOURCE | CAMEL_PROVIDER_IS_STORAGE,
128 CAMEL_URL_NEED_PATH | CAMEL_URL_PATH_IS_ABSOLUTE | CAMEL_URL_FRAGMENT_IS_PATH,
129 spool_conf_entries,
130 NULL,
131 /* ... */
132 };
133
134 static CamelProvider spool_directory_provider = {
135 "spooldir",
136 N_("Standard Unix mbox spool directory"),
137 N_("For reading and storing local mail in external standard mbox "
138 "spool files.\nMay also be used to read a tree of Elm, Pine, or Mutt "
139 "style folders."),
140 "mail",
141 CAMEL_PROVIDER_IS_SOURCE | CAMEL_PROVIDER_IS_STORAGE,
142 CAMEL_URL_NEED_PATH | CAMEL_URL_NEED_PATH_DIR | CAMEL_URL_PATH_IS_ABSOLUTE | CAMEL_URL_FRAGMENT_IS_PATH,
143 spool_conf_entries,
144 NULL,
145 /* ... */
146 };
147
148 #endif
149
150 /* build a canonical 'path' */
151 static gchar *
make_can_path(gchar * p,gchar * o)152 make_can_path (gchar *p,
153 gchar *o)
154 {
155 gchar c, last, *start = o;
156
157 d (printf ("canonical '%s' = ", p));
158
159 last = 0;
160 while ((c = *p++)) {
161 if (c != '/'
162 || (c == '/' && last != '/'))
163 *o++ = c;
164 last = c;
165 }
166 if (o > start && o[-1] == '/')
167 o[-1] = 0;
168 else
169 *o = 0;
170
171 d (printf ("'%s'\n", start));
172
173 return start;
174 }
175
176 /* 'helper' function for it */
177 #define get_can_path(p) ((p == NULL) ? NULL : (make_can_path ((p), g_alloca (strlen (p) + 1))))
178
179 static guint
local_url_hash(gconstpointer v)180 local_url_hash (gconstpointer v)
181 {
182 const CamelURL *u = v;
183 guint hash = 0;
184
185 #define ADD_HASH(s) if (s && *s) hash ^= g_str_hash (s);
186
187 ADD_HASH (u->protocol);
188 ADD_HASH (u->user);
189 ADD_HASH (u->authmech);
190 ADD_HASH (u->host);
191 if (u->path)
192 hash ^= g_str_hash (get_can_path (u->path));
193 ADD_HASH (u->path);
194 ADD_HASH (u->query);
195 hash ^= u->port;
196
197 return hash;
198 }
199
200 static gint
check_equal(gchar * s1,gchar * s2)201 check_equal (gchar *s1,
202 gchar *s2)
203 {
204 if (s1 == NULL || *s1 == 0) {
205 if (s2 == NULL || *s2 == 0)
206 return TRUE;
207 else
208 return FALSE;
209 }
210
211 if (s2 == NULL)
212 return FALSE;
213
214 return strcmp (s1, s2) == 0;
215 }
216
217 static gint
local_url_equal(gconstpointer v,gconstpointer v2)218 local_url_equal (gconstpointer v,
219 gconstpointer v2)
220 {
221 const CamelURL *u1 = v, *u2 = v2;
222 gchar *p1, *p2;
223
224 p1 = get_can_path (u1->path);
225 p2 = get_can_path (u2->path);
226 return check_equal (p1, p2)
227 && check_equal (u1->protocol, u2->protocol);
228 }
229
230 void
camel_provider_module_init(void)231 camel_provider_module_init (void)
232 {
233 static gint init = 0;
234
235 if (init)
236 abort ();
237 init = 1;
238
239 #ifndef G_OS_WIN32
240 mh_conf_entries[0].value = ""; /* default path */
241 mh_provider.object_types[CAMEL_PROVIDER_STORE] = camel_mh_store_get_type ();
242 mh_provider.url_hash = local_url_hash;
243 mh_provider.url_equal = local_url_equal;
244 mh_provider.translation_domain = GETTEXT_PACKAGE;
245 camel_provider_register (&mh_provider);
246 #endif
247
248 mbox_provider.object_types[CAMEL_PROVIDER_STORE] = CAMEL_TYPE_MBOX_STORE;
249 mbox_provider.url_hash = local_url_hash;
250 mbox_provider.url_equal = local_url_equal;
251 mbox_provider.translation_domain = GETTEXT_PACKAGE;
252 camel_provider_register (&mbox_provider);
253
254 #ifndef G_OS_WIN32
255 spool_file_provider.object_types[CAMEL_PROVIDER_STORE] = camel_spool_store_get_type ();
256 spool_file_provider.url_hash = local_url_hash;
257 spool_file_provider.url_equal = local_url_equal;
258 spool_file_provider.translation_domain = GETTEXT_PACKAGE;
259 camel_provider_register (&spool_file_provider);
260
261 spool_directory_provider.object_types[CAMEL_PROVIDER_STORE] = camel_spool_store_get_type ();
262 spool_directory_provider.url_hash = local_url_hash;
263 spool_directory_provider.url_equal = local_url_equal;
264 spool_directory_provider.translation_domain = GETTEXT_PACKAGE;
265 camel_provider_register (&spool_directory_provider);
266 #endif
267
268 maildir_provider.object_types[CAMEL_PROVIDER_STORE] = camel_maildir_store_get_type ();
269 maildir_provider.url_hash = local_url_hash;
270 maildir_provider.url_equal = local_url_equal;
271 maildir_provider.translation_domain = GETTEXT_PACKAGE;
272 camel_provider_register (&maildir_provider);
273 }
274