Temporarily added some debugs and an assert() statement to show where the message...
[citadel.git] / citadel / msgbase.c
index 63bbf006c71f88c94445f37eb6380599fc1acb43..17e58e261df7fdd4e874d7443a43ff2c67c2e88d 100644 (file)
@@ -1,6 +1,6 @@
 // Implements the message store.
 //
-// Copyright (c) 1987-2021 by the citadel.org team
+// Copyright (c) 1987-2022 by the citadel.org team
 //
 // This program is open source software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 3.
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <regex.h>
 #include <sys/stat.h>
+#include <assert.h>
 #include <libcitadel.h>
 #include "ctdl_module.h"
 #include "citserver.h"
@@ -384,7 +385,7 @@ int CtdlMsgCmp(struct CtdlMessage *msg, struct CtdlMessage *template) {
                }
        }
 
-       /* All compares succeeded: we have a match! */
+       // All compares succeeded: we have a match!
        return 0;
 }
 
@@ -464,7 +465,7 @@ void CtdlSetSeen(long *target_msgnums, int num_target_msgnums,
        is_set = malloc(num_msgs * sizeof(char));
        memset(is_set, 0, (num_msgs * sizeof(char)) );
 
-       /* Decide which message set we're manipulating */
+       // Decide which message set we're manipulating
        switch(which_set) {
        case ctdlsetseen_seen:
                vset = NewStrBufPlain(vbuf.v_seen, -1);
@@ -652,7 +653,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                need_to_free_re = 1;
        }
 
-       /* Learn about the user and room in question */
+       // Learn about the user and room in question
        if (server_shutting_down) {
                if (need_to_free_re) regfree(&re);
                return -1;
@@ -670,18 +671,18 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                return -1;
        }
 
-       /* Load the message list */
+       // Load the message list
        cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
        if (cdbfr == NULL) {
                if (need_to_free_re) regfree(&re);
-               return 0;       /* No messages at all?  No further action. */
+               return 0;       // No messages at all?  No further action.
        }
 
        msglist = (long *) cdbfr->ptr;
        num_msgs = cdbfr->len / sizeof(long);
 
-       cdbfr->ptr = NULL;      /* clear this so that cdb_free() doesn't free it */
-       cdb_free(cdbfr);        /* we own this memory now */
+       cdbfr->ptr = NULL;      // clear this so that cdb_free() doesn't free it
+       cdb_free(cdbfr);        // we own this memory now
 
        /*
         * Now begin the traversal.
@@ -801,18 +802,17 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                                is_seen = 0;
                        }
                        else {
-                               is_seen = is_msg_in_sequence_set(
-                                                       vbuf.v_seen, thismsg);
+                               is_seen = is_msg_in_sequence_set(vbuf.v_seen, thismsg);
                                if (is_seen) lastold = thismsg;
                        }
-                       if ((thismsg > 0L)
-                           && (
-
-                                      (mode == MSGS_ALL)
-                                      || ((mode == MSGS_OLD) && (is_seen))
-                                      || ((mode == MSGS_NEW) && (!is_seen))
-                                      || ((mode == MSGS_LAST) && (a >= (num_msgs - ref)))
-                                  || ((mode == MSGS_FIRST) && (a < ref))
+                       if (
+                               (thismsg > 0L)
+                       && (
+                               (mode == MSGS_ALL)
+                               || ((mode == MSGS_OLD) && (is_seen))
+                               || ((mode == MSGS_NEW) && (!is_seen))
+                               || ((mode == MSGS_LAST) && (a >= (num_msgs - ref)))
+                               || ((mode == MSGS_FIRST) && (a < ref))
                                || ((mode == MSGS_GT) && (thismsg > ref))
                                || ((mode == MSGS_LT) && (thismsg < ref))
                                || ((mode == MSGS_EQ) && (thismsg == ref))
@@ -1224,7 +1224,6 @@ void fixed_output_post(char *name, char *filename, char *partnum, char *disp,
 
 
 // Inline callback function for mime parser that wants to display text
-//
 void fixed_output(char *name, char *filename, char *partnum, char *disp,
                void *content, char *cbtype, char *cbcharset, size_t length,
                char *encoding, char *cbid, void *cbuserdata)
@@ -1243,7 +1242,6 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
 
        // If we're in the middle of a multipart/alternative scope and
        // we've already printed another section, skip this one.
-       //      
        if ( (ma->is_ma) && (ma->did_print) ) {
                syslog(LOG_DEBUG, "msgbase: skipping part %s (%s)", partnum, cbtype);
                return;
@@ -1296,7 +1294,6 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
 // and then set ma->chosen_pref to that MIME type's position in our preference
 // list.  If we then hit another match, we only replace the first match if
 // the preference value is lower.
-//
 void choose_preferred(char *name, char *filename, char *partnum, char *disp,
                void *content, char *cbtype, char *cbcharset, size_t length,
                char *encoding, char *cbid, void *cbuserdata)
@@ -1321,7 +1318,6 @@ void choose_preferred(char *name, char *filename, char *partnum, char *disp,
 
 
 // Now that we've chosen our preferred part, output it.
-//
 void output_preferred(char *name, 
                      char *filename, 
                      char *partnum, 
@@ -2712,7 +2708,6 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
 
        syslog(LOG_DEBUG, "msgbase: final selection: %s (%s)", actual_rm, room);
        if (strcasecmp(actual_rm, CC->room.QRname)) {
-               /* CtdlGetRoom(&CC->room, actual_rm); */
                CtdlUserGoto(actual_rm, 0, 1, NULL, NULL, NULL, NULL);
        }
 
