diff options
author | Paul J Stevens <paul@nfg.nl> | 2010-05-22 22:59:44 +0200 |
---|---|---|
committer | Paul J Stevens <paul@nfg.nl> | 2010-05-22 22:59:44 +0200 |
commit | be6cdee2f0c5a5fb483c46ad4a3df09e98db518a (patch) | |
tree | 155b736b9f1c09e09abd2800603cd62673375e4b | |
parent | 1e2458c3aaa9817778adeff3d86e5c0bf395dc50 (diff) |
re-instate crlf encoding of all output from imap
-rw-r--r-- | src/dbmail-imapsession.c | 23 | ||||
-rw-r--r-- | src/dbmail-message.c | 6 | ||||
-rw-r--r-- | src/dm_cache.c | 16 | ||||
-rw-r--r-- | src/dm_misc.c | 23 | ||||
-rw-r--r-- | test/check_dbmail.h | 2 | ||||
-rw-r--r-- | test/check_dbmail_imapd.c | 67 | ||||
-rw-r--r-- | test/check_dbmail_message.c | 5 |
7 files changed, 82 insertions, 60 deletions
diff --git a/src/dbmail-imapsession.c b/src/dbmail-imapsession.c index 8f803a26..57f178f9 100644 --- a/src/dbmail-imapsession.c +++ b/src/dbmail-imapsession.c @@ -557,18 +557,24 @@ void _send_headers(ImapSession *self, const body_fetch_t *bodyfetch, gboolean no ts = g_string_new(s); if (bodyfetch->octetcnt > 0) { - - if (bodyfetch->octetstart > 0 && bodyfetch->octetstart < ts->len) - ts = g_string_erase(ts, 0, bodyfetch->octetstart); - - if (ts->len > bodyfetch->octetcnt) - ts = g_string_truncate(ts, bodyfetch->octetcnt); - + char *p; + tmp = get_crlf_encoded(ts->str); cnt = strlen(tmp); + + p = tmp; + if (bodyfetch->octetstart > 0 && bodyfetch->octetstart < (guint64)cnt) { + p += bodyfetch->octetstart; + cnt -= bodyfetch->octetstart; + } + + if ((guint64)cnt > bodyfetch->octetcnt) { + p[bodyfetch->octetcnt] = '\0'; + cnt = bodyfetch->octetcnt; + } dbmail_imap_session_buff_printf(self, "<%llu> {%llu}\r\n%s\r\n", - bodyfetch->octetstart, cnt+2, tmp); + bodyfetch->octetstart, cnt+2, p); } else { tmp = get_crlf_encoded(ts->str); cnt = strlen(tmp); @@ -704,6 +710,7 @@ static u64_t get_dumpsize(body_fetch_t *bodyfetch, gsize dumpsize) return bodyfetch->octetcnt; return (dumpsize - bodyfetch->octetstart); } + static void _imap_send_part(ImapSession *self, GMimeObject *part, body_fetch_t *bodyfetch, const char *type) { TRACE(TRACE_DEBUG,"[%p] type [%s]", self, type); diff --git a/src/dbmail-message.c b/src/dbmail-message.c index 4bab38ce..0c7cfaf3 100644 --- a/src/dbmail-message.c +++ b/src/dbmail-message.c @@ -913,6 +913,7 @@ gchar * dbmail_message_body_to_string(const DbmailMessage *self) assert(self && self->content); return g_mime_object_get_body(GMIME_OBJECT(self->content)); } + gchar * dbmail_message_hdrs_to_string(const DbmailMessage *self) { gchar *h; @@ -1006,10 +1007,7 @@ static DbmailMessage * _retrieve(DbmailMessage *self, const char *query_template /* * - * retrieve the header messageblk - * - * TODO: this call is yet unused in the code, but here for - * forward compatibility's sake. + * retrieve the message headers as a single mime object * */ static DbmailMessage * _fetch_head(DbmailMessage *self) diff --git a/src/dm_cache.c b/src/dm_cache.c index 9270fc96..6094c297 100644 --- a/src/dm_cache.c +++ b/src/dm_cache.c @@ -108,7 +108,7 @@ void Cache_clear(T C) u64_t Cache_update(T C, DbmailMessage *message, int filter) { u64_t tmpcnt = 0, outcnt = 0; - char *buf = NULL; + char *crlf = NULL, *buf = NULL; TRACE(TRACE_DEBUG,"[%p] C->id[%llu] message->id[%llu]", C, C->id, message->id); @@ -117,9 +117,11 @@ u64_t Cache_update(T C, DbmailMessage *message, int filter) Cache_clear(C); buf = dbmail_message_to_string(message); - outcnt = Cache_set_dump(C,buf,IMAP_CACHE_MEMDUMP); - tmpcnt = Cache_set_dump(C,buf,IMAP_CACHE_TMPDUMP); + crlf = get_crlf_encoded(buf); + outcnt = Cache_set_dump(C,crlf,IMAP_CACHE_MEMDUMP); + tmpcnt = Cache_set_dump(C,crlf,IMAP_CACHE_TMPDUMP); g_free(buf); + g_free(crlf); assert(tmpcnt==outcnt); @@ -132,13 +134,17 @@ u64_t Cache_update(T C, DbmailMessage *message, int filter) /* for these two update the temp MEM buffer */ case DBMAIL_MESSAGE_FILTER_HEAD: buf = dbmail_message_hdrs_to_string(message); - outcnt = Cache_set_dump(C,buf,IMAP_CACHE_TMPDUMP); + crlf = get_crlf_encoded(buf); + outcnt = Cache_set_dump(C,crlf,IMAP_CACHE_TMPDUMP); g_free(buf); + g_free(crlf); break; case DBMAIL_MESSAGE_FILTER_BODY: buf = dbmail_message_body_to_string(message); - outcnt = Cache_set_dump(C,buf,IMAP_CACHE_TMPDUMP); + crlf = get_crlf_encoded(buf); + outcnt = Cache_set_dump(C,crlf,IMAP_CACHE_TMPDUMP); g_free(buf); + g_free(crlf); break; case DBMAIL_MESSAGE_FILTER_FULL: outcnt = C->size; diff --git a/src/dm_misc.c b/src/dm_misc.c index 3919babb..fd319cf3 100644 --- a/src/dm_misc.c +++ b/src/dm_misc.c @@ -1934,24 +1934,27 @@ char * imap_get_envelope(GMimeMessage *message) char * imap_get_logical_part(const GMimeObject *object, const char * specifier) { - gchar *t=NULL; - GString *s = g_string_new(""); - - if (strcasecmp(specifier,"HEADER")==0 || strcasecmp(specifier,"MIME")==0) { + gchar *s = NULL, *t=NULL; + + if (specifier == NULL) { + t = g_mime_object_to_string(GMIME_OBJECT(object)); + s = get_crlf_encoded(t); + g_free(t); + } + + else if (strcasecmp(specifier,"HEADER")==0 || strcasecmp(specifier,"MIME")==0) { t = g_mime_object_get_headers(GMIME_OBJECT(object)); - g_string_printf(s,"%s\n", t); + s = get_crlf_encoded(t); g_free(t); } else if (strcasecmp(specifier,"TEXT")==0) { t = g_mime_object_get_body(GMIME_OBJECT(object)); - g_string_printf(s,"%s",t); + s = get_crlf_encoded(t); g_free(t); - } + } - t = s->str; - g_string_free(s,FALSE); - return t; + return s; } diff --git a/test/check_dbmail.h b/test/check_dbmail.h index 0e62fbc9..b7111f5a 100644 --- a/test/check_dbmail.h +++ b/test/check_dbmail.h @@ -106,6 +106,8 @@ char *multipart_message = "From: \"Brother from another planet\" <vol@inter7.com "Content-disposition: inline\n" "\n" "Test message one\n" + " and more.\n" + "\n" "--boundary\n" "Content-type: text/plain; charset=us-ascii; name=testfile\n" "Content-transfer-encoding: base64\n" diff --git a/test/check_dbmail_imapd.c b/test/check_dbmail_imapd.c index 064e51c7..0345917c 100644 --- a/test/check_dbmail_imapd.c +++ b/test/check_dbmail_imapd.c @@ -236,7 +236,7 @@ START_TEST(test_imap_get_structure) message = dbmail_message_new(); message = dbmail_message_init_with_string(message, g_string_new(multipart_message)); result = imap_get_structure(GMIME_MESSAGE(message->content), 1); - strncpy(expect,"((\"text\" \"html\" NIL NIL NIL \"7BIT\" 16 1 NIL (\"inline\" NIL) NIL NIL)" + strncpy(expect,"((\"text\" \"html\" NIL NIL NIL \"7BIT\" 30 3 NIL (\"inline\" NIL) NIL NIL)" "(\"text\" \"plain\" (\"name\" \"testfile\" \"charset\" \"us-ascii\") NIL NIL \"base64\" 432 7 NIL NIL NIL NIL)" " \"mixed\" (\"boundary\" \"boundary\") NIL NIL NIL)",1024); fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_structure failed\n[%s] !=\n[%s]\n", expect, result); @@ -564,16 +564,15 @@ START_TEST(test_imap_get_partspec) object = imap_get_partspec(GMIME_OBJECT(message->content),"HEADER"); result = imap_get_logical_part(object,"HEADER"); - - expect = g_strdup("From nobody Wed Sep 14 16:47:48 2005\n" - "Content-Type: text/plain; charset=\"us-ascii\"\n" - "MIME-Version: 1.0\n" - "Content-Transfer-Encoding: 7bit\n" - "Message-Id: <1199706209l.3020l.1l@(none)>\n" - "To: testuser@foo.org\n" - "From: somewher@foo.org\n" - "Subject: dbmail test message\n" - "\n"); + expect = g_strdup("From nobody Wed Sep 14 16:47:48 2005\r\n" + "Content-Type: text/plain; charset=\"us-ascii\"\r\n" + "MIME-Version: 1.0\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "Message-Id: <1199706209l.3020l.1l@(none)>\r\n" + "To: testuser@foo.org\r\n" + "From: somewher@foo.org\r\n" + "Subject: dbmail test message\r\n" + ""); fail_unless(MATCH(expect,result),"imap_get_partsec failed \n[%s] !=\n[%s]\n", expect, result); g_free(expect); @@ -581,7 +580,11 @@ START_TEST(test_imap_get_partspec) object = imap_get_partspec(GMIME_OBJECT(message->content),"TEXT"); result = imap_get_logical_part(object,"TEXT"); - fail_unless(strlen(result)==29,"imap_get_partspec failed"); + expect = g_strdup("\r\n" + " this is a test message\r\n" + "\r\n"); + fail_unless(MATCH(expect,result),"imap_get_partsec failed \n[%s] !=\n[%s]\n", expect, result); + g_free(expect); g_free(result); dbmail_message_free(message); @@ -592,35 +595,42 @@ START_TEST(test_imap_get_partspec) message = dbmail_message_init_with_string(message, g_string_new(multipart_message)); object = imap_get_partspec(GMIME_OBJECT(message->content),"1"); - result = g_mime_object_to_string(object); - expect = g_strdup("Content-type: text/html\n" - "Content-disposition: inline\n\n" - "Test message one"); - + result = imap_get_logical_part(object,NULL); + expect = g_strdup("Content-type: text/html\r\n" + "Content-disposition: inline\r\n\r\n" + "Test message one\r\n" + " and more.\r\n"); fail_unless(MATCH(expect,result),"imap_get_partspec failed:\n[%s] != \n[%s]\n", expect, result); g_free(result); g_free(expect); object = imap_get_partspec(GMIME_OBJECT(message->content),"1.TEXT"); result = imap_get_logical_part(object,"TEXT"); - fail_unless(strlen(result)==16,"imap_get_partspec failed"); + expect = g_strdup("Test message one\r\n" + " and more.\r\n"); + fail_unless(MATCH(expect,result),"imap_get_partspec failed:\n[%s] != \n[%s]\n", expect, result); g_free(result); + g_free(expect); object = imap_get_partspec(GMIME_OBJECT(message->content),"1.HEADER"); result = imap_get_logical_part(object,"HEADER"); - fail_unless(strlen(result)==53,"imap_get_partspec failed"); + expect = g_strdup("Content-type: text/html\r\n" + "Content-disposition: inline\r\n"); + fail_unless(MATCH(expect,result),"imap_get_partspec failed:\n[%s] != \n[%s]\n", expect, result); g_free(result); + g_free(expect); object = imap_get_partspec(GMIME_OBJECT(message->content),"2.MIME"); result = imap_get_logical_part(object,"MIME"); - fail_unless(strlen(result)==93,"imap_get_partspec failed"); + expect = g_strdup("Content-type: text/plain; charset=us-ascii; name=testfile\r\n" + "Content-transfer-encoding: base64\r\n"); + fail_unless(MATCH(expect,result),"imap_get_partspec failed:\n[%s] != \n[%s]\n", expect, result); g_free(result); + g_free(expect); dbmail_message_free(message); - /* multipart mixed */ - message = dbmail_message_new(); message = dbmail_message_init_with_string(message, g_string_new(multipart_mixed)); @@ -630,19 +640,16 @@ START_TEST(test_imap_get_partspec) g_free(result); object = imap_get_partspec(GMIME_OBJECT(message->content),"2.1.1"); - result = g_mime_object_to_string(object); - expect = g_strdup("Content-Type: text/plain;\n" - " charset=\"us-ascii\"\n" - "Content-Transfer-Encoding: 7bit\n\n" - "Body of doc2\n\n"); + result = imap_get_logical_part(object,NULL); + expect = g_strdup("Content-Type: text/plain;\r\n" + " charset=\"us-ascii\"\r\n" + "Content-Transfer-Encoding: 7bit\r\n\r\n" + "Body of doc2\r\n\r\n"); fail_unless(MATCH(expect,result),"imap_get_partspec failed:\n[%s] != \n[%s]\n", expect, result); g_free(result); g_free(expect); - - dbmail_message_free(message); - } END_TEST diff --git a/test/check_dbmail_message.c b/test/check_dbmail_message.c index aab41db5..c0699ee5 100644 --- a/test/check_dbmail_message.c +++ b/test/check_dbmail_message.c @@ -173,7 +173,7 @@ START_TEST(test_g_mime_object_get_body) m = message_init(multipart_message); result = g_mime_object_get_body(GMIME_OBJECT(m->content)); - fail_unless(strlen(result)==1045,"g_mime_object_get_body failed [%s]\n", result); + fail_unless(strlen(result)==1057,"g_mime_object_get_body failed [%d:%s]\n", strlen(result), result); g_free(result); dbmail_message_free(m); @@ -528,7 +528,7 @@ START_TEST(test_dbmail_message_body_to_string) m = dbmail_message_new(); m = dbmail_message_init_with_string(m,s); result = dbmail_message_body_to_string(m); - fail_unless(strlen(result)==1045, "dbmail_message_body_to_string failed [%d] != [1045]\n[%s]\n", strlen(result),result); + fail_unless(strlen(result)==1057, "dbmail_message_body_to_string failed [%d] != [1057]\n[%s]\n", strlen(result),result); dbmail_message_free(m); g_string_free(s,TRUE); @@ -538,7 +538,6 @@ START_TEST(test_dbmail_message_body_to_string) m = dbmail_message_new(); m = dbmail_message_init_with_string(m,s); result = dbmail_message_body_to_string(m); -// printf("{%d} [%s]\n", strlen(result), result); fail_unless(strlen(result)==330, "dbmail_message_body_to_string failed [330 != %d:%s]", strlen(result), result); dbmail_message_free(m); |