#include "room_ops.h"
#include "parsedate.h"
#include "database.h"
-
#include "ctdl_module.h"
-
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-
-
#ifdef HAVE_ICONV
#include <iconv.h>
pField++, sField++)
{
if ((*sField=='\r') || (*sField=='\n')) {
- while (isspace(*sField))
- sField++;
- *pField = *sField;
+ sField++;
+ if (*sField == '\n')
+ sField++;
+ *pField = *sField;
}
else {
if (*sField=='\"') quote = 1 - quote;
int i;
const char *colonpos = NULL;
int processed = 0;
- char buf[SIZ];
char user[1024];
char node[1024];
char name[1024];
if (!strcasecmp(key, "Date")) {
parsed_date = parsedate(value);
if (parsed_date < 0L) parsed_date = time(NULL);
- snprintf(buf, sizeof buf, "%ld", (long)parsed_date );
- if (msg->cm_fields['T'] == NULL)
- msg->cm_fields['T'] = strdup(buf);
+
+ if (CM_IsEmpty(msg, eTimestamp))
+ CM_SetFieldLONG(msg, eTimestamp, parsed_date);
processed = 1;
}
else if (!strcasecmp(key, "From")) {
process_rfc822_addr(value, user, node, name);
- CtdlLogPrintf(CTDL_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
- snprintf(addr, sizeof addr, "%s@%s", user, node);
- if (msg->cm_fields['A'] == NULL)
- msg->cm_fields['A'] = strdup(name);
- processed = 1;
- if (msg->cm_fields['F'] == NULL)
- msg->cm_fields['F'] = strdup(addr);
+ syslog(LOG_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
+ snprintf(addr, sizeof(addr), "%s@%s", user, node);
+ if (CM_IsEmpty(msg, eAuthor))
+ CM_SetField(msg, eAuthor, name, strlen(name));
+ if (CM_IsEmpty(msg, erFc822Addr))
+ CM_SetField(msg, erFc822Addr, addr, strlen(addr));
processed = 1;
}
else if (!strcasecmp(key, "Subject")) {
- if (msg->cm_fields['U'] == NULL)
- msg->cm_fields['U'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eMsgSubject))
+ CM_SetField(msg, eMsgSubject, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "List-ID")) {
- if (msg->cm_fields['L'] == NULL)
- msg->cm_fields['L'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eListID))
+ CM_SetField(msg, eListID, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "To")) {
- if (msg->cm_fields['R'] == NULL)
- msg->cm_fields['R'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eRecipient))
+ CM_SetField(msg, eRecipient, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "CC")) {
- if (msg->cm_fields['Y'] == NULL)
- msg->cm_fields['Y'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eCarbonCopY))
+ CM_SetField(msg, eCarbonCopY, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "Message-ID")) {
- if (msg->cm_fields['I'] != NULL) {
- CtdlLogPrintf(CTDL_WARNING, "duplicate message id\n");
+ if (!CM_IsEmpty(msg, emessageId)) {
+ syslog(LOG_WARNING, "duplicate message id\n");
}
+ else {
+ char *pValue;
+ long pValueLen;
- if (msg->cm_fields['I'] == NULL) {
- msg->cm_fields['I'] = strndup(value, valuelen);
-
+ pValue = value;
+ pValueLen = valuelen;
/* Strip angle brackets */
- while (haschar(msg->cm_fields['I'], '<') > 0) {
- strcpy(&msg->cm_fields['I'][0],
- &msg->cm_fields['I'][1]);
+ while (haschar(pValue, '<') > 0) {
+ pValue ++;
+ pValueLen --;
}
- for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
- if (msg->cm_fields['I'][i] == '>')
- msg->cm_fields['I'][i] = 0;
+
+ for (i = 0; i <= pValueLen; ++i)
+ if (pValue[i] == '>') {
+ pValueLen = i;
+ break;
+ }
+
+ CM_SetField(msg, emessageId, pValue, pValueLen);
}
processed = 1;
}
else if (!strcasecmp(key, "Return-Path")) {
- if (msg->cm_fields['P'] == NULL)
- msg->cm_fields['P'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eMessagePath))
+ CM_SetField(msg, eMessagePath, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "Envelope-To")) {
- if (msg->cm_fields['V'] == NULL)
- msg->cm_fields['V'] = strndup(value, valuelen);
+ if (CM_IsEmpty(msg, eenVelopeTo))
+ CM_SetField(msg, eenVelopeTo, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "References")) {
- if (msg->cm_fields['W'] != NULL) {
- free(msg->cm_fields['W']);
- }
- msg->cm_fields['W'] = strndup(value, valuelen);
+ CM_SetField(msg, eWeferences, value, valuelen);
+ processed = 1;
+ }
+
+ else if (!strcasecmp(key, "Reply-To")) {
+ CM_SetField(msg, eReplyTo, value, valuelen);
processed = 1;
}
else if (!strcasecmp(key, "In-reply-to")) {
- if (msg->cm_fields['W'] == NULL) { /* References: supersedes In-reply-to: */
- msg->cm_fields['W'] = strndup(value, valuelen);
- }
+ if (CM_IsEmpty(msg, eWeferences)) /* References: supersedes In-reply-to: */
+ CM_SetField(msg, eWeferences, value, valuelen);
processed = 1;
}
/* Clean up and move on. */
free(key); /* Don't free 'value', it's actually the same buffer */
- return(processed);
+ return processed;
}
struct CtdlMessage *msg;
const char *pos, *beg, *end, *totalend;
int done, alldone = 0;
- char buf[SIZ];
int converted;
StrBuf *OtherHeaders;
if (pos < totalend)
StrBufAppendBufPlain(OtherHeaders, pos, totalend - pos, 0);
FreeStrBuf(rfc822);
- msg->cm_fields['M'] = SmashStrBuf(&OtherHeaders);
+ CM_SetAsFieldSB(msg, eMesageText, &OtherHeaders);
/* Follow-up sanity checks... */
/* If there's no timestamp on this message, set it to now. */
- if (msg->cm_fields['T'] == NULL) {
- snprintf(buf, sizeof buf, "%ld", (long)time(NULL));
- msg->cm_fields['T'] = strdup(buf);
+ 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['W'] != NULL) {
- convert_references_to_wefewences(msg->cm_fields['W']);
+ if (!CM_IsEmpty(msg, eWeferences)) {
+ /// todo: API!
+ convert_references_to_wefewences(msg->cm_fields[eWeferences]);
}
return msg;
}
key[keylen++] = 0;
- CtdlLogPrintf(CTDL_DEBUG, "Directory key is <%s>\n", key);
+ syslog(LOG_DEBUG, "Directory key is <%s>\n", key);
}
/*
* Add an Internet e-mail address to the directory for a user
*/
-void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
+int CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
char key[SIZ];
- if (IsDirectory(internet_addr, 0) == 0) return;
- CtdlLogPrintf(CTDL_DEBUG, "Create directory entry: %s --> %s\n", internet_addr, citadel_addr);
+ if (IsDirectory(internet_addr, 0) == 0)
+ return 0;
+ syslog(LOG_DEBUG, "Create directory entry: %s --> %s\n", internet_addr, citadel_addr);
directory_key(key, internet_addr);
cdb_store(CDB_DIRECTORY, key, strlen(key), citadel_addr, strlen(citadel_addr)+1 );
+ return 1;
}
* (NOTE: we don't actually use or need the citadel_addr variable; it's merely
* here because the callback API expects to be able to send it.)
*/
-void CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
+int CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
char key[SIZ];
- CtdlLogPrintf(CTDL_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
+ syslog(LOG_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
directory_key(key, internet_addr);
- cdb_delete(CDB_DIRECTORY, key, strlen(key) );
+ return cdb_delete(CDB_DIRECTORY, key, strlen(key) ) == 0;
}
char user[256], node[256], name[256];
int is_harvestable;
int i, j, h;
- int field = 0;
+ eMsgField field = 0;
if (msg == NULL) return(NULL);
is_harvestable = 1;
strcpy(addr, "");
- if (msg->cm_fields['A'] != NULL) {
- strcat(addr, msg->cm_fields['A']);
+ if (!CM_IsEmpty(msg, eAuthor)) {
+ strcat(addr, msg->cm_fields[eAuthor]);
}
- if (msg->cm_fields['F'] != NULL) {
+ if (!CM_IsEmpty(msg, erFc822Addr)) {
strcat(addr, " <");
- strcat(addr, msg->cm_fields['F']);
+ strcat(addr, msg->cm_fields[erFc822Addr]);
strcat(addr, ">");
- if (IsDirectory(msg->cm_fields['F'], 0)) {
+ if (IsDirectory(msg->cm_fields[erFc822Addr], 0)) {
is_harvestable = 0;
}
}
/* Scan both the R (To) and Y (CC) fields */
for (i = 0; i < 2; ++i) {
- if (i == 0) field = 'R' ;
- if (i == 1) field = 'Y' ;
+ 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)