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);
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;
}
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 {
}
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;
}
}
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;
}
/* 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]);
}
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, ">");
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)
struct jnlq *jptr = NULL;
/* Avoid double journaling! */
- if (msg->cm_fields[eJournal] != NULL) {
+ if (!CM_IsEmpty(msg, eJournal)) {
FreeStrBuf(&saved_rfc822_version);
return;
}
}
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 */
"\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);
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]);
}
/*
* 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);
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! */
}
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],
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))
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],
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;
time_t msgdate;
if (!msg) return;
- if (msg->cm_fields[eTimestamp] != NULL) {
+ if (!CM_IsEmpty(msg, eTimestamp)) {
msgdate = atol(msg->cm_fields[eTimestamp]);
}
else {
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(" ");
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 {
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;
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;
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;
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;
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;
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;
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) {
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;
int rlen;
char *pCh;
- if (msg->cm_fields[eMsgSubject] == NULL) {
+ if (CM_IsEmpty(msg, eMsgSubject)) {
Subject = NewStrBufPlain(HKEY("(no subject)"));
}
else {
"------------------------------------"
"-------\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]);
* 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]));
}
* 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;
* 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;
}
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);
}
/* 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 */
}
/* 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,
/* 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,
/* 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);
}
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);
}
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 {
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 {
}
/* 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 {
}
/* 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, '<', '>');
}
}
/* 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]);
}
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;
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) ) )
{
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"));
}
}
if (is_spam) {
- if (msg->cm_fields[eErrorMsg] != NULL) {
- free(msg->cm_fields[eErrorMsg]);
- }
CM_SetField(msg, eErrorMsg, HKEY("message rejected by spam filter"));
}
}
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]);
*/
int vcard_upload_beforesave(struct CtdlMessage *msg) {
struct CitContext *CCC = CC;
- char *ptr;
char *s;
char buf[SIZ];
struct ctdluser usbuf;
/* 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,
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);
}
}
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);
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");
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;
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]);
}
/* 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);
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;
}
msg = NULL;
}
- if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+ if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
CtdlFreeMessage(msg);
msg = NULL;
}
msg = NULL;
}
- if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+ if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
CtdlFreeMessage(msg);
msg = NULL;
}
msg = NULL;
}
- if ((msg != NULL) && (msg->cm_fields[eMesageText] == NULL)) {
+ if ((msg != NULL) && CM_IsEmpty(msg, eMesageText)) {
CtdlFreeMessage(msg);
msg = NULL;
}
};
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)
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);
}
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);
}
* 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"));
}
/* 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);
* 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) ||
/* 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]));
}
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);
}
);
/* 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];
/* 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);*/
/* 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])) {
}
}
else {
- CM_SetField(msg,eMessagePath, HKEY("unknown"));
+ CM_SetField(msg, eMessagePath, HKEY("unknown"));
}
}
}
/* 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);
}
/*
* 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));
}
/* 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
/*
* Determine whether this message qualifies for journaling.
*/
- if (msg->cm_fields[eJournal] != NULL) {
+ if (!CM_IsEmpty(msg, eJournal)) {
qualified_for_journaling = 0;
}
else {
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");
);
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);