fix dlen
[citadel.git] / citadel / server / msgbase.c
index f3188bcbd66dedf1c920da97c37e97f33ffcd884..aaf4446c604f07f6b434bffa7dc905fd26e84109 100644 (file)
@@ -1488,16 +1488,13 @@ int CtdlOutputMsg(long msg_num,         // message number (local) to fetch
                        );
 
                if ((Author != NULL) && (*Author == NULL)) {
-                       long len;
-                       CM_GetAsField(TheMessage, eAuthor, Author, &len);
+                       *Author = strdup(TheMessage->cm_fields[eAuthor]);
                }
                if ((Address != NULL) && (*Address == NULL)) {  
-                       long len;
-                       CM_GetAsField(TheMessage, erFc822Addr, Address, &len);
+                       *Address = strdup(TheMessage->cm_fields[erFc822Addr]);
                }
                if ((MessageID != NULL) && (*MessageID == NULL)) {      
-                       long len;
-                       CM_GetAsField(TheMessage, emessageId, MessageID, &len);
+                       *MessageID = strdup(TheMessage->cm_fields[emessageId]);
                }
                CM_Free(TheMessage);
                TheMessage = NULL;
@@ -2011,12 +2008,13 @@ int CtdlOutputPreLoadedMsg(
        }
 
        if (mode == MT_RFC822) {
-               // Construct a fun message id
-               cprintf("Message-ID: <%s", mid);
-               if (strchr(mid, '@')==NULL) {
-                       cprintf("@%s", snode);
-               }
-               cprintf(">%s", nl);
+               // Make the message ID RFC2822 compliant
+               cprintf("Message-ID: <%s%s%s>%s",               // put it in angle brackets
+                       mid,
+                       (strchr(mid, '@') ? "" : "@"),          // if there is no domain part,
+                       (strchr(mid, '@') ? "" : snode),        // tack on ours.
+                       nl
+               );
 
                if (!is_room_aide() && (TheMessage->cm_anon_type == MES_ANONONLY)) {
                        cprintf("From: \"----\" <x@x.org>%s", nl);
@@ -2122,14 +2120,14 @@ DONE:   // now we're done
 // (Returns 0 for success, nonzero for failure)
 // roomname may be NULL to use the current room
 //
-// Note that the 'supplied_msg' field may be set to NULL, in which case
+// Note that the 'msg_in' field may be set to NULL, in which case
 // the message will be fetched from disk, by number, if we need to perform
 // replication checks.  This adds an additional database read, so if the
 // caller already has the message in memory then it should be supplied.  (Obviously
 // this mode of operation only works if we're saving a single message.)
 //
 int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
-                       int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj
+                       int do_repl_check, struct CtdlMessage *msg_in, int suppress_refcount_adj
 ) {
        int i, j, unique;
        char hold_rm[ROOMNAMELEN];
@@ -2154,7 +2152,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
        // Sanity checks
        if (newmsgidlist == NULL) return(ERROR + INTERNAL_ERROR);
        if (num_newmsgs < 1) return(ERROR + INTERNAL_ERROR);
-       if (num_newmsgs > 1) supplied_msg = NULL;
+       if (num_newmsgs > 1) msg_in = NULL;
 
        // Now the regular stuff
        if (CtdlGetRoomLock(&CC->room, ((roomname != NULL) ? roomname : CC->room.QRname) ) != 0) {
@@ -2217,8 +2215,8 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                for (i=0; i<num_msgs_to_be_merged; ++i) {
                        msgid = msgs_to_be_merged[i];
        
-                       if (supplied_msg != NULL) {
-                               msg = supplied_msg;
+                       if (msg_in != NULL) {
+                               msg = msg_in;
                        }
                        else {
                                msg = CtdlFetchMessage(msgid, 0);
@@ -2233,7 +2231,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                                }
 
                                // Free up the memory we may have allocated
-                               if (msg != supplied_msg) {
+                               if (msg != msg_in) {
                                        CM_Free(msg);
                                }
                        }
@@ -2270,8 +2268,8 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
 
 
 // This is the same as CtdlSaveMsgPointersInRoom() but it only accepts a single message.
-int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *supplied_msg) {
-       return CtdlSaveMsgPointersInRoom(roomname, &msgid, 1, do_repl_check, supplied_msg, 0);
+int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg_in) {
+       return CtdlSaveMsgPointersInRoom(roomname, &msgid, 1, do_repl_check, msg_in, 0);
 }
 
 
@@ -2320,7 +2318,7 @@ long CtdlSaveThisMessage(struct CtdlMessage *msg, long msgid) {
        }
 
        if (error_count > 0) {
-               syslog(LOG_ERR, "msgbase: encountered %d errors storing message %ld", error_count, msgid);
+               syslog(LOG_ERR, "msgbase: encountered %ld errors storing message %ld", error_count, msgid);
        }
 
        // Free the memory we used for the serialized message
@@ -2768,7 +2766,7 @@ long quickie_message(char *from,
        if (!IsEmptyStr(room)) CM_SetField(msg, eOriginalRoom, room);
        if (!IsEmptyStr(to)) {
                CM_SetField(msg, eRecipient, to);
-               recp = validate_recipients(to, NULL, 0);
+               recp = validate_recipients(to, 0);
        }
        if (!IsEmptyStr(subject)) {
                CM_SetField(msg, eMsgSubject, subject);
@@ -2883,7 +2881,7 @@ struct CtdlMessage *CtdlMakeMessage(
         char *fake_name,                // who we're masquerading as
        char *my_email,                 // which of my email addresses to use (empty is ok)
         char *subject,                  // Subject (optional)
-       char *supplied_euid,            // ...or NULL if this is irrelevant
+       char *euid_in,          // ...or NULL if this is irrelevant
         char *preformatted_text,        // ...or NULL to read text from client
        char *references                // Thread references
 ) {
@@ -2903,8 +2901,8 @@ struct CtdlMessage *CtdlMakeMessage(
                (my_email)?strlen(my_email): 0,
                subject,                                // Subject (optional)
                (subject)?strlen(subject): 0,
-               supplied_euid,                          // ...or NULL if this is irrelevant
-               (supplied_euid)?strlen(supplied_euid):0,
+               euid_in,                                // ...or NULL if this is irrelevant
+               (euid_in)?strlen(euid_in):0,
                preformatted_text,                      // ...or NULL to read text from client
                (preformatted_text)?strlen(preformatted_text) : 0,
                references,                             // Thread references
@@ -2934,7 +2932,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        long myelen,
        char *subject,                  // Subject (optional)
        long subjlen,
-       char *supplied_euid,            // ...or NULL if this is irrelevant
+       char *euid_in,          // ...or NULL if this is irrelevant
        long euidlen,
        char *preformatted_text,        // ...or NULL to read text from client
        long textlen,
@@ -3025,7 +3023,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        }
 
        if (euidlen > 0) {
-               CM_SetField(msg, eExclusiveID, supplied_euid);
+               CM_SetField(msg, eExclusiveID, euid_in);
        }
 
        if (reflen > 0) {