@@ -2886,7 +2881,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                if (recps == NULL) {
                        qualified_for_journaling = CtdlGetConfigInt("c_journal_pubmsgs");
                }
-               else if (recps->num_local + recps->num_ignet + recps->num_internet > 0) {
+               else if (recps->num_local + recps->num_internet > 0) {
                        qualified_for_journaling = CtdlGetConfigInt("c_journal_email");
                }
                else {
@@ -2974,18 +2969,18 @@ long quickie_message(const char *from,
 /*
  * Back end function used by CtdlMakeMessage() and similar functions
  */
-StrBuf *CtdlReadMessageBodyBuf(char *terminator,       /* token signalling EOT */
+StrBuf *CtdlReadMessageBodyBuf(char *terminator,       // token signalling EOT
                               long tlen,
-                              size_t maxlen,           /* maximum message length */
-                              StrBuf *exist,           /* if non-null, append to it;
-                                                          exist is ALWAYS freed  */
-                              int crlf                 /* CRLF newlines instead of LF */
+                              size_t maxlen,           // maximum message length
+                              StrBuf *exist,           // if non-null, append to it; exist is ALWAYS freed
+                              int crlf                 // CRLF newlines instead of LF
 ) {
        StrBuf *Message;
        StrBuf *LineBuf;
        int flushing = 0;
        int finished = 0;
        int dotdot = 0;
+       int lines_read = 0;                             // FIXME remove this after debugging
 
        LineBuf = NewStrBufPlain(NULL, SIZ);
        if (exist == NULL) {
@@ -3005,6 +3000,7 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator,  /* token signalling EOT */
                if (CtdlClientGetLine(LineBuf) < 0) {
                        finished = 1;
                }
+               ++lines_read;
                if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) {
                        finished = 1;
                }
@@ -3028,6 +3024,14 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator, /* token signalling EOT */
 
        } while (!finished);
        FreeStrBuf(&LineBuf);
+
+       // DEBUG remove this
+       int lines_in_buffer = num_tokens(ChrPtr(Message), '\n');
+       syslog(LOG_DEBUG, "\033[31mLines from client : %d\033[0m", lines_read);
+       syslog(LOG_DEBUG, "\033[32mLines in buffer   : %d\033[0m", lines_in_buffer);
+       assert(lines_read == lines_in_buffer);
+
+
        return Message;
 }