[evolution-data-server] Bug #649757 - Return back camel_filter_driver_filter_mbox()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug #649757 - Return back camel_filter_driver_filter_mbox()
- Date: Wed, 1 Jun 2011 21:10:52 +0000 (UTC)
commit 9b4f49294a828381ace999b847b470036d097751
Author: Milan Crha <mcrha redhat com>
Date: Wed Jun 1 23:07:41 2011 +0200
Bug #649757 - Return back camel_filter_driver_filter_mbox()
It's still used for "Local delivery" mbox files and it has nothing
to do with On This Computer store type.
camel/camel-filter-driver.c | 147 ++++++++++++++++++++
camel/camel-filter-driver.h | 5 +
docs/reference/camel/camel-sections.txt | 1 +
docs/reference/camel/tmpl/camel-filter-driver.sgml | 13 ++
docs/reference/camel/tmpl/camel-unused.sgml | 12 --
5 files changed, 166 insertions(+), 12 deletions(-)
---
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index d10c058..b2746e9 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -1198,6 +1198,153 @@ camel_filter_driver_flush (CamelFilterDriver *driver,
g_propagate_error (error, data.error);
}
+static gint
+decode_flags_from_xev (const gchar *xev, CamelMessageInfoBase *mi)
+{
+ guint32 uid, flags = 0;
+ gchar *header;
+
+ /* check for uid/flags */
+ header = camel_header_token_decode (xev);
+ if (!(header && strlen (header) == strlen ("00000000-0000")
+ && sscanf (header, "%08x-%04x", &uid, &flags) == 2)) {
+ g_free (header);
+ return 0;
+ }
+ g_free (header);
+
+ mi->flags = flags;
+ return 0;
+}
+
+/**
+ * camel_filter_driver_filter_mbox:
+ * @driver: CamelFilterDriver
+ * @mbox: mbox filename to be filtered
+ * @original_source_url:
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Filters an mbox file based on rules defined in the FilterDriver
+ * object. Is more efficient as it doesn't need to open the folder
+ * through Camel directly.
+ *
+ * Returns: -1 if errors were encountered during filtering,
+ * otherwise returns 0.
+ *
+ **/
+gint
+camel_filter_driver_filter_mbox (CamelFilterDriver *driver,
+ const gchar *mbox,
+ const gchar *original_source_url,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelFilterDriverPrivate *p = driver->priv;
+ CamelMimeParser *mp = NULL;
+ gchar *source_url = NULL;
+ gint fd = -1;
+ gint i = 0;
+ struct stat st;
+ gint status;
+ goffset last = 0;
+ gint ret = -1;
+
+ fd = g_open (mbox, O_RDONLY|O_BINARY, 0);
+ if (fd == -1) {
+ g_set_error (
+ error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+ _("Unable to open spool folder"));
+ goto fail;
+ }
+ /* to get the filesize */
+ fstat (fd, &st);
+
+ mp = camel_mime_parser_new ();
+ camel_mime_parser_scan_from (mp, TRUE);
+ if (camel_mime_parser_init_with_fd (mp, fd) == -1) {
+ g_set_error (
+ error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+ _("Unable to process spool folder"));
+ goto fail;
+ }
+ fd = -1;
+
+ source_url = g_filename_to_uri (mbox, NULL, NULL);
+
+ while (camel_mime_parser_step (mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM) {
+ CamelMessageInfo *info;
+ CamelMimeMessage *message;
+ CamelMimePart *mime_part;
+ gint pc = 0;
+ const gchar *xev;
+ GError *local_error = NULL;
+
+ if (st.st_size > 0)
+ pc = (gint)(100.0 * ((double)camel_mime_parser_tell (mp) / (double)st.st_size));
+
+ report_status (driver, CAMEL_FILTER_STATUS_START, pc, _("Getting message %d (%d%%)"), i, pc);
+
+ message = camel_mime_message_new ();
+ mime_part = CAMEL_MIME_PART (message);
+
+ if (!camel_mime_part_construct_from_parser_sync (
+ mime_part, mp, cancellable, error)) {
+ report_status (driver, CAMEL_FILTER_STATUS_END, 100, _("Failed on message %d"), i);
+ g_object_unref (message);
+ goto fail;
+ }
+
+ info = camel_message_info_new_from_header (NULL, mime_part->headers);
+ /* Try and see if it has X-Evolution headers */
+ xev = camel_header_raw_find(&mime_part->headers, "X-Evolution", NULL);
+ if (xev)
+ decode_flags_from_xev (xev, (CamelMessageInfoBase *)info);
+
+ ((CamelMessageInfoBase *)info)->size = camel_mime_parser_tell (mp) - last;
+
+ last = camel_mime_parser_tell (mp);
+ status = camel_filter_driver_filter_message (
+ driver, message, info, NULL, NULL, source_url,
+ original_source_url ? original_source_url :
+ source_url, cancellable, &local_error);
+ g_object_unref (message);
+ if (local_error != NULL || status == -1) {
+ report_status (
+ driver, CAMEL_FILTER_STATUS_END, 100,
+ _("Failed on message %d"), i);
+ camel_message_info_free (info);
+ g_propagate_error (error, local_error);
+ goto fail;
+ }
+
+ i++;
+
+ /* skip over the FROM_END state */
+ camel_mime_parser_step (mp, NULL, NULL);
+
+ camel_message_info_free (info);
+ }
+
+ if (p->defaultfolder) {
+ report_status(driver, CAMEL_FILTER_STATUS_PROGRESS, 100, _("Syncing folder"));
+ camel_folder_synchronize_sync (
+ p->defaultfolder, FALSE, cancellable, NULL);
+ }
+
+ report_status (driver, CAMEL_FILTER_STATUS_END, 100, _("Complete"));
+
+ ret = 0;
+fail:
+ g_free (source_url);
+ if (fd != -1)
+ close (fd);
+ if (mp)
+ g_object_unref (mp);
+
+ return ret;
+}
+
/**
* camel_filter_driver_filter_folder:
* @driver: CamelFilterDriver
diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h
index 703a648..cbe583d 100644
--- a/camel/camel-filter-driver.h
+++ b/camel/camel-filter-driver.h
@@ -117,6 +117,11 @@ gint camel_filter_driver_filter_message
const gchar *original_store_uid,
GCancellable *cancellable,
GError **error);
+gint camel_filter_driver_filter_mbox (CamelFilterDriver *driver,
+ const gchar *mbox,
+ const gchar *original_source_url,
+ GCancellable *cancellable,
+ GError **error);
gint camel_filter_driver_filter_folder
(CamelFilterDriver *driver,
CamelFolder *folder,
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index 817e447..d9f4339 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -403,6 +403,7 @@ camel_filter_driver_add_rule
camel_filter_driver_remove_rule_by_name
camel_filter_driver_flush
camel_filter_driver_filter_message
+camel_filter_driver_filter_mbox
camel_filter_driver_filter_folder
<SUBSECTION Standard>
CAMEL_FILTER_DRIVER
diff --git a/docs/reference/camel/tmpl/camel-filter-driver.sgml b/docs/reference/camel/tmpl/camel-filter-driver.sgml
index 30d82a0..8b36834 100644
--- a/docs/reference/camel/tmpl/camel-filter-driver.sgml
+++ b/docs/reference/camel/tmpl/camel-filter-driver.sgml
@@ -162,6 +162,19 @@ CamelFilterDriver
@Returns:
+<!-- ##### FUNCTION camel_filter_driver_filter_mbox ##### -->
+<para>
+
+</para>
+
+ driver:
+ mbox:
+ original_source_url:
+ cancellable:
+ error:
+ Returns:
+
+
<!-- ##### FUNCTION camel_filter_driver_filter_folder ##### -->
<para>
diff --git a/docs/reference/camel/tmpl/camel-unused.sgml b/docs/reference/camel/tmpl/camel-unused.sgml
index 4831cf1..b5d09f4 100644
--- a/docs/reference/camel/tmpl/camel-unused.sgml
+++ b/docs/reference/camel/tmpl/camel-unused.sgml
@@ -5413,18 +5413,6 @@ streams
@action:
@op:
-<!-- ##### FUNCTION camel_filter_driver_filter_mbox ##### -->
-<para>
-
-</para>
-
- driver:
- mbox:
- original_source_url:
- cancellable:
- error:
- Returns:
-
<!-- ##### FUNCTION camel_filter_driver_rule_count ##### -->
<para>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]