Replace all discrete checks for empty message fields by CM_IsEmpty()
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 1 Sep 2013 12:33:21 +0000 (14:33 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 1 Sep 2013 12:33:21 +0000 (14:33 +0200)
21 files changed:
citadel/euidindex.c
citadel/internet_addressing.c
citadel/journaling.c
citadel/modules/blog/serv_blog.c
citadel/modules/calendar/serv_calendar.c
citadel/modules/extnotify/extnotify_main.c
citadel/modules/fulltext/serv_fulltext.c
citadel/modules/imap/imap_fetch.c
citadel/modules/imap/imap_search.c
citadel/modules/inetcfg/serv_inetcfg.c
citadel/modules/network/serv_netfilter.c
citadel/modules/network/serv_netmail.c
citadel/modules/network/serv_netspool.c
citadel/modules/network/serv_network.c
citadel/modules/sieve/serv_sieve.c
citadel/modules/smtp/serv_smtp.c
citadel/modules/spam/serv_spam.c
citadel/modules/vcard/serv_vcard.c
citadel/modules/wiki/serv_wiki.c
citadel/msgbase.c
citadel/msgbase.h

index bcf0606ed1ea67dc79476c2f6f34c39f2a78d66c..8a40cce13662a8b8100a0ffe760e454d6b2939de 100644 (file)
@@ -162,7 +162,7 @@ void rebuild_euid_index_for_msg(long msgnum, void *userdata) {
 
        msg = CtdlFetchMessage(msgnum, 0);
        if (msg == NULL) return;
-       if (msg->cm_fields[eExclusiveID] != NULL) {
+       if (!CM_IsEmpty(msg, eExclusiveID)) {
                index_message_by_euid(msg->cm_fields[eExclusiveID], &CC->room, msgnum);
        }
        CtdlFreeMessage(msg);
index 14c9900dfcc1bfd4cf8a6ec43f7d685e7634162d..32e70af1a1a73f034025c0e03152b0fa1ff12038 100644 (file)
@@ -589,7 +589,7 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
                parsed_date = parsedate(value);
                if (parsed_date < 0L) parsed_date = time(NULL);
 
-               if (msg->cm_fields[eTimestamp] == NULL)
+               if (CM_IsEmpty(msg, eTimestamp))
                        CM_SetFieldLONG(msg, eTimestamp, parsed_date);
                processed = 1;
        }
@@ -598,39 +598,39 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
                process_rfc822_addr(value, user, node, name);
                syslog(LOG_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
                snprintf(addr, sizeof(addr), "%s@%s", user, node);
-               if (msg->cm_fields[eAuthor] == NULL)
+               if (CM_IsEmpty(msg, eAuthor))
                        CM_SetField(msg, eAuthor, name, strlen(name));
-               if (msg->cm_fields[erFc822Addr] == NULL)
+               if (CM_IsEmpty(msg, erFc822Addr))
                        CM_SetField(msg, erFc822Addr, addr, strlen(addr));
                processed = 1;
        }
 
        else if (!strcasecmp(key, "Subject")) {
-               if (msg->cm_fields[eMsgSubject] == NULL)
+               if (CM_IsEmpty(msg, eMsgSubject))
                        CM_SetField(msg, eMsgSubject, value, valuelen);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "List-ID")) {
-               if (msg->cm_fields[eListID] == NULL)
+               if (CM_IsEmpty(msg, eListID))
                        CM_SetField(msg, eListID, value, valuelen);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "To")) {
-               if (msg->cm_fields[eRecipient] == NULL)
+               if (CM_IsEmpty(msg, eRecipient))
                        CM_SetField(msg, eRecipient, value, valuelen);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "CC")) {
-               if (msg->cm_fields[eCarbonCopY] == NULL)
+               if (CM_IsEmpty(msg, eCarbonCopY))
                        CM_SetField(msg, eCarbonCopY, value, valuelen);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "Message-ID")) {
-               if (msg->cm_fields[emessageId] != NULL) {
+               if (!CM_IsEmpty(msg, emessageId)) {
                        syslog(LOG_WARNING, "duplicate message id\n");
                }
                else {
@@ -658,13 +658,13 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
        }
 
        else if (!strcasecmp(key, "Return-Path")) {
-               if (msg->cm_fields[eMessagePath] == NULL)
+               if (CM_IsEmpty(msg, eMessagePath))
                        CM_SetField(msg, eMessagePath, value, valuelen);
                processed = 1;
        }
 
        else if (!strcasecmp(key, "Envelope-To")) {
-               if (msg->cm_fields[eenVelopeTo] == NULL)
+               if (CM_IsEmpty(msg, eenVelopeTo))
                        CM_SetField(msg, eenVelopeTo, value, valuelen);
                processed = 1;
        }
@@ -680,7 +680,7 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
        }
 
        else if (!strcasecmp(key, "In-reply-to")) {
-               if (msg->cm_fields[eWeferences] == NULL) /* References: supersedes In-reply-to: */
+               if (CM_IsEmpty(msg, eWeferences)) /* References: supersedes In-reply-to: */
                        CM_SetField(msg, eWeferences, value, valuelen);
                processed = 1;
        }
@@ -821,14 +821,14 @@ struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822)
        /* Follow-up sanity checks... */
 
        /* If there's no timestamp on this message, set it to now. */
