[evolution-data-server] Camel: Store UIDs in X-Evolution-Source headers.



commit c09c1380e1c86f8bd6d3ecc49d106a2f9e8c4755
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri May 6 11:23:08 2011 -0400

    Camel: Store UIDs in X-Evolution-Source headers.
    
    CamelStore UIDs are easier to deal with than URLs.
    
    For backward-compatibility, CamelFilterDriver can still handle
    X-Evolution-Source headers with URLs.

 camel/camel-filter-driver.c                        |   80 +++++++-------------
 camel/camel-filter-driver.h                        |    4 +-
 camel/camel-filter-search.c                        |   40 ++++++-----
 camel/camel-folder.c                               |   24 +-----
 camel/camel-mime-message.c                         |   43 +++++++----
 camel/camel-mime-message.h                         |    2 +-
 docs/reference/camel/tmpl/camel-filter-driver.sgml |    4 +-
 docs/reference/camel/tmpl/camel-mime-message.sgml  |    2 +-
 8 files changed, 89 insertions(+), 110 deletions(-)
---
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index 8791780..9aea4fa 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -48,6 +48,7 @@
 #include "camel-mime-message.h"
 #include "camel-service.h"
 #include "camel-session.h"
+#include "camel-store.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
 
@@ -1197,25 +1198,6 @@ 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_folder:
  * @driver: CamelFilterDriver
@@ -1246,17 +1228,13 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver,
 	CamelFilterDriverPrivate *p = driver->priv;
 	gboolean freeuids = FALSE;
 	CamelMessageInfo *info;
-	gchar *source_url, *service_url;
+	CamelStore *parent_store;
+	const gchar *store_uid;
 	gint status = 0;
-	CamelURL *url;
 	gint i;
 
-	service_url = camel_service_get_url (CAMEL_SERVICE (camel_folder_get_parent_store (folder)));
-	url = camel_url_new (service_url, NULL);
-	g_free (service_url);
-
-	source_url = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-	camel_url_free (url);
+	parent_store = camel_folder_get_parent_store (folder);
+	store_uid = camel_service_get_uid (CAMEL_SERVICE (parent_store));
 
 	if (uids == NULL) {
 		uids = camel_folder_get_uids (folder);
@@ -1277,7 +1255,7 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver,
 
 		status = camel_filter_driver_filter_message (
 			driver, NULL, info, uids->pdata[i], folder,
-			source_url, source_url, cancellable, &local_error);
+			store_uid, store_uid, cancellable, &local_error);
 
 		if (camel_folder_has_summary_capability (folder))
 			camel_folder_free_message_info (folder, info);
@@ -1314,41 +1292,37 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver,
 	if (freeuids)
 		camel_folder_free_uids (folder, uids);
 
-	g_free (source_url);
-
 	return status;
 }
 
 struct _get_message {
-	struct _CamelFilterDriverPrivate *p;
-	const gchar *source_url;
+	struct _CamelFilterDriverPrivate *priv;
+	const gchar *store_uid;
 };
 
 static CamelMimeMessage *
 get_message_cb (gpointer data, GError **error)
 {
 	struct _get_message *msgdata = data;
-	struct _CamelFilterDriverPrivate *p = msgdata->p;
-	const gchar *source_url = msgdata->source_url;
 	CamelMimeMessage *message;
 
-	if (p->message) {
-		message = g_object_ref (p->message);
+	if (msgdata->priv->message) {
+		message = g_object_ref (msgdata->priv->message);
 	} else {
 		const gchar *uid;
 
-		if (p->uid)
-			uid = p->uid;
+		if (msgdata->priv->uid != NULL)
+			uid = msgdata->priv->uid;
 		else
-			uid = camel_message_info_uid (p->info);
+			uid = camel_message_info_uid (msgdata->priv->info);
 
 		/* FIXME Pass a GCancellable */
 		message = camel_folder_get_message_sync (
-			p->source, uid, NULL, error);
+			msgdata->priv->source, uid, NULL, error);
 	}
 
-	if (source_url && message && camel_mime_message_get_source (message) == NULL)
-		camel_mime_message_set_source (message, source_url);
+	if (message != NULL && camel_mime_message_get_source (message) == NULL)
+		camel_mime_message_set_source (message, msgdata->store_uid);
 
 	return message;
 }
@@ -1360,8 +1334,8 @@ get_message_cb (gpointer data, GError **error)
  * @info: message info or NULL
  * @uid: message uid or NULL
  * @source: source folder or NULL
- * @source_url: url of source folder or NULL
- * @original_source_url: url of original source folder (pre-movemail) or NULL
+ * @store_uid: UID of source store, or %NULL
+ * @original_store_uid: UID of source store (pre-movemail), or %NULL
  * @cancellable: optional #GCancellable object, or %NULL
  * @error: return location for a #GError, or %NULL
  *
@@ -1381,8 +1355,8 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
                                     CamelMessageInfo *info,
                                     const gchar *uid,
                                     CamelFolder *source,
