]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/imap_misc.c
* migrate append to StrBuf; switch the lineconverter out to stringbuf
[citadel.git] / citadel / modules / imap / imap_misc.c
index c5c7dfbbd03acda001efb2317ee0e2a2f176c292..ef7f48b26675d7587adb86069aca5264fd46e443 100644 (file)
@@ -53,7 +53,6 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
 #include "database.h"
@@ -143,7 +142,7 @@ int imap_do_copy(char *destination_folder) {
        }
 
        /* Set the flags... */
-       i = getroom(&qrbuf, roomname);
+       i = CtdlGetRoom(&qrbuf, roomname);
        if (i == 0) {
                CtdlSetSeen(seen_yes, num_seen_yes, 1, ctdlsetseen_seen, NULL, &qrbuf);
                CtdlSetSeen(seen_no, num_seen_no, 0, ctdlsetseen_seen, NULL, &qrbuf);
@@ -286,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;
@@ -333,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;
        }
@@ -360,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; i<literal_length; ++i) {
-               if (strncmp(&Imap->transmitted_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) {
@@ -383,13 +370,13 @@ void imap_append(int num_parms, char *parms[]) {
        }
 
        /*
-        * usergoto() formally takes us to the desired room.  (If another
+        * CtdlUserGoto() formally takes us to the desired room.  (If another
         * folder is selected, save its name so we can return there!!!!!)
         */
        if (Imap->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       usergoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
 
        /* If the user is locally authenticated, FORCE the From: header to
         * show up as the real sender.  FIXME do we really want to do this?
@@ -441,7 +428,7 @@ void imap_append(int num_parms, char *parms[]) {
         * our happy day without violent explosions.
         */
        if (Imap->selected) {
-               usergoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
        }
 
        /* We don't need this buffer anymore */