2 * This file contains functions which handle the mapping of Internet addresses
3 * to users on the Citadel system.
15 #include <sys/types.h>
17 #if TIME_WITH_SYS_TIME
18 # include <sys/time.h>
22 # include <sys/time.h>
31 #include <libcitadel.h>
34 #include "sysdep_decls.h"
35 #include "citserver.h"
39 #include "internet_addressing.h"
42 #include "parsedate.h"
45 #include "ctdl_module.h"
56 /* This is the non-define version in case of s.b. needing to debug */
57 inline void FindNextEnd (char *bptr, char *end)
59 /* Find the next ?Q? */
60 end = strchr(bptr + 2, '?');
61 if (end == NULL) return NULL;
62 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
63 (*(end + 2) == '?')) {
64 /* skip on to the end of the cluster, the next ?= */
65 end = strstr(end + 3, "?=");
68 /* sort of half valid encoding, try to find an end. */
69 end = strstr(bptr, "?=");
73 #define FindNextEnd(bptr, end) { \
74 end = strchr(bptr + 2, '?'); \
76 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) && (*(end + 2) == '?')) { \
77 end = strstr(end + 3, "?="); \
78 } else end = strstr(bptr, "?="); \
83 * Handle subjects with RFC2047 encoding such as:
84 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
86 void utf8ify_rfc822_string(char *buf) {
87 char *start, *end, *next, *nextend, *ptr;
92 iconv_t ic = (iconv_t)(-1) ;
93 char *ibuf; /**< Buffer of characters to be converted */
94 char *obuf; /**< Buffer for converted characters */
95 size_t ibuflen; /**< Length of input buffer */
96 size_t obuflen; /**< Length of output buffer */
97 char *isav; /**< Saved pointer to input buffer */
98 char *osav; /**< Saved pointer to output buffer */
101 int illegal_non_rfc2047_encoding = 0;
103 /* Sometimes, badly formed messages contain strings which were simply
104 * written out directly in some foreign character set instead of
105 * using RFC2047 encoding. This is illegal but we will attempt to
106 * handle it anyway by converting from a user-specified default
107 * charset to UTF-8 if we see any nonprintable characters.
110 for (i=0; i<len; ++i) {
111 if ((buf[i] < 32) || (buf[i] > 126)) {
112 illegal_non_rfc2047_encoding = 1;
113 i = len; ///< take a shortcut, it won't be more than one.
116 if (illegal_non_rfc2047_encoding) {
117 const char *default_header_charset = "iso-8859-1";
118 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
119 ctdl_iconv_open("UTF-8", default_header_charset, &ic);
120 if (ic != (iconv_t)(-1) ) {
123 safestrncpy(ibuf, buf, 1024);
124 ibuflen = strlen(ibuf);
126 obuf = (char *) malloc(obuflen);
128 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
129 osav[1024-obuflen] = 0;
138 /* pre evaluate the first pair */
139 nextend = end = NULL;
141 start = strstr(buf, "=?");
143 FindNextEnd (start, end);
145 while ((start != NULL) && (end != NULL))
147 next = strstr(end, "=?");
149 FindNextEnd(next, nextend);
153 /* did we find two partitions */
154 if ((next != NULL) &&
158 while ((ptr < next) &&
164 /* did we find a gab just filled with blanks? */
169 len - (next - start));
171 /* now terminate the gab at the end */
172 delta = (next - end) - 2;
176 /* move next to its new location. */
181 /* our next-pair is our new first pair now. */
186 /* Now we handle foreign character sets properly encoded
189 start = strstr(buf, "=?");
190 FindNextEnd((start != NULL)? start : buf, end);
191 while (start != NULL && end != NULL && end > start)
193 extract_token(charset, start, 1, '?', sizeof charset);
194 extract_token(encoding, start, 2, '?', sizeof encoding);
195 extract_token(istr, start, 3, '?', sizeof istr);
199 if (!strcasecmp(encoding, "B")) { /**< base64 */
200 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
202 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
210 if (istr[pos] == '_') istr[pos] = ' ';
214 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
217 strcpy(ibuf, istr); /**< unknown encoding */
218 ibuflen = strlen(istr);
221 ctdl_iconv_open("UTF-8", charset, &ic);
222 if (ic != (iconv_t)(-1) ) {
224 obuf = (char *) malloc(obuflen);
226 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
227 osav[1024-obuflen] = 0;
232 remove_token(end, 0, '?');
233 remove_token(end, 0, '?');
234 remove_token(end, 0, '?');
235 remove_token(end, 0, '?');
236 strcpy(end, &end[1]);
238 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
247 remove_token(end, 0, '?');
248 remove_token(end, 0, '?');
249 remove_token(end, 0, '?');
250 remove_token(end, 0, '?');
251 strcpy(end, &end[1]);
253 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
260 * Since spammers will go to all sorts of absurd lengths to get their
261 * messages through, there are LOTS of corrupt headers out there.
262 * So, prevent a really badly formed RFC2047 header from throwing
263 * this function into an infinite loop.
266 if (passes > 20) return;
268 start = strstr(buf, "=?");
269 FindNextEnd((start != NULL)? start : buf, end);
274 inline void utf8ify_rfc822_string(char *a){};
285 char *inetcfg = NULL;
286 struct spamstrings_t *spamstrings = NULL;
290 * Return nonzero if the supplied name is an alias for this host.
292 int CtdlHostAlias(char *fqdn) {
296 char host[256], type[256];
299 if (fqdn == NULL) return(hostalias_nomatch);
300 if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
301 if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
302 if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
303 if (!strcasecmp(fqdn, config.c_nodename)) return(hostalias_localhost);
304 if (inetcfg == NULL) return(hostalias_nomatch);
306 config_lines = num_tokens(inetcfg, '\n');
307 for (i=0; i<config_lines; ++i) {
308 extract_token(buf, inetcfg, i, '\n', sizeof buf);
309 extract_token(host, buf, 0, '|', sizeof host);
310 extract_token(type, buf, 1, '|', sizeof type);
314 /* Process these in a specific order, in case there are multiple matches.
315 * We want directory to override masq, for example.
318 if ( (!strcasecmp(type, "masqdomain")) && (!strcasecmp(fqdn, host))) {
319 found = hostalias_masq;
321 if ( (!strcasecmp(type, "localhost")) && (!strcasecmp(fqdn, host))) {
322 found = hostalias_localhost;
324 if ( (!strcasecmp(type, "directory")) && (!strcasecmp(fqdn, host))) {
325 found = hostalias_directory;
328 if (found) return(found);
331 return(hostalias_nomatch);
341 * Return 0 if a given string fuzzy-matches a Citadel user account
343 * FIXME ... this needs to be updated to handle aliases.
345 int fuzzy_match(struct ctdluser *us, char *matchstring) {
349 if ( (!strncasecmp(matchstring, "cit", 3))
350 && (atol(&matchstring[3]) == us->usernum)) {
354 len = strlen(matchstring);
355 for (a=0; !IsEmptyStr(&us->fullname[a]); ++a) {
356 if (!strncasecmp(&us->fullname[a],
366 * Unfold a multi-line field into a single line, removing multi-whitespaces
368 void unfold_rfc822_field(char **field, char **FieldEnd)
371 char *pField = *field;
373 char *pFieldEnd = *FieldEnd;
375 while (isspace(*pField))
377 /* remove leading/trailing whitespace */
380 while (isspace(*pFieldEnd))
383 *FieldEnd = pFieldEnd;
384 /* convert non-space whitespace to spaces, and remove double blanks */
385 for (sField = *field = pField;
389 if ((*sField=='\r') || (*sField=='\n')) {
396 if (*sField=='\"') quote = 1 - quote;
398 if (isspace(*sField))
404 while ((sField < pFieldEnd) &&
409 else *pField = *sField;
411 else *pField = *sField;
415 *FieldEnd = pField - 1;
421 * Split an RFC822-style address into userid, host, and full name
424 void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name)
429 strcpy(node, config.c_fqdn);
432 if (rfc822 == NULL) return;
434 /* extract full name - first, it's From minus <userid> */
435 strcpy(name, rfc822);
436 stripout(name, '<', '>');
438 /* strip anything to the left of a bang */
439 while ((!IsEmptyStr(name)) && (haschar(name, '!') > 0))
440 strcpy(name, &name[1]);
442 /* and anything to the right of a @ or % */
443 for (a = 0; a < strlen(name); ++a) {
450 /* but if there are parentheses, that changes the rules... */
451 if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
452 strcpy(name, rfc822);
453 stripallbut(name, '(', ')');
456 /* but if there are a set of quotes, that supersedes everything */
457 if (haschar(rfc822, 34) == 2) {
458 strcpy(name, rfc822);
459 while ((!IsEmptyStr(name)) && (name[0] != 34)) {
460 strcpy(&name[0], &name[1]);
462 strcpy(&name[0], &name[1]);
463 for (a = 0; a < strlen(name); ++a)
467 /* extract user id */
468 strcpy(user, rfc822);
470 /* first get rid of anything in parens */
471 stripout(user, '(', ')');
473 /* if there's a set of angle brackets, strip it down to that */
474 if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
475 stripallbut(user, '<', '>');
478 /* strip anything to the left of a bang */
479 while ((!IsEmptyStr(user)) && (haschar(user, '!') > 0))
480 strcpy(user, &user[1]);
482 /* and anything to the right of a @ or % */
483 for (a = 0; a < strlen(user); ++a) {
491 /* extract node name */
492 strcpy(node, rfc822);
494 /* first get rid of anything in parens */
495 stripout(node, '(', ')');
497 /* if there's a set of angle brackets, strip it down to that */
498 if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
499 stripallbut(node, '<', '>');
502 /* If no node specified, tack ours on instead */
504 (haschar(node, '@')==0)
505 && (haschar(node, '%')==0)
506 && (haschar(node, '!')==0)
508 strcpy(node, config.c_nodename);
513 /* strip anything to the left of a @ */
514 while ((!IsEmptyStr(node)) && (haschar(node, '@') > 0))
515 strcpy(node, &node[1]);
517 /* strip anything to the left of a % */
518 while ((!IsEmptyStr(node)) && (haschar(node, '%') > 0))
519 strcpy(node, &node[1]);
521 /* reduce multiple system bang paths to node!user */
522 while ((!IsEmptyStr(node)) && (haschar(node, '!') > 1))
523 strcpy(node, &node[1]);
525 /* now get rid of the user portion of a node!user string */
526 for (a = 0; a < strlen(node); ++a)
531 /* strip leading and trailing spaces in all strings */
536 /* If we processed a string that had the address in angle brackets
537 * but no name outside the brackets, we now have an empty name. In
538 * this case, use the user portion of the address as the name.
540 if ((IsEmptyStr(name)) && (!IsEmptyStr(user))) {
548 * convert_field() is a helper function for convert_internet_message().
549 * Given start/end positions for an rfc822 field, it converts it to a Citadel
550 * field if it wants to, and unfolds it if necessary.
552 * Returns 1 if the field was converted and inserted into the Citadel message
553 * structure, implying that the source field should be removed from the
556 int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
557 char *key, *value, *valueend;
561 const char *colonpos = NULL;
571 for (pos = end; pos >= beg; pos--) {
572 if (*pos == ':') colonpos = pos;
575 if (colonpos == NULL) return(0); /* no colon? not a valid header line */
578 key = malloc(len + 2);
579 memcpy(key, beg, len + 1);
581 valueend = key + len;
582 * ( key + (colonpos - beg) ) = '\0';
583 value = &key[(colonpos - beg) + 1];
584 /* printf("Header: [%s]\nValue: [%s]\n", key, value); */
585 unfold_rfc822_field(&value, &valueend);
586 valuelen = valueend - value + 1;
587 /* printf("UnfoldedValue: [%s]\n", value); */
590 * Here's the big rfc822-to-citadel loop.
593 /* Date/time is converted into a unix timestamp. If the conversion
594 * fails, we replace it with the time the message arrived locally.
596 if (!strcasecmp(key, "Date")) {
597 parsed_date = parsedate(value);
598 if (parsed_date < 0L) parsed_date = time(NULL);
599 snprintf(buf, sizeof buf, "%ld", (long)parsed_date );
600 if (msg->cm_fields['T'] == NULL)
601 msg->cm_fields['T'] = strdup(buf);
605 else if (!strcasecmp(key, "From")) {
606 process_rfc822_addr(value, user, node, name);
607 syslog(LOG_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
608 snprintf(addr, sizeof addr, "%s@%s", user, node);
609 if (msg->cm_fields['A'] == NULL)
610 msg->cm_fields['A'] = strdup(name);
612 if (msg->cm_fields['F'] == NULL)
613 msg->cm_fields['F'] = strdup(addr);
617 else if (!strcasecmp(key, "Subject")) {
618 if (msg->cm_fields['U'] == NULL)
619 msg->cm_fields['U'] = strndup(value, valuelen);
623 else if (!strcasecmp(key, "List-ID")) {
624 if (msg->cm_fields['L'] == NULL)
625 msg->cm_fields['L'] = strndup(value, valuelen);
629 else if (!strcasecmp(key, "To")) {
630 if (msg->cm_fields['R'] == NULL)
631 msg->cm_fields['R'] = strndup(value, valuelen);
635 else if (!strcasecmp(key, "CC")) {
636 if (msg->cm_fields['Y'] == NULL)
637 msg->cm_fields['Y'] = strndup(value, valuelen);
641 else if (!strcasecmp(key, "Message-ID")) {
642 if (msg->cm_fields['I'] != NULL) {
643 syslog(LOG_WARNING, "duplicate message id\n");
646 if (msg->cm_fields['I'] == NULL) {
647 msg->cm_fields['I'] = strndup(value, valuelen);
649 /* Strip angle brackets */
650 while (haschar(msg->cm_fields['I'], '<') > 0) {
651 strcpy(&msg->cm_fields['I'][0],
652 &msg->cm_fields['I'][1]);
654 for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
655 if (msg->cm_fields['I'][i] == '>')
656 msg->cm_fields['I'][i] = 0;
662 else if (!strcasecmp(key, "Return-Path")) {
663 if (msg->cm_fields['P'] == NULL)
664 msg->cm_fields['P'] = strndup(value, valuelen);
668 else if (!strcasecmp(key, "Envelope-To")) {
669 if (msg->cm_fields['V'] == NULL)
670 msg->cm_fields['V'] = strndup(value, valuelen);
674 else if (!strcasecmp(key, "References")) {
675 if (msg->cm_fields['W'] != NULL) {
676 free(msg->cm_fields['W']);
678 msg->cm_fields['W'] = strndup(value, valuelen);
682 else if (!strcasecmp(key, "Reply-To")) {
683 if (msg->cm_fields['K'] != NULL) {
684 free(msg->cm_fields['K']);
686 msg->cm_fields['K'] = strndup(value, valuelen);
690 else if (!strcasecmp(key, "In-reply-to")) {
691 if (msg->cm_fields['W'] == NULL) { /* References: supersedes In-reply-to: */
692 msg->cm_fields['W'] = strndup(value, valuelen);
699 /* Clean up and move on. */
700 free(key); /* Don't free 'value', it's actually the same buffer */
706 * Convert RFC822 references format (References) to Citadel references format (Weferences)
708 void convert_references_to_wefewences(char *str) {
709 int bracket_nesting = 0;
711 char *moveptr = NULL;
718 if (bracket_nesting < 0) bracket_nesting = 0;
720 if ((ch == '>') && (bracket_nesting == 0) && (*(ptr+1)) && (ptr>str) ) {
724 else if (bracket_nesting > 0) {
730 *moveptr = *(moveptr+1);
734 if (ch == '<') ++bracket_nesting;
741 * Convert an RFC822 message (headers + body) to a CtdlMessage structure.
742 * NOTE: the supplied buffer becomes part of the CtdlMessage structure, and
743 * will be deallocated when CtdlFreeMessage() is called. Therefore, the
744 * supplied buffer should be DEREFERENCED. It should not be freed or used
747 struct CtdlMessage *convert_internet_message(char *rfc822) {
748 StrBuf *RFCBuf = NewStrBufPlain(rfc822, -1);
750 return convert_internet_message_buf(&RFCBuf);
755 struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822)
757 struct CtdlMessage *msg;
758 const char *pos, *beg, *end, *totalend;
759 int done, alldone = 0;
762 StrBuf *OtherHeaders;
764 msg = malloc(sizeof(struct CtdlMessage));
765 if (msg == NULL) return msg;
767 memset(msg, 0, sizeof(struct CtdlMessage));
768 msg->cm_magic = CTDLMESSAGE_MAGIC; /* self check */
769 msg->cm_anon_type = 0; /* never anonymous */
770 msg->cm_format_type = FMT_RFC822; /* internet message */
772 pos = ChrPtr(*rfc822);
773 totalend = pos + StrLength(*rfc822);
775 OtherHeaders = NewStrBufPlain(NULL, StrLength(*rfc822));
779 /* Locate beginning and end of field, keeping in mind that
780 * some fields might be multiline
784 while ((end < totalend) &&
789 if ( (*pos=='\n') && ((*(pos+1))!=0x20) && ((*(pos+1))!=0x09) )
794 /* done with headers? */
796 ( (*(pos+1)=='\n') ||
802 if (pos >= (totalend - 1) )
812 /* At this point we have a field. Are we interested in it? */
813 converted = convert_field(msg, beg, end);
815 /* Strip the field out of the RFC822 header if we used it */
817 StrBufAppendBufPlain(OtherHeaders, beg, end - beg, 0);
818 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
821 /* If we've hit the end of the message, bail out */
825 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
827 StrBufAppendBufPlain(OtherHeaders, pos, totalend - pos, 0);
829 msg->cm_fields['M'] = SmashStrBuf(&OtherHeaders);
831 /* Follow-up sanity checks... */
833 /* If there's no timestamp on this message, set it to now. */
834 if (msg->cm_fields['T'] == NULL) {
835 snprintf(buf, sizeof buf, "%ld", (long)time(NULL));
836 msg->cm_fields['T'] = strdup(buf);
839 /* If a W (references, or rather, Wefewences) field is present, we
840 * have to convert it from RFC822 format to Citadel format.
842 if (msg->cm_fields['W'] != NULL) {
843 convert_references_to_wefewences(msg->cm_fields['W']);
852 * Look for a particular header field in an RFC822 message text. If the
853 * requested field is found, it is unfolded (if necessary) and returned to
854 * the caller. The field name is stripped out, leaving only its contents.
855 * The caller is responsible for freeing the returned buffer. If the requested
856 * field is not present, or anything else goes wrong, it returns NULL.
858 char *rfc822_fetch_field(const char *rfc822, const char *fieldname) {
859 char *fieldbuf = NULL;
860 const char *end_of_headers;
861 const char *field_start;
866 /* Should never happen, but sometimes we get stupid */
867 if (rfc822 == NULL) return(NULL);
868 if (fieldname == NULL) return(NULL);
870 snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname);
872 /* Locate the end of the headers, so we don't run past that point */
873 end_of_headers = cbmstrcasestr(rfc822, "\n\r\n");
874 if (end_of_headers == NULL) {
875 end_of_headers = cbmstrcasestr(rfc822, "\n\n");
877 if (end_of_headers == NULL) return (NULL);
879 field_start = cbmstrcasestr(rfc822, fieldhdr);
880 if (field_start == NULL) return(NULL);
881 if (field_start > end_of_headers) return(NULL);
883 fieldbuf = malloc(SIZ);
884 strcpy(fieldbuf, "");
887 ptr = cmemreadline(ptr, fieldbuf, SIZ-strlen(fieldbuf) );
888 while ( (isspace(ptr[0])) && (ptr < end_of_headers) ) {
889 strcat(fieldbuf, " ");
890 cont = &fieldbuf[strlen(fieldbuf)];
891 ptr = cmemreadline(ptr, cont, SIZ-strlen(fieldbuf) );
895 strcpy(fieldbuf, &fieldbuf[strlen(fieldhdr)]);
903 /*****************************************************************************
904 * DIRECTORY MANAGEMENT FUNCTIONS *
905 *****************************************************************************/
908 * Generate the index key for an Internet e-mail address to be looked up
911 void directory_key(char *key, char *addr) {
915 for (i=0; !IsEmptyStr(&addr[i]); ++i) {
916 if (!isspace(addr[i])) {
917 key[keylen++] = tolower(addr[i]);
922 syslog(LOG_DEBUG, "Directory key is <%s>\n", key);
927 /* Return nonzero if the supplied address is in a domain we keep in
930 int IsDirectory(char *addr, int allow_masq_domains) {
934 extract_token(domain, addr, 1, '@', sizeof domain);
937 h = CtdlHostAlias(domain);
939 if ( (h == hostalias_masq) && allow_masq_domains)
942 if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
952 * Initialize the directory database (erasing anything already there)
954 void CtdlDirectoryInit(void) {
955 cdb_trunc(CDB_DIRECTORY);
960 * Add an Internet e-mail address to the directory for a user
962 void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
965 if (IsDirectory(internet_addr, 0) == 0) return;
966 syslog(LOG_DEBUG, "Create directory entry: %s --> %s\n", internet_addr, citadel_addr);
967 directory_key(key, internet_addr);
968 cdb_store(CDB_DIRECTORY, key, strlen(key), citadel_addr, strlen(citadel_addr)+1 );
973 * Delete an Internet e-mail address from the directory.
975 * (NOTE: we don't actually use or need the citadel_addr variable; it's merely
976 * here because the callback API expects to be able to send it.)
978 void CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
981 syslog(LOG_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
982 directory_key(key, internet_addr);
983 cdb_delete(CDB_DIRECTORY, key, strlen(key) );
988 * Look up an Internet e-mail address in the directory.
989 * On success: returns 0, and Citadel address stored in 'target'
990 * On failure: returns nonzero
992 int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
993 struct cdbdata *cdbrec;
996 /* Dump it in there unchanged, just for kicks */
997 safestrncpy(target, internet_addr, targbuflen);
999 /* Only do lookups for addresses with hostnames in them */
1000 if (num_tokens(internet_addr, '@') != 2) return(-1);
1002 /* Only do lookups for domains in the directory */
1003 if (IsDirectory(internet_addr, 0) == 0) return(-1);
1005 directory_key(key, internet_addr);
1006 cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
1007 if (cdbrec != NULL) {
1008 safestrncpy(target, cdbrec->ptr, targbuflen);
1018 * Harvest any email addresses that someone might want to have in their
1019 * "collected addresses" book.
1021 char *harvest_collected_addresses(struct CtdlMessage *msg) {
1024 char user[256], node[256], name[256];
1029 if (msg == NULL) return(NULL);
1033 if (msg->cm_fields['A'] != NULL) {
1034 strcat(addr, msg->cm_fields['A']);
1036 if (msg->cm_fields['F'] != NULL) {
1038 strcat(addr, msg->cm_fields['F']);
1040 if (IsDirectory(msg->cm_fields['F'], 0)) {
1045 if (is_harvestable) {
1046 coll = strdup(addr);
1052 if (coll == NULL) return(NULL);
1054 /* Scan both the R (To) and Y (CC) fields */
1055 for (i = 0; i < 2; ++i) {
1056 if (i == 0) field = 'R' ;
1057 if (i == 1) field = 'Y' ;
1059 if (msg->cm_fields[field] != NULL) {
1060 for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
1061 extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
1062 if (strstr(addr, "=?") != NULL)
1063 utf8ify_rfc822_string(addr);
1064 process_rfc822_addr(addr, user, node, name);
1065 h = CtdlHostAlias(node);
1066 if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {
1067 coll = realloc(coll, strlen(coll) + strlen(addr) + 4);
1068 if (coll == NULL) return(NULL);
1069 if (!IsEmptyStr(coll)) {
1079 if (IsEmptyStr(coll)) {