[evolution-ews] Moving email creation functions to the utils lib, so other backends will be able to use them
- From: Or Goshen <ogosh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Moving email creation functions to the utils lib, so other backends will be able to use them
- Date: Tue, 14 Jun 2011 10:18:21 +0000 (UTC)
commit 1f20c336ad372d4b48d68df6d20f55d5ba3c5125
Author: Or Goshen <orx goshen intel com>
Date: Tue Jun 14 13:04:19 2011 +0300
Moving email creation functions to the utils lib, so other backends will be able to use them
src/camel/camel-ews-utils.c | 100 --------------------------------
src/camel/camel-ews-utils.h | 7 --
src/utils/Makefile.am | 10 ++-
src/utils/ews-camel-common.c | 129 ++++++++++++++++++++++++++++++++++++++++++
src/utils/ews-camel-common.h | 43 ++++++++++++++
5 files changed, 179 insertions(+), 110 deletions(-)
---
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index d983130..dbddc52 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -941,103 +941,3 @@ camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder, GSList *items_cr
camel_folder_change_info_free (ci);
g_slist_free (items_created);
}
-
-struct _create_mime_msg_data {
- CamelMimeMessage *message;
- gint32 message_camel_flags;
- CamelAddress *from;
-};
-
-static void
-create_mime_message_cb (ESoapMessage *msg, gpointer user_data)
-{
- struct _create_mime_msg_data *create_data = user_data;
- CamelStream *mem, *filtered;
- CamelMimeFilter *filter;
- GByteArray *bytes;
- gchar *base64;
-
- e_soap_message_start_element (msg, "Message", NULL, NULL);
- e_soap_message_start_element (msg, "MimeContent", NULL, NULL);
-
- /* This is horrid. We really need to extend ESoapMessage to allow us
- to stream this directly rather than storing it in RAM. Which right
- now we are doing about four times: the GByteArray in the mem stream,
- then the base64 version, then the xmlDoc, then the soup request. */
- camel_mime_message_set_best_encoding (create_data->message,
- CAMEL_BESTENC_GET_ENCODING,
- CAMEL_BESTENC_8BIT);
-
- mem = camel_stream_mem_new();
- filtered = camel_stream_filter_new (mem);
-
- filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE,
- CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
- camel_stream_filter_add (CAMEL_STREAM_FILTER (filtered), filter);
- g_object_unref (filter);
-
- EVO3_sync(camel_data_wrapper_write_to_stream)
- (CAMEL_DATA_WRAPPER (create_data->message),
- filtered, EVO3(NULL,) NULL);
- camel_stream_flush (filtered, EVO3(NULL,) NULL);
- camel_stream_flush (mem, EVO3(NULL,) NULL);
- bytes = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (mem));
-
- base64 = g_base64_encode (bytes->data, bytes->len);
- g_object_unref (mem);
- g_object_unref (filtered);
-
- e_soap_message_write_string (msg, base64);
- g_free (base64);
-
- e_soap_message_end_element (msg); /* MimeContent */
-
- /* FIXME: Handle From address and message_camel_flags */
-
- e_soap_message_end_element (msg); /* Message */
-
- g_free (create_data);
-}
-
-gboolean
-camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *disposition,
- const gchar *save_folder, CamelMimeMessage *message,
- gint32 message_camel_flags, CamelAddress *from,
- gchar **itemid, gchar **changekey,
- GCancellable *cancellable, GError **error)
-{
- struct _create_mime_msg_data *create_data;
- GSList *ids;
- EEwsItem *item;
- const EwsId *ewsid;
- gboolean res;
-
- create_data = g_new0 (struct _create_mime_msg_data, 1);
-
- create_data->message = message;
- create_data->message_camel_flags = message_camel_flags;
- create_data->from = from;
-
- res = e_ews_connection_create_items (cnc, EWS_PRIORITY_MEDIUM,
- disposition, NULL, save_folder,
- create_mime_message_cb, create_data,
- &ids, cancellable, error);
- if (!res || (!itemid && !changekey))
- return res;
-
- item = (EEwsItem *)ids->data;
- if (!item || !(ewsid = e_ews_item_get_id (item))) {
- g_set_error(error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
- _("CreateItem call failed to return ID for new message"));
- return FALSE;
- }
-
- if (itemid)
- *itemid = g_strdup (ewsid->id);
- if (changekey)
- *changekey = g_strdup (ewsid->change_key);
-
- g_object_unref (item);
- g_slist_free (ids);
- return TRUE;
-}
diff --git a/src/camel/camel-ews-utils.h b/src/camel/camel-ews-utils.h
index bcbb528..2c4d02d 100644
--- a/src/camel/camel-ews-utils.h
+++ b/src/camel/camel-ews-utils.h
@@ -90,13 +90,6 @@ void camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder,
void camel_ews_utils_sync_updated_items (CamelEwsFolder *ews_folder,
GSList *items_updated);
-gboolean
-camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *disposition,
- const gchar *save_folder, CamelMimeMessage *message,
- gint32 message_camel_flags, CamelAddress *from,
- gchar **itemid, gchar **changekey,
- GCancellable *cancellable, GError **error);
-
G_END_DECLS
#endif
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index 846e244..0733e57 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -8,18 +8,22 @@ libewsutils_la_CPPFLAGS = \
-I$(top_builddir)/src/server \
$(LIBEDATASERVER_CFLAGS) \
$(SQLITE3_CFLAGS) \
- $(DEBUG_CFLAGS)
+ $(DEBUG_CFLAGS) \
+ $(CAMEL_CFLAGS)
libewsutils_la_SOURCES = \
ews-esource-utils.h \
ews-esource-utils.c \
e-sqlite3-vfs.c \
- e-sqlite3-vfs.h
+ e-sqlite3-vfs.h \
+ ews-camel-common.c \
+ ews-camel-common.h
libewsutils_la_LIBADD = \
$(top_builddir)/src/server/libeews-1.2.la \
$(SQLITE3_LIBS) \
- $(LIBEDATASERVER_LIBS)
+ $(LIBEDATASERVER_LIBS) \
+ $(CAMEL_LIBS)
libewsutils_la_LDFLAGS = $(NO_UNDEFINED)
diff --git a/src/utils/ews-camel-common.c b/src/utils/ews-camel-common.c
new file mode 100644
index 0000000..98e2b77
--- /dev/null
+++ b/src/utils/ews-camel-common.c
@@ -0,0 +1,129 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* ews-camel-common.c
+ *
+ * Copyright (C) 1999-2011 Intel, Inc. (www.intel.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+
+#include "ews-camel-common.h"
+#include "e-ews-compat.h"
+
+struct _create_mime_msg_data {
+ CamelMimeMessage *message;
+ gint32 message_camel_flags;
+ CamelAddress *from;
+};
+
+static void
+create_mime_message_cb (ESoapMessage *msg, gpointer user_data)
+{
+ struct _create_mime_msg_data *create_data = user_data;
+ CamelStream *mem, *filtered;
+ CamelMimeFilter *filter;
+ GByteArray *bytes;
+ gchar *base64;
+
+ e_soap_message_start_element (msg, "Message", NULL, NULL);
+ e_soap_message_start_element (msg, "MimeContent", NULL, NULL);
+
+ /* This is horrid. We really need to extend ESoapMessage to allow us
+ to stream this directly rather than storing it in RAM. Which right
+ now we are doing about four times: the GByteArray in the mem stream,
+ then the base64 version, then the xmlDoc, then the soup request. */
+ camel_mime_message_set_best_encoding (create_data->message,
+ CAMEL_BESTENC_GET_ENCODING,
+ CAMEL_BESTENC_8BIT);
+
+ mem = camel_stream_mem_new();
+ filtered = camel_stream_filter_new (mem);
+
+ filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE,
+ CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
+ camel_stream_filter_add (CAMEL_STREAM_FILTER (filtered), filter);
+ g_object_unref (filter);
+
+ EVO3_sync(camel_data_wrapper_write_to_stream)
+ (CAMEL_DATA_WRAPPER (create_data->message),
+ filtered, EVO3(NULL,) NULL);
+ camel_stream_flush (filtered, EVO3(NULL,) NULL);
+ camel_stream_flush (mem, EVO3(NULL,) NULL);
+ bytes = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (mem));
+
+ base64 = g_base64_encode (bytes->data, bytes->len);
+ g_object_unref (mem);
+ g_object_unref (filtered);
+
+ e_soap_message_write_string (msg, base64);
+ g_free (base64);
+
+ e_soap_message_end_element (msg); /* MimeContent */
+
+ /* FIXME: Handle From address and message_camel_flags */
+
+ e_soap_message_end_element (msg); /* Message */
+
+ g_free (create_data);
+}
+
+gboolean
+camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *disposition,
+ const gchar *save_folder, CamelMimeMessage *message,
+ gint32 message_camel_flags, CamelAddress *from,
+ gchar **itemid, gchar **changekey,
+ GCancellable *cancellable, GError **error)
+{
+ struct _create_mime_msg_data *create_data;
+ GSList *ids;
+ EEwsItem *item;
+ const EwsId *ewsid;
+ gboolean res;
+
+ create_data = g_new0 (struct _create_mime_msg_data, 1);
+
+ create_data->message = message;
+ create_data->message_camel_flags = message_camel_flags;
+ create_data->from = from;
+
+ res = e_ews_connection_create_items (cnc, EWS_PRIORITY_MEDIUM,
+ disposition, NULL, save_folder,
+ create_mime_message_cb, create_data,
+ &ids, cancellable, error);
+ if (!res || (!itemid && !changekey))
+ return res;
+
+ item = (EEwsItem *)ids->data;
+ if (!item || !(ewsid = e_ews_item_get_id (item))) {
+ g_set_error(error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+ _("CreateItem call failed to return ID for new message"));
+ return FALSE;
+ }
+
+ if (itemid)
+ *itemid = g_strdup (ewsid->id);
+ if (changekey)
+ *changekey = g_strdup (ewsid->change_key);
+
+ g_object_unref (item);
+ g_slist_free (ids);
+ return TRUE;
+}
diff --git a/src/utils/ews-camel-common.h b/src/utils/ews-camel-common.h
new file mode 100644
index 0000000..9e8b4df
--- /dev/null
+++ b/src/utils/ews-camel-common.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 1999-2011 Intel, Inc. (www.intel.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef EWS_CAMEL_COMMON_H
+#define EWS_CAMEL_COMMON_H
+
+#include <camel/camel.h>
+#include <e-ews-connection.h>
+
+G_BEGIN_DECLS
+
+gboolean
+camel_ews_utils_create_mime_message (EEwsConnection *cnc, const gchar *disposition,
+ const gchar *save_folder, CamelMimeMessage *message,
+ gint32 message_camel_flags, CamelAddress *from,
+ gchar **itemid, gchar **changekey,
+ GCancellable *cancellable, GError **error);
+
+G_END_DECLS
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* EWS_CAMEL_COMMON_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]