modest-plugin.c \
modest-plugin-factory.c \
modest-plugin-factory.h \
+ modest-presets.c \
+ modest-presets.h \
modest-progress-object.c \
modest-progress-object.h \
modest-protocol.c \
modest-osso-autosave-callbacks.h \
modest-osso-state-saving.c \
modest-osso-state-saving.h \
- modest-presets.h modest-presets.c \
modest-limit-retrieve-picker.h modest-limit-retrieve-picker.c \
modest-retrieve-picker.h modest-retrieve-picker.c \
modest-secureauth-picker.h modest-secureauth-picker.c \
+++ /dev/null
-/* Copyright (c) 2006, Nokia Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Nokia Corporation nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h> /* for strcmp */
-#include <modest-protocol-registry.h>
-#include <modest-runtime.h>
-#include "modest-presets.h"
-#include <stdio.h>
-
-/* Include config.h so that _() works: */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define MODEST_PRESETS_KEY_NAME "Name"
-#define MODEST_PRESETS_KEY_DOMAIN "Domain"
-#define MODEST_PRESETS_KEY_MCC "MCC"
-#define MODEST_PRESETS_KEY_INCOMING "IncomingMailServer"
-#define MODEST_PRESETS_KEY_INCOMING_SECURITY "IncomingSecurity"
-#define MODEST_PRESETS_KEY_OUTGOING "OutgoingMailServer"
-#define MODEST_PRESETS_KEY_MAILBOX_TYPE "MailboxType"
-#define MODEST_PRESETS_KEY_APOP "APOPSecureLogin"
-#define MODEST_PRESETS_KEY_SECURE_SMTP "SecureSmtp"
-#define MODEST_PRESETS_KEY_SMTP_PORT "SmtpPort"
-
-
-ModestPresets*
-modest_presets_new (const gchar *presetfile)
-{
- ModestPresets *presets = NULL;
- GError *err = NULL;
-
- g_return_val_if_fail (presetfile, NULL);
-
- presets = g_new (ModestPresets, 1);
- presets->keyfile = g_key_file_new ();
-
- if (!presets->keyfile) {
- g_printerr ("modest: cannot instantiate GKeyFile\n");
- g_free (presets);
- return NULL;
- }
-
- if (!g_key_file_load_from_file (presets->keyfile, presetfile,
- G_KEY_FILE_NONE, &err)) {
- g_printerr ("modest: cannot open keyfile from %s:\n %s\n", presetfile,
- err ? err->message : "unknown reason");
- g_error_free (err);
- g_free (presets);
- return NULL;
- }
-
- return presets;
-}
-
-gchar**
-modest_presets_get_providers (ModestPresets *self, guint mcc,
- gboolean include_globals, gchar ***provider_ids)
-{
- gchar **all_providers = NULL;
- gchar **all_provider_ids = NULL;
- gchar **filtered = NULL;
- gchar **filtered_ids = NULL;
- GError *err = NULL;
- guint i, j, len;
-
- g_return_val_if_fail (self && self->keyfile, NULL);
-
- /* Get all the provider IDs: */
- all_provider_ids = g_key_file_get_groups (self->keyfile, NULL);
- len = g_strv_length(all_provider_ids);
-
- /* Get the names for all these providers: */
- all_providers = g_new0(gchar*, len + 1); /* Provider names. */
- for (i=0; i != len; ++i) {
- const gchar * provider_id = all_provider_ids[i];
- if(provider_id) {
- gchar* name = g_key_file_get_string(self->keyfile, provider_id,
- MODEST_PRESETS_KEY_NAME, NULL);
-
- /* Be forgiving of missing names.
- * If we use NULL then we will null-terminate the array.
- */
- if(!name)
- name = g_strdup("");
-
- all_providers[i] = name;
- }
- else
- all_providers[i] = NULL;
- };
-
- /* return *all* providers? */
- /*
- if (mcc == 0 && include_globals) {
- *provider_ids = all_provider_ids;
- return all_providers;
- }
- */
-
- /* nope: filter them */
-
- filtered = g_new0(gchar*, len + 1); /* Provider names. */
- filtered_ids = g_new0(gchar*, len + 1); /* Provider IDs */
-
- for (i=0, j=0; i != len; ++i) {
-
- int this_mcc;
- this_mcc = g_key_file_get_integer (self->keyfile, all_provider_ids[i],
- MODEST_PRESETS_KEY_MCC, &err);
- if (err) {
- g_strfreev (all_providers);
- g_strfreev (all_provider_ids);
- g_strfreev (filtered);
- g_strfreev (filtered_ids);
-
- g_printerr ("modest: error parsing keyfile: %s\n", err->message);
- g_error_free (err);
-
- return NULL;
- }
-
- if (this_mcc == mcc || (this_mcc == 0 && include_globals)) {
- filtered[j] = all_providers[i];
- filtered_ids[j] = all_provider_ids[i];
- ++j;
- filtered[j] = NULL; /* the array must be NULL-terminated */
- filtered_ids[j] = NULL; /* the array must be NULL-terminated */
-
- all_providers[i] = NULL; /* g_strfreev: leave it alone */
- all_provider_ids[i] = NULL; /* g_strfreev: leave it alone */
- }
- }
-
- g_strfreev (all_providers);
- g_strfreev (all_provider_ids);
-
- *provider_ids = filtered_ids;
- return filtered;
-}
-
-
-gchar*
-modest_presets_get_server (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- g_return_val_if_fail (self && self->keyfile, NULL);
- g_return_val_if_fail (provider_id, NULL);
-
- return g_key_file_get_string (self->keyfile, provider_id,
- incoming_server ?
- MODEST_PRESETS_KEY_INCOMING :
- MODEST_PRESETS_KEY_OUTGOING,
- NULL);
-}
-
-gchar *
-modest_presets_get_domain (ModestPresets *self,
- const gchar *provider_id)
-{
- g_return_val_if_fail (self && self->keyfile, NULL);
- g_return_val_if_fail (provider_id, NULL);
-
- return g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_DOMAIN,
- NULL);
-}
-
-
-
-
-ModestProtocolType
-modest_presets_get_info_server_type (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
- ModestProtocolRegistry *protocol_registry;
- ModestProtocol *protocol;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, 0);
- protocol_registry = modest_runtime_get_protocol_registry ();
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (!val)
- return protocol_type;
-
- g_free (val);
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_MAILBOX_TYPE,NULL);
-
- protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry, MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, val);
- if (protocol == NULL)
- return protocol_type;
- protocol_type = modest_protocol_get_type_id (protocol);
- } else {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (!val)
- return protocol_type;
-
- protocol_type = MODEST_PROTOCOLS_TRANSPORT_SMTP;
- }
- g_free (val);
-
- /* debug: */
-/* g_message ("provider id: %s, server type: %d", provider_id, info); */
- return protocol_type;
-}
-
-
-
-ModestProtocolType
-modest_presets_get_info_server_security (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOLS_CONNECTION_NONE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
- if (val && ((strcmp (val, "1") == 0) || (strcmp (val, "2") == 0))) {
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- } else if (val && (strcmp (val, "tls") == 0)) {
- protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
- } else if (val && (strcmp (val, "ssl") == 0)) {
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- }
- g_free (val);
- }
- } else /* outgoing: */ {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
- /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
- if (val && strcmp(val,"true") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- else if (val && strcmp (val, "ssl") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- else if (val && strcmp (val, "2") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- else if (val && strcmp (val, "tls") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
- else if (val && strcmp (val, "1") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
- g_free(val);
- }
- }
-
- return protocol_type;
-}
-
-gboolean
-modest_presets_get_info_server_use_alternate_port (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- gboolean result = FALSE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
- if (val && (strcmp (val, "2") == 0)) {
- result = TRUE;
- }
- g_free (val);
- }
- }
-
- return result;
-}
-
-ModestProtocolType
-modest_presets_get_info_server_auth (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOLS_AUTH_NONE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_AUTH_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_APOP, NULL);
- if (val && strcmp(val, "true") == 0)
- protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
- g_free(val);
-
- }
- } else /* outgoing: */ {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
- /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
- if (val && strcmp(val,"true") == 0)
- protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
- g_free(val);
- }
- }
-
- return protocol_type;
-}
-
-/*
- * at the moment, this only for mac.com, which have a special SMTP port
- */
-guint
-modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
- gboolean incoming_server)
-{
- guint port;
-
- g_return_val_if_fail (self && self->keyfile, 0);
-
- if (incoming_server)
- port = 0; /* not used yet */
- else
- port = (guint)g_key_file_get_integer (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SMTP_PORT, NULL);
-
- return port;
-}
-
-
-
-
-
-void
-modest_presets_destroy (ModestPresets *self)
-{
- if (!self)
- return;
-
- g_key_file_free (self->keyfile);
- self->keyfile = NULL;
-
- g_free (self);
-}
+++ /dev/null
-/* Copyright (c) 2006, Nokia Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Nokia Corporation nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __MODEST_PRESETS_H__
-#define __MODEST_PRESETS_H__
-
-#include <glib.h>
-#include <modest-protocol.h>
-
-struct _ModestPresets {
-/* private data: don't touch */
- GKeyFile *keyfile;
-};
-typedef struct _ModestPresets ModestPresets;
-
-
-/**
- * modest_presets_new:
- * @presetfile: the full path to the file with presets (in GKeyFile format)
- *
- * make a new ModestPresets instance
- *
- * Returns: a new ModestPresets instance, or NULL in case of error.
- */
-ModestPresets* modest_presets_new (const gchar *presetfile);
-
-
-/**
- * modest_presets_get_providers:
- * @self: a valid ModestPresets instance
- * @mcc: limit the search to providers with this mcc (Mobile Country Code),
- * or 0 to get all
- * @include_globals: include (global) providers without MCC (such as GMail, Yahoo)
- * @provider_ids: Output parameter, which will be set to a newly allocated array of strings, or NULL in case of error.
- *
- * get a list of providers matching certian criteria
- *
- * Returns: The provider names, as a newly allocated array of strings, or NULL in case of error
- * should be freed with g_strfreev
- *
- **/
-gchar ** modest_presets_get_providers (ModestPresets *self, guint mcc,
- gboolean include_globals, gchar ***provider_ids);
-
-/**
- * modest_presets_get_server:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get the name of a incoming or outgoing mailserver
- *
- * Returns: a newly allocated string with the servername, or NULL in case
- * of error, or server not found. (FIXME). Note that if the (incoming) server uses a
- * non-standard port, the port number is appended to the name, eg. pop.foo.fi:995
- */
-gchar * modest_presets_get_server (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_domain:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- *
- * Get the name of the most-used domain for theis provider. For instance. hotmail.com
- *
- * Returns: a newly allocated string with the domain name, or NULL in case
- * of error.
- */
-gchar * modest_presets_get_domain (ModestPresets *self,
- const gchar *provider_id);
-
-/**
- * modest_presets_get_info_server_type:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: a #ModestProtocolType with the required information
- */
-ModestProtocolType modest_presets_get_info_server_type (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: #ModestProtocolType with server auth
- */
-ModestProtocolType modest_presets_get_info_server_auth (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: #ModestProtocolType with server security
- */
-ModestProtocolType modest_presets_get_info_server_security (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: %TRUE if we should use the alternate port.
- */
-gboolean modest_presets_get_info_server_use_alternate_port (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-
-/**
- * modest_presets_get_port:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get port# for the incoming mailserver if TRUE, for the outgoing server otherwise
- *
- * Returns: the specific port number for some provider
- * function return 0 if the normal port number is valid
- *
- */
-guint modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
- gboolean incoming_server);
-
-
-/**
- * modest_presets_destroy:
- * @self: a valid ModestPresets instance (ie. must not be NULL)
- *
- * destroy ModestPresets instance; this is required after you're done with it.
- */
-void modest_presets_destroy (ModestPresets *self);
-
-
-#endif /*__MODEST_PRESETS__*/
-
-
#define _MODEST_PROVIDER_PICKER
#include <hildon/hildon-picker-button.h>
-#include "modest-presets.h"
+#include <modest-presets.h>
G_BEGIN_DECLS
libmodest-easysetup.la
libmodest_easysetup_la_SOURCES= \
- modest-presets.h modest-presets.c \
modest-easysetup-wizard-dialog.h modest-easysetup-wizard-dialog.c \
modest-easysetup-country-combo-box.h modest-easysetup-country-combo-box.c \
modest-easysetup-provider-combo-box.h modest-easysetup-provider-combo-box.c \
#define _EASYSETUP_PROVIDER_COMBO_BOX
#include <gtk/gtkcombobox.h>
-#include "modest-presets.h"
+#include <modest-presets.h>
G_BEGIN_DECLS
+++ /dev/null
-/* Copyright (c) 2006, Nokia Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Nokia Corporation nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <string.h> /* for strcmp */
-#include <modest-protocol-registry.h>
-#include <modest-runtime.h>
-#include "modest-presets.h"
-#include <stdio.h>
-
-/* Include config.h so that _() works: */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#define MODEST_PRESETS_KEY_NAME "Name"
-#define MODEST_PRESETS_KEY_DOMAIN "Domain"
-#define MODEST_PRESETS_KEY_MCC "MCC"
-#define MODEST_PRESETS_KEY_INCOMING "IncomingMailServer"
-#define MODEST_PRESETS_KEY_INCOMING_SECURITY "IncomingSecurity"
-#define MODEST_PRESETS_KEY_OUTGOING "OutgoingMailServer"
-#define MODEST_PRESETS_KEY_MAILBOX_TYPE "MailboxType"
-#define MODEST_PRESETS_KEY_APOP "APOPSecureLogin"
-#define MODEST_PRESETS_KEY_SECURE_SMTP "SecureSmtp"
-#define MODEST_PRESETS_KEY_SMTP_PORT "SmtpPort"
-
-
-ModestPresets*
-modest_presets_new (const gchar *presetfile)
-{
- ModestPresets *presets = NULL;
- GError *err = NULL;
-
- g_return_val_if_fail (presetfile, NULL);
-
- presets = g_new (ModestPresets, 1);
- presets->keyfile = g_key_file_new ();
-
- if (!presets->keyfile) {
- g_printerr ("modest: cannot instantiate GKeyFile\n");
- g_free (presets);
- return NULL;
- }
-
- if (!g_key_file_load_from_file (presets->keyfile, presetfile,
- G_KEY_FILE_NONE, &err)) {
- g_printerr ("modest: cannot open keyfile from %s:\n %s\n", presetfile,
- err ? err->message : "unknown reason");
- g_error_free (err);
- g_free (presets);
- return NULL;
- }
-
- return presets;
-}
-
-gchar**
-modest_presets_get_providers (ModestPresets *self, guint mcc,
- gboolean include_globals, gchar ***provider_ids)
-{
- gchar **all_providers = NULL;
- gchar **all_provider_ids = NULL;
- gchar **filtered = NULL;
- gchar **filtered_ids = NULL;
- GError *err = NULL;
- guint i, j, len;
-
- g_return_val_if_fail (self && self->keyfile, NULL);
-
- /* Get all the provider IDs: */
- all_provider_ids = g_key_file_get_groups (self->keyfile, NULL);
- len = g_strv_length(all_provider_ids);
-
- /* Get the names for all these providers: */
- all_providers = g_new0(gchar*, len + 1); /* Provider names. */
- for (i=0; i != len; ++i) {
- const gchar * provider_id = all_provider_ids[i];
- if(provider_id) {
- gchar* name = g_key_file_get_string(self->keyfile, provider_id,
- MODEST_PRESETS_KEY_NAME, NULL);
-
- /* Be forgiving of missing names.
- * If we use NULL then we will null-terminate the array.
- */
- if(!name)
- name = g_strdup("");
-
- all_providers[i] = name;
- }
- else
- all_providers[i] = NULL;
- };
-
- /* return *all* providers? */
- /*
- if (mcc == 0 && include_globals) {
- *provider_ids = all_provider_ids;
- return all_providers;
- }
- */
-
- /* nope: filter them */
-
- filtered = g_new0(gchar*, len + 1); /* Provider names. */
- filtered_ids = g_new0(gchar*, len + 1); /* Provider IDs */
-
- for (i=0, j=0; i != len; ++i) {
-
- int this_mcc;
- this_mcc = g_key_file_get_integer (self->keyfile, all_provider_ids[i],
- MODEST_PRESETS_KEY_MCC, &err);
- if (err) {
- g_strfreev (all_providers);
- g_strfreev (all_provider_ids);
- g_strfreev (filtered);
- g_strfreev (filtered_ids);
-
- g_printerr ("modest: error parsing keyfile: %s\n", err->message);
- g_error_free (err);
-
- return NULL;
- }
-
- if (this_mcc == mcc || (this_mcc == 0 && include_globals)) {
- filtered[j] = all_providers[i];
- filtered_ids[j] = all_provider_ids[i];
- ++j;
- filtered[j] = NULL; /* the array must be NULL-terminated */
- filtered_ids[j] = NULL; /* the array must be NULL-terminated */
-
- all_providers[i] = NULL; /* g_strfreev: leave it alone */
- all_provider_ids[i] = NULL; /* g_strfreev: leave it alone */
- }
- }
-
- g_strfreev (all_providers);
- g_strfreev (all_provider_ids);
-
- *provider_ids = filtered_ids;
- return filtered;
-}
-
-
-gchar*
-modest_presets_get_server (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- g_return_val_if_fail (self && self->keyfile, NULL);
- g_return_val_if_fail (provider_id, NULL);
-
- return g_key_file_get_string (self->keyfile, provider_id,
- incoming_server ?
- MODEST_PRESETS_KEY_INCOMING :
- MODEST_PRESETS_KEY_OUTGOING,
- NULL);
-}
-
-gchar *
-modest_presets_get_domain (ModestPresets *self,
- const gchar *provider_id)
-{
- g_return_val_if_fail (self && self->keyfile, NULL);
- g_return_val_if_fail (provider_id, NULL);
-
- return g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_DOMAIN,
- NULL);
-}
-
-
-
-
-ModestProtocolType
-modest_presets_get_info_server_type (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
- ModestProtocolRegistry *protocol_registry;
- ModestProtocol *protocol;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, 0);
- protocol_registry = modest_runtime_get_protocol_registry ();
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (!val)
- return protocol_type;
-
- g_free (val);
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_MAILBOX_TYPE,NULL);
-
- protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry, MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, val);
- if (protocol == NULL)
- return protocol_type;
- protocol_type = modest_protocol_get_type_id (protocol);
- } else {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (!val)
- return protocol_type;
-
- protocol_type = MODEST_PROTOCOLS_TRANSPORT_SMTP;
- }
- g_free (val);
-
- /* debug: */
-/* g_message ("provider id: %s, server type: %d", provider_id, info); */
- return protocol_type;
-}
-
-
-
-ModestProtocolType
-modest_presets_get_info_server_security (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOLS_CONNECTION_NONE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
- if (val && ((strcmp (val, "1") == 0) || (strcmp (val, "2") == 0))) {
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- }
- g_free (val);
- }
- } else /* outgoing: */ {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
- /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
- if (val && strcmp(val,"true") == 0)
- protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
- g_free(val);
- }
- }
-
- return protocol_type;
-}
-
-gboolean
-modest_presets_get_info_server_use_alternate_port (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- gboolean result = FALSE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
- if (val && (strcmp (val, "2") == 0)) {
- result = TRUE;
- }
- g_free (val);
- }
- }
-
- return result;
-}
-
-ModestProtocolType
-modest_presets_get_info_server_auth (ModestPresets *self, const gchar *provider_id,
- gboolean incoming_server)
-{
- ModestProtocolType protocol_type = MODEST_PROTOCOLS_AUTH_NONE;
- gchar *val = NULL;
-
- g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_AUTH_NONE);
-
- if (incoming_server) {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_INCOMING, NULL);
- if (val) {
- g_free (val);
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_APOP, NULL);
- if (val && strcmp(val, "true") == 0)
- protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
- g_free(val);
-
- }
- } else /* outgoing: */ {
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_OUTGOING, NULL);
- if (val) {
- g_free (val);
-
- val = g_key_file_get_string (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
- /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
- if (val && strcmp(val,"true") == 0)
- protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
- g_free(val);
- }
- }
-
- return protocol_type;
-}
-
-/*
- * at the moment, this only for mac.com, which have a special SMTP port
- */
-guint
-modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
- gboolean incoming_server)
-{
- guint port;
-
- g_return_val_if_fail (self && self->keyfile, 0);
-
- if (incoming_server)
- port = 0; /* not used yet */
- else
- port = (guint)g_key_file_get_integer (self->keyfile, provider_id,
- MODEST_PRESETS_KEY_SMTP_PORT, NULL);
-
- return port;
-}
-
-
-
-
-
-void
-modest_presets_destroy (ModestPresets *self)
-{
- if (!self)
- return;
-
- g_key_file_free (self->keyfile);
- self->keyfile = NULL;
-
- g_free (self);
-}
+++ /dev/null
-/* Copyright (c) 2006, Nokia Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Nokia Corporation nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __MODEST_PRESETS_H__
-#define __MODEST_PRESETS_H__
-
-#include <glib.h>
-#include <modest-protocol.h>
-
-struct _ModestPresets {
-/* private data: don't touch */
- GKeyFile *keyfile;
-};
-typedef struct _ModestPresets ModestPresets;
-
-
-/**
- * modest_presets_new:
- * @presetfile: the full path to the file with presets (in GKeyFile format)
- *
- * make a new ModestPresets instance
- *
- * Returns: a new ModestPresets instance, or NULL in case of error.
- */
-ModestPresets* modest_presets_new (const gchar *presetfile);
-
-
-/**
- * modest_presets_get_providers:
- * @self: a valid ModestPresets instance
- * @mcc: limit the search to providers with this mcc (Mobile Country Code),
- * or 0 to get all
- * @include_globals: include (global) providers without MCC (such as GMail, Yahoo)
- * @provider_ids: Output parameter, which will be set to a newly allocated array of strings, or NULL in case of error.
- *
- * get a list of providers matching certian criteria
- *
- * Returns: The provider names, as a newly allocated array of strings, or NULL in case of error
- * should be freed with g_strfreev
- *
- **/
-gchar ** modest_presets_get_providers (ModestPresets *self, guint mcc,
- gboolean include_globals, gchar ***provider_ids);
-
-/**
- * modest_presets_get_server:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get the name of a incoming or outgoing mailserver
- *
- * Returns: a newly allocated string with the servername, or NULL in case
- * of error, or server not found. (FIXME). Note that if the (incoming) server uses a
- * non-standard port, the port number is appended to the name, eg. pop.foo.fi:995
- */
-gchar * modest_presets_get_server (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_domain:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- *
- * Get the name of the most-used domain for theis provider. For instance. hotmail.com
- *
- * Returns: a newly allocated string with the domain name, or NULL in case
- * of error.
- */
-gchar * modest_presets_get_domain (ModestPresets *self,
- const gchar *provider_id);
-
-/**
- * modest_presets_get_info_server_type:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: a #ModestProtocolType with the required information
- */
-ModestProtocolType modest_presets_get_info_server_type (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: #ModestProtocolType with server auth
- */
-ModestProtocolType modest_presets_get_info_server_auth (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: #ModestProtocolType with server security
- */
-ModestProtocolType modest_presets_get_info_server_security (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-/**
- * modest_presets_get_info_server_security:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get the incoming mailserver if TRUE, get the
- * outgoing server otherwise
- *
- * get information about some incoming or outgoing mailserver
- *
- * Returns: %TRUE if we should use the alternate port.
- */
-gboolean modest_presets_get_info_server_use_alternate_port (ModestPresets *self,
- const gchar *provider_id,
- gboolean incoming_server);
-
-
-/**
- * modest_presets_get_port:
- * @self: a valid ModestPresets instance
- * @provider_id: ID of the provider
- * @incoming_server: get port# for the incoming mailserver if TRUE, for the outgoing server otherwise
- *
- * Returns: the specific port number for some provider
- * function return 0 if the normal port number is valid
- *
- */
-guint modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
- gboolean incoming_server);
-
-
-/**
- * modest_presets_destroy:
- * @self: a valid ModestPresets instance (ie. must not be NULL)
- *
- * destroy ModestPresets instance; this is required after you're done with it.
- */
-void modest_presets_destroy (ModestPresets *self);
-
-
-#endif /*__MODEST_PRESETS__*/
-
-
--- /dev/null
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h> /* for strcmp */
+#include <modest-protocol-registry.h>
+#include <modest-runtime.h>
+#include "modest-presets.h"
+#include <stdio.h>
+
+/* Include config.h so that _() works: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define MODEST_PRESETS_KEY_NAME "Name"
+#define MODEST_PRESETS_KEY_DOMAIN "Domain"
+#define MODEST_PRESETS_KEY_MCC "MCC"
+#define MODEST_PRESETS_KEY_INCOMING "IncomingMailServer"
+#define MODEST_PRESETS_KEY_INCOMING_SECURITY "IncomingSecurity"
+#define MODEST_PRESETS_KEY_OUTGOING "OutgoingMailServer"
+#define MODEST_PRESETS_KEY_MAILBOX_TYPE "MailboxType"
+#define MODEST_PRESETS_KEY_APOP "APOPSecureLogin"
+#define MODEST_PRESETS_KEY_SECURE_SMTP "SecureSmtp"
+#define MODEST_PRESETS_KEY_SMTP_PORT "SmtpPort"
+
+
+ModestPresets*
+modest_presets_new (const gchar *presetfile)
+{
+ ModestPresets *presets = NULL;
+ GError *err = NULL;
+
+ g_return_val_if_fail (presetfile, NULL);
+
+ presets = g_new (ModestPresets, 1);
+ presets->keyfile = g_key_file_new ();
+
+ if (!presets->keyfile) {
+ g_printerr ("modest: cannot instantiate GKeyFile\n");
+ g_free (presets);
+ return NULL;
+ }
+
+ if (!g_key_file_load_from_file (presets->keyfile, presetfile,
+ G_KEY_FILE_NONE, &err)) {
+ g_printerr ("modest: cannot open keyfile from %s:\n %s\n", presetfile,
+ err ? err->message : "unknown reason");
+ g_error_free (err);
+ g_free (presets);
+ return NULL;
+ }
+
+ return presets;
+}
+
+gchar**
+modest_presets_get_providers (ModestPresets *self, guint mcc,
+ gboolean include_globals, gchar ***provider_ids)
+{
+ gchar **all_providers = NULL;
+ gchar **all_provider_ids = NULL;
+ gchar **filtered = NULL;
+ gchar **filtered_ids = NULL;
+ GError *err = NULL;
+ guint i, j, len;
+
+ g_return_val_if_fail (self && self->keyfile, NULL);
+
+ /* Get all the provider IDs: */
+ all_provider_ids = g_key_file_get_groups (self->keyfile, NULL);
+ len = g_strv_length(all_provider_ids);
+
+ /* Get the names for all these providers: */
+ all_providers = g_new0(gchar*, len + 1); /* Provider names. */
+ for (i=0; i != len; ++i) {
+ const gchar * provider_id = all_provider_ids[i];
+ if(provider_id) {
+ gchar* name = g_key_file_get_string(self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_NAME, NULL);
+
+ /* Be forgiving of missing names.
+ * If we use NULL then we will null-terminate the array.
+ */
+ if(!name)
+ name = g_strdup("");
+
+ all_providers[i] = name;
+ }
+ else
+ all_providers[i] = NULL;
+ };
+
+ /* return *all* providers? */
+ /*
+ if (mcc == 0 && include_globals) {
+ *provider_ids = all_provider_ids;
+ return all_providers;
+ }
+ */
+
+ /* nope: filter them */
+
+ filtered = g_new0(gchar*, len + 1); /* Provider names. */
+ filtered_ids = g_new0(gchar*, len + 1); /* Provider IDs */
+
+ for (i=0, j=0; i != len; ++i) {
+
+ int this_mcc;
+ this_mcc = g_key_file_get_integer (self->keyfile, all_provider_ids[i],
+ MODEST_PRESETS_KEY_MCC, &err);
+ if (err) {
+ g_strfreev (all_providers);
+ g_strfreev (all_provider_ids);
+ g_strfreev (filtered);
+ g_strfreev (filtered_ids);
+
+ g_printerr ("modest: error parsing keyfile: %s\n", err->message);
+ g_error_free (err);
+
+ return NULL;
+ }
+
+ if (this_mcc == mcc || (this_mcc == 0 && include_globals)) {
+ filtered[j] = all_providers[i];
+ filtered_ids[j] = all_provider_ids[i];
+ ++j;
+ filtered[j] = NULL; /* the array must be NULL-terminated */
+ filtered_ids[j] = NULL; /* the array must be NULL-terminated */
+
+ all_providers[i] = NULL; /* g_strfreev: leave it alone */
+ all_provider_ids[i] = NULL; /* g_strfreev: leave it alone */
+ }
+ }
+
+ g_strfreev (all_providers);
+ g_strfreev (all_provider_ids);
+
+ *provider_ids = filtered_ids;
+ return filtered;
+}
+
+
+gchar*
+modest_presets_get_server (ModestPresets *self, const gchar *provider_id,
+ gboolean incoming_server)
+{
+ g_return_val_if_fail (self && self->keyfile, NULL);
+ g_return_val_if_fail (provider_id, NULL);
+
+ return g_key_file_get_string (self->keyfile, provider_id,
+ incoming_server ?
+ MODEST_PRESETS_KEY_INCOMING :
+ MODEST_PRESETS_KEY_OUTGOING,
+ NULL);
+}
+
+gchar *
+modest_presets_get_domain (ModestPresets *self,
+ const gchar *provider_id)
+{
+ g_return_val_if_fail (self && self->keyfile, NULL);
+ g_return_val_if_fail (provider_id, NULL);
+
+ return g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_DOMAIN,
+ NULL);
+}
+
+
+
+
+ModestProtocolType
+modest_presets_get_info_server_type (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server)
+{
+ ModestProtocolType protocol_type = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocol *protocol;
+ gchar *val = NULL;
+
+ g_return_val_if_fail (self && self->keyfile, 0);
+ protocol_registry = modest_runtime_get_protocol_registry ();
+
+ if (incoming_server) {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING, NULL);
+ if (!val)
+ return protocol_type;
+
+ g_free (val);
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_MAILBOX_TYPE,NULL);
+
+ protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry, MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS, val);
+ if (protocol == NULL)
+ return protocol_type;
+ protocol_type = modest_protocol_get_type_id (protocol);
+ } else {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_OUTGOING, NULL);
+ if (!val)
+ return protocol_type;
+
+ protocol_type = MODEST_PROTOCOLS_TRANSPORT_SMTP;
+ }
+ g_free (val);
+
+ /* debug: */
+/* g_message ("provider id: %s, server type: %d", provider_id, info); */
+ return protocol_type;
+}
+
+
+
+ModestProtocolType
+modest_presets_get_info_server_security (ModestPresets *self, const gchar *provider_id,
+ gboolean incoming_server)
+{
+ ModestProtocolType protocol_type = MODEST_PROTOCOLS_CONNECTION_NONE;
+ gchar *val = NULL;
+
+ g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
+
+ if (incoming_server) {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING, NULL);
+ if (val) {
+ g_free (val);
+
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
+ if (val && ((strcmp (val, "1") == 0) || (strcmp (val, "2") == 0))) {
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+ } else if (val && (strcmp (val, "tls") == 0)) {
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
+ } else if (val && (strcmp (val, "ssl") == 0)) {
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+ }
+ g_free (val);
+ }
+ } else /* outgoing: */ {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_OUTGOING, NULL);
+ if (val) {
+ g_free (val);
+
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
+ /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
+ if (val && strcmp(val,"true") == 0)
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+ else if (val && strcmp (val, "ssl") == 0)
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+ else if (val && strcmp (val, "2") == 0)
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_SSL;
+ else if (val && strcmp (val, "tls") == 0)
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
+ else if (val && strcmp (val, "1") == 0)
+ protocol_type = MODEST_PROTOCOLS_CONNECTION_TLS;
+ g_free(val);
+ }
+ }
+
+ return protocol_type;
+}
+
+gboolean
+modest_presets_get_info_server_use_alternate_port (ModestPresets *self, const gchar *provider_id,
+ gboolean incoming_server)
+{
+ gboolean result = FALSE;
+ gchar *val = NULL;
+
+ g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_CONNECTION_NONE);
+
+ if (incoming_server) {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING, NULL);
+ if (val) {
+ g_free (val);
+
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING_SECURITY, NULL);
+ if (val && (strcmp (val, "2") == 0)) {
+ result = TRUE;
+ }
+ g_free (val);
+ }
+ }
+
+ return result;
+}
+
+ModestProtocolType
+modest_presets_get_info_server_auth (ModestPresets *self, const gchar *provider_id,
+ gboolean incoming_server)
+{
+ ModestProtocolType protocol_type = MODEST_PROTOCOLS_AUTH_NONE;
+ gchar *val = NULL;
+
+ g_return_val_if_fail (self && self->keyfile, MODEST_PROTOCOLS_AUTH_NONE);
+
+ if (incoming_server) {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_INCOMING, NULL);
+ if (val) {
+ g_free (val);
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_APOP, NULL);
+ if (val && strcmp(val, "true") == 0)
+ protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
+ g_free(val);
+
+ }
+ } else /* outgoing: */ {
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_OUTGOING, NULL);
+ if (val) {
+ g_free (val);
+
+ val = g_key_file_get_string (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_SECURE_SMTP, NULL);
+ /* printf("debug: %s: provider_id=%s, secure-smtp val=%s\n", __FUNCTION__, provider_id, val); */
+ if (val && strcmp(val,"true") == 0)
+ protocol_type = MODEST_PROTOCOLS_AUTH_PASSWORD;
+ g_free(val);
+ }
+ }
+
+ return protocol_type;
+}
+
+/*
+ * at the moment, this only for mac.com, which have a special SMTP port
+ */
+guint
+modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
+ gboolean incoming_server)
+{
+ guint port;
+
+ g_return_val_if_fail (self && self->keyfile, 0);
+
+ if (incoming_server)
+ port = 0; /* not used yet */
+ else
+ port = (guint)g_key_file_get_integer (self->keyfile, provider_id,
+ MODEST_PRESETS_KEY_SMTP_PORT, NULL);
+
+ return port;
+}
+
+
+
+
+
+void
+modest_presets_destroy (ModestPresets *self)
+{
+ if (!self)
+ return;
+
+ g_key_file_free (self->keyfile);
+ self->keyfile = NULL;
+
+ g_free (self);
+}
--- /dev/null
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MODEST_PRESETS_H__
+#define __MODEST_PRESETS_H__
+
+#include <glib.h>
+#include <modest-protocol.h>
+
+struct _ModestPresets {
+/* private data: don't touch */
+ GKeyFile *keyfile;
+};
+typedef struct _ModestPresets ModestPresets;
+
+
+/**
+ * modest_presets_new:
+ * @presetfile: the full path to the file with presets (in GKeyFile format)
+ *
+ * make a new ModestPresets instance
+ *
+ * Returns: a new ModestPresets instance, or NULL in case of error.
+ */
+ModestPresets* modest_presets_new (const gchar *presetfile);
+
+
+/**
+ * modest_presets_get_providers:
+ * @self: a valid ModestPresets instance
+ * @mcc: limit the search to providers with this mcc (Mobile Country Code),
+ * or 0 to get all
+ * @include_globals: include (global) providers without MCC (such as GMail, Yahoo)
+ * @provider_ids: Output parameter, which will be set to a newly allocated array of strings, or NULL in case of error.
+ *
+ * get a list of providers matching certian criteria
+ *
+ * Returns: The provider names, as a newly allocated array of strings, or NULL in case of error
+ * should be freed with g_strfreev
+ *
+ **/
+gchar ** modest_presets_get_providers (ModestPresets *self, guint mcc,
+ gboolean include_globals, gchar ***provider_ids);
+
+/**
+ * modest_presets_get_server:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get the name of a incoming or outgoing mailserver
+ *
+ * Returns: a newly allocated string with the servername, or NULL in case
+ * of error, or server not found. (FIXME). Note that if the (incoming) server uses a
+ * non-standard port, the port number is appended to the name, eg. pop.foo.fi:995
+ */
+gchar * modest_presets_get_server (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server);
+
+/**
+ * modest_presets_get_domain:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ *
+ * Get the name of the most-used domain for theis provider. For instance. hotmail.com
+ *
+ * Returns: a newly allocated string with the domain name, or NULL in case
+ * of error.
+ */
+gchar * modest_presets_get_domain (ModestPresets *self,
+ const gchar *provider_id);
+
+/**
+ * modest_presets_get_info_server_type:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: a #ModestProtocolType with the required information
+ */
+ModestProtocolType modest_presets_get_info_server_type (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server);
+
+/**
+ * modest_presets_get_info_server_security:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: #ModestProtocolType with server auth
+ */
+ModestProtocolType modest_presets_get_info_server_auth (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server);
+
+/**
+ * modest_presets_get_info_server_security:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: #ModestProtocolType with server security
+ */
+ModestProtocolType modest_presets_get_info_server_security (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server);
+
+/**
+ * modest_presets_get_info_server_security:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get the incoming mailserver if TRUE, get the
+ * outgoing server otherwise
+ *
+ * get information about some incoming or outgoing mailserver
+ *
+ * Returns: %TRUE if we should use the alternate port.
+ */
+gboolean modest_presets_get_info_server_use_alternate_port (ModestPresets *self,
+ const gchar *provider_id,
+ gboolean incoming_server);
+
+
+/**
+ * modest_presets_get_port:
+ * @self: a valid ModestPresets instance
+ * @provider_id: ID of the provider
+ * @incoming_server: get port# for the incoming mailserver if TRUE, for the outgoing server otherwise
+ *
+ * Returns: the specific port number for some provider
+ * function return 0 if the normal port number is valid
+ *
+ */
+guint modest_presets_get_port (ModestPresets *self, const gchar* provider_id,
+ gboolean incoming_server);
+
+
+/**
+ * modest_presets_destroy:
+ * @self: a valid ModestPresets instance (ie. must not be NULL)
+ *
+ * destroy ModestPresets instance; this is required after you're done with it.
+ */
+void modest_presets_destroy (ModestPresets *self);
+
+
+#endif /*__MODEST_PRESETS__*/
+
+