-       if (msg->cm_fields[eTimestamp] == NULL) {
+       if (CM_IsEmpty(msg, eTimestamp)) {
                CM_SetFieldLONG(msg, eTimestamp, time(NULL));
        }
 
        /* If a W (references, or rather, Wefewences) field is present, we
         * have to convert it from RFC822 format to Citadel format.
         */
-       if (msg->cm_fields[eWeferences] != NULL) {
+       if (!CM_IsEmpty(msg, eWeferences)) {
                /// todo: API!
                convert_references_to_wefewences(msg->cm_fields[eWeferences]);
        }
@@ -1022,10 +1022,10 @@ char *harvest_collected_addresses(struct CtdlMessage *msg) {
 
        is_harvestable = 1;
        strcpy(addr, "");       
-       if (msg->cm_fields[eAuthor] != NULL) {
+       if (!CM_IsEmpty(msg, eAuthor)) {
                strcat(addr, msg->cm_fields[eAuthor]);
        }
-       if (msg->cm_fields[erFc822Addr] != NULL) {
+       if (!CM_IsEmpty(msg, erFc822Addr)) {
                strcat(addr, " <");
                strcat(addr, msg->cm_fields[erFc822Addr]);
                strcat(addr, ">");
@@ -1048,7 +1048,7 @@ char *harvest_collected_addresses(struct CtdlMessage *msg) {
                if (i == 0) field = eRecipient;
                if (i == 1) field = eCarbonCopY;
 
-               if (msg->cm_fields[field] != NULL) {
+               if (!CM_IsEmpty(msg, field)) {
                        for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
                                extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
                                if (strstr(addr, "=?") != NULL)
index d1daf5a7acd7ca3628f23c18638ec4f33e12e8ab..9ea593bd827f9615e620a51b807d786b8704e8b3 100644 (file)
@@ -59,7 +59,7 @@ void JournalBackgroundSubmit(struct CtdlMessage *msg,
        struct jnlq *jptr = NULL;
 
        /* Avoid double journaling! */
-       if (msg->cm_fields[eJournal] != NULL) {
+       if (!CM_IsEmpty(msg, eJournal)) {
                FreeStrBuf(&saved_rfc822_version);
                return;
        }
@@ -71,11 +71,11 @@ void JournalBackgroundSubmit(struct CtdlMessage *msg,
        }
        memset(jptr, 0, sizeof(struct jnlq));
        if (recps != NULL) memcpy(&jptr->recps, recps, sizeof(struct recptypes));
-       if (msg->cm_fields[eAuthor] != NULL) jptr->from = strdup(msg->cm_fields[eAuthor]);
-       if (msg->cm_fields[eNodeName] != NULL) jptr->node = strdup(msg->cm_fields[eNodeName]);
-       if (msg->cm_fields[erFc822Addr] != NULL) jptr->rfca = strdup(msg->cm_fields[erFc822Addr]);
-       if (msg->cm_fields[eMsgSubject] != NULL) jptr->subj = strdup(msg->cm_fields[eMsgSubject]);
-       if (msg->cm_fields[emessageId] != NULL) jptr->msgn = strdup(msg->cm_fields[emessageId]);
+       if (!CM_IsEmpty(msg, eAuthor)) jptr->from = strdup(msg->cm_fields[eAuthor]);
+       if (!CM_IsEmpty(msg, eNodeName)) jptr->node = strdup(msg->cm_fields[eNodeName]);
+       if (!CM_IsEmpty(msg, erFc822Addr)) jptr->rfca = strdup(msg->cm_fields[erFc822Addr]);
+       if (!CM_IsEmpty(msg, eMsgSubject)) jptr->subj = strdup(msg->cm_fields[eMsgSubject]);
+       if (!CM_IsEmpty(msg, emessageId)) jptr->msgn = strdup(msg->cm_fields[emessageId]);
        jptr->rfc822 = SmashStrBuf(&saved_rfc822_version);
 
        /* Add to the queue */
@@ -193,7 +193,7 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
                                     "\r\n"
                                     "Sender: "), 0);
 
-                       if (journal_msg->cm_fields[eAuthor])
+                       if (CM_IsEmpty(journal_msg, eAuthor))
                                StrBufAppendBufPlain(
                                        message_text, 
                                        journal_msg->cm_fields[eAuthor], -1, 0);
@@ -202,11 +202,11 @@ void JournalRunQueueMsg(struct jnlq *jmsg) {
                                        message_text, 
                                        HKEY("(null)"), 0);
 
-                       if (journal_msg->cm_fields[erFc822Addr]) {
+                       if (!CM_IsEmpty(journal_msg, erFc822Addr)) {
                                StrBufAppendPrintf(message_text, " <%s>",
                                                   journal_msg->cm_fields[erFc822Addr]);
                        }
-                       else if (journal_msg->cm_fields[eNodeName]) {
+                       else if (!CM_IsEmpty(journal_msg, eNodeName)) {
                                StrBufAppendPrintf(message_text, " @ %s",
                                                   journal_msg->cm_fields[eNodeName]);
                        }
index a6513e775cab8f93e5a2aff0ff97cd496b072646..891c2cccffe57429b8b54729edab3c49e5559bcb 100644 (file)
@@ -72,7 +72,7 @@ int blog_upload_beforesave(struct CtdlMessage *msg) {
        /* 
         * If the message doesn't have an EUID, give it one.
         */
-       if (msg->cm_fields[eExclusiveID] == NULL)
+       if (CM_IsEmpty(msg, eExclusiveID))
        {
                char uuid[SIZ];
                generate_uuid(uuid);
index a70baada454a2f2542ba6e3c23b993cf64abe9e5..e6b4fb4b097a93ccba07312525ecb11935522199 100644 (file)
@@ -2407,7 +2407,7 @@ int ical_obj_beforesave(struct CtdlMessage *msg)
                return(1);              /* You tried to save a non-RFC822 message! */
        }
 
-       if (msg->cm_fields[eMesageText] == NULL) {
+       if (CM_IsEmpty(msg, eMesageText)) {
                return(1);              /* You tried to save a null message! */
        }
 
@@ -2478,7 +2478,7 @@ int ical_obj_aftersave(struct CtdlMessage *msg)
        if (msg->cm_format_type != 4) return(1);
 
        /* Reject null messages */
-       if (msg->cm_fields[eMesageText] == NULL) return(1);
+       if (CM_IsEmpty(msg, eMesageText)) return(1);
        
        /* Now recurse through it looking for our icalendar data */
        mime_parser(msg->cm_fields[eMesageText],
index 6d865082ca7f30e0d5b9cf41958bf273834c4f28..3eced5a59967aaff2c5211dcb576936968e5ba4b 100644 (file)
@@ -186,7 +186,7 @@ eNotifyType extNotify_getConfigMessage(char *username,
        for (a = 0; a < num_msgs; ++a) {
                msg = CtdlFetchMessage(msglist[a], 1);
                if (msg != NULL) {
-                       if ((msg->cm_fields[eMsgSubject] != NULL) &&
+                       if (!CM_IsEmpty(msg, eMsgSubject) &&
                            (strncasecmp(msg->cm_fields[eMsgSubject],
                                         PAGER_CONFIG_MESSAGE,
                                         strlen(PAGER_CONFIG_MESSAGE)) == 0))
@@ -280,7 +280,7 @@ void process_notify(long NotifyMsgnum, void *usrdata)
        Ctx = (NotifyContext*) usrdata;
 
        msg = CtdlFetchMessage(NotifyMsgnum, 1);
-       if ( msg->cm_fields[eExtnotify] != NULL)
+       if (!CM_IsEmpty(msg, eExtnotify))
        {
                Type = extNotify_getConfigMessage(
                        msg->cm_fields[eExtnotify],
index 547caaefd216ea810535d6d67ed66f053e06ae7f..7943e344cc87a392c0947917e1374f7249b35318 100644 (file)
@@ -126,7 +126,7 @@ void ft_index_message(long msgnum, int op) {
                return;
        }
 
-       if (msg->cm_fields[eSuppressIdx] != NULL) {
+       if (!CM_IsEmpty(msg, eSuppressIdx)) {
                syslog(LOG_DEBUG, "ft_index_message() excluded msg %ld", msgnum);
                CtdlFreeMessage(msg);
                return;
index b9319610c8f0ed1e19ee07c8cdd8e14f45beeb3e..eb36ff9b38864062a99a1bdd30ed18bcd9457d2a 100644 (file)
@@ -110,7 +110,7 @@ void imap_fetch_internaldate(struct CtdlMessage *msg) {
        time_t msgdate;
 
        if (!msg) return;
-       if (msg->cm_fields[eTimestamp] != NULL) {
+       if (!CM_IsEmpty(msg, eTimestamp)) {
                msgdate = atol(msg->cm_fields[eTimestamp]);
        }
        else {
@@ -359,7 +359,7 @@ void imap_output_envelope_from(struct CtdlMessage *msg) {
        IAPuts(" NIL ");        /* source route (not used) */
 
 
-       if (msg->cm_fields[erFc822Addr] != NULL) {
+       if (!CM_IsEmpty(msg, erFc822Addr)) {
                process_rfc822_addr(msg->cm_fields[erFc822Addr], user, node, name);
                plain_imap_strout(user);                /* mailbox name (user id) */
                IAPuts(" ");
@@ -445,7 +445,7 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        if (!msg) return;
 
        /* Parse the message date into an IMAP-format date string */
-       if (msg->cm_fields[eTimestamp] != NULL) {
+       if (!CM_IsEmpty(msg, eTimestamp)) {
                msgdate = atol(msg->cm_fields[eTimestamp]);
        }
        else {
index 387e747c9e080eb67a353b9418cff4b1872bf8a5..aaa02dbe23260e4c3fbd8e22aa3317552b09df0f 100644 (file)
@@ -142,7 +142,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) < 0) {
                                        match = 1;
@@ -308,7 +308,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) == 0) {
                                        match = 1;
@@ -338,7 +338,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) < 0) {
                                        match = 1;
@@ -354,7 +354,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) == 0) {
                                        match = 1;
@@ -370,7 +370,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) >= 0) {
                                        match = 1;
@@ -386,7 +386,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (msg->cm_fields[eTimestamp] != NULL) {
+                       if (!CM_IsEmpty(msg, eTimestamp)) {
                                if (imap_datecmp(itemlist[pos+1].Key,
                                                atol(msg->cm_fields[eTimestamp])) >= 0) {
                                        match = 1;
index 8aa98b2d1da5dec9374f38046b8a25ffe7444de6..44e1a4c0149fb24db782a89c949e89c694746c06 100644 (file)
@@ -66,7 +66,7 @@ void inetcfg_setTo(struct CtdlMessage *msg) {
        char *conf;
        char buf[SIZ];
        
-       if (msg->cm_fields[eMesageText]==NULL) return;
+       if (CM_IsEmpty(msg, eMesageText)) return;
        conf = strdup(msg->cm_fields[eMesageText]);
 
        if (conf != NULL) {
index 0c2ca0e587d477e8bd2ae293c1dfdcb7737af5bc..588cced6ad6cea299220ae3dac6090af244afbd6 100644 (file)
@@ -149,28 +149,28 @@ int filter_the_idiots(struct CtdlMessage *msg, char *target_room) {
                zap_room = 0;
                zap_node = 0;
 
-               if (msg->cm_fields[eAuthor] != NULL) {
+               if (!CM_IsEmpty(msg, eAuthor)) {
                        if ( (!strcasecmp(msg->cm_fields[eAuthor], fptr->fl_user))
                           || (fptr->fl_user[0] == 0) ) {
                                zap_user = 1;
                        }
                }
 
-               if (msg->cm_fields[eRemoteRoom] != NULL) {
+               if (!CM_IsEmpty(msg, eRemoteRoom)) {
                        if ( (!strcasecmp(msg->cm_fields[eRemoteRoom], fptr->fl_room))
                           || (fptr->fl_room[0] == 0) ) {
                                zap_room = 1;
                        }
                }
 
-               if (msg->cm_fields[eOriginalRoom] != NULL) {
+               if (!CM_IsEmpty(msg, eOriginalRoom)) {
                        if ( (!strcasecmp(msg->cm_fields[eOriginalRoom], fptr->fl_room))
                           || (fptr->fl_room[0] == 0) ) {
                                zap_room = 1;
                        }
                }
 
-               if (msg->cm_fields[eNodeName] != NULL) {
+               if (!CM_IsEmpty(msg, eNodeName)) {
                        if ( (!strcasecmp(msg->cm_fields[eNodeName], fptr->fl_node))
                           || (fptr->fl_node[0] == 0) ) {
                                zap_node = 1;
index dd47f2592c3f2562c743b1fa8bdd6738aa6b07ac..287436bbfa0bc535745352b27e2fbf358b9d1708 100644 (file)
@@ -133,7 +133,7 @@ static void ListCalculateSubject(struct CtdlMessage *msg)
        int rlen;
        char *pCh;
 
-       if (msg->cm_fields[eMsgSubject] == NULL) {
+       if (CM_IsEmpty(msg, eMsgSubject)) {
                Subject = NewStrBufPlain(HKEY("(no subject)"));
        }
        else {
@@ -263,23 +263,23 @@ void network_process_digest(SpoolControl *sc, struct CtdlMessage *omsg, long *de
                        "------------------------------------"
                        "-------\n");
                fprintf(sc->digestfp, "From: ");
-               if (msg->cm_fields[eAuthor] != NULL) {
+               if (!CM_IsEmpty(msg, eAuthor)) {
                        fprintf(sc->digestfp,
                                "%s ",
                                msg->cm_fields[eAuthor]);
                }
-               if (msg->cm_fields[erFc822Addr] != NULL) {
+               if (!CM_IsEmpty(msg, erFc822Addr)) {
                        fprintf(sc->digestfp,
                                "<%s> ",
                                msg->cm_fields[erFc822Addr]);
                }
-               else if (msg->cm_fields[eNodeName] != NULL) {
+               else if (!CM_IsEmpty(msg, eNodeName)) {
                        fprintf(sc->digestfp,
                                "@%s ",
                                msg->cm_fields[eNodeName]);
                }
                fprintf(sc->digestfp, "\n");
-               if (msg->cm_fields[eMsgSubject] != NULL) {
+               if (!CM_IsEmpty(msg, eMsgSubject)) {
                        fprintf(sc->digestfp,
                                "Subject: %s\n",
                                msg->cm_fields[eMsgSubject]);
@@ -333,8 +333,7 @@ void network_process_list(SpoolControl *sc, struct CtdlMessage *omsg, long *dele
         * of the list message to the email address of the
         * room itself.
         */
-       if ((msg->cm_fields[eRecipient] == NULL) ||
-           IsEmptyStr(msg->cm_fields[eRecipient]))
+       if (CM_IsEmpty(msg, eRecipient))
        {
                CM_SetField(msg, eRecipient, SKEY(sc->Users[roommailalias]));
        }
@@ -403,7 +402,7 @@ void network_process_participate(SpoolControl *sc, struct CtdlMessage *omsg, lon
         * is rude...
         */
        ok_to_participate = 0;
-       if (msg->cm_fields[eNodeName] != NULL) {
+       if (!CM_IsEmpty(msg, eNodeName)) {
                if (!strcasecmp(msg->cm_fields[eNodeName],
                                config.c_nodename)) {
                        ok_to_participate = 1;
@@ -471,7 +470,7 @@ void network_process_ignetpush(SpoolControl *sc, struct CtdlMessage *omsg, long
         * Determine if this message is set to be deleted
         * after sending out on the network
         */
-       if (msg->cm_fields[eSpecialField] != NULL) {
+       if (!CM_IsEmpty(msg, eSpecialField)) {
                if (!strcasecmp(msg->cm_fields[eSpecialField], "CANCEL")) {
                        *delete_after_send = 1;
                }
index dac6db41c3bce08bd93df8a2b5cd992c814ace90..586b945da602211353986efa4f10609f0e841f66 100644 (file)
@@ -166,7 +166,7 @@ void Netmap_AddMe(struct CtdlMessage *msg, const char *defl, long defllen)
        char buf[SIZ];
 
        /* prepend our node to the path */
-       if (msg->cm_fields[eMessagePath] == NULL) {
+       if (CM_IsEmpty(msg, eMessagePath)) {
                CM_SetField(msg, eMessagePath, defl, defllen);
        }
        node_len = strlen(config.c_nodename);
@@ -459,7 +459,7 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
        }
 
        /* Check for message routing */
-       if (msg->cm_fields[eDestination] != NULL) {
+       if (!CM_IsEmpty(msg, eDestination)) {
                if (strcasecmp(msg->cm_fields[eDestination], config.c_nodename)) {
 
                        /* route the message */
@@ -527,7 +527,7 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
        }
 
        /* Learn network topology from the path */
-       if ((msg->cm_fields[eNodeName] != NULL) && (msg->cm_fields[eMessagePath] != NULL)) {
+       if (!CM_IsEmpty(msg, eNodeName) && !CM_IsEmpty(msg, eMessagePath)) {
                NetworkLearnTopology(msg->cm_fields[eNodeName], 
                                     msg->cm_fields[eMessagePath], 
                                     the_netmap, 
@@ -537,12 +537,12 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
        /* Is the sending node giving us a very persuasive suggestion about
         * which room this message should be saved in?  If so, go with that.
         */
-       if (msg->cm_fields[eRemoteRoom] != NULL) {
+       if (!CM_IsEmpty(msg, eRemoteRoom)) {
                safestrncpy(target_room, msg->cm_fields[eRemoteRoom], sizeof target_room);
        }
 
        /* Otherwise, does it have a recipient?  If so, validate it... */
-       else if (msg->cm_fields[eRecipient] != NULL) {
+       else if (!CM_IsEmpty(msg, eRecipient)) {
                recp = validate_recipients(msg->cm_fields[eRecipient], NULL, 0);
                if (recp != NULL) if (recp->num_error != 0) {
                        network_bounce(msg,
@@ -559,7 +559,7 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
        /* Our last shot at finding a home for this message is to see if
         * it has the eOriginalRoom (O) field (Originating room) set.
         */
-       else if (msg->cm_fields[eOriginalRoom] != NULL) {
+       else if (!CM_IsEmpty(msg, eOriginalRoom)) {
                safestrncpy(target_room, msg->cm_fields[eOriginalRoom], sizeof target_room);
        }
 
index b2b296ef8bae2510ac99513535abe49b8943ccfb..8533d8410fce7e0954b5561c8a701dde34859689 100644 (file)
@@ -111,7 +111,7 @@ int network_usetable(struct CtdlMessage *msg)
        time_t now;
 
        /* Bail out if we can't generate a message ID */
-       if ((msg == NULL) || (msg->cm_fields[emessageId] == NULL) || (IsEmptyStr(msg->cm_fields[emessageId])))
+       if ((msg == NULL) || CM_IsEmpty(msg, emessageId))
        {
                return(0);
        }
@@ -120,7 +120,7 @@ int network_usetable(struct CtdlMessage *msg)
        msgid = NewStrBufPlain(msg->cm_fields[emessageId], -1);
        if (haschar(ChrPtr(msgid), '@') == 0) {
                StrBufAppendBufPlain(msgid, HKEY("@"), 0);
-               if (msg->cm_fields[eNodeName] != NULL) {
+               if (!CM_IsEmpty(msg, eNodeName)) {
                        StrBufAppendBufPlain(msgid, msg->cm_fields[eNodeName], -1, 0);
                }
                else {
index 4a9fcbf0f4a5a87da0ca1d6c4393a5e4efe158d8..a1b6f40080ab4852759ea17dbc2ca96b57c2aae0 100644 (file)
@@ -586,13 +586,13 @@ void sieve_do_msg(long msgnum, void *userdata) {
        process_rfc822_addr(msg->cm_fields[eRecipient], my.recp_user, my.recp_node, my.recp_name);
 
        /* Keep track of the sender so we can use it for REJECT and VACATION responses */
-       if (msg->cm_fields[erFc822Addr] != NULL) {
+       if (!CM_IsEmpty(msg, erFc822Addr)) {
                safestrncpy(my.sender, msg->cm_fields[erFc822Addr], sizeof my.sender);
        }
-       else if ( (msg->cm_fields[eAuthor] != NULL) && (msg->cm_fields[eNodeName] != NULL) ) {
+       else if ( (!CM_IsEmpty(msg, eAuthor)) && (!CM_IsEmpty(msg, eNodeName)) ) {
                snprintf(my.sender, sizeof my.sender, "%s@%s", msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
        }
-       else if (msg->cm_fields[eAuthor] != NULL) {
+       else if (!CM_IsEmpty(msg, eAuthor)) {
                safestrncpy(my.sender, msg->cm_fields[eAuthor], sizeof my.sender);
        }
        else {
@@ -600,7 +600,7 @@ void sieve_do_msg(long msgnum, void *userdata) {
        }
 
        /* Keep track of the subject so we can use it for VACATION responses */
-       if (msg->cm_fields[eMsgSubject] != NULL) {
+       if (!CM_IsEmpty(msg, eMsgSubject)) {
                safestrncpy(my.subject, msg->cm_fields[eMsgSubject], sizeof my.subject);
        }
        else {
@@ -608,11 +608,11 @@ void sieve_do_msg(long msgnum, void *userdata) {
        }
 
        /* Keep track of the envelope-from address (use body-from if not found) */
-       if (msg->cm_fields[eMessagePath] != NULL) {
+       if (!CM_IsEmpty(msg, eMessagePath)) {
                safestrncpy(my.envelope_from, msg->cm_fields[eMessagePath], sizeof my.envelope_from);
                stripallbut(my.envelope_from, '<', '>');
        }
-       else if (msg->cm_fields[erFc822Addr] != NULL) {
+       else if (!CM_IsEmpty(msg, erFc822Addr)) {
                safestrncpy(my.envelope_from, msg->cm_fields[erFc822Addr], sizeof my.envelope_from);
                stripallbut(my.envelope_from, '<', '>');
        }
@@ -630,13 +630,13 @@ void sieve_do_msg(long msgnum, void *userdata) {
        }
 
        /* Keep track of the envelope-to address (use body-to if not found) */
-       if (msg->cm_fields[eenVelopeTo] != NULL) {
+       if (!CM_IsEmpty(msg, eenVelopeTo)) {
                safestrncpy(my.envelope_to, msg->cm_fields[eenVelopeTo], sizeof my.envelope_to);
                stripallbut(my.envelope_to, '<', '>');
        }
-       else if (msg->cm_fields[eRecipient] != NULL) {
+       else if (!CM_IsEmpty(msg, eRecipient)) {
                safestrncpy(my.envelope_to, msg->cm_fields[eRecipient], sizeof my.envelope_to);
-               if (msg->cm_fields[eDestination] != NULL) {
+               if (!CM_IsEmpty(msg, eDestination)) {
                        strcat(my.envelope_to, "@");
                        strcat(my.envelope_to, msg->cm_fields[eDestination]);
                }
index 9559d1c5a22e73251b4a5936cc1ae7d3254ae440..44fa78804c39283a5cd9d22c1e12d9fb580c3848 100644 (file)
@@ -320,7 +320,9 @@ void smtp_webcit_preferences_hack_backend(long msgnum, void *userdata) {
                return;
        }
 
-       if ( (msg->cm_fields[eMsgSubject]) && (!strcasecmp(msg->cm_fields[eMsgSubject], "__ WebCit Preferences __")) ) {
+       if ( !CM_IsEmpty(msg, eMsgSubject) &&
+            (!strcasecmp(msg->cm_fields[eMsgSubject], "__ WebCit Preferences __")))
+       {
                /* This is it!  Change ownership of the message text so it doesn't get freed. */
                *webcit_conf = (char *)msg->cm_fields[eMesageText];
                msg->cm_fields[eMesageText] = NULL;
@@ -813,7 +815,7 @@ void smtp_data(long offset, long flags)
        if ( (CCC->logged_in) && (config.c_rfc822_strict_from != CFG_SMTP_FROM_NOFILTER) ) {
                int validemail = 0;
                
-               if (!IsEmptyStr(msg->cm_fields[erFc822Addr])       &&
+               if (!CM_IsEmpty(msg, erFc822Addr)       &&
                    ((config.c_rfc822_strict_from == CFG_SMTP_FROM_CORRECT) || 
                     (config.c_rfc822_strict_from == CFG_SMTP_FROM_REJECT)    )  )
                {
@@ -875,7 +877,7 @@ void smtp_data(long offset, long flags)
 
        if (scan_errors > 0) {  /* We don't want this message! */
 
-               if (msg->cm_fields[eErrorMsg] == NULL) {
+               if (CM_IsEmpty(msg, eErrorMsg)) {
                        CM_SetField(msg, eErrorMsg, HKEY("Message rejected by filter"));
                }
 
index c0ced7eeb1dc86332c9439274c972e4ad0d09365..77365b16c3844735e16340dcb3d6f463d9a8a962 100644 (file)
@@ -176,9 +176,6 @@ int spam_assassin(struct CtdlMessage *msg) {
                }
 
                if (is_spam) {
-                       if (msg->cm_fields[eErrorMsg] != NULL) {
-                               free(msg->cm_fields[eErrorMsg]);
-                       }
                        CM_SetField(msg, eErrorMsg, HKEY("message rejected by spam filter"));
                }
        }
index 36fdb257d60d2f87cf14ed9999fcf06a6f0b8444..9f493a65d8f1ad63c7762ad9b586203ccd7f2a4e 100644 (file)
@@ -94,8 +94,8 @@ void vcard_extract_internet_addresses(struct CtdlMessage *msg, int (*callback)(c
        int instance = 0;
        int found_something = 0;
 
-       if (msg->cm_fields[eAuthor] == NULL) return;
-       if (msg->cm_fields[eNodeName] == NULL) return;
+       if (CM_IsEmpty(msg, eAuthor)) return;
+       if (CM_IsEmpty(msg, eNodeName)) return;
        snprintf(citadel_address, sizeof citadel_address, "%s @ %s",
                msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
 
@@ -330,7 +330,6 @@ void vcard_extract_vcard(char *name, char *filename, char *partnum, char *disp,
  */
 int vcard_upload_beforesave(struct CtdlMessage *msg) {
        struct CitContext *CCC = CC;
-       char *ptr;
        char *s;
        char buf[SIZ];
        struct ctdluser usbuf;
@@ -373,8 +372,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
 
        /* Ok, if we got this far, look into the situation further... */
 
-       ptr = msg->cm_fields[eMesageText];
-       if (ptr == NULL) return(0);
+       if (CM_IsEmpty(msg, eMesageText)) return(0);
 
        mime_parser(msg->cm_fields[eMesageText],
                NULL,
@@ -460,7 +458,7 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) {
        s = vcard_get_prop(v, "UID", 1, 0, 0);
        if (s != NULL) {
                CM_SetField(msg, eExclusiveID, s, strlen(s));
-               if (msg->cm_fields[eMsgSubject] == NULL) {
+               if (CM_IsEmpty(msg, eMsgSubject)) {
                        CM_CopyField(msg, eMsgSubject, eExclusiveID);
                }
        }
@@ -535,8 +533,10 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) {
 
        if (!is_UserConf && !is_GAB) return(0);
 
+       if (CM_IsEmpty(msg, eMesageText))
+               return 0;
+
        ptr = msg->cm_fields[eMesageText];
-       if (ptr == NULL) return(0);
 
        NewStrBufDupAppendFlush(&CCC->StatusMessage, NULL, NULL, 0);
 
@@ -934,8 +934,11 @@ int vcard_extract_from_network(struct CtdlMessage *msg, char *target_room) {
 
        if (msg->cm_format_type != 4) return(0);
 
+       if (CM_IsEmpty(msg, eMesageText))
+               return 0;
+
        ptr = msg->cm_fields[eMesageText];
-       if (ptr == NULL) return(0);
+
        while (ptr != NULL) {
        
                linelen = strcspn(ptr, "\n");
@@ -977,8 +980,11 @@ void vcard_delete_remove(char *room, long msgnum) {
        msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
 
+       if (CM_IsEmpty(msg, eMesageText))
+               goto EOH;
+
        ptr = msg->cm_fields[eMesageText];
-       if (ptr == NULL) goto EOH;
+
        while (ptr != NULL) {
                linelen = strcspn(ptr, "\n");
                if (linelen == 0) goto EOH;
index 33d856310f55e0907e9e04616239cac9af1932d3..052ab2ff37c2b7eb2a3394262043f4d7e2ea2c8d 100644 (file)
@@ -101,7 +101,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
        if (msg->cm_format_type != 4) return(0);
 
        /* If there's no EUID we can't do this.  Reject the post. */
-       if (msg->cm_fields[eExclusiveID] == NULL) return(1);
+       if (CM_IsEmpty(msg, eExclusiveID)) return(1);
 
        history_page_len = snprintf(history_page, sizeof history_page,
                                    "%s_HISTORY_", msg->cm_fields[eExclusiveID]);
@@ -117,7 +117,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
        }
 
        /* If there's no message text, obviously this is all b0rken and shouldn't happen at all */
-       if (msg->cm_fields[eMesageText] == NULL) return(0);
+       if (CM_IsEmpty(msg, eMesageText)) return(0);
 
        /* Set the message subject identical to the page name */
        CM_CopyField(msg, eMsgSubject, eExclusiveID);
@@ -131,7 +131,7 @@ int wiki_upload_beforesave(struct CtdlMessage *msg) {
                old_msg = NULL;
        }
 
-       if ((old_msg != NULL) && (old_msg->cm_fields[eMesageText] == NULL)) {   /* old version is corrupt? */
+       if ((old_msg != NULL) && (CM_IsEmpty(old_msg, eMesageText))) {  /* old version is corrupt? */
                CtdlFreeMessage(old_msg);
                old_msg = NULL;
        }
@@ -394,7 +394,7 @@ void wiki_history(char *pagename) {
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
                CtdlFreeMessage(msg);
                msg = NULL;
        }
@@ -526,7 +526,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
                CtdlFreeMessage(msg);
                msg = NULL;
        }
@@ -560,7 +560,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
                msg = NULL;
        }
 
-       if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+       if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
                CtdlFreeMessage(msg);
                msg = NULL;
        }
index cc52aec73a6ab67abb45b58e5931f8357b8ad486..73d6bfe199af3f8bce5cc17d615ea9d48ec1a80a 100644 (file)
@@ -156,6 +156,13 @@ eMsgField FieldOrder[]  = {
 };
 
 static const long NDiskFields = sizeof(FieldOrder) / sizeof(eMsgField);
+
+int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which)
+{
+       return !((Msg->cm_fields[which] != NULL) &&
+                (Msg->cm_fields[which][0] != '\0'));
+}
+
 void CM_SetField(struct CtdlMessage *Msg, eMsgField which, const char *buf, long length)
 {
        if (Msg->cm_fields[which] != NULL)
@@ -425,11 +432,11 @@ void headers_listing(long msgnum, void *userdata)
 
        cprintf("%ld|%s|%s|%s|%s|%s|\n",
                msgnum,
-               (msg->cm_fields[eTimestamp] ? msg->cm_fields[eTimestamp] : "0"),
-               (msg->cm_fields[eAuthor] ? msg->cm_fields[eAuthor] : ""),
-               (msg->cm_fields[eNodeName] ? msg->cm_fields[eNodeName] : ""),
-               (msg->cm_fields[erFc822Addr] ? msg->cm_fields[erFc822Addr] : ""),
-               (msg->cm_fields[eMsgSubject] ? msg->cm_fields[eMsgSubject] : "")
+               (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0"),
+               (!CM_IsEmpty(msg, eAuthor) ? msg->cm_fields[eAuthor] : ""),
+               (!CM_IsEmpty(msg, eNodeName) ? msg->cm_fields[eNodeName] : ""),
+               (!CM_IsEmpty(msg, erFc822Addr) ? msg->cm_fields[erFc822Addr] : ""),
+               (!CM_IsEmpty(msg, eMsgSubject) ? msg->cm_fields[eMsgSubject] : "")
        );
        CtdlFreeMessage(msg);
 }
@@ -449,8 +456,8 @@ void headers_euid(long msgnum, void *userdata)
 
        cprintf("%ld|%s|%s\n", 
                msgnum, 
-               (msg->cm_fields[eExclusiveID] ? msg->cm_fields[eExclusiveID] : ""),
-               (msg->cm_fields[eTimestamp] ? msg->cm_fields[eTimestamp] : "0"));
+               (!CM_IsEmpty(msg, eExclusiveID) ? msg->cm_fields[eExclusiveID] : ""),
+               (!CM_IsEmpty(msg, eTimestamp) ? msg->cm_fields[eTimestamp] : "0"));
        CtdlFreeMessage(msg);
 }
 
@@ -1398,14 +1405,14 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body)
         * so go ahead and fetch that.  Failing that, just set a dummy
         * body so other code doesn't barf.
         */
-       if ( (ret->cm_fields[eMesageText] == NULL) && (with_body) ) {
+       if ( (CM_IsEmpty(ret, eMesageText)) && (with_body) ) {
                dmsgtext = cdb_fetch(CDB_BIGMSGS, &msgnum, sizeof(long));
                if (dmsgtext != NULL) {
                        CM_SetAsField(ret, eMesageText, &dmsgtext->ptr, dmsgtext->len);
                        cdb_free(dmsgtext);
                }
        }
-       if (ret->cm_fields[eMesageText] == NULL) {
+       if (CM_IsEmpty(ret, eMesageText)) {
                CM_SetField(ret, eMesageText, HKEY("\r\n\r\n (no text)\r\n"));
        }
 
@@ -2148,7 +2155,7 @@ void OutputCtdlMsgHeaders(
 
        /* begin header processing loop for Citadel message format */
        safestrncpy(display_name, "<unknown>", sizeof display_name);
-       if (TheMessage->cm_fields[eAuthor]) {
+       if (!CM_IsEmpty(TheMessage, eAuthor)) {
                strcpy(buf, TheMessage->cm_fields[eAuthor]);
                if (TheMessage->cm_anon_type == MES_ANONONLY) {
                        safestrncpy(display_name, "****", sizeof display_name);
@@ -2173,18 +2180,18 @@ void OutputCtdlMsgHeaders(
         * local Citadel network.
         */
        suppress_f = 0;
-       if (TheMessage->cm_fields[eNodeName] != NULL)
-               if (!IsEmptyStr(TheMessage->cm_fields[eNodeName]))
-                       if (haschar(TheMessage->cm_fields[eNodeName], '.') == 0) {
-                               suppress_f = 1;
-                       }
+       if (!CM_IsEmpty(TheMessage, eNodeName) &&
+           (haschar(TheMessage->cm_fields[eNodeName], '.') == 0))
+       {
+               suppress_f = 1;
+       }
 
        /* Now spew the header fields in the order we like them. */
        for (i=0; i< NDiskFields; ++i) {
                eMsgField Field;
                Field = FieldOrder[i];
                if (Field != eMesageText) {
-                       if ( (TheMessage->cm_fields[Field] != NULL)
+                       if ( (!CM_IsEmpty(TheMessage, Field))
                             && (msgkeys[Field] != NULL) ) {
                                if ((Field == eenVelopeTo) ||
                                    (Field == eRecipient) ||
@@ -2525,7 +2532,7 @@ int CtdlOutputPreLoadedMsg(
        /* Suppress envelope recipients if required to avoid disclosing BCC addresses.
         * Pad it with spaces in order to avoid changing the RFC822 length of the message.
         */
-       if ( (flags & SUPPRESS_ENV_TO) && (TheMessage->cm_fields[eenVelopeTo] != NULL) ) {
+       if ( (flags & SUPPRESS_ENV_TO) && (!CM_IsEmpty(TheMessage, eenVelopeTo)) ) {
                memset(TheMessage->cm_fields[eenVelopeTo], ' ', strlen(TheMessage->cm_fields[eenVelopeTo]));
        }
                
@@ -3013,7 +3020,7 @@ int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newms
                                ReplicationChecks(msg);
                
                                /* If the message has an Exclusive ID, index that... */
-                               if (msg->cm_fields[eExclusiveID] != NULL) {
+                               if (!CM_IsEmpty(msg, eExclusiveID)) {
                                        index_message_by_euid(msg->cm_fields[eExclusiveID], &CCC->room, msgid);
                                }
 
@@ -3091,12 +3098,12 @@ long send_message(struct CtdlMessage *msg) {
                );
 
        /* Generate an ID if we don't have one already */
-       if (msg->cm_fields[emessageId]==NULL) {
+       if (CM_IsEmpty(msg, emessageId)) {
                CM_SetField(msg, emessageId, msgidbuf, msgidbuflen);
        }
 
        /* If the message is big, set its body aside for storage elsewhere */
-       if (msg->cm_fields[eMesageText] != NULL) {
+       if (!CM_IsEmpty(msg, eMesageText)) {
                if (strlen(msg->cm_fields[eMesageText]) > BIGMSG) {
                        is_bigmsg = 1;
                        holdM = msg->cm_fields[eMesageText];
@@ -3231,8 +3238,8 @@ void ReplicationChecks(struct CtdlMessage *msg) {
 
        /* No exclusive id?  Don't do anything. */
        if (msg == NULL) return;
-       if (msg->cm_fields[eExclusiveID] == NULL) return;
-       if (IsEmptyStr(msg->cm_fields[eExclusiveID])) return;
+       if (CM_IsEmpty(msg, eExclusiveID)) return;
+
        /*MSG_syslog(LOG_DEBUG, "Exclusive ID: <%s> for room <%s>\n",
          msg->cm_fields[eExclusiveID], CCC->room.QRname);*/
 
@@ -3287,14 +3294,14 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
        /* If this message has no timestamp, we take the liberty of
         * giving it one, right now.
         */
-       if (msg->cm_fields[eTimestamp] == NULL) {
+       if (CM_IsEmpty(msg, eTimestamp)) {
                CM_SetFieldLONG(msg, eTimestamp, time(NULL));
        }
 
        /* If this message has no path, we generate one.
         */
-       if (msg->cm_fields[eMessagePath] == NULL) {
-               if (msg->cm_fields[eAuthor] != NULL) {
+       if (CM_IsEmpty(msg, eMessagePath)) {
+               if (!CM_IsEmpty(msg, eAuthor)) {
                        CM_CopyField(msg, eMessagePath, eAuthor);
                        for (a=0; !IsEmptyStr(&msg->cm_fields[eMessagePath][a]); ++a) {
                                if (isspace(msg->cm_fields[eMessagePath][a])) {
@@ -3303,7 +3310,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
                        }
                }
                else {
-                       CM_SetField(msg,eMessagePath, HKEY("unknown"));
+                       CM_SetField(msg, eMessagePath, HKEY("unknown"));
                }
        }
 
@@ -3315,7 +3322,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        }
 
        /* Learn about what's inside, because it's what's inside that counts */
-       if (msg->cm_fields[eMesageText] == NULL) {
+       if (CM_IsEmpty(msg, eMesageText)) {
                MSGM_syslog(LOG_ERR, "ERROR: attempt to save message with NULL body\n");
                return(-2);
        }
@@ -3379,7 +3386,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        /*
         * If this message has no O (room) field, generate one.
         */
-       if (msg->cm_fields[eOriginalRoom] == NULL) {
+       if (CM_IsEmpty(msg, eOriginalRoom)) {
                CM_SetField(msg, eOriginalRoom, CCC->room.QRname, strlen(CCC->room.QRname));
        }
 
@@ -3532,12 +3539,10 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
 
        /* Perform "after save" hooks */
        MSGM_syslog(LOG_DEBUG, "Performing after-save hooks\n");
-       if (msg->cm_fields[eVltMsgNum] != NULL) free(msg->cm_fields[eVltMsgNum]);
-       msg->cm_fields[eVltMsgNum] = malloc(20);
-       snprintf(msg->cm_fields[eVltMsgNum], 20, "%ld", newmsgid);
+
+       CM_SetFieldLONG(msg, eVltMsgNum, newmsgid);
        PerformMessageHooks(msg, EVT_AFTERSAVE);
-       free(msg->cm_fields[eVltMsgNum]);
-       msg->cm_fields[eVltMsgNum] = NULL;
+       CM_FlushField(msg, eVltMsgNum);
 
        /* For IGnet mail, we have to save a new copy into the spooler for
         * each recipient, with the R and D fields set to the recipient and
@@ -3667,7 +3672,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,       /* message to save */
        /*
         * Determine whether this message qualifies for journaling.
         */
-       if (msg->cm_fields[eJournal] != NULL) {
+       if (!CM_IsEmpty(msg, eJournal)) {
                qualified_for_journaling = 0;
        }
        else {
@@ -4912,7 +4917,7 @@ void cmd_ent0(char *entargs)
                                client_write(HKEY("Internal error.\n"));
                        }
 
-                       if (msg->cm_fields[eExclusiveID] != NULL) {
+                       if (!CM_IsEmpty(msg, eExclusiveID)) {
                                cprintf("%s\n", msg->cm_fields[eExclusiveID]);
                        } else {
                                cprintf("\n");
index 06c426174152de33660aefafdba33ec42548d8e6..e94b46deded550b4f1d6a13654b1238e2383b102 100644 (file)
@@ -164,6 +164,7 @@ void CtdlWriteObject(char *req_room,                        /* Room to stuff it in */
 );
 struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body);
 struct CtdlMessage * CtdlDuplicateMessage(struct CtdlMessage *OrgMsg);
+int  CM_IsEmpty        (struct CtdlMessage *Msg, eMsgField which);
 void CM_SetField       (struct CtdlMessage *Msg, eMsgField which, const char *buf, long length);
 void CM_SetFieldLONG   (struct CtdlMessage *Msg, eMsgField which, long lvalue);
 void CM_CopyField      (struct CtdlMessage *Msg, eMsgField WhichToPutTo, eMsgField WhichtToCopy);