"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/camel/camel-mapi-transport.c" (2 Dec 2022, 6200 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-transport.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 <string.h>
   27 
   28 #include <glib/gi18n-lib.h>
   29 
   30 #include <libmapi/libmapi.h>
   31 #include <gen_ndr/exchange.h>
   32 
   33 #include "camel-mapi-transport.h"
   34 
   35 #include <stdio.h>
   36 #include <string.h>
   37 #include <ctype.h>
   38 #include <errno.h>
   39 
   40 #include "camel-mapi-settings.h"
   41 #include "camel-mapi-store.h"
   42 #include "camel-mapi-folder.h"
   43 #include "camel-mapi-store-summary.h"
   44 #define d(x)
   45 
   46 #include <e-mapi-defs.h>
   47 #include "e-mapi-mail-utils.h"
   48 #include "e-mapi-utils.h"
   49 
   50 #define STREAM_SIZE 4000
   51 
   52 G_DEFINE_TYPE (CamelMapiTransport, camel_mapi_transport, CAMEL_TYPE_TRANSPORT)
   53 
   54 static gboolean
   55 convert_message_to_object_cb (EMapiConnection *conn,
   56                   TALLOC_CTX *mem_ctx,
   57                   EMapiObject **object, /* out */
   58                   gpointer user_data,
   59                   GCancellable *cancellable,
   60                   GError **perror)
   61 {
   62     CamelMimeMessage *message = user_data;
   63 
   64     g_return_val_if_fail (conn != NULL, FALSE);
   65     g_return_val_if_fail (mem_ctx != NULL, FALSE);
   66     g_return_val_if_fail (object != NULL, FALSE);
   67     g_return_val_if_fail (message != NULL, FALSE);
   68 
   69     return e_mapi_mail_utils_message_to_object (message, 0, E_MAPI_CREATE_FLAG_SUBMIT, object, mem_ctx, cancellable, perror);
   70 }
   71 
   72 static gboolean
   73 mapi_send_to_sync (CamelTransport *transport,
   74                    CamelMimeMessage *message,
   75                    CamelAddress *from,
   76                    CamelAddress *recipients,
   77            gboolean *out_sent_message_saved,
   78                    GCancellable *cancellable,
   79                    GError **error)
   80 {
   81     EMapiConnection *conn;
   82     const gchar *namep;
   83     const gchar *addressp;
   84     mapi_id_t mid = 0;
   85     mapi_object_t obj_folder;
   86     CamelService *service;
   87     CamelSettings *settings;
   88     gchar *profile;
   89     GError *mapi_error = NULL;
   90 
   91     if (!camel_internet_address_get (CAMEL_INTERNET_ADDRESS (from), 0, &namep, &addressp)) {
   92         return (FALSE);
   93     }
   94 
   95     g_return_val_if_fail (CAMEL_IS_SERVICE (transport), FALSE);
   96 
   97     service = CAMEL_SERVICE (transport);
   98 
   99     settings = camel_service_ref_settings (service);
  100     profile = camel_mapi_settings_dup_profile (CAMEL_MAPI_SETTINGS (settings));
  101     g_object_unref (settings);
  102 
  103     if (!profile) {
  104         /* try to find corresponding CamelStore with profile name filled */
  105         const gchar *my_uid = camel_service_get_uid (service);
  106         CamelSession *session;
  107         GList *services, *s;
  108 
  109         session = camel_service_ref_session (service);
  110 
  111         services = camel_session_list_services (session);
  112         for (s = services; s && my_uid && !profile; s = s->next) {
  113             CamelService *store = s->data;
  114             const gchar *store_uid;
  115 
  116             if (!CAMEL_IS_STORE (store))
  117                 continue;
  118 
  119             store_uid = camel_service_get_uid (store);
  120             if (!store_uid)
  121                 continue;
  122 
  123             if (g_strcmp0 (my_uid, store_uid) == 0 ||
  124                 g_str_has_prefix (my_uid, store_uid) ||
  125                 g_str_has_prefix (store_uid, my_uid)) {
  126                 settings = camel_service_ref_settings (store);
  127                 profile = camel_mapi_settings_dup_profile (CAMEL_MAPI_SETTINGS (settings));
  128                 g_object_unref (settings);
  129             }
  130         }
  131 
  132         g_list_free_full (services, g_object_unref);
  133 
  134         g_object_unref (session);
  135     }
  136 
  137     conn = e_mapi_connection_find (profile);
  138 
  139     g_free (profile);
  140 
  141     if (!conn) {
  142         g_set_error (
  143             error, CAMEL_SERVICE_ERROR,
  144             CAMEL_SERVICE_ERROR_UNAVAILABLE,
  145             _("Could not send message."));
  146         return FALSE;
  147     }
  148 
  149     if (e_mapi_connection_open_default_folder (conn, olFolderSentMail, &obj_folder, cancellable, &mapi_error)) {
  150         e_mapi_connection_create_object (conn, &obj_folder, E_MAPI_CREATE_FLAG_SUBMIT, convert_message_to_object_cb, message, &mid, cancellable, &mapi_error);
  151 
  152         e_mapi_connection_close_folder (conn, &obj_folder, cancellable, &mapi_error);
  153     }
  154 
  155     g_object_unref (conn);
  156 
  157     if (mid == 0) {
  158         if (mapi_error) {
  159             if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
  160                 g_set_error (
  161                     error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
  162                     _("Could not send message: %s"), mapi_error->message);
  163             g_error_free (mapi_error);
  164         } else {
  165             g_set_error (
  166                 error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
  167                 _("Could not send message."));
  168         }
  169         return FALSE;
  170     }
  171 
  172     return TRUE;
  173 }
  174 
  175 static gchar *
  176 mapi_transport_get_name(CamelService *service, gboolean brief)
  177 {
  178     CamelNetworkSettings *network_settings;
  179     CamelSettings *settings;
  180     gchar *host;
  181     gchar *name;
  182     gchar *user;
  183 
  184     settings = camel_service_ref_settings (service);
  185 
  186     network_settings = CAMEL_NETWORK_SETTINGS (settings);
  187     host = camel_network_settings_dup_host (network_settings);
  188     user = camel_network_settings_dup_user (network_settings);
  189 
  190     g_object_unref (settings);
  191 
  192     if (brief) {
  193         /* Translators: The %s is replaced with a server's host name */
  194         name = g_strdup_printf (_("Exchange MAPI server %s"), host);
  195     } else {
  196         /* Translators: The first %s is replaced with a user name, the second with a server's host name */
  197         name = g_strdup_printf (_("Exchange MAPI service for %s on %s"),
  198                     user, host);
  199     }
  200 
  201     g_free (host);
  202     g_free (user);
  203 
  204     return name;
  205 }
  206 
  207 static void
  208 camel_mapi_transport_class_init (CamelMapiTransportClass *class)
  209 {
  210     CamelServiceClass *service_class;
  211     CamelTransportClass *transport_class;
  212 
  213     service_class = CAMEL_SERVICE_CLASS (class);
  214     service_class->get_name = mapi_transport_get_name;
  215     service_class->settings_type = CAMEL_TYPE_MAPI_SETTINGS;
  216 
  217     transport_class = CAMEL_TRANSPORT_CLASS (class);
  218     transport_class->send_to_sync = mapi_send_to_sync;
  219 }
  220 
  221 static void
  222 camel_mapi_transport_init (CamelMapiTransport *transport)
  223 {
  224 }