"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/camel/camel-mapi-provider.c" (2 Dec 2022, 4886 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "camel-mapi-provider.c" see the Fossies "Dox" file reference documentation.

    1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    2 /*
    3  * This program is free software; you can redistribute it and/or
    4  * modify it under the terms of the GNU Lesser General Public
    5  * License as published by the Free Software Foundation; either
    6  * version 2 of the License, or (at your option) version 3.
    7  *
    8  * This program is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * Lesser General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public
   14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
   15  *
   16  *
   17  * Authors:
   18  *     Johnny Jacob <jjohnny@novell.com>
   19  *
   20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
   21  *
   22  */
   23 
   24 #include "evolution-mapi-config.h"
   25 
   26 #include <sys/types.h>
   27 #include <string.h>
   28 #include <glib/gi18n-lib.h>
   29 
   30 #include <gmodule.h>
   31 
   32 #include "camel-mapi-sasl-krb.h"
   33 #include "camel-mapi-store.h"
   34 #include "camel-mapi-transport.h"
   35 
   36 static void add_hash (guint *, gchar *);
   37 static guint mapi_url_hash (gconstpointer);
   38 static gint check_equal (gchar *, gchar *);
   39 static gint mapi_url_equal (gconstpointer, gconstpointer);
   40 
   41 static CamelProviderConfEntry mapi_conf_entries[] = {
   42     { CAMEL_PROVIDER_CONF_SECTION_START, "mailcheck", NULL,
   43       N_("Checking for new mail") },
   44     { CAMEL_PROVIDER_CONF_CHECKBOX, "check-all", NULL,
   45       N_("C_heck for new messages in all folders"), "1" },
   46     { CAMEL_PROVIDER_CONF_CHECKBOX, "listen-notifications", NULL,
   47       N_("Lis_ten for server change notifications"), "1" },
   48     { CAMEL_PROVIDER_CONF_SECTION_END },
   49 
   50     { CAMEL_PROVIDER_CONF_SECTION_START, "generals", NULL,
   51       N_("Options") },
   52     { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-inbox", NULL,
   53       /* i18n: copy from evolution:camel-imap-provider.c */
   54       N_("_Apply filters to new messages in Inbox on this server"), "0" },
   55     { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk", NULL,
   56       N_("Check new messages for _Junk contents"), "0" },
   57     { CAMEL_PROVIDER_CONF_CHECKBOX, "filter-junk-inbox", "filter-junk",
   58       N_("Only check for Junk messag_es in the Inbox folder"), "0" },
   59     { CAMEL_PROVIDER_CONF_CHECKBOX, "stay-synchronized", NULL,
   60       N_("Synchroni_ze remote mail locally in all folders"), "0" },
   61     { CAMEL_PROVIDER_CONF_PLACEHOLDER, "mapi-limit-by-age-placeholder", NULL },
   62     { CAMEL_PROVIDER_CONF_SECTION_END },
   63 
   64     { CAMEL_PROVIDER_CONF_END }
   65 };
   66 
   67 static CamelProvider mapi_provider = {
   68     "mapi",
   69 
   70     "Exchange MAPI",
   71 
   72     N_("For accessing Microsoft Exchange 2007/OpenChange servers via MAPI"),
   73 
   74     "mail",
   75 
   76     CAMEL_PROVIDER_IS_REMOTE | CAMEL_PROVIDER_IS_SOURCE |
   77     CAMEL_PROVIDER_IS_STORAGE | CAMEL_PROVIDER_DISABLE_SENT_FOLDER | CAMEL_PROVIDER_IS_EXTERNAL,
   78 
   79     CAMEL_URL_NEED_USER | CAMEL_URL_NEED_HOST,
   80 
   81     mapi_conf_entries,
   82 
   83     /* ... */
   84 };
   85 
   86 CamelServiceAuthType camel_mapi_password_authtype = {
   87     N_("Password"),
   88     N_("This option will connect to the OpenChange server using a plaintext password."),
   89     "",
   90     TRUE
   91 };
   92 
   93 static gint
   94 mapi_auto_detect_cb(CamelURL *url, GHashTable **auto_detected, GError **error)
   95 {
   96     *auto_detected = g_hash_table_new (g_str_hash, g_str_equal);
   97     g_hash_table_insert (*auto_detected, g_strdup ("poa"), g_strdup (url->host));
   98 
   99     return 0;
  100 }
  101 
  102 void
  103 camel_provider_module_init(void)
  104 {
  105     mapi_provider.name = "Exchange MAPI";
  106     mapi_provider.translation_domain = (gchar *) GETTEXT_PACKAGE;
  107     mapi_provider.auto_detect = mapi_auto_detect_cb;
  108     mapi_provider.authtypes = g_list_prepend (mapi_provider.authtypes, &camel_mapi_password_authtype);
  109     mapi_provider.url_hash = mapi_url_hash;
  110     mapi_provider.url_equal = mapi_url_equal;
  111     mapi_provider.object_types[CAMEL_PROVIDER_STORE] = camel_mapi_store_get_type();
  112     mapi_provider.object_types[CAMEL_PROVIDER_TRANSPORT] = camel_mapi_transport_get_type();
  113 
  114     bindtextdomain (GETTEXT_PACKAGE, EXCHANGE_MAPI_LOCALEDIR);
  115     bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  116 
  117     /* register MAPIKRB auth type */
  118     CAMEL_TYPE_MAPI_SASL_KRB;
  119 
  120     camel_provider_register (&mapi_provider);
  121 }
  122 
  123 static void
  124 add_hash(guint *hash, gchar *s)
  125 {
  126     if (s) {
  127         *hash ^= g_str_hash(s);
  128     }
  129 }
  130 
  131 static guint
  132 mapi_url_hash(gconstpointer key)
  133 {
  134     const CamelURL  *u = (CamelURL *)key;
  135     guint       hash = 0;
  136 
  137     add_hash (&hash, u->user);
  138     add_hash (&hash, u->authmech);
  139     add_hash (&hash, u->host);
  140     hash ^= u->port;
  141 
  142     return hash;
  143 }
  144 
  145 static gint
  146 check_equal(gchar *s1, gchar *s2)
  147 {
  148     if (s1 == NULL) {
  149         if (s2 == NULL) {
  150             return TRUE;
  151         } else {
  152             return FALSE;
  153         }
  154     }
  155     if (s2 == NULL) {
  156         return FALSE;
  157     }
  158 
  159     return strcmp (s1, s2) == 0;
  160 }
  161 
  162 static gint
  163 mapi_url_equal (gconstpointer a, gconstpointer b)
  164 {
  165     const CamelURL  *u1 = a;
  166     const CamelURL  *u2 = b;
  167 
  168     return check_equal (u1->protocol, u2->protocol)
  169         && check_equal (u1->user, u2->user)
  170         && check_equal (u1->authmech, u2->authmech)
  171         && check_equal (u1->host, u2->host)
  172         && u1->port == u2->port;
  173 }