1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <glib/gi18n.h>
31 #include <string.h> /* strcmp */
32 #include <modest-protocol-info.h>
33 #include <modest-pair.h>
34 #include <modest-defs.h>
40 const gchar* display_name;
43 static const ProtocolInfo TransportStoreProtocolMap[] = {
44 { MODEST_PROTOCOL_TRANSPORT_SENDMAIL, "sendmail", N_("Sendmail") },
45 { MODEST_PROTOCOL_TRANSPORT_SMTP, "smtp", N_("SMTP Server") },
47 { MODEST_PROTOCOL_STORE_POP, "pop", N_("POP3") },
48 { MODEST_PROTOCOL_STORE_IMAP, "imap", N_("IMAPv4") },
49 { MODEST_PROTOCOL_STORE_MAILDIR, "maildir", N_("Maildir") },
50 { MODEST_PROTOCOL_STORE_MBOX, "mbox", N_("MBox") }
53 static const ProtocolInfo ConnectionProtocolMap[] = {
54 { MODEST_PROTOCOL_CONNECTION_NORMAL, "none", N_("None") },
55 { MODEST_PROTOCOL_CONNECTION_SSL, "ssl", N_("SSL") },
56 { MODEST_PROTOCOL_CONNECTION_TLS, "tls", N_("TLS") },
57 { MODEST_PROTOCOL_CONNECTION_TLS_OP, "tls-op", N_("TLS when possible") }
58 /* op stands for optional */
62 /* FIXME: these names must match those of tny_camel_account_get_supported_secure_auth */
63 static const ProtocolInfo AuthProtocolMap[] = {
64 { MODEST_PROTOCOL_AUTH_NONE, MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE, N_("None") },
65 { MODEST_PROTOCOL_AUTH_PASSWORD, MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD, N_("Password") },
66 { MODEST_PROTOCOL_AUTH_CRAMMD5, MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5, N_("Cram MD5") }
70 static ModestPairList*
71 get_protocol_pair_list (const ProtocolInfo* map, guint size)
73 g_return_val_if_fail (map, NULL);
75 ModestPairList *proto_list = NULL;
77 for (i = 0; i != size; ++i) {
78 const ProtocolInfo info = map[i];
79 proto_list = g_slist_append (proto_list,
80 (gpointer)modest_pair_new(
82 (gpointer)info.display_name,
90 modest_protocol_info_get_transport_store_protocol_pair_list ()
92 return get_protocol_pair_list (TransportStoreProtocolMap,
93 G_N_ELEMENTS(TransportStoreProtocolMap));
97 modest_protocol_info_get_auth_protocol_pair_list ()
99 return get_protocol_pair_list (AuthProtocolMap,
100 G_N_ELEMENTS(AuthProtocolMap));
104 modest_protocol_info_get_connection_protocol_pair_list ()
106 return get_protocol_pair_list (ConnectionProtocolMap,
107 G_N_ELEMENTS(ConnectionProtocolMap));
111 ModestTransportStoreProtocol
112 modest_protocol_info_get_transport_store_protocol (const gchar* name)
114 const ProtocolInfo *map = TransportStoreProtocolMap;
115 const guint size = G_N_ELEMENTS(TransportStoreProtocolMap);
118 g_return_val_if_fail (name, MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN);
120 g_return_val_if_fail (map, MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN);
122 for (i = 0; i != size; ++i) {
123 const ProtocolInfo info = map[i];
124 if (strcmp(name, info.name) == 0)
128 return MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
133 /* get either the name or the display_name for the protocol */
135 get_protocol_string (gint proto, const ProtocolInfo* map, guint size, gboolean get_name)
137 g_return_val_if_fail (map, NULL);
140 for (i = 0; i != size; ++i) {
141 ProtocolInfo info = map[i];
142 if (info.proto == proto)
143 return get_name ? info.name : info.display_name;
145 g_return_val_if_reached (NULL);
149 modest_protocol_info_get_transport_store_protocol_name (ModestTransportStoreProtocol proto)
151 return get_protocol_string (proto, TransportStoreProtocolMap,
152 G_N_ELEMENTS(TransportStoreProtocolMap), TRUE);
156 modest_protocol_info_get_auth_protocol_name (ModestAuthProtocol proto)
158 return get_protocol_string (proto, AuthProtocolMap,
159 G_N_ELEMENTS(AuthProtocolMap), TRUE);
163 modest_protocol_info_get_connection_protocol_name (ModestAuthProtocol proto)
165 return get_protocol_string (proto, ConnectionProtocolMap,
166 G_N_ELEMENTS(ConnectionProtocolMap), TRUE);
171 modest_protocol_info_protocol_is_local_store (ModestTransportStoreProtocol proto)
173 return proto == MODEST_PROTOCOL_STORE_MBOX || proto == MODEST_PROTOCOL_STORE_MAILDIR;
179 modest_protocol_info_protocol_is_store (ModestTransportStoreProtocol proto)
181 return proto == MODEST_PROTOCOL_STORE_MBOX || proto == MODEST_PROTOCOL_STORE_MAILDIR ||
182 proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP;
186 modest_protocol_info_is_secure(ModestConnectionProtocol protocol)
188 return (protocol == MODEST_PROTOCOL_CONNECTION_SSL ||
189 protocol == MODEST_PROTOCOL_CONNECTION_TLS);
192 gboolean modest_protocol_info_auth_is_secure(ModestAuthProtocol protocol)
194 return (protocol == MODEST_PROTOCOL_AUTH_CRAMMD5);