CM_SetField() and CM_SetAsField() now accept -1 as a length to have the function...
[citadel.git] / citadel / msgbase.c
index d120ca41093bdf812d15535f95abfe2e9bbba1af..0bc88bf08f3f08243e3ca6af3d01eec54b835e32 100644 (file)
@@ -149,6 +149,9 @@ void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long
        if (Msg->cm_fields[which] != NULL) {
                free (Msg->cm_fields[which]);
        }
+       if (length < 0) {                       // You can set the length to -1 to have CM_SetField measure it for you
+               length = strlen(buf);
+       }
        Msg->cm_fields[which] = malloc(length + 1);
        memcpy(Msg->cm_fields[which], buf, length);
        Msg->cm_fields[which][length] = '\0';
@@ -256,7 +259,12 @@ void CM_SetAsField(struct CtdlMessage *Msg, eMsgField which, char **buf, long le
 
        Msg->cm_fields[which] = *buf;
        *buf = NULL;
-       Msg->cm_lengths[which] = length;
+       if (length < 0) {                       // You can set the length to -1 to have CM_SetField measure it for you
+               Msg->cm_lengths[which] = strlen(buf);
+       }
+       else {
+               Msg->cm_lengths[which] = length;
+       }
 }
 
 
@@ -756,7 +764,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                                        free(msglist);
                                        return -1;
                                }
-                               msg = CtdlFetchMessage(msglist[a], 1, 1);
+                               msg = CtdlFetchMessage(msglist[a], 1);
                                if (msg != NULL) {
                                        if (CtdlMsgCmp(msg, compare)) {
                                                msglist[a] = 0L;
@@ -1163,7 +1171,7 @@ struct CtdlMessage *CtdlDeserializeMessage(long msgnum, int with_body, const cha
  * NOTE: Caller is responsible for freeing the returned CtdlMessage struct
  *       using the CM_Free(); function.
  */
-struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hooks)
+struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body)
 {
        struct cdbdata *dmsgtext;
        struct CtdlMessage *ret = NULL;
@@ -1204,12 +1212,6 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body, int run_msg_hoo
                CM_SetField(ret, eMesageText, HKEY("\r\n\r\n (no text)\r\n"));
        }
 
-       /* Perform "before read" hooks (aborting if any return nonzero) */
-       if (run_msg_hooks && (PerformMessageHooks(ret, NULL, EVT_BEFOREREAD) > 0)) {
-               CM_Free(ret);
-               return NULL;
-       }
-
        return (ret);
 }
 
@@ -1596,10 +1598,10 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
         * request that we don't even bother loading the body into memory.
         */
        if (headers_only == HEADERS_FAST) {
-               TheMessage = CtdlFetchMessage(msg_num, 0, 1);
+               TheMessage = CtdlFetchMessage(msg_num, 0);
        }
        else {
-               TheMessage = CtdlFetchMessage(msg_num, 1, 1);
+               TheMessage = CtdlFetchMessage(msg_num, 1);
        }
 
        if (TheMessage == NULL) {
@@ -2394,7 +2396,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                                msg = supplied_msg;
                        }
                        else {
-                               msg = CtdlFetchMessage(msgid, 0, 1);
+                               msg = CtdlFetchMessage(msgid, 0);
                        }
        
                        if (msg != NULL) {
@@ -2419,7 +2421,10 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
        }
 
        /* Submit this room for processing by hooks */
-       PerformRoomHooks(&CC->room);
+       int total_roomhook_errors = PerformRoomHooks(&CC->room);
+       if (total_roomhook_errors) {
+               syslog(LOG_WARNING, "msgbase: room hooks returned %d errors", total_roomhook_errors);
+       }
 
        /* Go back to the room we were in before we wandered here... */
        CtdlGetRoom(&CC->room, hold_rm);