[PATCH] Fetch ENVELOPE instead of fetching headers



---
 libtinymail-camel/camel-lite/bs/bodystruct.c       |   17 +++++---
 libtinymail-camel/camel-lite/bs/envelope.h         |    2 +-
 .../camel/providers/imap/camel-imap-folder.c       |   41 ++++++++++++++++---
 3 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/libtinymail-camel/camel-lite/bs/bodystruct.c b/libtinymail-camel/camel-lite/bs/bodystruct.c
index e602c28..3bae208 100644
--- a/libtinymail-camel/camel-lite/bs/bodystruct.c
+++ b/libtinymail-camel/camel-lite/bs/bodystruct.c
@@ -1139,18 +1139,21 @@ bodystruct_parse (guchar *inbuf, guint inlen, GError **err)
 }
 
 envelope_t*
-envelope_parse (guchar *inbuf, guint inlen, GError **err)
+envelope_parse (guchar *inbuf, guchar **end, guint inlen, GError **err)
 {
-	unsigned char *start = (unsigned char  *) strstr ((const char *) inbuf, "ENVELOPE");
 	int lendif;
 
-	if (!start)
-		return decode_envelope (&inbuf, inbuf + inlen, err);
+	*end = (guchar *) strstr ((const char *) inbuf, "ENVELOPE");
 
-	start += 8;
-	lendif = (int) start - (int) inbuf;
+	if (*end == NULL) {
+		*end = inbuf;
+		return decode_envelope (end, inbuf + inlen, err);
+	}
+
+	*end += 8;
+	lendif = (int) *end - (int) inbuf;
 
-	return decode_envelope (&start, (unsigned char *) ( start + (inlen - lendif) ), err);
+	return decode_envelope (end, (unsigned char *) ( *end + (inlen - lendif) ), err);
 }
 
 
diff --git a/libtinymail-camel/camel-lite/bs/envelope.h b/libtinymail-camel/camel-lite/bs/envelope.h
index fd05b0f..9cf77b7 100644
--- a/libtinymail-camel/camel-lite/bs/envelope.h
+++ b/libtinymail-camel/camel-lite/bs/envelope.h
@@ -21,7 +21,7 @@ struct _envelope {
 };
 
 envelope_t* envelope_new (void);
-envelope_t* envelope_parse (guchar *inbuf, guint inlen, GError **err);
+envelope_t* envelope_parse (guchar *inbuf, guchar **end, guint inlen, GError **err);
 void envelope_free (envelope_t *node);
 
 G_END_DECLS
diff --git a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
index fabde50..3b484a8 100644
--- a/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
+++ b/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
@@ -94,8 +94,8 @@
 #include "camel-imap-utils.h"
 #include "camel-imap-wrapper.h"
 
-
 #include <camel/camel-tcp-stream.h>
+#include "bs/envelope.h"
 
 #define d(x)
 
@@ -3489,7 +3489,7 @@ imap_update_summary (CamelFolder *folder, int exists,
 		{
 			uidset = imap_uid_array_to_set (folder->summary, needheaders, uid, UID_SET_LIMIT, &uid);
 			if (!camel_imap_command_start (store, folder, ex,
-						       "UID FETCH %s (FLAGS RFC822.SIZE INTERNALDATE BODY.PEEK[%s])",
+						       "UID FETCH %s (FLAGS RFC822.SIZE INTERNALDATE ENVELOPE)",
 						       uidset, header_spec))
 			{
 				if (camel_operation_cancel_check (NULL))
@@ -3659,7 +3659,6 @@ imap_update_summary (CamelFolder *folder, int exists,
 
 		}
 
-
 		if (camel_folder_change_info_changed (mchanges)) {
 			camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", mchanges);
 			/* printf ("Changes!\n"); */
@@ -6279,10 +6278,6 @@ errorhander:
 	return NULL;
 }
 
-
-
-
-
 static GData *
 parse_fetch_response (CamelImapFolder *imap_folder, char *response)
 {
@@ -6399,6 +6394,38 @@ parse_fetch_response (CamelImapFolder *imap_folder, char *response)
 
 			if (!marker)
 				g_warning ("Unexpected MODSEQ format: %s", response);
+		} else if (!g_ascii_strncasecmp (response, "ENVELOPE ", 8)) {
+			struct _envelope *envelope;
+			GString *tmp;
+			guchar *end = NULL;
+
+			response += 8;
+
+			envelope = envelope_parse (response, &end, strlen (response), NULL);
+			if (!envelope)
+				break;
+
+			tmp = g_string_sized_new (512);
+			g_string_append_printf (tmp,
+						"Date: %s\nSubject: %s\nFrom: %s\n"
+						"Sender: %s\nReply-To: %s\nTo: %s\n"
+						"Cc: %s\nBcc: %s\nIn-Reply-To: %s\nMessage-ID: %s",
+						envelope->date,
+						envelope->subject,
+						envelope->from,
+						envelope->sender,
+						envelope->reply_to,
+						envelope->to,
+						envelope->cc,
+						envelope->bcc,
+						envelope->in_reply_to,
+						envelope->message_id);
+			body_len = tmp->len;
+			body = g_string_free (tmp, FALSE);
+			header = TRUE;
+			cache_header = FALSE;
+			envelope_free (envelope);
+			response = end;
 		} else {
 			g_warning ("Unexpected FETCH response from server: (%s", response);
 			break;
-- 
1.5.6.1


--------------080401090707020201030201--


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