| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 1999-2008 Novell, Inc. (www.novell.com) |
| 3 |
* SPDX-FileContributor: Jeffrey Stedfast <[email protected]> |
| 4 |
* SPDX-FileContributor: Sivaiah Nallagatla <[email protected]> |
| 5 |
* SPDX-FileContributor: Rodrigo Moya <[email protected]> |
| 6 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "evolution-ews-config.h" |
| 10 |
|
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
#include <glib/gi18n-lib.h> |
| 14 |
#include <gmodule.h> |
| 15 |
#include <libedataserver/libedataserver.h> |
| 16 |
|
| 17 |
#include "common/camel-sasl-xoauth2-office365.h" |
| 18 |
|
| 19 |
#include "camel-ews-store.h" |
| 20 |
#include "camel-ews-transport.h" |
| 21 |
|
| 22 |
static void add_hash (guint *hash, gchar *s); |
| 23 |
static guint ews_url_hash (gconstpointer key); |
| 24 |
static gint ews_url_equal (gconstpointer a, gconstpointer b); |
| 25 |
|
| 26 |
static CamelProviderConfEntry ews_conf_entries[] = { |
| 27 |
/* override the labels/defaults of the standard settings */ |
| 28 |
|
| 29 |
{ CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL, |
| 30 |
N_("Checking for new mail") }, |
| 31 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL, |
| 32 |
N_("C_heck for new messages in all folders"), "1" }, |
| 33 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "listen-notifications", NULL, |
| 34 |
N_("_Listen for server change notifications"), "1" }, |
| 35 |
{ CAMEL_PROVIDER_CONF_SECTION_END }, |
| 36 |
|
| 37 |
{ CAMEL_PROVIDER_CONF_SECTION_START, "general", NULL, N_("Options") }, |
| 38 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL, |
| 39 |
N_("_Apply filters to new messages in Inbox on this server"), "0" }, |
| 40 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL, |
| 41 |
N_("Check new messages for _Junk contents"), "0" }, |
| 42 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk", |
| 43 |
N_("Only check for Junk messages in the IN_BOX folder"), "0" }, |
| 44 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL, |
| 45 |
N_("Synchroni_ze remote mail locally in all folders"), "0" }, |
| 46 |
{ CAMEL_PROVIDER_CONF_PLACEHOLDER, "ews-limit-by-age-placeholder", NULL }, |
| 47 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "show-public-folders", NULL, |
| 48 |
N_("Show _Public Folders beside user folders"), "0" }, |
| 49 |
{ CAMEL_PROVIDER_CONF_SECTION_END }, |
| 50 |
|
| 51 |
{ CAMEL_PROVIDER_CONF_SECTION_START, "connection", NULL, N_("Connection") }, |
| 52 |
{ CAMEL_PROVIDER_CONF_CHECKSPIN, "timeout", NULL, |
| 53 |
/* Translators: '%s' is preplaced with a widget, where " |
| 54 |
* user can select how long the timeout should be. */ |
| 55 |
N_("Connection _timeout (in seconds) %s"), "0:1:0:32768" }, |
| 56 |
{ CAMEL_PROVIDER_CONF_CHECKSPIN, "concurrent-connections", NULL, |
| 57 |
N_("Numbe_r of concurrent connections to use"), "y:1:1:7" }, |
| 58 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "override-user-agent", NULL, |
| 59 |
N_("Override _User-Agent header value"), "0" }, |
| 60 |
{ CAMEL_PROVIDER_CONF_ENTRY, "user-agent", "override-user-agent", "" }, |
| 61 |
{ CAMEL_PROVIDER_CONF_CHECKBOX, "force-http1", NULL, |
| 62 |
N_("Al_ways connect with HTTP/1"), "0" }, |
| 63 |
{ CAMEL_PROVIDER_CONF_SECTION_END }, |
| 64 |
|
| 65 |
{ CAMEL_PROVIDER_CONF_END } |
| 66 |
}; |
| 67 |
|
| 68 |
static CamelProvider ews_provider = { |
| 69 |
"ews", |
| 70 |
N_("Exchange Web Services"), |
| 71 |
|
| 72 |
N_("For accessing Exchange servers using Web Services"), |
| 73 |
|
| 74 |
"mail", |
| 75 |
|
| 76 |
CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE | |
| 77 |
CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_IS_EXTERNAL, |
| 78 |
|
| 79 |
CAMEL_URL_ALLOW_USER | CAMEL_URL_ALLOW_AUTH | CAMEL_URL_HIDDEN_HOST, |
| 80 |
|
| 81 |
ews_conf_entries, |
| 82 |
|
| 83 |
/* ... */ |
| 84 |
}; |
| 85 |
|
| 86 |
CamelServiceAuthType camel_ews_ntlm_authtype = { |
| 87 |
N_("NTLM"), |
| 88 |
|
| 89 |
N_("This option will connect to the Exchange server using a " |
| 90 |
"plaintext password with NTLM authentication."), |
| 91 |
|
| 92 |
"", |
| 93 |
TRUE |
| 94 |
}; |
| 95 |
|
| 96 |
CamelServiceAuthType camel_ews_basic_authtype = { |
| 97 |
N_("Basic"), |
| 98 |
|
| 99 |
N_("This option will connect to the Exchange server using a " |
| 100 |
"plaintext password with Basic authentication."), |
| 101 |
|
| 102 |
"PLAIN", |
| 103 |
TRUE |
| 104 |
}; |
| 105 |
|
| 106 |
CamelServiceAuthType camel_ews_gssapi_authtype = { |
| 107 |
N_("Kerberos"), |
| 108 |
|
| 109 |
N_("This option will connect to the Exchange server using a " |
| 110 |
"Kerberos/GSSAPI authentication."), |
| 111 |
|
| 112 |
"GSSAPI", |
| 113 |
FALSE |
| 114 |
}; |
| 115 |
|
| 116 |
void |
| 117 |
camel_provider_module_init (void) |
| 118 |
{ |
| 119 |
ews_provider.url_hash = ews_url_hash; |
| 120 |
ews_provider.url_equal = ews_url_equal; |
| 121 |
ews_provider.authtypes = g_list_append (g_list_append (g_list_append (NULL, |
| 122 |
&camel_ews_ntlm_authtype), |
| 123 |
&camel_ews_basic_authtype), |
| 124 |
&camel_ews_gssapi_authtype); |
| 125 |
ews_provider.translation_domain = GETTEXT_PACKAGE; |
| 126 |
|
| 127 |
ews_provider.object_types[CAMEL_PROVIDER_STORE] = CAMEL_TYPE_EWS_STORE; |
| 128 |
ews_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = CAMEL_TYPE_EWS_TRANSPORT; |
| 129 |
|
| 130 |
bindtextdomain (GETTEXT_PACKAGE, EXCHANGE_EWS_LOCALEDIR); |
| 131 |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
| 132 |
|
| 133 |
g_type_ensure (CAMEL_TYPE_SASL_XOAUTH2_OFFICE365); |
| 134 |
|
| 135 |
/* Hide the option when not supported */ |
| 136 |
if (!e_soup_session_util_get_force_http1_supported ()) { |
| 137 |
gint ii; |
| 138 |
|
| 139 |
for (ii = G_N_ELEMENTS (ews_conf_entries) - 1; ii >= 0 ; ii--) { |
| 140 |
if (ews_conf_entries[ii].type == CAMEL_PROVIDER_CONF_CHECKBOX && |
| 141 |
g_strcmp0 (ews_conf_entries[ii].name, "force-http1") == 0) { |
| 142 |
ews_conf_entries[ii].type = CAMEL_PROVIDER_CONF_HIDDEN; |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
camel_provider_register (&ews_provider); |
| 149 |
} |
| 150 |
|
| 151 |
static void |
| 152 |
add_hash (guint *hash, |
| 153 |
gchar *s) |
| 154 |
{ |
| 155 |
if (s) |
| 156 |
*hash ^= g_str_hash(s); |
| 157 |
} |
| 158 |
|
| 159 |
static guint |
| 160 |
ews_url_hash (gconstpointer key) |
| 161 |
{ |
| 162 |
const CamelURL *u = (CamelURL *) key; |
| 163 |
guint hash = 0; |
| 164 |
|
| 165 |
add_hash (&hash, u->user); |
| 166 |
add_hash (&hash, u->host); |
| 167 |
hash ^= u->port; |
| 168 |
|
| 169 |
return hash; |
| 170 |
} |
| 171 |
|
| 172 |
static gint |
| 173 |
ews_url_equal (gconstpointer a, |
| 174 |
gconstpointer b) |
| 175 |
{ |
| 176 |
const CamelURL *u1 = a, *u2 = b; |
| 177 |
|
| 178 |
return ((g_strcmp0 (u1->protocol, u2->protocol) == 0) |
| 179 |
&& (g_strcmp0 (u1->user, u2->user) == 0) |
| 180 |
&& (g_strcmp0 (u1->host, u2->host) == 0) |
| 181 |
&& (u1->port == u2->port)); |
| 182 |
} |