From 6cc2cbc37723c6b7eecc0cdca2432be932cec87a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 21 Feb 2010 12:48:07 +0000 Subject: [PATCH] * migrate append to StrBuf; switch the lineconverter out to stringbuf --- citadel/modules/imap/imap_misc.c | 30 +++++++++--------------------- citadel/modules/imap/serv_imap.c | 6 +----- citadel/modules/imap/serv_imap.h | 3 +-- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/citadel/modules/imap/imap_misc.c b/citadel/modules/imap/imap_misc.c index 5c3a12796..ef7f48b26 100644 --- a/citadel/modules/imap/imap_misc.c +++ b/citadel/modules/imap/imap_misc.c @@ -285,7 +285,6 @@ void imap_do_append_flags(long new_msgnum, char *new_message_flags) { void imap_append(int num_parms, char *parms[]) { long literal_length; long bytes_transferred; - long stripped_length = 0; struct CtdlMessage *msg = NULL; long new_msgnum = (-1L); int ret = 0; @@ -332,21 +331,20 @@ void imap_append(int num_parms, char *parms[]) { Imap = IMAP; imap_free_transmitted_message(); /* just in case. */ - Imap->transmitted_message = malloc(literal_length + 1); - if (Imap->transmitted_message == NULL) { + + Imap->TransmittedMessage = NewStrBufPlain(NULL, literal_length); + + if (Imap->TransmittedMessage == NULL) { cprintf("%s NO Cannot allocate memory.\r\n", parms[0]); return; } - Imap->transmitted_length = literal_length; - + cprintf("+ Transmit message now.\r\n"); bytes_transferred = 0; + client_read_blob(Imap->TransmittedMessage, literal_length, config.c_sleeping); - ret = client_read(Imap->transmitted_message, literal_length); - Imap->transmitted_message[literal_length] = 0; - - if (ret != 1) { + if ((ret < 0) || (StrLength(Imap->TransmittedMessage) < literal_length)) { cprintf("%s NO Read failed.\r\n", parms[0]); return; } @@ -359,20 +357,10 @@ void imap_append(int num_parms, char *parms[]) { /* Convert RFC822 newlines (CRLF) to Unix newlines (LF) */ CtdlLogPrintf(CTDL_DEBUG, "Converting CRLF to LF\n"); - stripped_length = 0; - for (i=0; itransmitted_message[i], "\r\n", 2)) { - Imap->transmitted_message[stripped_length++] = - Imap->transmitted_message[i]; - } - } - literal_length = stripped_length; - Imap->transmitted_message[literal_length] = 0; /* reterminate it */ + StrBufToUnixLF(Imap->TransmittedMessage); CtdlLogPrintf(CTDL_DEBUG, "Converting message format\n"); - msg = convert_internet_message(Imap->transmitted_message); - Imap->transmitted_message = NULL; - Imap->transmitted_length = 0; + msg = convert_internet_message_buf(&Imap->TransmittedMessage); ret = imap_grabroom(roomname, parms[2], 1); if (ret != 0) { diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index e3f9e4b5f..de11077be 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -113,11 +113,7 @@ void imap_free_msgids(void) */ void imap_free_transmitted_message(void) { - if (IMAP->transmitted_message != NULL) { - free(IMAP->transmitted_message); - IMAP->transmitted_message = NULL; - IMAP->transmitted_length = 0; - } + FreeStrBuf(&IMAP->TransmittedMessage); } diff --git a/citadel/modules/imap/serv_imap.h b/citadel/modules/imap/serv_imap.h index 27ace03bf..ee7d68308 100644 --- a/citadel/modules/imap/serv_imap.h +++ b/citadel/modules/imap/serv_imap.h @@ -24,8 +24,7 @@ struct citimap { time_t last_mtime; /* For checking whether the room was modified... */ long *msgids; unsigned int *flags; - char *transmitted_message; /* for APPEND command... */ - size_t transmitted_length; + StrBuf *TransmittedMessage; /* for APPEND command... */ /* Cache most recent RFC822 FETCH because client might load in pieces */ char *cached_rfc822_data; -- 2.30.2