diff options
author | Paul J Stevens <paul@nfg.nl> | 2009-05-12 16:33:11 +0200 |
---|---|---|
committer | Paul J Stevens <paul@nfg.nl> | 2009-05-12 16:33:11 +0200 |
commit | c4c4a6a56c7c9ed5f11211166a42d36c884a2ae5 (patch) | |
tree | 5de05ffb695bcbbc8c8cf89a7dacb068636d8eec | |
parent | 817b4d8fd54f1c7aa3683faefafd7c40e791d4c7 (diff) |
update message reconstruction
this should fix bugs #775 and #783
-rw-r--r-- | src/dbmail-message.c | 30 | ||||
-rw-r--r-- | test/check_dbmail.h | 79 | ||||
-rw-r--r-- | test/check_dbmail_message.c | 25 |
3 files changed, 128 insertions, 6 deletions
diff --git a/src/dbmail-message.c b/src/dbmail-message.c index 203b57e2..0092bbcf 100644 --- a/src/dbmail-message.c +++ b/src/dbmail-message.c @@ -30,6 +30,9 @@ extern db_param_t _db_params; #define DBMAIL_TEMPMBOX "INBOX" #define THIS_MODULE "message" +/* + * used for debugging message de/re-construction + */ //#define dprint(fmt, args...) printf(fmt, ##args) #define dprint(fmt, args...) 0 @@ -261,11 +264,12 @@ static int store_blob(DbmailMessage *m, const char *buf, gboolean is_header) return 0; } -static char * find_boundary(const char *s) + +static GMimeContentType *find_type(const char *s) { GMimeContentType *type; GString *header; - char *boundary, *rest, *h; + char *rest, *h; int i=0; rest = g_strcasestr(s, "\nContent-type: "); @@ -293,10 +297,16 @@ static char * find_boundary(const char *s) h = header->str; g_strstrip(h); type = g_mime_content_type_new_from_string(h); + g_string_free(header,TRUE); + return type; +} + +static char * find_boundary(const char *s) +{ + gchar *boundary; + GMimeContentType *type = find_type(s); boundary = g_strdup(g_mime_content_type_get_parameter(type,"boundary")); g_mime_content_type_destroy(type); - g_string_free(header,TRUE); - return boundary; } @@ -306,10 +316,12 @@ static DbmailMessage * _mime_retrieve(DbmailMessage *self) C c; R r; char *str = NULL, *internal_date = NULL; char *boundary = NULL; + GMimeContentType *mimetype = NULL; char **blist = g_new0(char *,32); int prevdepth, depth = 0, order, row = 0, key = 1; volatile int t = FALSE; gboolean got_boundary = FALSE, prev_boundary = FALSE, is_header = TRUE, prev_header, finalized=FALSE; + gboolean prev_is_message = FALSE, is_message = FALSE; GString *m = NULL; const void *blob; field_t frag; @@ -344,7 +356,13 @@ static DbmailMessage * _mime_retrieve(DbmailMessage *self) str = g_new0(char,l+1); str = strncpy(str,blob,l); - if (is_header) prev_boundary = got_boundary; + if (is_header) { + prev_boundary = got_boundary; + prev_is_message = is_message; + mimetype = find_type(str); + is_message = g_mime_content_type_is_type(mimetype, "message", "rfc822"); + g_mime_content_type_destroy(mimetype); + } got_boundary = FALSE; @@ -366,7 +384,7 @@ static DbmailMessage * _mime_retrieve(DbmailMessage *self) if (depth>0 && blist[depth-1]) boundary = (char *)blist[depth-1]; - if (is_header && (!prev_header || prev_boundary)) { + if (is_header && (!prev_header || prev_boundary || (prev_header && depth>0 && !prev_is_message))) { dprint("\n--%s\n", boundary); g_string_append_printf(m, "\n--%s\n", boundary); } diff --git a/test/check_dbmail.h b/test/check_dbmail.h index 3f6cb604..458907b4 100644 --- a/test/check_dbmail.h +++ b/test/check_dbmail.h @@ -229,6 +229,85 @@ char *multipart_message2 = "From return@trafficmagnet.com Mon Aug 5 19:26:52 2 "\n"; // +// +// +char *multipart_message3 = "Message-ID: <4A0976DF.3060600@nfg.nl>\n" + "Date: Tue, 12 May 2009 15:17:19 +0200\n" + "From: testuser1@localhost\n" + "User-Agent: Thunderbird 2.0.0.21 (X11/20090318)\n" + "To: testuser1@localhost\n" + "Subject: test\n" + "MIME-Version: 1.0\n" + "Content-Type: multipart/mixed; boundary=------------020202020106060900060806\n" + "\n" + "This is a multi-part message in MIME format.\n" + "--------------020202020106060900060806\n" + "Content-Type: text/plain; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: 7bit\n" + "\n" + "--------------020202020106060900060806\n" + "Content-Type: text/plain;\n" + " name=\"blah.txt\"\n" + "Content-Transfer-Encoding: 7bit\n" + "Content-Disposition: inline;\n" + " filename=\"blah.txt\"\n" + "\n" + "\n" + "blah\n" + "--------------020202020106060900060806--\n" + "\n"; + +char *message_rfc822 = "Content-Type: multipart/mixed; boundary=\"===============3760031584070578424==\"\n" + "MIME-Version: 1.0\n" + "Subject: test\n" + "From: testuser1@localhost\n" + "\n" + "preamble for MIME message\n" + "--===============3760031584070578424==\n" + "Content-Type: message/rfc822\n" + "MIME-Version: 1.0\n" + "\n" + "Content-Type: text/plain; charset=\"us-ascii\"\n" + "MIME-Version: 1.0\n" + "Content-Transfer-Encoding: 7bit\n" + "\n" + "body text\n" + "--===============3760031584070578424==--\n"; + +char *multipart_message4 = "To: testuser1@localhost\n" + "From: testuser1@localhost\n" + "Date: Sun, 01 Mar 2009 01:48:31 EST\n" + "Subject: Email\n" + "Message-ID: <200903010148.7e0449aa2fc43c0@localhost>\n" + "MIME-Version: 1.0\n" + "Content-Type: multipart/report; report-type=feedback-report;\n" + " boundary=boundary-1138-29572-2659438-28175\n" + "\n" + "\n" + "--boundary-1138-29572-2659438-28175\n" + "Content-Type: text/plain; charset=\"US-ASCII\"\n" + "Content-Transfer-Encoding: 7bit\n" + "\n" + "This is an email message\n" + "\n" + "\n" + "--boundary-1138-29572-2659438-28175\n" + "Content-Disposition: inline\n" + "Content-Type: message/feedback-report\n" + "\n" + "--boundary-1138-29572-2659438-28175\n" + "Content-Type: message/rfc822\n" + "Content-Disposition: inline\n" + "\n" + "Content-Type: text/plain; charset=\"us-ascii\"\n" + "MIME-Version: 1.0\n" + "Content-Transfer-Encoding: 7bit\n" + "\n" + "body text\n" + "\n" + "--boundary-1138-29572-2659438-28175--\n"; + + char *multipart_alternative = "From paul@nfg.nl Tue Oct 11 13:06:24 2005\n" "Message-ID: <43E5FE98.4030609@nfg.nl>\n" "Date: Sun, 05 Feb 2006 14:33:12 +0100\n" diff --git a/test/check_dbmail_message.c b/test/check_dbmail_message.c index d41b5a23..a992ce70 100644 --- a/test/check_dbmail_message.c +++ b/test/check_dbmail_message.c @@ -197,6 +197,27 @@ START_TEST(test_dbmail_message_store) g_free(e); g_free(t); //----------------------------------------- + m = message_init(message_rfc822); + e = dbmail_message_to_string(m); + t = store_and_retrieve(m); + COMPARE(e,t); + g_free(e); + g_free(t); + //----------------------------------------- + m = message_init(multipart_message3); + e = dbmail_message_to_string(m); + t = store_and_retrieve(m); + COMPARE(e,t); + g_free(e); + g_free(t); + //----------------------------------------- + m = message_init(multipart_message4); + e = dbmail_message_to_string(m); + t = store_and_retrieve(m); + COMPARE(e,t); + g_free(e); + g_free(t); + //----------------------------------------- m = message_init(multipart_mixed); e = dbmail_message_to_string(m); t = store_and_retrieve(m); @@ -850,12 +871,15 @@ Suite *dbmail_message_suite(void) suite_add_tcase(s, tc_message); tcase_add_checked_fixture(tc_message, setup, teardown); +/* tcase_add_test(tc_message, test_dbmail_message_new); tcase_add_test(tc_message, test_dbmail_message_new_from_stream); tcase_add_test(tc_message, test_dbmail_message_set_class); tcase_add_test(tc_message, test_dbmail_message_get_class); tcase_add_test(tc_message, test_dbmail_message_get_internal_date); +*/ tcase_add_test(tc_message, test_dbmail_message_store); +/* tcase_add_test(tc_message, test_dbmail_message_store2); tcase_add_test(tc_message, test_dbmail_message_retrieve); tcase_add_test(tc_message, test_dbmail_message_init_with_string); @@ -877,6 +901,7 @@ Suite *dbmail_message_suite(void) tcase_add_test(tc_message, test_get_crlf_encoded_opt1); tcase_add_test(tc_message, test_get_crlf_encoded_opt2); tcase_add_test(tc_message, test_encoding); +*/ return s; } |