-                                    const gchar *source_url,
-                                    const gchar *original_source_url,
+                                    const gchar *store_uid,
+                                    const gchar *original_store_uid,
                                     GCancellable *cancellable,
                                     GError **error)
 {
@@ -1433,8 +1407,8 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
 	p->uid = uid;
 	p->source = source;
 
-	if (message && original_source_url && camel_mime_message_get_source (message) == NULL)
-		camel_mime_message_set_source (message, original_source_url);
+	if (message != NULL && camel_mime_message_get_source (message) == NULL)
+		camel_mime_message_set_source (message, original_store_uid);
 
 	node = (struct _filter_rule *) p->rules.head;
 	result = CAMEL_SEARCH_NOMATCH;
@@ -1443,13 +1417,15 @@ camel_filter_driver_filter_message (CamelFilterDriver *driver,
 
 		d(printf("applying rule %s\naction %s\n", node->match, node->action));
 
-		data.p = p;
-		data.source_url = original_source_url;
+		data.priv = p;
+		data.store_uid = original_store_uid;
+
+		if (original_store_uid == NULL)
+			original_store_uid = store_uid;
 
 		result = camel_filter_search_match (
 			p->session, get_message_cb, &data, p->info,
-			original_source_url ? original_source_url : source_url,
-			node->match, &p->error);
+			original_store_uid, node->match, &p->error);
 
 		switch (result) {
 		case CAMEL_SEARCH_ERROR:
diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h
index 68e4919..703a648 100644
--- a/camel/camel-filter-driver.h
+++ b/camel/camel-filter-driver.h
@@ -113,8 +113,8 @@ gint		camel_filter_driver_filter_message
 						 CamelMessageInfo *info,
 						 const gchar *uid,
 						 CamelFolder *source,
-						 const gchar *source_url,
-						 const gchar *original_source_url,
+						 const gchar *store_uid,
+						 const gchar *original_store_uid,
 						 GCancellable *cancellable,
 						 GError **error);
 gint		camel_filter_driver_filter_folder
diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c
index 1c17f5a..b15f925 100644
--- a/camel/camel-filter-search.c
+++ b/camel/camel-filter-search.c
@@ -464,11 +464,9 @@ static ESExpResult *
 header_source (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms)
 {
 	CamelMimeMessage *message;
+	CamelService *service = NULL;
 	ESExpResult *r;
 	const gchar *src;
-	gint truth = FALSE, i;
-	CamelProvider *provider;
-	CamelURL *uria, *urib;
 
 	if (fms->source) {
 		src = fms->source;
@@ -477,24 +475,30 @@ header_source (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMe
 		src = camel_mime_message_get_source (message);
 	}
 
-	if (src
-	    && (provider = camel_provider_get (src, NULL))
-	    && provider->url_equal) {
-		uria = camel_url_new (src, NULL);
-		if (uria) {
-			for (i=0;i<argc && !truth;i++) {
-				if (argv[i]->type == ESEXP_RES_STRING
-				    && (urib = camel_url_new (argv[i]->value.string, NULL))) {
-					truth = provider->url_equal (uria, urib);
-					camel_url_free (urib);
-				}
-			}
-			camel_url_free (uria);
-		}
+	/* Source strings are now CamelService UIDs. */
+	if (src != NULL)
+		service = camel_session_get_service (fms->session, src);
+
+	/* For backward-compability, also handle CamelService URLs. */
+	if (service == NULL && src != NULL) {
+		CamelURL *url;
+
+		url = camel_url_new (src, NULL);
+
+		if (service == NULL && url != NULL)
+			service = camel_session_get_service_by_url (
+				fms->session, url, CAMEL_PROVIDER_STORE);
+
+		if (service == NULL && url != NULL)
+			service = camel_session_get_service_by_url (
+				fms->session, url, CAMEL_PROVIDER_TRANSPORT);
+
+		if (url != NULL)
+			camel_url_free (url);
 	}
 
 	r = e_sexp_result_new (f, ESEXP_RES_BOOL);
-	r->value.boolean = truth;
+	r->value.boolean = (service != NULL);
 
 	return r;
 }
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 8a9240f..c9a008a 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -219,8 +219,6 @@ folder_filter (CamelSession *session,
 	CamelMessageInfo *info;
 	CamelStore *parent_store;
 	gint i, status = 0;
-	CamelURL *uri;
-	gchar *source_url;
 	CamelJunkPlugin *csp;
 	const gchar *full_name;
 
@@ -303,6 +301,7 @@ folder_filter (CamelSession *session,
 
 	if (data->driver && data->recents) {
 		CamelService *service;
+		const gchar *store_uid;
 
 		/* Translators: The %s is replaced with the
 		 * folder name where the operation is running. */
@@ -313,20 +312,7 @@ folder_filter (CamelSession *session,
 			data->recents->len), full_name);
 
 		service = CAMEL_SERVICE (parent_store);
-		source_url = camel_service_get_url (service);
-		uri = camel_url_new (source_url, NULL);
-		g_free (source_url);
-
-		if (full_name != NULL && *full_name != '/') {
-			gchar *tmp;
-
-			tmp = alloca (strlen (full_name) + 2);
-			sprintf (tmp, "/%s", full_name);
-			camel_url_set_path (uri, tmp);
-		} else
-			camel_url_set_path (uri, full_name);
-		source_url = camel_url_to_string (uri, CAMEL_URL_HIDE_ALL);
-		camel_url_free (uri);
+		store_uid = camel_service_get_uid (service);
 
 		for (i = 0; status == 0 && i < data->recents->len; i++) {
 			gchar *uid = data->recents->pdata[i];
@@ -339,19 +325,17 @@ folder_filter (CamelSession *session,
 			if (info == NULL) {
 				g_warning (
 					"uid '%s' vanished from folder '%s'",
-					uid, source_url);
+					uid, full_name);
 				continue;
 			}
 
 			status = camel_filter_driver_filter_message (
 				data->driver, NULL, info, uid, data->folder,
-				source_url, source_url, cancellable, error);
+				store_uid, store_uid, cancellable, error);
 
 			camel_folder_free_message_info (data->folder, info);
 		}
 
-		g_free (source_url);
-
 		camel_operation_pop_message (cancellable);
 
 		camel_filter_driver_flush (data->driver, error);
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index a6bc1b5..3eb49ce 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -740,34 +740,49 @@ camel_mime_message_get_recipients (CamelMimeMessage *mime_message, const gchar *
 }
 
 void
-camel_mime_message_set_source (CamelMimeMessage *mime_message, const gchar *src)
+camel_mime_message_set_source (CamelMimeMessage *mime_message,
+                               const gchar *source_uid)
 {
-	CamelURL *url;
-	gchar *uri;
+	CamelMedium *medium;
+	const gchar *name;
 
-	g_assert (mime_message);
+	g_return_if_fail (CAMEL_IS_MIME_MESSAGE (mime_message));
 
-	url = camel_url_new (src, NULL);
-	if (url) {
-		uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
-		camel_medium_add_header (CAMEL_MEDIUM (mime_message), "X-Evolution-Source", uri);
-		g_free (uri);
-		camel_url_free (url);
-	}
+	/* FIXME The header name is Evolution-specific.
+	 *       "X" header prefix should be configurable
+	 *       somehow, perhaps through CamelSession. */
+
+	name = "X-Evolution-Source";
+	medium = CAMEL_MEDIUM (mime_message);
+
+	if (source_uid != NULL)
+		camel_medium_add_header (medium, name, source_uid);
+	else
+		camel_medium_remove_header (medium, name);
 }
 
 const gchar *
 camel_mime_message_get_source (CamelMimeMessage *mime_message)
 {
+	CamelMedium *medium;
+	const gchar *name;
 	const gchar *src;
 
-	g_assert (mime_message);
+	g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (mime_message), NULL);
+
+	/* FIXME The header name is Evolution-specific.
+	 *       "X" header prefix should be configurable
+	 *       somehow, perhaps through CamelSession. */
 
-	src = camel_medium_get_header (CAMEL_MEDIUM (mime_message), "X-Evolution-Source");
-	if (src) {
+	name = "X-Evolution-Source";
+	medium = CAMEL_MEDIUM (mime_message);
+
+	src = camel_medium_get_header (medium, name);
+	if (src != NULL) {
 		while (*src && isspace ((unsigned) *src))
 			++src;
 	}
+
 	return src;
 }
 
diff --git a/camel/camel-mime-message.h b/camel/camel-mime-message.h
index 3f6ae1f..65a51a1 100644
--- a/camel/camel-mime-message.h
+++ b/camel/camel-mime-message.h
@@ -129,7 +129,7 @@ void		camel_mime_message_set_recipients
 						 const gchar *type,
 						 CamelInternetAddress *recipients);
 void		camel_mime_message_set_source	(CamelMimeMessage *message,
-						 const gchar *identity);
+						 const gchar *source_uid);
 const gchar *	camel_mime_message_get_source	(CamelMimeMessage *message);
 
 /* utility functions */
diff --git a/docs/reference/camel/tmpl/camel-filter-driver.sgml b/docs/reference/camel/tmpl/camel-filter-driver.sgml
index 9efc59d..30d82a0 100644
--- a/docs/reference/camel/tmpl/camel-filter-driver.sgml
+++ b/docs/reference/camel/tmpl/camel-filter-driver.sgml
@@ -155,8 +155,8 @@ CamelFilterDriver
 @info: 
 @uid: 
 @source: 
- source_url: 
- original_source_url: 
+ store_uid: 
+ original_store_uid: 
 @cancellable: 
 @error: 
 @Returns: 
diff --git a/docs/reference/camel/tmpl/camel-mime-message.sgml b/docs/reference/camel/tmpl/camel-mime-message.sgml
index dd7e37b..545d2b4 100644
--- a/docs/reference/camel/tmpl/camel-mime-message.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-message.sgml
@@ -212,7 +212,7 @@ CamelMimeMessage
 </para>
 
 @message: 
- identity: 
+ source_uid: 
 
 
 <!-- ##### FUNCTION camel_mime_message_get_source ##### -->



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]