In case you haven't figured it out yet...
authorArt Cancro <ajc@citadel.org>
Wed, 3 Jan 2024 18:34:06 +0000 (13:34 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 3 Jan 2024 18:34:06 +0000 (13:34 -0500)
This is what I do when I'm avoiding some other task.

citadel/server/msgbase.c

index ae77f36336bb057f3545f5184d533f68662ea105..8a709492334a0d88cb3c586efefdb81b21964c8c 100644 (file)
@@ -1,9 +1,9 @@
 // Implements the message store.
 //
-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 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.
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License version 3.
 
 #include <stdlib.h>
 #include <unistd.h>
@@ -94,7 +94,7 @@ void FillMsgKeyLookupTable(void) {
 
 
 eMsgField FieldOrder[]  = {
-/* Important fields */
+// Important fields
        emessageId   ,
        eMessagePath ,
        eTimestamp   ,
@@ -102,29 +102,29 @@ eMsgField FieldOrder[]  = {
        erFc822Addr  ,
        eOriginalRoom,
        eRecipient   ,
-/* Semi-important fields */
+// Semi-important fields
        eBig_message ,
        eExclusiveID ,
        eWeferences  ,
        eJournal     ,
-/* G is not used yet */
+// G is not used yet
        eReplyTo     ,
        eListID      ,
-/* Q is not used yet */
+// Q is not used yet
        eenVelopeTo  ,
-/* X is not used yet */
-/* Z is not used yet */
+// X is not used yet
+// Z is not used yet
        eCarbonCopY  ,
        eMsgSubject  ,
-/* internal only */
+// internal only
        eErrorMsg    ,
        eSuppressIdx ,
        eExtnotify   ,
-/* Message text (MUST be last) */
+// Message text (MUST be last)
        eMesageText 
-/* Not saved to disk: 
-       eVltMsgNum
-*/
+// Not saved to disk: 
+//     eVltMsgNum
+//
 };
 
 static const long NDiskFields = sizeof(FieldOrder) / sizeof(eMsgField);
@@ -702,23 +702,21 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                }
        }
 
-       /* If a search string was specified, get a message list from
-        * the full text index and remove messages which aren't on both
-        * lists.
-        *
-        * How this works:
-        * Since the lists are sorted and strictly ascending, and the
-        * output list is guaranteed to be shorter than or equal to the
-        * input list, we overwrite the bottom of the input list.  This
-        * eliminates the need to memmove big chunks of the list over and
-        * over again.
-        */
+       // If a search string was specified, get a message list from
+       // the full text index and remove messages which aren't on both
+       // lists.
+       //
+       // How this works:
+       // Since the lists are sorted and strictly ascending, and the
+       // output list is guaranteed to be shorter than or equal to the
+       // input list, we overwrite the bottom of the input list.  This
+       // eliminates the need to memmove big chunks of the list over and
+       // over again.
        if ( (num_msgs > 0) && (mode == MSGS_SEARCH) && (search_string) ) {
 
-               /* Call search module via hook mechanism.
-                * NULL means use any search function available.
-                * otherwise replace with a char * to name of search routine
-                */
+               // Call search module via hook mechanism.
+               // NULL means use any search function available.
+               // otherwise replace with a char * to name of search routine
                search = CtdlFullTextSearch(search_string);
 
                if (array_len(search) > 0) {
@@ -738,21 +736,18 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                        }
                }
                else {
-                       num_msgs = 0;   /* No messages qualify */
+                       num_msgs = 0;   // No messages qualify
                }
                if (search != NULL) array_free(search);
 
-               /* Now that we've purged messages which don't contain the search
-                * string, treat a MSGS_SEARCH just like a MSGS_ALL from this
-                * point on.
-                */
+               // Now that we've purged messages which don't contain the search
+               // string, treat a MSGS_SEARCH just like a MSGS_ALL from this
+               // point on.
                mode = MSGS_ALL;
        }
 
