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  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5  *
6  * This library is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Authors :
19  *   Dan Winship <danw@ximian.com>
20  *   Michael Zucchi <notzed@ximian.com>
21  */
22 
23 #include "evolution-data-server-config.h"
24 
25 #include <glib/gi18n-lib.h>
26 
27 #include "camel-pop3-store.h"
28 
29 static guint pop3_url_hash (gconstpointer key);
30 static gint pop3_url_equal (gconstpointer a, gconstpointer b);
31 
32 static CamelProviderConfEntry pop3_conf_entries[] = {
33 	{ CAMEL_PROVIDER_CONF_SECTION_START, "storage", NULL,
34 	  N_("Message Storage") },
35 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "keep-on-server", NULL,
36 	  N_("_Leave messages on server"), "1" },
37 	{ CAMEL_PROVIDER_CONF_CHECKSPIN, "delete-after-days", "keep-on-server",
38 	  /* Translators: '%s' is replaced with a widget, where user can
39 	   * select how many days can be message left on the server. */
40 	  N_("_Delete after %s day(s)"), "0:1:7:365" },
41 	{ CAMEL_PROVIDER_CONF_LABEL, "delete-after-days-hint", "keep-on-server",
42 	  N_("Hint: Use 0 days to keep messages on the server indefinitely.") },
43 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "delete-expunged", "keep-on-server",
44 	  N_("Delete _expunged from local Inbox"), "0" },
45 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "disable-extensions", NULL,
46 	  N_("Disable _support for all POP3 extensions"), "0" },
47 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "enable-utf8", "!disable-extensions",
48 	  N_("Enable _UTF-8 extension, when the server supports it"), "1" },
49 	{ CAMEL_PROVIDER_CONF_SECTION_END },
50 	{ CAMEL_PROVIDER_CONF_END }
51 };
52 
53 CamelProviderPortEntry pop3_port_entries[] = {
54 	{ 110, N_("Default POP3 port"), FALSE },
55 	{ 995, N_("POP3 over TLS"), TRUE },
56 	{ 0, NULL, 0 }
57 };
58 
59 static CamelProvider pop3_provider = {
60 	"pop",
61 
62 	N_("POP"),
63 
64 	N_("For connecting to and downloading mail from POP servers."),
65 
66 	"mail",
67 
68 	CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
69 	CAMEL_PROVIDER_SUPPORTS_SSL |
70 	CAMEL_PROVIDER_SUPPORTS_MOBILE_DEVICES,
71 
72 	CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
73 
74 	pop3_conf_entries,
75 
76 	pop3_port_entries,
77 
78 	/* ... */
79 };
80 
81 CamelServiceAuthType camel_pop3_password_authtype = {
82 	N_("Password"),
83 
84 	N_("This option will connect to the POP server using a plaintext "
85 	   "password. This is the only option supported by many POP servers."),
86 
87 	"",
88 	TRUE
89 };
90 
91 CamelServiceAuthType camel_pop3_apop_authtype = {
92 	"APOP",
93 
94 	N_("This option will connect to the POP server using an encrypted "
95 	   "password via the APOP protocol. This may not work for all users "
96 	   "even on servers that claim to support it."),
97 
98 	"+APOP",
99 	TRUE
100 };
101 
102 void
camel_provider_module_init(void)103 camel_provider_module_init (void)
104 {
105 	CamelServiceAuthType *auth;
106 
107 	pop3_provider.object_types[CAMEL_PROVIDER_STORE] =
108 		CAMEL_TYPE_POP3_STORE;
109 	pop3_provider.url_hash = pop3_url_hash;
110 	pop3_provider.url_equal = pop3_url_equal;
111 
112 	pop3_provider.authtypes = camel_sasl_authtype_list (FALSE);
113 	auth = camel_sasl_authtype ("LOGIN");
114 	if (auth)
115 		pop3_provider.authtypes = g_list_prepend (
116 			pop3_provider.authtypes, auth);
117 	pop3_provider.authtypes = g_list_prepend (
118 		pop3_provider.authtypes,
119 		&camel_pop3_apop_authtype);
120 	pop3_provider.authtypes = g_list_prepend (
121 		pop3_provider.authtypes,
122 		&camel_pop3_password_authtype);
123 	pop3_provider.translation_domain = GETTEXT_PACKAGE;
124 
125 	camel_provider_register (&pop3_provider);
126 }
127 
128 static void
add_hash(guint * hash,gchar * s)129 add_hash (guint *hash,
130           gchar *s)
131 {
132 	if (s)
133 		*hash ^= g_str_hash(s);
134 }
135 
136 static guint
pop3_url_hash(gconstpointer key)137 pop3_url_hash (gconstpointer key)
138 {
139 	const CamelURL *u = (CamelURL *) key;
140 	guint hash = 0;
141 
142 	add_hash (&hash, u->user);
143 	add_hash (&hash, u->host);
144 	hash ^= u->port;
145 
146 	return hash;
147 }
148 
149 static gint
check_equal(gchar * s1,gchar * s2)150 check_equal (gchar *s1,
151              gchar *s2)
152 {
153 	if (s1 == NULL) {
154 		if (s2 == NULL)
155 			return TRUE;
156 		else
157 			return FALSE;
158 	}
159 
160 	if (s2 == NULL)
161 		return FALSE;
162 
163 	return strcmp (s1, s2) == 0;
164 }
165 
166 static gint
pop3_url_equal(gconstpointer a,gconstpointer b)167 pop3_url_equal (gconstpointer a,
168                 gconstpointer b)
169 {
170 	const CamelURL *u1 = a, *u2 = b;
171 
172 	return check_equal (u1->protocol, u2->protocol)
173 		&& check_equal (u1->user, u2->user)
174 		&& check_equal (u1->host, u2->host)
175 		&& u1->port == u2->port;
176 }
177