]> 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 4f26dd9318ff88bf1df3f467fc135b3d58f67495..ef7f48b26675d7587adb86069aca5264fd46e443 100644 (file)
@@ -2,6 +2,22 @@
  * $Id$
  *
  *
+ *
+ * Copyright (c) 2001-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 
@@ -37,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"
@@ -127,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);
@@ -270,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;
@@ -317,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;
        }
@@ -344,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) {
@@ -367,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?
@@ -425,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 */