remember the lengths of config strings.
[citadel.git] / citadel / modules / imap / imap_misc.c
index 14cc8afa95e3ecbadd6c3c4aa162c59ab1c13343..5cfe8be8fcf93177b4b59c4280051ab96d38b109 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1987-2010 by the citadel.org team
+ * Copyright (c) 1987-2011 by the citadel.org team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source 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.
@@ -52,6 +52,7 @@
 #include "user_ops.h"
 #include "database.h"
 #include "msgbase.h"
+#include "room_ops.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
@@ -280,8 +281,8 @@ void imap_do_append_flags(long new_msgnum, char *new_message_flags) {
  * This function is called by the main command loop.
  */
 void imap_append(int num_parms, ConstStr *Params) {
+       struct CitContext *CCC = CC;
        long literal_length;
-       long bytes_transferred;
        struct CtdlMessage *msg = NULL;
        long new_msgnum = (-1L);
        int ret = 0;
@@ -340,7 +341,6 @@ void imap_append(int num_parms, ConstStr *Params) {
        
        IUnbuffer ();
 
-       bytes_transferred = 0;
        client_read_blob(Imap->TransmittedMessage, literal_length, config.c_sleeping);
 
        if ((ret < 0) || (StrLength(Imap->TransmittedMessage) < literal_length)) {
@@ -355,10 +355,10 @@ void imap_append(int num_parms, ConstStr *Params) {
        client_getln(dummy, sizeof dummy);
 
        /* Convert RFC822 newlines (CRLF) to Unix newlines (LF) */
-       syslog(LOG_DEBUG, "Converting CRLF to LF\n");
+       IMAPM_syslog(LOG_DEBUG, "Converting CRLF to LF");
        StrBufToUnixLF(Imap->TransmittedMessage);
 
-       syslog(LOG_DEBUG, "Converting message format\n");
+       IMAPM_syslog(LOG_DEBUG, "Converting message format");
        msg = convert_internet_message_buf(&Imap->TransmittedMessage);
 
        ret = imap_grabroom(roomname, Params[2].Key, 1);
@@ -372,7 +372,7 @@ void imap_append(int num_parms, ConstStr *Params) {
         * folder is selected, save its name so we can return there!!!!!)
         */
        if (Imap->selected) {
-               strcpy(savedroom, CC->room.QRname);
+               strcpy(savedroom, CCC->room.QRname);
        }
        CtdlUserGoto(roomname, 0, 0, &msgs, &new);
 
@@ -383,14 +383,12 @@ void imap_append(int num_parms, ConstStr *Params) {
         * For now, we allow "forgeries" if the room is one of the user's
         * private mailboxes.
         */
-       if (CC->logged_in) {
-          if ( ((CC->room.QRflags & QR_MAILBOX) == 0) && (config.c_imap_keep_from == 0)) {
-               if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
-               if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
-               if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
-               msg->cm_fields['A'] = strdup(CC->user.fullname);
-               msg->cm_fields['N'] = strdup(config.c_nodename);
-               msg->cm_fields['H'] = strdup(config.c_humannode);
+       if (CCC->logged_in) {
+          if ( ((CCC->room.QRflags & QR_MAILBOX) == 0) && (config.c_imap_keep_from == 0)) {
+
+               CM_SetField(msg, eAuthor, CCC->user.fullname, strlen(CCC->user.fullname));
+               CM_SetField(msg, eNodeName, CFG_KEY(c_nodename));
+               CM_SetField(msg, eHumanNode, CFG_KEY(c_humannode));
            }
        }
 
@@ -430,7 +428,7 @@ void imap_append(int num_parms, ConstStr *Params) {
        }
 
        /* We don't need this buffer anymore */
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
 
        if (new_message_flags != NULL) {
                imap_do_append_flags(new_msgnum, new_message_flags);