-       /*
-        * Now iterate through the message list, according to the
-        * criteria supplied by the caller.
-        */
+       // Now iterate through the message list, according to the
+       // criteria supplied by the caller.
        if (num_msgs > 0)
                for (a = 0; a < num_msgs; ++a) {
                        if (server_shutting_down) {
@@ -796,9 +791,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
                }
        if (need_to_free_re) regfree(&re);
 
-       /*
-        * We cache the most recent msglist in order to do security checks later
-        */
+       // We cache the most recent msglist in order to do security checks later
        if (CC->client_socket > 0) {
                if (CC->cached_msglist != NULL) {
                        free(CC->cached_msglist);
@@ -814,16 +807,14 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
 }
 
 
-/*
- * memfmout()  -  Citadel text formatter and paginator.
- *          Although the original purpose of this routine was to format
- *          text to the reader's screen width, all we're really using it
- *          for here is to format text out to 80 columns before sending it
- *          to the client.  The client software may reformat it again.
- */
+// memfmout() - Citadel text formatter and paginator.
+//     Although the original purpose of this routine was to format
+//     text to the reader's screen width, all we're really using it
+//     for here is to format text out to 80 columns before sending it
+//     to the client.  The client software MAY reformat it again.
 void memfmout(
-       char *mptr,             /* where are we going to get our text from? */
-       const char *nl          /* string to terminate lines with */
+       char *mptr,             // where are we going to get our text from?
+       const char *nl          // string to terminate lines with
 ) {
        int column = 0;
        unsigned char ch = 0;
@@ -848,10 +839,10 @@ void memfmout(
                        column = 0;
                }
                else if (ch == '\r') {
-                       /* Ignore carriage returns.  Newlines are always LF or CRLF but never CR. */
+                       // Ignore carriage returns.  Newlines are always LF or CRLF but never CR.
                }
                else if (isspace(ch)) {
-                       if (column > 72) {              /* Beyond 72 columns, break on the next space */
+                       if (column > 72) {              // Beyond 72 columns, break on the next space
                                if (client_write(outbuf, len) == -1) {
                                        syslog(LOG_ERR, "msgbase: memfmout() aborting due to write failure");
                                        return;
@@ -871,7 +862,7 @@ void memfmout(
                else {
                        outbuf[len++] = ch;
                        ++column;
-                       if (column > 1000) {            /* Beyond 1000 columns, break anywhere */
+                       if (column > 1000) {            // Beyond 1000 columns, break anywhere
                                if (client_write(outbuf, len) == -1) {
                                        syslog(LOG_ERR, "msgbase: memfmout() aborting due to write failure");
                                        return;
@@ -896,9 +887,7 @@ void memfmout(
 }
 
 
-/*
- * Callback function for mime parser that simply lists the part
- */
+// Callback function for mime parser that simply lists the part
 void list_this_part(char *name, char *filename, char *partnum, char *disp,
                    void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
                    char *cbid, void *cbuserdata)
@@ -920,9 +909,7 @@ void list_this_part(char *name, char *filename, char *partnum, char *disp,
 }
 
 
-/* 
- * Callback function for multipart prefix
- */
+// Callback function for multipart prefix
 void list_this_pref(char *name, char *filename, char *partnum, char *disp,
                    void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
                    char *cbid, void *cbuserdata)
@@ -940,9 +927,7 @@ void list_this_pref(char *name, char *filename, char *partnum, char *disp,
 }
 
 
-/* 
- * Callback function for multipart sufffix
- */
+// Callback function for multipart sufffix
 void list_this_suff(char *name, char *filename, char *partnum, char *disp,
                    void *content, char *cbtype, char *cbcharset, size_t length, char *encoding,
                    char *cbid, void *cbuserdata)
@@ -959,10 +944,8 @@ void list_this_suff(char *name, char *filename, char *partnum, char *disp,
 }
 
 
-/*
- * Callback function for mime parser that opens a section for downloading
- * we use serv_files function here: 
- */
+// Callback function for mime parser that opens a section for downloading
+// we use serv_files function here: 
 extern void OpenCmdResult(char *filename, const char *mime_type);
 void mime_download(char *name, char *filename, char *partnum, char *disp,
                   void *content, char *cbtype, char *cbcharset, size_t length,
@@ -970,7 +953,7 @@ void mime_download(char *name, char *filename, char *partnum, char *disp,
 {
        int rv = 0;
 
-       /* Silently go away if there's already a download open. */
+       // Silently go away if there's already a download open.
        if (CC->download_fp != NULL)
                return;
 
@@ -1001,10 +984,8 @@ void mime_download(char *name, char *filename, char *partnum, char *disp,
 }
 
 
-/*
- * Callback function for mime parser that outputs a section all at once.
- * We can specify the desired section by part number *or* content-id.
- */
+// Callback function for mime parser that outputs a section all at once.
+// We can specify the desired section by part number *or* content-id.
 void mime_spew_section(char *name, char *filename, char *partnum, char *disp,
                   void *content, char *cbtype, char *cbcharset, size_t length,
                   char *encoding, char *cbid, void *cbuserdata)
@@ -1308,7 +1289,7 @@ void output_preferred(char *name,
        for (i=0; i<num_tokens(CC->preferred_formats, '|'); ++i) {
                extract_token(buf, CC->preferred_formats, i, '|', sizeof buf);
                if (!strcasecmp(buf, cbtype)) {
-                       /* Yeah!  Go!  W00t!! */
+                       // Yeah!  Go!  W00t!!
                        if (ma->dont_decode == 0) 
                                rc = mime_decode_now (content, 
                                                      length,
@@ -1572,7 +1553,7 @@ void OutputCtdlMsgHeaders(struct CtdlMessage *TheMessage, int do_proto) {
        char buf[SIZ];
        char display_name[256];
 
-       /* begin header processing loop for Citadel message format */
+       // begin header processing loop for Citadel message format
        safestrncpy(display_name, "<unknown>", sizeof display_name);
        if (!CM_IsEmpty(TheMessage, eAuthor)) {
                strcpy(buf, TheMessage->cm_fields[eAuthor]);
@@ -1595,7 +1576,7 @@ void OutputCtdlMsgHeaders(struct CtdlMessage *TheMessage, int do_proto) {
                }
        }
 
-       /* Now spew the header fields in the order we like them. */
+       // Now spew the header fields in the order we like them.
        for (i=0; i< NDiskFields; ++i) {
                eMsgField Field;
                Field = FieldOrder[i];
@@ -1609,13 +1590,13 @@ void OutputCtdlMsgHeaders(struct CtdlMessage *TheMessage, int do_proto) {
                                                cprintf("%s=%s\n", msgkeys[Field], display_name);
                                        }
                                }
-                               /* Masquerade display name if needed */
+                               // Masquerade display name if needed
                                else {
                                        if (do_proto) {
                                                cprintf("%s=%s\n", msgkeys[Field], TheMessage->cm_fields[Field]);
                                        }
                                }
-                               /* Give the client a hint about whether the message originated locally */
+                               // Give the client a hint about whether the message originated locally
                                if (Field == erFc822Addr) {
                                        if (IsDirectory(TheMessage->cm_fields[Field] ,0)) {
                                                cprintf("locl=yes\n");                          // message originated locally.
@@ -1632,7 +1613,7 @@ void OutputCtdlMsgHeaders(struct CtdlMessage *TheMessage, int do_proto) {
 
 void OutputRFC822MsgHeaders(
        struct CtdlMessage *TheMessage,
-       int flags,              /* should the message be exported clean */
+       int flags,              // should the message be exported clean
        const char *nl, int nlen,
        char *mid, long sizeof_mid,
        char *suser, long sizeof_suser,
@@ -1738,7 +1719,7 @@ void OutputRFC822MsgHeaders(
                        case eSuppressIdx:
                        case eExtnotify:
                        case eVltMsgNum:
-                               /* these don't map to mime message headers. */
+                               // these don't map to mime message headers.
                                break;
                        }
                        if (mptr != mpptr) {
@@ -1754,8 +1735,8 @@ void OutputRFC822MsgHeaders(
 
 void Dump_RFC822HeadersBody(
        struct CtdlMessage *TheMessage,
-       int headers_only,       /* eschew the message body? */
-       int flags,              /* should the bessage be exported clean? */
+       int headers_only,       // eschew the message body?
+       int flags,              // should the bessage be exported clean?
        const char *nl, int nlen)
 {
        cit_uint8_t prev_ch;
@@ -1772,7 +1753,7 @@ void Dump_RFC822HeadersBody(
        prev_ch = '\0';
        while (*mptr != '\0') {
                if (*mptr == '\r') {
-                       /* do nothing */
+                       // do nothing
                }
                else {
                        if ((!eoh) &&
@@ -1828,13 +1809,12 @@ void Dump_RFC822HeadersBody(
 }
 
 
-/* If the format type on disk is 1 (fixed-format), then we want
- * everything to be output completely literally ... regardless of
- * what message transfer format is in use.
- */
+// If the format type on disk is 1 (fixed-format), then we want
+// everything to be output completely literally ... regardless of
+// what message transfer format is in use.
 void DumpFormatFixed(
        struct CtdlMessage *TheMessage,
-       int mode,               /* how would you like that message? */
+       int mode,               // how would you like that message?
        const char *nl, int nllen)
 {
        cit_uint8_t ch;
@@ -1871,7 +1851,7 @@ void DumpFormatFixed(
                        }
                }
 
-               /* if we reach the outer bounds of our buffer, abort without respect for what we purge. */
+               // if we reach the outer bounds of our buffer, abort without respect for what we purge.
                if (xlline && ((isspace(ch)) || (buflen > SIZ - nllen - 2))) {
                        ch = '\r';
                }
@@ -2455,10 +2435,8 @@ void CtdlSerializeMessage(struct ser_ret *ret,           // return values
 }
 
 
-/*
- * Check to see if any messages already exist in the current room which
- * carry the same Exclusive ID as this one.  If any are found, delete them.
- */
+// Check to see if any messages already exist in the current room which
+// carry the same Exclusive ID as this one.  If any are found, delete them.
 void ReplicationChecks(struct CtdlMessage *msg) {
        long old_msgnum = (-1L);
 
@@ -2466,13 +2444,10 @@ void ReplicationChecks(struct CtdlMessage *msg) {
 
        syslog(LOG_DEBUG, "msgbase: performing replication checks in <%s>", CC->room.QRname);
 
-       /* No exclusive id?  Don't do anything. */
+       // No exclusive id?  Don't do anything.
        if (msg == NULL) return;
        if (CM_IsEmpty(msg, eExclusiveID)) return;
 
-       /*syslog(LOG_DEBUG, "msgbase: exclusive ID: <%s> for room <%s>",
-         msg->cm_fields[eExclusiveID], CC->room.QRname);*/
-
        old_msgnum = CtdlLocateMessageByEuid(msg->cm_fields[eExclusiveID], &CC->room);
        if (old_msgnum > 0L) {
                syslog(LOG_DEBUG, "msgbase: ReplicationChecks() replacing message %ld", old_msgnum);
@@ -2481,17 +2456,15 @@ void ReplicationChecks(struct CtdlMessage *msg) {
 }
 
 
-/*
- * Save a message to disk and submit it into the delivery system.
- */
-long CtdlSubmitMsg(struct CtdlMessage *msg,    /* message to save */
-                  struct recptypes *recps,     /* recipients (if mail) */
-                  const char *force            /* force a particular room? */
+// Save a message to disk and submit it into the delivery system.
+long CtdlSubmitMsg(struct CtdlMessage *msg,    // message to save
+                  struct recptypes *recps,     // recipients (if mail)
+                  const char *force            // force a particular room?
 ) {
        char hold_rm[ROOMNAMELEN];
        char actual_rm[ROOMNAMELEN];
        char force_room[ROOMNAMELEN];
-       char content_type[SIZ];                 /* We have to learn this */
+       char content_type[SIZ];                 // We have to learn this
        char recipient[SIZ];
        char bounce_to[1024];
        const char *room;
@@ -2506,17 +2479,14 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        int qualified_for_journaling = 0;
 
        syslog(LOG_DEBUG, "msgbase: CtdlSubmitMsg() called");
-       if (CM_IsValidMsg(msg) == 0) return(-1);        /* self check */
+       if (CM_IsValidMsg(msg) == 0) return(-1);        // self check
 
-       /* If this message has no timestamp, we take the liberty of
-        * giving it one, right now.
-        */
+       // If this message has no timestamp, we take the liberty of giving it one, right now.
        if (CM_IsEmpty(msg, eTimestamp)) {
                CM_SetFieldLONG(msg, eTimestamp, time(NULL));
        }
 
-       /* If this message has no path, we generate one.
-        */
+       // If this message has no path, we generate one.
        if (CM_IsEmpty(msg, eMessagePath)) {
                if (!CM_IsEmpty(msg, eAuthor)) {
                        CM_CopyField(msg, eMessagePath, eAuthor);
@@ -2538,7 +2508,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                strcpy(force_room, force);
        }
 
-       /* Learn about what's inside, because it's what's inside that counts */
+       // Learn about what's inside, because it's what's inside that counts
        if (CM_IsEmpty(msg, eMesageText)) {
                syslog(LOG_ERR, "msgbase: ERROR; attempt to save message with NULL body");
                return(-2);
@@ -2571,7 +2541,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                }
        }
 
-       /* Goto the correct room */
+       // Goto the correct room
        room = (recps) ? CC->room.QRname : SENTITEMS;
        syslog(LOG_DEBUG, "msgbase: selected room %s", room);
        strcpy(hold_rm, CC->room.QRname);
@@ -2580,7 +2550,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                strcpy(actual_rm, SENTITEMS);
        }
 
-       /* If the user is a twit, move to the twit room for posting */
+       // If the user is a twit, move to the twit room for posting
        if (TWITDETECT) {
                if (CC->user.axlevel == AxProbU) {
                        strcpy(hold_rm, actual_rm);
@@ -2589,7 +2559,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                }
        }
 
-       /* ...or if this message is destined for Aide> then go there. */
+       // ...or if this message is destined for Aide> then go there.
        if (!IsEmptyStr(force_room)) {
                strcpy(actual_rm, force_room);
        }
@@ -2599,50 +2569,42 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
                CtdlUserGoto(actual_rm, 0, 1, NULL, NULL, NULL, NULL);
        }
 
-       /*
-        * If this message has no O (room) field, generate one.
-        */
+       // If this message has no O (room) field, generate one.
        if (CM_IsEmpty(msg, eOriginalRoom) && !IsEmptyStr(CC->room.QRname)) {
                CM_SetField(msg, eOriginalRoom, CC->room.QRname);
        }
 
-       /* Perform "before save" hooks (aborting if any return nonzero) */
+       // Perform "before save" hooks (aborting if any return nonzero)
        syslog(LOG_DEBUG, "msgbase: performing before-save hooks");
        if (PerformMessageHooks(msg, recps, EVT_BEFORESAVE) > 0) return(-3);
 
-       /*
-        * If this message has an Exclusive ID, and the room is replication
-        * checking enabled, then do replication checks.
-        */
+       // If this message has an Exclusive ID, and the room is replication
+       // checking enabled, then do replication checks.
        if (DoesThisRoomNeedEuidIndexing(&CC->room)) {
                ReplicationChecks(msg);
        }
 
-       /* Save it to disk */
+       // Save it to disk
        syslog(LOG_DEBUG, "msgbase: saving to disk");
        newmsgid = send_message(msg);
        if (newmsgid <= 0L) return(-5);
 
-       /* Write a supplemental message info record.  This doesn't have to
-        * be a critical section because nobody else knows about this message
-        * yet.
-        */
+       // Write a supplemental message info record.  This doesn't have to be
+       // a critical section because nobody else knows about this message yet.
        syslog(LOG_DEBUG, "msgbase: creating metadata record");
        memset(&smi, 0, sizeof(struct MetaData));
        smi.meta_msgnum = newmsgid;
        smi.meta_refcount = 0;
        safestrncpy(smi.meta_content_type, content_type, sizeof smi.meta_content_type);
 
-       /*
-        * Measure how big this message will be when rendered as RFC822.
-        * We do this for two reasons:
-        * 1. We need the RFC822 length for the new metadata record, so the
-        *    POP and IMAP services don't have to calculate message lengths
-        *    while the user is waiting (multiplied by potentially hundreds
-        *    or thousands of messages).
-        * 2. If journaling is enabled, we will need an RFC822 version of the
-        *    message to attach to the journalized copy.
-        */
+       // Measure how big this message will be when rendered as RFC822.
+       // We do this for two reasons:
+       // 1. We need the RFC822 length for the new metadata record, so the
+       //    POP and IMAP services don't have to calculate message lengths
+       //    while the user is waiting (multiplied by potentially hundreds
+       //    or thousands of messages).
+       // 2. If journaling is enabled, we will need an RFC822 version of the
+       //    message to attach to the journalized copy.
        if (CC->redirect_buffer != NULL) {
                syslog(LOG_ALERT, "msgbase: CC->redirect_buffer is not NULL during message submission!");
                exit(CTDLEXIT_REDIRECT);
@@ -2655,13 +2617,12 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
 
        PutMetaData(&smi);
 
-       /* Now figure out where to store the pointers */
+       // Now figure out where to store the pointers
        syslog(LOG_DEBUG, "msgbase: storing pointers");
 
-       /* If this is being done by the networker delivering a private
-        * message, we want to BYPASS saving the sender's copy (because there
-        * is no local sender; it would otherwise go to the Trashcan).
-        */
+       // If this is being done by the networker delivering a private
+       // message, we want to BYPASS saving the sender's copy (because there
+       // is no local sender; it would otherwise go to the Trashcan).
        if ((!CC->internal_pgm) || (recps == NULL)) {
                if (CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 1, msg) != 0) {
                        syslog(LOG_ERR, "msgbase: ERROR saving message pointer %ld in %s", newmsgid, actual_rm);
@@ -2669,12 +2630,12 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
                }
        }
 
-       /* For internet mail, drop a copy in the outbound queue room */
+       // For internet mail, drop a copy in the outbound queue room
        if ((recps != NULL) && (recps->num_internet > 0)) {
                CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, newmsgid, 0, msg);
        }
 
-       /* If other rooms are specified, drop them there too. */
+       // If other rooms are specified, drop them there too.
        if ((recps != NULL) && (recps->num_room > 0)) {
                for (i=0; i<num_tokens(recps->recp_room, '|'); ++i) {
                        extract_token(recipient, recps->recp_room, i, '|', sizeof recipient);
@@ -2683,7 +2644,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                }
        }
 
-       /* Decide where bounces need to be delivered */
+       // Decide where bounces need to be delivered
        if ((recps != NULL) && (recps->bounce_to == NULL)) {
                if (CC->logged_in) {
                        strcpy(bounce_to, CC->user.fullname);
@@ -2721,21 +2682,19 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
                recps->recp_local = pch;
        }
 
-       /* Perform "after save" hooks */
+       // Perform "after save" hooks
        syslog(LOG_DEBUG, "msgbase: performing after-save hooks");
 
        PerformMessageHooks(msg, recps, EVT_AFTERSAVE);
        CM_FlushField(msg, eVltMsgNum);
 
-       /* Go back to the room we started from */
+       // Go back to the room we started from
        syslog(LOG_DEBUG, "msgbase: returning to original room %s", hold_rm);
        if (strcasecmp(hold_rm, CC->room.QRname)) {
                CtdlUserGoto(hold_rm, 0, 1, NULL, NULL, NULL, NULL);
        }
 
-       /*
-        * Any addresses to harvest for someone's address book?
-        */
+       // Any addresses to harvest for someone's address book?
        if ( (CC->logged_in) && (recps != NULL) ) {
                collected_addresses = harvest_collected_addresses(msg);
        }
@@ -2751,9 +2710,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                end_critical_section(S_ATBF);
        }
 
-       /*
-        * Determine whether this message qualifies for journaling.
-        */
+       // Determine whether this message qualifies for journaling.
        if (!CM_IsEmpty(msg, eJournal)) {
                qualified_for_journaling = 0;
        }
@@ -2769,11 +2726,9 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,      /* message to save */
                }
        }
 
-       /*
-        * Do we have to perform journaling?  If so, hand off the saved
-        * RFC822 version will be handed off to the journaler for background
-        * submit.  Otherwise, we have to free the memory ourselves.
-        */
+       // Do we have to perform journaling?  If so, hand off the saved
+       // RFC822 version will be handed off to the journaler for background
+       // submit.  Otherwise, we have to free the memory ourselves.
        if (saved_rfc822_version != NULL) {
                if (qualified_for_journaling) {
                        JournalBackgroundSubmit(msg, saved_rfc822_version, recps);
@@ -2786,14 +2741,12 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        if ((recps != NULL) && (recps->bounce_to == bounce_to))
                recps->bounce_to = NULL;
 
-       /* Done. */
+       // Done.
        return(newmsgid);
 }
 
 
-/*
- * Convenience function for generating small administrative messages.
- */
+// Convenience function for generating small administrative messages.
 long quickie_message(char *from,
                     char *fromaddr,
                     char *to,
@@ -2846,9 +2799,7 @@ long quickie_message(char *from,
 }
 
 
-/*
- * Back end function used by CtdlMakeMessage() and similar functions
- */
+// Back end function used by CtdlMakeMessage() and similar functions
 StrBuf *CtdlReadMessageBodyBuf(char *terminator,       // token signalling EOT
                               long tlen,
                               size_t maxlen,           // maximum message length
@@ -2869,12 +2820,12 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator,        // token signalling EOT
                Message = NewStrBufDup(exist);
        }
 
-       /* Do we need to change leading ".." to "." for SMTP escaping? */
+       // Do we need to change leading ".." to "." for SMTP escaping?
        if ((tlen == 1) && (*terminator == '.')) {
                dotdot = 1;
        }
 
-       /* read in the lines of message text one by one */
+       // read in the lines of message text one by one
        do {
                if (CtdlClientGetLine(LineBuf) < 0) {
                        finished = 1;
@@ -2890,14 +2841,14 @@ StrBuf *CtdlReadMessageBodyBuf(char *terminator,        // token signalling EOT
                                StrBufAppendBufPlain(LineBuf, HKEY("\n"), 0);
                        }
                        
-                       /* Unescape SMTP-style input of two dots at the beginning of the line */
+                       // Unescape SMTP-style input of two dots at the beginning of the line
                        if ((dotdot) && (StrLength(LineBuf) > 1) && (ChrPtr(LineBuf)[0] == '.')) {
                                StrBufCutLeft(LineBuf, 1);
                        }
                        StrBufAppendBuf(Message, LineBuf, 0);
                }
 
-               /* if we've hit the max msg length, flush the rest */
+               // if we've hit the max msg length, flush the rest
                if (StrLength(Message) >= maxlen) {
                        flushing = 1;
                }
@@ -2938,73 +2889,71 @@ char *CtdlReadMessageBody(char *terminator,     // token signalling EOT
 
 
 struct CtdlMessage *CtdlMakeMessage(
-        struct ctdluser *author,        /* author's user structure */
-        char *recipient,                /* NULL if it's not mail */
-        char *recp_cc,                 /* NULL if it's not mail */
-        char *room,                     /* room where it's going */
-        int type,                       /* see MES_ types in header file */
-        int format_type,                /* variformat, plain text, MIME... */
-        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 *preformatted_text,        /* ...or NULL to read text from client */
-       char *references                /* Thread references */
+        struct ctdluser *author,        // author's user structure
+        char *recipient,                // NULL if it's not mail
+        char *recp_cc,                 // NULL if it's not mail
+        char *room,                     // room where it's going
+        int type,                       // see MES_ types in header file
+        int format_type,                // variformat, plain text, MIME...
+        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 *preformatted_text,        // ...or NULL to read text from client
+       char *references                // Thread references
 ) {
        return CtdlMakeMessageLen(
-               author, /* author's user structure */
-               recipient,              /* NULL if it's not mail */
+               author,                                 // author's user structure 
+               recipient,                              // NULL if it's not mail
                (recipient)?strlen(recipient) : 0,
-               recp_cc,                        /* NULL if it's not mail */
+               recp_cc,                                // NULL if it's not mail
                (recp_cc)?strlen(recp_cc): 0,
-               room,                   /* room where it's going */
+               room,                                   // room where it's going
                (room)?strlen(room): 0,
-               type,                   /* see MES_ types in header file */
-               format_type,            /* variformat, plain text, MIME... */
-               fake_name,              /* who we're masquerading as */
+               type,                                   // see MES_ types in header file
+               format_type,                            // variformat, plain text, MIME...
+               fake_name,                              // who we're masquerading as
                (fake_name)?strlen(fake_name): 0,
-               my_email,                       /* which of my email addresses to use (empty is ok) */
+               my_email,                               // which of my email addresses to use (empty is ok)
                (my_email)?strlen(my_email): 0,
-               subject,                        /* Subject (optional) */
+               subject,                                // Subject (optional)
                (subject)?strlen(subject): 0,
-               supplied_euid,          /* ...or NULL if this is irrelevant */
+               supplied_euid,                          // ...or NULL if this is irrelevant
                (supplied_euid)?strlen(supplied_euid):0,
-               preformatted_text,      /* ...or NULL to read text from client */
+               preformatted_text,                      // ...or NULL to read text from client
                (preformatted_text)?strlen(preformatted_text) : 0,
-               references,             /* Thread references */
+               references,                             // Thread references
                (references)?strlen(references):0);
 
 }
 
 
-/*
- * Build a binary message to be saved on disk.
- * (NOTE: if you supply 'preformatted_text', the buffer you give it
- * will become part of the message.  This means you are no longer
- * responsible for managing that memory -- it will be freed along with
- * the rest of the fields when CM_Free() is called.)
- */
+// Build a binary message to be saved on disk.
+// (NOTE: if you supply 'preformatted_text', the buffer you give it
+// will become part of the message.  This means you are no longer
+// responsible for managing that memory -- it will be freed along with
+// the rest of the fields when CM_Free() is called.)
 struct CtdlMessage *CtdlMakeMessageLen(
-       struct ctdluser *author,        /* author's user structure */
-       char *recipient,                /* NULL if it's not mail */
+       struct ctdluser *author,        // author's user structure
+       char *recipient,                // NULL if it's not mail
        long rcplen,
-       char *recp_cc,                  /* NULL if it's not mail */
+       char *recp_cc,                  // NULL if it's not mail
        long cclen,
-       char *room,                     /* room where it's going */
+       char *room,                     // room where it's going
        long roomlen,
-       int type,                       /* see MES_ types in header file */
-       int format_type,                /* variformat, plain text, MIME... */
-       char *fake_name,                /* who we're masquerading as */
+       int type,                       // see MES_ types in header file
+       int format_type,                // variformat, plain text, MIME...
+       char *fake_name,                // who we're masquerading as
        long fnlen,
-       char *my_email,                 /* which of my email addresses to use (empty is ok) */
+       char *my_email,                 // which of my email addresses to use (empty is ok)
        long myelen,
-       char *subject,                  /* Subject (optional) */
+       char *subject,                  // Subject (optional)
        long subjlen,
-       char *supplied_euid,            /* ...or NULL if this is irrelevant */
+       char *supplied_euid,            // ...or NULL if this is irrelevant
        long euidlen,
-       char *preformatted_text,        /* ...or NULL to read text from client */
+       char *preformatted_text,        // ...or NULL to read text from client
        long textlen,
-       char *references,               /* Thread references */
+       char *references,               // Thread references
        long reflen
 ) {
        long blen;
@@ -3022,7 +2971,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        if (recipient != NULL) rcplen = string_trim(recipient);
        if (recp_cc != NULL) cclen = string_trim(recp_cc);
 
-       /* Path or Return-Path */
+       // Path or Return-Path
        if (myelen > 0) {
                CM_SetField(msg, eMessagePath, my_email);
        }
@@ -3045,7 +2994,7 @@ struct CtdlMessage *CtdlMakeMessageLen(
        FreeStrBuf(&FakeAuthor);
 
        if (!!IsEmptyStr(CC->room.QRname)) {
-               if (CC->room.QRflags & QR_MAILBOX) {            /* room */
+               if (CC->room.QRflags & QR_MAILBOX) {            // room
                        CM_SetField(msg, eOriginalRoom, &CC->room.QRname[11]);
                }
                else {
@@ -3075,13 +3024,11 @@ struct CtdlMessage *CtdlMakeMessageLen(
                        long IsAscii;
                        IsAscii = -1;
                        i = 0;
-                       while ((subject[i] != '\0') &&
-                              (IsAscii = isascii(subject[i]) != 0 ))
+                       while ((subject[i] != '\0') && (IsAscii = isascii(subject[i]) != 0 ))
                                i++;
                        if (IsAscii != 0)
                                CM_SetField(msg, eMsgSubject, subject);
-                       else /* ok, we've got utf8 in the string. */
-                       {
+                       else {  // ok, we've got utf8 in the string.
                                char *rfc2047Subj;
                                rfc2047Subj = rfc2047encode(subject, length);
                                CM_SetAsField(msg, eMsgSubject, &rfc2047Subj, strlen(rfc2047Subj));
@@ -3113,10 +3060,8 @@ struct CtdlMessage *CtdlMakeMessageLen(
 }
 
 
-/*
- * API function to delete messages which match a set of criteria
- * (returns the actual number of messages deleted)
- */
+// API function to delete messages which match a set of criteria
+// (returns the actual number of messages deleted)
 int CtdlDeleteMessages(const char *room_name,  // which room
                       long *dmsgnums,          // array of msg numbers to be deleted
                       int num_dmsgnums,        // number of msgs to be deleted, or 0 for "any"
@@ -3141,11 +3086,11 @@ int CtdlDeleteMessages(const char *room_name,   // which room
                }
        syslog(LOG_DEBUG, "msgbase: CtdlDeleteMessages(%s, %d msgs, %s)", room_name, num_dmsgnums, content_type);
 
-       /* get room record, obtaining a lock... */
+       // get room record, obtaining a lock...
        if (CtdlGetRoomLock(&qrbuf, room_name) != 0) {
                syslog(LOG_ERR, "msgbase: CtdlDeleteMessages(): Room <%s> not found", room_name);
                if (need_to_free_re) regfree(&re);
-               return(0);      /* room not found */
+               return(0);      // room not found
        }
 
        num_msgs = CtdlFetchMsgList(qrbuf.QRnumber, &msglist);
@@ -3164,11 +3109,10 @@ int CtdlDeleteMessages(const char *room_name,   // which room
                while ((i < num_msgs) && (have_more_del)) {
                        delete_this = 0x00;
 
-                       /* Set/clear a bit for each criterion */
+                       // Set/clear a bit for each criterion
 
-                       /* 0 messages in the list or a null list means that we are
-                        * interested in deleting any messages which meet the other criteria.
-                        */
+                       // 0 messages in the list or a null list means that we are
+                       // interested in deleting any messages which meet the other criteria.
                        if (have_delmsgs) {
                                delete_this |= 0x01;
                        }
@@ -3190,11 +3134,12 @@ int CtdlDeleteMessages(const char *room_name,   // which room
                                if (regexec(&re, smi.meta_content_type, 1, &pm, 0) == 0) {
                                        delete_this |= 0x02;
                                }
-                       } else {
+                       }
+                       else {
                                delete_this |= 0x02;
                        }
 
-                       /* Delete message only if all bits are set */
+                       // Delete message only if all bits are set
                        if (delete_this == 0x03) {
                                dellist[num_deleted++] = msglist[i];
                                msglist[i] = 0L;
@@ -3214,21 +3159,19 @@ int CtdlDeleteMessages(const char *room_name,   // which room
        }
        CtdlPutRoomLock(&qrbuf);
 
-       /* Go through the messages we pulled out of the index, and decrement
-        * their reference counts by 1.  If this is the only room the message
-        * was in, the reference count will reach zero and the message will
-        * automatically be deleted from the database.  We do this in a
-        * separate pass because there might be plug-in hooks getting called,
-        * and we don't want that happening during an S_ROOMS critical
-        * section.
-        */
+       // Go through the messages we pulled out of the index, and decrement
+       // their reference counts by 1.  If this is the only room the message
+       // was in, the reference count will reach zero and the message will
+       // automatically be deleted from the database.  We do this in a
+       // separate pass because there might be plug-in hooks getting called,
+       // and we don't want that happening during an S_ROOMS critical section.
        if (num_deleted) {
                for (i=0; i<num_deleted; ++i) {
                        PerformDeleteHooks(qrbuf.QRname, dellist[i]);
                }
                AdjRefCountList(dellist, num_deleted, -1);
        }
-       /* Now free the memory we used, and go away. */
+       // Now free the memory we used, and go away.
        if (msglist != NULL) free(msglist);
        if (dellist != NULL) free(dellist);
        syslog(LOG_DEBUG, "msgbase: %d message(s) deleted", num_deleted);
@@ -3237,37 +3180,32 @@ int CtdlDeleteMessages(const char *room_name,   // which room
 }
 
 
-/*
- * GetMetaData()  -  Get the supplementary record for a message
- */
+// GetMetaData()  -  Get the supplementary record for a message
 void GetMetaData(struct MetaData *smibuf, long msgnum) {
        struct cdbdata cdbsmi;
        long TheIndex;
 
        memset(smibuf, 0, sizeof(struct MetaData));
        smibuf->meta_msgnum = msgnum;
-       smibuf->meta_refcount = 1;      /* Default reference count is 1 */
+       smibuf->meta_refcount = 1;      // Default reference count is 1
 
-       /* Use the negative of the message number for its supp record index */
+       // Use the negative of the message number for its supp record index
        TheIndex = (0L - msgnum);
 
        cdbsmi = cdb_fetch(CDB_MSGMAIN, &TheIndex, sizeof(long));
        if (cdbsmi.ptr == NULL) {
-               return;                 /* record not found; leave it alone */
+               return;                 // record not found; leave it alone
        }
        memcpy(smibuf, cdbsmi.ptr, ((cdbsmi.len > sizeof(struct MetaData)) ? sizeof(struct MetaData) : cdbsmi.len));
        return;
 }
 
 
-/*
- * PutMetaData()  -  (re)write supplementary record for a message
- */
-void PutMetaData(struct MetaData *smibuf)
-{
+// PutMetaData()  -  (re)write supplementary record for a message
+void PutMetaData(struct MetaData *smibuf) {
        long TheIndex;
 
-       /* Use the negative of the message number for the metadata db index */
+       // Use the negative of the message number for the metadata db index
        TheIndex = (0L - smibuf->meta_msgnum);
 
        cdb_store(CDB_MSGMAIN,
@@ -3383,27 +3321,27 @@ long CtdlWriteObject(char *req_room,                    // Room to stuff it in
        
        CM_SetAsFieldSB(msg, eMesageText, &encoded_message);
 
-       /* Create the requested room if we have to. */
+       // Create the requested room if we have to.
        if (CtdlGetRoom(&qrbuf, roomname) != 0) {
                CtdlCreateRoom(roomname, ( (is_mailbox != NULL) ? 5 : 3 ), "", 0, 1, 0, VIEW_BBS);
        }
 
-       /* Now write the data */
+       // Now write the data
        long new_msgnum = CtdlSubmitMsg(msg, NULL, roomname);
        CM_Free(msg);
        return new_msgnum;
 }
 
 
-/************************************************************************/
-/*                      MODULE INITIALIZATION                           */
-/************************************************************************/
+/************************************************************************/
+/*                      MODULE INITIALIZATION                           */
+/************************************************************************/
 
 char *ctdl_module_init_msgbase(void) {
        if (!threading) {
                FillMsgKeyLookupTable();
        }
 
-        /* return our module id for the log */
+        // return our module id for the log
        return "msgbase";
 }