refactor naming of core message manipulation funcions
[citadel.git] / citadel / modules / smtp / serv_smtp.c
index ad9137ff3961073ae65e030a35f12d7af89c5f4a..f21e9d16ecd55c82de1a2a4f9c414314b393c12e 100644 (file)
@@ -320,12 +320,14 @@ 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;
        }
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
 }
 
 
@@ -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)    )  )
                {
@@ -839,32 +841,21 @@ void smtp_data(long offset, long flags)
                        return;
                }
 
-               if (msg->cm_fields[eAuthor] != NULL) free(msg->cm_fields[eAuthor]);
-               if (msg->cm_fields[eNodeName] != NULL) free(msg->cm_fields[eNodeName]);
-               if (msg->cm_fields[eHumanNode] != NULL) free(msg->cm_fields[eHumanNode]);
-               if (msg->cm_fields[eOriginalRoom] != NULL) free(msg->cm_fields[eOriginalRoom]);
-               msg->cm_fields[eAuthor] = strdup(CCC->user.fullname);
-               msg->cm_fields[eNodeName] = strdup(config.c_nodename);
-               msg->cm_fields[eHumanNode] = strdup(config.c_humannode);
-               msg->cm_fields[eOriginalRoom] = strdup(MAILROOM);
+               CM_SetField(msg, eAuthor, CCC->user.fullname, strlen(CCC->user.fullname));
+               CM_SetField(msg, eNodeName, config.c_nodename, strlen(config.c_nodename));
+               CM_SetField(msg, eHumanNode, config.c_humannode, strlen(config.c_humannode));
+               CM_SetField(msg, eOriginalRoom, HKEY(MAILROOM));
 
                if (!validemail) {
-                       if (msg->cm_fields[erFc822Addr] != NULL) free(msg->cm_fields[erFc822Addr]);
-                       msg->cm_fields[erFc822Addr] = strdup(CCC->cs_inet_email);
+                       CM_SetField(msg, erFc822Addr, CCC->cs_inet_email, strlen(CCC->cs_inet_email));
                }
        }
 
        /* Set the "envelope from" address */
-       if (msg->cm_fields[eMessagePath] != NULL) {
-               free(msg->cm_fields[eMessagePath]);
-       }
-       msg->cm_fields[eMessagePath] = strdup(ChrPtr(sSMTP->from));
+       CM_SetField(msg, eMessagePath, SKEY(sSMTP->from));
 
        /* Set the "envelope to" address */
-       if (msg->cm_fields[eenVelopeTo] != NULL) {
-               free(msg->cm_fields[eenVelopeTo]);
-       }
-       msg->cm_fields[eenVelopeTo] = strdup(ChrPtr(sSMTP->recipients));
+       CM_SetField(msg, eenVelopeTo, SKEY(sSMTP->recipients));
 
        /* Submit the message into the Citadel system. */
        valid = validate_recipients(
@@ -886,8 +877,8 @@ void smtp_data(long offset, long flags)
 
        if (scan_errors > 0) {  /* We don't want this message! */
 
-               if (msg->cm_fields[eErrorMsg] == NULL) {
-                       msg->cm_fields[eErrorMsg] = strdup("Message rejected by filter");
+               if (CM_IsEmpty(msg, eErrorMsg)) {
+                       CM_SetField(msg, eErrorMsg, HKEY("Message rejected by filter"));
                }
 
                StrBufPrintf(sSMTP->OneRcpt, "550 %s\r\n", msg->cm_fields[eErrorMsg]);
@@ -932,7 +923,7 @@ void smtp_data(long offset, long flags)
        );
 
        /* Clean up */
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
        free_recipients(valid);
        smtp_data_clear(0, 0);  /* clear out the buffers now */
 }