Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / providers / groupwise / camel-groupwise-provider.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-groupwise-provider.c: GroupWise provider registration code */
3
4 /*
5  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
6  *           Sivaiah Nallagatla <snallagatla@novell.com>
7  *           Rodrigo Moya <rodrigo@ximian.com>
8  *
9  *  Copyright 2003 Novell, Inc. (www.novell.com)
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of version 2 of the GNU Lesser General Public
13  * License as published by the Free Software Foundation.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this program; if not, write to the
22  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <string.h>
32
33 #include <glib.h>
34 #include <glib/gi18n-lib.h>
35 #include <gmodule.h>
36
37 #include "camel-provider.h"
38 #include "camel-sasl.h"
39 #include "camel-session.h"
40 #include "camel-url.h"
41
42 #include "camel-groupwise-store.h"
43 #include "camel-groupwise-transport.h"
44
45 static void add_hash (guint *hash, char *s);
46 static guint groupwise_url_hash (gconstpointer key);
47 static gint check_equal (char *s1, char *s2);
48 static gint groupwise_url_equal (gconstpointer a, gconstpointer b);
49
50
51 CamelProviderConfEntry groupwise_conf_entries[] = {
52         /* override the labels/defaults of the standard settings */
53
54         { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
55           N_("Checking for new mail") },
56         { CAMEL_PROVIDER_CONF_CHECKBOX, "check_all", NULL,
57           N_("C_heck for new messages in all folders"), "1" },
58         { CAMEL_PROVIDER_CONF_SECTION_END },
59
60         { CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") },
61         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter", NULL,
62           N_("_Apply filters to new messages in Inbox on this server"), "0" },
63         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk", NULL,
64           N_("Check new messages for J_unk contents"), "0" },
65         { CAMEL_PROVIDER_CONF_CHECKBOX, "filter_junk_inbox", "filter_junk",
66           N_("Only check for Junk messages in the IN_BOX folder"), "0" },
67         { CAMEL_PROVIDER_CONF_CHECKBOX, "sync_offline", NULL,
68           N_("Automatically synchroni_ze account locally"), "0" },
69         { CAMEL_PROVIDER_CONF_SECTION_END },
70
71         /* extra GroupWise  configuration settings */
72         {CAMEL_PROVIDER_CONF_SECTION_START, "soapport", NULL,
73           N_("SOAP Settings") },
74
75         { CAMEL_PROVIDER_CONF_ENTRY, "soap_port", NULL,
76           N_("Post Office Agent SOAP Port:"), "7191" },
77
78         { CAMEL_PROVIDER_CONF_HIDDEN, "auth-domain", NULL,
79           NULL, "Groupwise" },
80                 
81         { CAMEL_PROVIDER_CONF_SECTION_END }, 
82
83         { CAMEL_PROVIDER_CONF_END }
84 };
85
86
87 static CamelProvider groupwise_provider = {
88         "groupwise",
89         N_("Novell GroupWise"),
90
91         N_("For accessing Novell GroupWise servers"),
92
93         "mail",
94
95         CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
96         CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_SUPPORTS_SSL | CAMEL_PROVIDER_DISABLE_SENT_FOLDER,
97
98         CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST | CAMEL_URL_ALLOW_AUTH,
99
100         groupwise_conf_entries,
101
102         /* ... */
103 };
104
105 CamelServiceAuthType camel_groupwise_password_authtype = {
106         N_("Password"),
107         
108         N_("This option will connect to the GroupWise server using a "
109            "plaintext password."),
110         
111         "",
112         TRUE
113 };
114
115 static int
116 groupwise_auto_detect_cb (CamelURL *url, GHashTable **auto_detected,
117                          CamelException *ex)
118 {
119         *auto_detected = g_hash_table_new (g_str_hash, g_str_equal);
120
121         g_hash_table_insert (*auto_detected, g_strdup ("poa"),
122                              g_strdup (url->host));
123
124         return 0;
125 }
126
127 void
128 camel_provider_module_init(void)
129 {
130         CamelProvider *imap_provider = NULL;
131         CamelException ex = CAMEL_EXCEPTION_INITIALISER;
132         gboolean use_imap = g_getenv ("USE_IMAP") != NULL;
133
134         if (use_imap)
135             imap_provider =  camel_provider_get("imap://", &ex);
136
137         groupwise_provider.url_hash = groupwise_url_hash;
138         groupwise_provider.url_equal = groupwise_url_equal;
139         groupwise_provider.auto_detect = groupwise_auto_detect_cb;
140         groupwise_provider.authtypes = g_list_prepend (groupwise_provider.authtypes, &camel_groupwise_password_authtype);
141         groupwise_provider.translation_domain = GETTEXT_PACKAGE;
142         
143         if (use_imap)
144                 groupwise_provider.object_types[CAMEL_PROVIDER_STORE] = imap_provider->object_types [CAMEL_PROVIDER_STORE];
145         else    {
146                 groupwise_provider.object_types[CAMEL_PROVIDER_STORE] =  camel_groupwise_store_get_type();
147                 groupwise_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_groupwise_transport_get_type();
148         } 
149         
150         camel_provider_register (&groupwise_provider);
151 }
152
153
154 static void
155 add_hash (guint *hash, char *s)
156 {
157         if (s)
158                 *hash ^= g_str_hash(s);
159 }
160
161 static guint
162 groupwise_url_hash (gconstpointer key)
163 {
164         const CamelURL *u = (CamelURL *)key;
165         guint hash = 0;
166
167         add_hash (&hash, u->user);
168         add_hash (&hash, u->authmech);
169         add_hash (&hash, u->host);
170         hash ^= u->port;
171         
172         return hash;
173 }
174
175 static gint
176 check_equal (char *s1, char *s2)
177 {
178         if (s1 == NULL) {
179                 if (s2 == NULL)
180                         return TRUE;
181                 else
182                         return FALSE;
183         }
184         
185         if (s2 == NULL)
186                 return FALSE;
187
188         return strcmp (s1, s2) == 0;
189 }
190
191 static gint
192 groupwise_url_equal (gconstpointer a, gconstpointer b)
193 {
194         const CamelURL *u1 = a, *u2 = b;
195         
196         return check_equal (u1->protocol, u2->protocol)
197                 && check_equal (u1->user, u2->user)
198                 && check_equal (u1->authmech, u2->authmech)
199                 && check_equal (u1->host, u2->host)
200                 && u1->port == u2->port;
201 }