4 * This file contains functions which handle the mapping of Internet addresses
5 * to users on the Citadel system.
17 #include <sys/types.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
33 #include <libcitadel.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
41 #include "internet_addressing.h"
44 #include "parsedate.h"
47 #include "ctdl_module.h"
58 /* This is the non-define version in case of s.b. needing to debug */
59 inline void FindNextEnd (char *bptr, char *end)
61 /* Find the next ?Q? */
62 end = strchr(bptr + 2, '?');
63 if (end == NULL) return NULL;
64 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
65 (*(end + 2) == '?')) {
66 /* skip on to the end of the cluster, the next ?= */
67 end = strstr(end + 3, "?=");
70 /* sort of half valid encoding, try to find an end. */
71 end = strstr(bptr, "?=");
75 #define FindNextEnd(bptr, end) { \
76 end = strchr(bptr + 2, '?'); \
78 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) && (*(end + 2) == '?')) { \
79 end = strstr(end + 3, "?="); \
80 } else end = strstr(bptr, "?="); \
85 * Handle subjects with RFC2047 encoding such as:
86 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
88 void utf8ify_rfc822_string(char *buf) {
89 char *start, *end, *next, *nextend, *ptr;
94 iconv_t ic = (iconv_t)(-1) ;
95 char *ibuf; /**< Buffer of characters to be converted */
96 char *obuf; /**< Buffer for converted characters */
97 size_t ibuflen; /**< Length of input buffer */
98 size_t obuflen; /**< Length of output buffer */
99 char *isav; /**< Saved pointer to input buffer */
100 char *osav; /**< Saved pointer to output buffer */
103 int illegal_non_rfc2047_encoding = 0;
105 /* Sometimes, badly formed messages contain strings which were simply
106 * written out directly in some foreign character set instead of
107 * using RFC2047 encoding. This is illegal but we will attempt to
108 * handle it anyway by converting from a user-specified default
109 * charset to UTF-8 if we see any nonprintable characters.
112 for (i=0; i<len; ++i) {
113 if ((buf[i] < 32) || (buf[i] > 126)) {
114 illegal_non_rfc2047_encoding = 1;
115 i = len; ///< take a shortcut, it won't be more than one.
118 if (illegal_non_rfc2047_encoding) {
119 const char *default_header_charset = "iso-8859-1";
120 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
121 ctdl_iconv_open("UTF-8", default_header_charset, &ic);
122 if (ic != (iconv_t)(-1) ) {
125 safestrncpy(ibuf, buf, 1024);
126 ibuflen = strlen(ibuf);
128 obuf = (char *) malloc(obuflen);
130 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
131 osav[1024-obuflen] = 0;
140 /* pre evaluate the first pair */
141 nextend = end = NULL;
143 start = strstr(buf, "=?");
145 FindNextEnd (start, end);
147 while ((start != NULL) && (end != NULL))
149 next = strstr(end, "=?");
151 FindNextEnd(next, nextend);
155 /* did we find two partitions */
156 if ((next != NULL) &&
160 while ((ptr < next) &&
166 /* did we find a gab just filled with blanks? */
171 len - (next - start));
173 /* now terminate the gab at the end */
174 delta = (next - end) - 2;
178 /* move next to its new location. */
183 /* our next-pair is our new first pair now. */
188 /* Now we handle foreign character sets properly encoded
191 start = strstr(buf, "=?");
192 FindNextEnd((start != NULL)? start : buf, end);
193 while (start != NULL && end != NULL && end > start)
195 extract_token(charset, start, 1, '?', sizeof charset);
196 extract_token(encoding, start, 2, '?', sizeof encoding);
197 extract_token(istr, start, 3, '?', sizeof istr);
201 if (!strcasecmp(encoding, "B")) { /**< base64 */
202 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
204 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
212 if (istr[pos] == '_') istr[pos] = ' ';
216 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
219 strcpy(ibuf, istr); /**< unknown encoding */
220 ibuflen = strlen(istr);
223 ctdl_iconv_open("UTF-8", charset, &ic);
224 if (ic != (iconv_t)(-1) ) {
226 obuf = (char *) malloc(obuflen);
228 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
229 osav[1024-obuflen] = 0;
234 remove_token(end, 0, '?');
235 remove_token(end, 0, '?');
236 remove_token(end, 0, '?');
237 remove_token(end, 0, '?');
238 strcpy(end, &end[1]);
240 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
249 remove_token(end, 0, '?');
250 remove_token(end, 0, '?');
251 remove_token(end, 0, '?');
252 remove_token(end, 0, '?');
253 strcpy(end, &end[1]);
255 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
262 * Since spammers will go to all sorts of absurd lengths to get their
263 * messages through, there are LOTS of corrupt headers out there.
264 * So, prevent a really badly formed RFC2047 header from throwing
265 * this function into an infinite loop.
268 if (passes > 20) return;
270 start = strstr(buf, "=?");
271 FindNextEnd((start != NULL)? start : buf, end);
276 inline void utf8ify_rfc822_string(char *a){};
287 char *inetcfg = NULL;
288 struct spamstrings_t *spamstrings = NULL;
292 * Return nonzero if the supplied name is an alias for this host.
294 int CtdlHostAlias(char *fqdn) {
298 char host[256], type[256];
301 if (fqdn == NULL) return(hostalias_nomatch);
302 if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
303 if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
304 if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
305 if (!strcasecmp(fqdn, config.c_nodename)) return(hostalias_localhost);
306 if (inetcfg == NULL) return(hostalias_nomatch);
308 config_lines = num_tokens(inetcfg, '\n');
309 for (i=0; i<config_lines; ++i) {
310 extract_token(buf, inetcfg, i, '\n', sizeof buf);
311 extract_token(host, buf, 0, '|', sizeof host);
312 extract_token(type, buf, 1, '|', sizeof type);
316 /* Process these in a specific order, in case there are multiple matches.
317 * We want directory to override masq, for example.
320 if ( (!strcasecmp(type, "masqdomain")) && (!strcasecmp(fqdn, host))) {
321 found = hostalias_masq;
323 if ( (!strcasecmp(type, "localhost")) && (!strcasecmp(fqdn, host))) {
324 found = hostalias_localhost;
326 if ( (!strcasecmp(type, "directory")) && (!strcasecmp(fqdn, host))) {
327 found = hostalias_directory;
330 if (found) return(found);
333 return(hostalias_nomatch);
343 * Return 0 if a given string fuzzy-matches a Citadel user account
345 * FIXME ... this needs to be updated to handle aliases.
347 int fuzzy_match(struct ctdluser *us, char *matchstring) {
351 if ( (!strncasecmp(matchstring, "cit", 3))
352 && (atol(&matchstring[3]) == us->usernum)) {
356 len = strlen(matchstring);
357 for (a=0; !IsEmptyStr(&us->fullname[a]); ++a) {
358 if (!strncasecmp(&us->fullname[a],
368 * Unfold a multi-line field into a single line, removing multi-whitespaces
370 void unfold_rfc822_field(char **field, char **FieldEnd)
373 char *pField = *field;
375 char *pFieldEnd = *FieldEnd;
377 while (isspace(*pField))
379 /* remove leading/trailing whitespace */
382 while (isspace(*pFieldEnd))
385 *FieldEnd = pFieldEnd;
386 /* convert non-space whitespace to spaces, and remove double blanks */
387 for (sField = *field = pField;
391 if ((*sField=='\r') || (*sField=='\n')) {
392 while (isspace(*sField))
397 if (*sField=='\"') quote = 1 - quote;
399 if (isspace(*sField))
405 while ((sField < pFieldEnd) &&
410 else *pField = *sField;
412 else *pField = *sField;
416 *FieldEnd = pField - 1;
422 * Split an RFC822-style address into userid, host, and full name
425 void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name)
430 strcpy(node, config.c_fqdn);
433 if (rfc822 == NULL) return;
435 /* extract full name - first, it's From minus <userid> */
436 strcpy(name, rfc822);
437 stripout(name, '<', '>');
439 /* strip anything to the left of a bang */
440 while ((!IsEmptyStr(name)) && (haschar(name, '!') > 0))
441 strcpy(name, &name[1]);
443 /* and anything to the right of a @ or % */
444 for (a = 0; a < strlen(name); ++a) {
451 /* but if there are parentheses, that changes the rules... */
452 if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
453 strcpy(name, rfc822);
454 stripallbut(name, '(', ')');
457 /* but if there are a set of quotes, that supersedes everything */
458 if (haschar(rfc822, 34) == 2) {
459 strcpy(name, rfc822);
460 while ((!IsEmptyStr(name)) && (name[0] != 34)) {
461 strcpy(&name[0], &name[1]);
463 strcpy(&name[0], &name[1]);
464 for (a = 0; a < strlen(name); ++a)
468 /* extract user id */
469 strcpy(user, rfc822);
471 /* first get rid of anything in parens */
472 stripout(user, '(', ')');
474 /* if there's a set of angle brackets, strip it down to that */
475 if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
476 stripallbut(user, '<', '>');
479 /* strip anything to the left of a bang */
480 while ((!IsEmptyStr(user)) && (haschar(user, '!') > 0))
481 strcpy(user, &user[1]);
483 /* and anything to the right of a @ or % */
484 for (a = 0; a < strlen(user); ++a) {
492 /* extract node name */
493 strcpy(node, rfc822);
495 /* first get rid of anything in parens */
496 stripout(node, '(', ')');
498 /* if there's a set of angle brackets, strip it down to that */
499 if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
500 stripallbut(node, '<', '>');
503 /* If no node specified, tack ours on instead */
505 (haschar(node, '@')==0)
506 && (haschar(node, '%')==0)
507 && (haschar(node, '!')==0)
509 strcpy(node, config.c_nodename);
514 /* strip anything to the left of a @ */
515 while ((!IsEmptyStr(node)) && (haschar(node, '@') > 0))
516 strcpy(node, &node[1]);
518 /* strip anything to the left of a % */
519 while ((!IsEmptyStr(node)) && (haschar(node, '%') > 0))
520 strcpy(node, &node[1]);
522 /* reduce multiple system bang paths to node!user */
523 while ((!IsEmptyStr(node)) && (haschar(node, '!') > 1))
524 strcpy(node, &node[1]);
526 /* now get rid of the user portion of a node!user string */
527 for (a = 0; a < strlen(node); ++a)
532 /* strip leading and trailing spaces in all strings */
537 /* If we processed a string that had the address in angle brackets
538 * but no name outside the brackets, we now have an empty name. In
539 * this case, use the user portion of the address as the name.
541 if ((IsEmptyStr(name)) && (!IsEmptyStr(user))) {
549 * convert_field() is a helper function for convert_internet_message().
550 * Given start/end positions for an rfc822 field, it converts it to a Citadel
551 * field if it wants to, and unfolds it if necessary.
553 * Returns 1 if the field was converted and inserted into the Citadel message
554 * structure, implying that the source field should be removed from the
557 int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
558 char *key, *value, *valueend;
562 const char *colonpos = NULL;
572 for (pos = end; pos >= beg; pos--) {
573 if (*pos == ':') colonpos = pos;
576 if (colonpos == NULL) return(0); /* no colon? not a valid header line */
579 key = malloc(len + 2);
580 memcpy(key, beg, len + 1);
582 valueend = key + len;
583 * ( key + (colonpos - beg) ) = '\0';
584 value = &key[(colonpos - beg) + 1];
585 /* printf("Header: [%s]\nValue: [%s]\n", key, value); */
586 unfold_rfc822_field(&value, &valueend);
587 valuelen = valueend - value + 1;
588 /* printf("UnfoldedValue: [%s]\n", value); */
591 * Here's the big rfc822-to-citadel loop.
594 /* Date/time is converted into a unix timestamp. If the conversion
595 * fails, we replace it with the time the message arrived locally.
597 if (!strcasecmp(key, "Date")) {
598 parsed_date = parsedate(value);
599 if (parsed_date < 0L) parsed_date = time(NULL);
600 snprintf(buf, sizeof buf, "%ld", (long)parsed_date );
601 if (msg->cm_fields['T'] == NULL)
602 msg->cm_fields['T'] = strdup(buf);
606 else if (!strcasecmp(key, "From")) {
607 process_rfc822_addr(value, user, node, name);
608 CtdlLogPrintf(CTDL_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
609 snprintf(addr, sizeof addr, "%s@%s", user, node);
610 if (msg->cm_fields['A'] == NULL)
611 msg->cm_fields['A'] = strdup(name);
613 if (msg->cm_fields['F'] == NULL)
614 msg->cm_fields['F'] = strdup(addr);
618 else if (!strcasecmp(key, "Subject")) {
619 if (msg->cm_fields['U'] == NULL)
620 msg->cm_fields['U'] = strndup(value, valuelen);
624 else if (!strcasecmp(key, "List-ID")) {
625 if (msg->cm_fields['L'] == NULL)
626 msg->cm_fields['L'] = strndup(value, valuelen);
630 else if (!strcasecmp(key, "To")) {
631 if (msg->cm_fields['R'] == NULL)
632 msg->cm_fields['R'] = strndup(value, valuelen);
636 else if (!strcasecmp(key, "CC")) {
637 if (msg->cm_fields['Y'] == NULL)
638 msg->cm_fields['Y'] = strndup(value, valuelen);
642 else if (!strcasecmp(key, "Message-ID")) {
643 if (msg->cm_fields['I'] != NULL) {
644 CtdlLogPrintf(CTDL_WARNING, "duplicate message id\n");
647 if (msg->cm_fields['I'] == NULL) {
648 msg->cm_fields['I'] = strndup(value, valuelen);
650 /* Strip angle brackets */
651 while (haschar(msg->cm_fields['I'], '<') > 0) {
652 strcpy(&msg->cm_fields['I'][0],
653 &msg->cm_fields['I'][1]);
655 for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
656 if (msg->cm_fields['I'][i] == '>')
657 msg->cm_fields['I'][i] = 0;
663 else if (!strcasecmp(key, "Return-Path")) {
664 if (msg->cm_fields['P'] == NULL)
665 msg->cm_fields['P'] = strndup(value, valuelen);
669 else if (!strcasecmp(key, "Envelope-To")) {
670 if (msg->cm_fields['V'] == NULL)
671 msg->cm_fields['V'] = strndup(value, valuelen);
675 else if (!strcasecmp(key, "References")) {
676 if (msg->cm_fields['W'] != NULL) {
677 free(msg->cm_fields['W']);
679 msg->cm_fields['W'] = strndup(value, valuelen);
683 else if (!strcasecmp(key, "In-reply-to")) {
684 if (msg->cm_fields['W'] == NULL) { /* References: supersedes In-reply-to: */
685 msg->cm_fields['W'] = strndup(value, valuelen);
692 /* Clean up and move on. */
693 free(key); /* Don't free 'value', it's actually the same buffer */
699 * Convert RFC822 references format (References) to Citadel references format (Weferences)
701 void convert_references_to_wefewences(char *str) {
702 int bracket_nesting = 0;
704 char *moveptr = NULL;
711 if (bracket_nesting < 0) bracket_nesting = 0;
713 if ((ch == '>') && (bracket_nesting == 0) && (*(ptr+1)) && (ptr>str) ) {
717 else if (bracket_nesting > 0) {
723 *moveptr = *(moveptr+1);
727 if (ch == '<') ++bracket_nesting;
734 * Convert an RFC822 message (headers + body) to a CtdlMessage structure.
735 * NOTE: the supplied buffer becomes part of the CtdlMessage structure, and
736 * will be deallocated when CtdlFreeMessage() is called. Therefore, the
737 * supplied buffer should be DEREFERENCED. It should not be freed or used
740 struct CtdlMessage *convert_internet_message(char *rfc822) {
741 StrBuf *RFCBuf = NewStrBufPlain(rfc822, -1);
743 return convert_internet_message_buf(&RFCBuf);
748 struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822)
750 struct CtdlMessage *msg;
751 const char *pos, *beg, *end, *totalend;
752 int done, alldone = 0;
755 StrBuf *OtherHeaders;
757 msg = malloc(sizeof(struct CtdlMessage));
758 if (msg == NULL) return msg;
760 memset(msg, 0, sizeof(struct CtdlMessage));
761 msg->cm_magic = CTDLMESSAGE_MAGIC; /* self check */
762 msg->cm_anon_type = 0; /* never anonymous */
763 msg->cm_format_type = FMT_RFC822; /* internet message */
765 pos = ChrPtr(*rfc822);
766 totalend = pos + StrLength(*rfc822);
768 OtherHeaders = NewStrBufPlain(NULL, StrLength(*rfc822));
772 /* Locate beginning and end of field, keeping in mind that
773 * some fields might be multiline
777 while ((end < totalend) &&
782 if ( (*pos=='\n') && ((*pos+1)!=0x20) && ((*pos+1)!=0x09) )
787 /* done with headers? */
789 ( (*(pos+1)=='\n') ||
795 if (pos >= (totalend - 1) )
805 /* At this point we have a field. Are we interested in it? */
806 converted = convert_field(msg, beg, end);
808 /* Strip the field out of the RFC822 header if we used it */
810 StrBufAppendBufPlain(OtherHeaders, beg, end - beg, 0);
811 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
814 /* If we've hit the end of the message, bail out */
818 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
820 StrBufAppendBufPlain(OtherHeaders, pos, totalend - pos, 0);
822 msg->cm_fields['M'] = SmashStrBuf(&OtherHeaders);
824 /* Follow-up sanity checks... */
826 /* If there's no timestamp on this message, set it to now. */
827 if (msg->cm_fields['T'] == NULL) {
828 snprintf(buf, sizeof buf, "%ld", (long)time(NULL));
829 msg->cm_fields['T'] = strdup(buf);
832 /* If a W (references, or rather, Wefewences) field is present, we
833 * have to convert it from RFC822 format to Citadel format.
835 if (msg->cm_fields['W'] != NULL) {
836 convert_references_to_wefewences(msg->cm_fields['W']);
845 * Look for a particular header field in an RFC822 message text. If the
846 * requested field is found, it is unfolded (if necessary) and returned to
847 * the caller. The field name is stripped out, leaving only its contents.
848 * The caller is responsible for freeing the returned buffer. If the requested
849 * field is not present, or anything else goes wrong, it returns NULL.
851 char *rfc822_fetch_field(const char *rfc822, const char *fieldname) {
852 char *fieldbuf = NULL;
853 const char *end_of_headers;
854 const char *field_start;
859 /* Should never happen, but sometimes we get stupid */
860 if (rfc822 == NULL) return(NULL);
861 if (fieldname == NULL) return(NULL);
863 snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname);
865 /* Locate the end of the headers, so we don't run past that point */
866 end_of_headers = cbmstrcasestr(rfc822, "\n\r\n");
867 if (end_of_headers == NULL) {
868 end_of_headers = cbmstrcasestr(rfc822, "\n\n");
870 if (end_of_headers == NULL) return (NULL);
872 field_start = cbmstrcasestr(rfc822, fieldhdr);
873 if (field_start == NULL) return(NULL);
874 if (field_start > end_of_headers) return(NULL);
876 fieldbuf = malloc(SIZ);
877 strcpy(fieldbuf, "");
880 ptr = cmemreadline(ptr, fieldbuf, SIZ-strlen(fieldbuf) );
881 while ( (isspace(ptr[0])) && (ptr < end_of_headers) ) {
882 strcat(fieldbuf, " ");
883 cont = &fieldbuf[strlen(fieldbuf)];
884 ptr = cmemreadline(ptr, cont, SIZ-strlen(fieldbuf) );
888 strcpy(fieldbuf, &fieldbuf[strlen(fieldhdr)]);
896 /*****************************************************************************
897 * DIRECTORY MANAGEMENT FUNCTIONS *
898 *****************************************************************************/
901 * Generate the index key for an Internet e-mail address to be looked up
904 void directory_key(char *key, char *addr) {
908 for (i=0; !IsEmptyStr(&addr[i]); ++i) {
909 if (!isspace(addr[i])) {
910 key[keylen++] = tolower(addr[i]);
915 CtdlLogPrintf(CTDL_DEBUG, "Directory key is <%s>\n", key);
920 /* Return nonzero if the supplied address is in a domain we keep in
923 int IsDirectory(char *addr, int allow_masq_domains) {
927 extract_token(domain, addr, 1, '@', sizeof domain);
930 h = CtdlHostAlias(domain);
932 if ( (h == hostalias_masq) && allow_masq_domains)
935 if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
945 * Initialize the directory database (erasing anything already there)
947 void CtdlDirectoryInit(void) {
948 cdb_trunc(CDB_DIRECTORY);
953 * Add an Internet e-mail address to the directory for a user
955 void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
958 if (IsDirectory(internet_addr, 0) == 0) return;
959 CtdlLogPrintf(CTDL_DEBUG, "Create directory entry: %s --> %s\n", internet_addr, citadel_addr);
960 directory_key(key, internet_addr);
961 cdb_store(CDB_DIRECTORY, key, strlen(key), citadel_addr, strlen(citadel_addr)+1 );
966 * Delete an Internet e-mail address from the directory.
968 * (NOTE: we don't actually use or need the citadel_addr variable; it's merely
969 * here because the callback API expects to be able to send it.)
971 void CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
974 CtdlLogPrintf(CTDL_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
975 directory_key(key, internet_addr);
976 cdb_delete(CDB_DIRECTORY, key, strlen(key) );
981 * Look up an Internet e-mail address in the directory.
982 * On success: returns 0, and Citadel address stored in 'target'
983 * On failure: returns nonzero
985 int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
986 struct cdbdata *cdbrec;
989 /* Dump it in there unchanged, just for kicks */
990 safestrncpy(target, internet_addr, targbuflen);
992 /* Only do lookups for addresses with hostnames in them */
993 if (num_tokens(internet_addr, '@') != 2) return(-1);
995 /* Only do lookups for domains in the directory */
996 if (IsDirectory(internet_addr, 0) == 0) return(-1);
998 directory_key(key, internet_addr);
999 cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
1000 if (cdbrec != NULL) {
1001 safestrncpy(target, cdbrec->ptr, targbuflen);
1011 * Harvest any email addresses that someone might want to have in their
1012 * "collected addresses" book.
1014 char *harvest_collected_addresses(struct CtdlMessage *msg) {
1017 char user[256], node[256], name[256];
1022 if (msg == NULL) return(NULL);
1026 if (msg->cm_fields['A'] != NULL) {
1027 strcat(addr, msg->cm_fields['A']);
1029 if (msg->cm_fields['F'] != NULL) {
1031 strcat(addr, msg->cm_fields['F']);
1033 if (IsDirectory(msg->cm_fields['F'], 0)) {
1038 if (is_harvestable) {
1039 coll = strdup(addr);
1045 if (coll == NULL) return(NULL);
1047 /* Scan both the R (To) and Y (CC) fields */
1048 for (i = 0; i < 2; ++i) {
1049 if (i == 0) field = 'R' ;
1050 if (i == 1) field = 'Y' ;
1052 if (msg->cm_fields[field] != NULL) {
1053 for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
1054 extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
1055 if (strstr(addr, "=?") != NULL)
1056 utf8ify_rfc822_string(addr);
1057 process_rfc822_addr(addr, user, node, name);
1058 h = CtdlHostAlias(node);
1059 if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {
1060 coll = realloc(coll, strlen(coll) + strlen(addr) + 4);
1061 if (coll == NULL) return(NULL);
1062 if (!IsEmptyStr(coll)) {
1072 if (IsEmptyStr(coll)) {