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"
44 #include "ctdl_module.h"
49 /* This is the non-define version in case of s.b. needing to debug */
50 inline void FindNextEnd (char *bptr, char *end)
52 /* Find the next ?Q? */
53 end = strchr(bptr + 2, '?');
54 if (end == NULL) return NULL;
55 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
56 (*(end + 2) == '?')) {
57 /* skip on to the end of the cluster, the next ?= */
58 end = strstr(end + 3, "?=");
61 /* sort of half valid encoding, try to find an end. */
62 end = strstr(bptr, "?=");
66 #define FindNextEnd(bptr, end) { \
67 end = strchr(bptr + 2, '?'); \
69 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) && (*(end + 2) == '?')) { \
70 end = strstr(end + 3, "?="); \
71 } else end = strstr(bptr, "?="); \
76 * Handle subjects with RFC2047 encoding such as:
77 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
79 void utf8ify_rfc822_string(char *buf) {
80 char *start, *end, *next, *nextend, *ptr;
85 iconv_t ic = (iconv_t)(-1) ;
86 char *ibuf; /**< Buffer of characters to be converted */
87 char *obuf; /**< Buffer for converted characters */
88 size_t ibuflen; /**< Length of input buffer */
89 size_t obuflen; /**< Length of output buffer */
90 char *isav; /**< Saved pointer to input buffer */
91 char *osav; /**< Saved pointer to output buffer */
94 int illegal_non_rfc2047_encoding = 0;
96 /* Sometimes, badly formed messages contain strings which were simply
97 * written out directly in some foreign character set instead of
98 * using RFC2047 encoding. This is illegal but we will attempt to
99 * handle it anyway by converting from a user-specified default
100 * charset to UTF-8 if we see any nonprintable characters.
103 for (i=0; i<len; ++i) {
104 if ((buf[i] < 32) || (buf[i] > 126)) {
105 illegal_non_rfc2047_encoding = 1;
106 i = len; ///< take a shortcut, it won't be more than one.
109 if (illegal_non_rfc2047_encoding) {
110 const char *default_header_charset = "iso-8859-1";
111 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
112 ctdl_iconv_open("UTF-8", default_header_charset, &ic);
113 if (ic != (iconv_t)(-1) ) {
116 safestrncpy(ibuf, buf, 1024);
117 ibuflen = strlen(ibuf);
119 obuf = (char *) malloc(obuflen);
121 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
122 osav[1024-obuflen] = 0;
131 /* pre evaluate the first pair */
132 nextend = end = NULL;
134 start = strstr(buf, "=?");
136 FindNextEnd (start, end);
138 while ((start != NULL) && (end != NULL))
140 next = strstr(end, "=?");
142 FindNextEnd(next, nextend);
146 /* did we find two partitions */
147 if ((next != NULL) &&
151 while ((ptr < next) &&
157 /* did we find a gab just filled with blanks? */
162 len - (next - start));
164 /* now terminate the gab at the end */
165 delta = (next - end) - 2;
169 /* move next to its new location. */
174 /* our next-pair is our new first pair now. */
179 /* Now we handle foreign character sets properly encoded
182 start = strstr(buf, "=?");
183 FindNextEnd((start != NULL)? start : buf, end);
184 while (start != NULL && end != NULL && end > start)
186 extract_token(charset, start, 1, '?', sizeof charset);
187 extract_token(encoding, start, 2, '?', sizeof encoding);
188 extract_token(istr, start, 3, '?', sizeof istr);
192 if (!strcasecmp(encoding, "B")) { /**< base64 */
193 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
195 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
203 if (istr[pos] == '_') istr[pos] = ' ';
207 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
210 strcpy(ibuf, istr); /**< unknown encoding */
211 ibuflen = strlen(istr);
214 ctdl_iconv_open("UTF-8", charset, &ic);
215 if (ic != (iconv_t)(-1) ) {
217 obuf = (char *) malloc(obuflen);
219 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
220 osav[1024-obuflen] = 0;
225 remove_token(end, 0, '?');
226 remove_token(end, 0, '?');
227 remove_token(end, 0, '?');
228 remove_token(end, 0, '?');
229 strcpy(end, &end[1]);
231 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
240 remove_token(end, 0, '?');
241 remove_token(end, 0, '?');
242 remove_token(end, 0, '?');
243 remove_token(end, 0, '?');
244 strcpy(end, &end[1]);
246 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
253 * Since spammers will go to all sorts of absurd lengths to get their
254 * messages through, there are LOTS of corrupt headers out there.
255 * So, prevent a really badly formed RFC2047 header from throwing
256 * this function into an infinite loop.
259 if (passes > 20) return;
261 start = strstr(buf, "=?");
262 FindNextEnd((start != NULL)? start : buf, end);
267 inline void utf8ify_rfc822_string(char *a){};
278 char *inetcfg = NULL;
279 struct spamstrings_t *spamstrings = NULL;
283 * Return nonzero if the supplied name is an alias for this host.
285 int CtdlHostAlias(char *fqdn) {
289 char host[256], type[256];
292 if (fqdn == NULL) return(hostalias_nomatch);
293 if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
294 if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
295 if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
296 if (!strcasecmp(fqdn, config.c_nodename)) return(hostalias_localhost);
297 if (inetcfg == NULL) return(hostalias_nomatch);
299 config_lines = num_tokens(inetcfg, '\n');
300 for (i=0; i<config_lines; ++i) {
301 extract_token(buf, inetcfg, i, '\n', sizeof buf);
302 extract_token(host, buf, 0, '|', sizeof host);
303 extract_token(type, buf, 1, '|', sizeof type);
307 /* Process these in a specific order, in case there are multiple matches.
308 * We want directory to override masq, for example.
311 if ( (!strcasecmp(type, "masqdomain")) && (!strcasecmp(fqdn, host))) {
312 found = hostalias_masq;
314 if ( (!strcasecmp(type, "localhost")) && (!strcasecmp(fqdn, host))) {
315 found = hostalias_localhost;
317 if ( (!strcasecmp(type, "directory")) && (!strcasecmp(fqdn, host))) {
318 found = hostalias_directory;
321 if (found) return(found);
324 return(hostalias_nomatch);
334 * Return 0 if a given string fuzzy-matches a Citadel user account
336 * FIXME ... this needs to be updated to handle aliases.
338 int fuzzy_match(struct ctdluser *us, char *matchstring) {
342 if ( (!strncasecmp(matchstring, "cit", 3))
343 && (atol(&matchstring[3]) == us->usernum)) {
347 len = strlen(matchstring);
348 for (a=0; !IsEmptyStr(&us->fullname[a]); ++a) {
349 if (!strncasecmp(&us->fullname[a],
359 * Unfold a multi-line field into a single line, removing multi-whitespaces
361 void unfold_rfc822_field(char **field, char **FieldEnd)
364 char *pField = *field;
366 char *pFieldEnd = *FieldEnd;
368 while (isspace(*pField))
370 /* remove leading/trailing whitespace */
373 while (isspace(*pFieldEnd))
376 *FieldEnd = pFieldEnd;
377 /* convert non-space whitespace to spaces, and remove double blanks */
378 for (sField = *field = pField;
382 if ((*sField=='\r') || (*sField=='\n')) {
389 if (*sField=='\"') quote = 1 - quote;
391 if (isspace(*sField))
397 while ((sField < pFieldEnd) &&
402 else *pField = *sField;
404 else *pField = *sField;
408 *FieldEnd = pField - 1;
414 * Split an RFC822-style address into userid, host, and full name
417 void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name)
422 strcpy(node, config.c_fqdn);
425 if (rfc822 == NULL) return;
427 /* extract full name - first, it's From minus <userid> */
428 strcpy(name, rfc822);
429 stripout(name, '<', '>');
431 /* strip anything to the left of a bang */
432 while ((!IsEmptyStr(name)) && (haschar(name, '!') > 0))
433 strcpy(name, &name[1]);
435 /* and anything to the right of a @ or % */
436 for (a = 0; a < strlen(name); ++a) {
443 /* but if there are parentheses, that changes the rules... */
444 if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
445 strcpy(name, rfc822);
446 stripallbut(name, '(', ')');
449 /* but if there are a set of quotes, that supersedes everything */
450 if (haschar(rfc822, 34) == 2) {
451 strcpy(name, rfc822);
452 while ((!IsEmptyStr(name)) && (name[0] != 34)) {
453 strcpy(&name[0], &name[1]);
455 strcpy(&name[0], &name[1]);
456 for (a = 0; a < strlen(name); ++a)
460 /* extract user id */
461 strcpy(user, rfc822);
463 /* first get rid of anything in parens */
464 stripout(user, '(', ')');
466 /* if there's a set of angle brackets, strip it down to that */
467 if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
468 stripallbut(user, '<', '>');
471 /* strip anything to the left of a bang */
472 while ((!IsEmptyStr(user)) && (haschar(user, '!') > 0))
473 strcpy(user, &user[1]);
475 /* and anything to the right of a @ or % */
476 for (a = 0; a < strlen(user); ++a) {
484 /* extract node name */
485 strcpy(node, rfc822);
487 /* first get rid of anything in parens */
488 stripout(node, '(', ')');
490 /* if there's a set of angle brackets, strip it down to that */
491 if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
492 stripallbut(node, '<', '>');
495 /* If no node specified, tack ours on instead */
497 (haschar(node, '@')==0)
498 && (haschar(node, '%')==0)
499 && (haschar(node, '!')==0)
501 strcpy(node, config.c_nodename);
506 /* strip anything to the left of a @ */
507 while ((!IsEmptyStr(node)) && (haschar(node, '@') > 0))
508 strcpy(node, &node[1]);
510 /* strip anything to the left of a % */
511 while ((!IsEmptyStr(node)) && (haschar(node, '%') > 0))
512 strcpy(node, &node[1]);
514 /* reduce multiple system bang paths to node!user */
515 while ((!IsEmptyStr(node)) && (haschar(node, '!') > 1))
516 strcpy(node, &node[1]);
518 /* now get rid of the user portion of a node!user string */
519 for (a = 0; a < strlen(node); ++a)
524 /* strip leading and trailing spaces in all strings */
529 /* If we processed a string that had the address in angle brackets
530 * but no name outside the brackets, we now have an empty name. In
531 * this case, use the user portion of the address as the name.
533 if ((IsEmptyStr(name)) && (!IsEmptyStr(user))) {
541 * convert_field() is a helper function for convert_internet_message().
542 * Given start/end positions for an rfc822 field, it converts it to a Citadel
543 * field if it wants to, and unfolds it if necessary.
545 * Returns 1 if the field was converted and inserted into the Citadel message
546 * structure, implying that the source field should be removed from the
549 int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
550 char *key, *value, *valueend;
554 const char *colonpos = NULL;
564 for (pos = end; pos >= beg; pos--) {
565 if (*pos == ':') colonpos = pos;
568 if (colonpos == NULL) return(0); /* no colon? not a valid header line */
571 key = malloc(len + 2);
572 memcpy(key, beg, len + 1);
574 valueend = key + len;
575 * ( key + (colonpos - beg) ) = '\0';
576 value = &key[(colonpos - beg) + 1];
577 /* printf("Header: [%s]\nValue: [%s]\n", key, value); */
578 unfold_rfc822_field(&value, &valueend);
579 valuelen = valueend - value + 1;
580 /* printf("UnfoldedValue: [%s]\n", value); */
583 * Here's the big rfc822-to-citadel loop.
586 /* Date/time is converted into a unix timestamp. If the conversion
587 * fails, we replace it with the time the message arrived locally.
589 if (!strcasecmp(key, "Date")) {
590 parsed_date = parsedate(value);
591 if (parsed_date < 0L) parsed_date = time(NULL);
592 snprintf(buf, sizeof buf, "%ld", (long)parsed_date );
593 if (msg->cm_fields['T'] == NULL)
594 msg->cm_fields['T'] = strdup(buf);
598 else if (!strcasecmp(key, "From")) {
599 process_rfc822_addr(value, user, node, name);
600 syslog(LOG_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
601 snprintf(addr, sizeof addr, "%s@%s", user, node);
602 if (msg->cm_fields['A'] == NULL)
603 msg->cm_fields['A'] = strdup(name);
604 if (msg->cm_fields['F'] == NULL)
605 msg->cm_fields['F'] = strdup(addr);
609 else if (!strcasecmp(key, "Subject")) {
610 if (msg->cm_fields['U'] == NULL)
611 msg->cm_fields['U'] = strndup(value, valuelen);
615 else if (!strcasecmp(key, "List-ID")) {
616 if (msg->cm_fields['L'] == NULL)
617 msg->cm_fields['L'] = strndup(value, valuelen);
621 else if (!strcasecmp(key, "To")) {
622 if (msg->cm_fields['R'] == NULL)
623 msg->cm_fields['R'] = strndup(value, valuelen);
627 else if (!strcasecmp(key, "CC")) {
628 if (msg->cm_fields['Y'] == NULL)
629 msg->cm_fields['Y'] = strndup(value, valuelen);
633 else if (!strcasecmp(key, "Message-ID")) {
634 if (msg->cm_fields['I'] != NULL) {
635 syslog(LOG_WARNING, "duplicate message id\n");
638 if (msg->cm_fields['I'] == NULL) {
639 msg->cm_fields['I'] = strndup(value, valuelen);
641 /* Strip angle brackets */
642 while (haschar(msg->cm_fields['I'], '<') > 0) {
643 strcpy(&msg->cm_fields['I'][0],
644 &msg->cm_fields['I'][1]);
646 for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
647 if (msg->cm_fields['I'][i] == '>')
648 msg->cm_fields['I'][i] = 0;
654 else if (!strcasecmp(key, "Return-Path")) {
655 if (msg->cm_fields['P'] == NULL)
656 msg->cm_fields['P'] = strndup(value, valuelen);
660 else if (!strcasecmp(key, "Envelope-To")) {
661 if (msg->cm_fields['V'] == NULL)
662 msg->cm_fields['V'] = strndup(value, valuelen);
666 else if (!strcasecmp(key, "References")) {
667 if (msg->cm_fields['W'] != NULL) {
668 free(msg->cm_fields['W']);
670 msg->cm_fields['W'] = strndup(value, valuelen);
674 else if (!strcasecmp(key, "Reply-To")) {
675 if (msg->cm_fields['K'] != NULL) {
676 free(msg->cm_fields['K']);
678 msg->cm_fields['K'] = strndup(value, valuelen);
682 else if (!strcasecmp(key, "In-reply-to")) {
683 if (msg->cm_fields['W'] == NULL) { /* References: supersedes In-reply-to: */
684 msg->cm_fields['W'] = strndup(value, valuelen);
691 /* Clean up and move on. */
692 free(key); /* Don't free 'value', it's actually the same buffer */
698 * Convert RFC822 references format (References) to Citadel references format (Weferences)
700 void convert_references_to_wefewences(char *str) {
701 int bracket_nesting = 0;
703 char *moveptr = NULL;
710 if (bracket_nesting < 0) bracket_nesting = 0;
712 if ((ch == '>') && (bracket_nesting == 0) && (*(ptr+1)) && (ptr>str) ) {
716 else if (bracket_nesting > 0) {
722 *moveptr = *(moveptr+1);
726 if (ch == '<') ++bracket_nesting;
733 * Convert an RFC822 message (headers + body) to a CtdlMessage structure.
734 * NOTE: the supplied buffer becomes part of the CtdlMessage structure, and
735 * will be deallocated when CtdlFreeMessage() is called. Therefore, the
736 * supplied buffer should be DEREFERENCED. It should not be freed or used
739 struct CtdlMessage *convert_internet_message(char *rfc822) {
740 StrBuf *RFCBuf = NewStrBufPlain(rfc822, -1);
742 return convert_internet_message_buf(&RFCBuf);
747 struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822)
749 struct CtdlMessage *msg;
750 const char *pos, *beg, *end, *totalend;
751 int done, alldone = 0;
754 StrBuf *OtherHeaders;
756 msg = malloc(sizeof(struct CtdlMessage));
757 if (msg == NULL) return msg;
759 memset(msg, 0, sizeof(struct CtdlMessage));
760 msg->cm_magic = CTDLMESSAGE_MAGIC; /* self check */
761 msg->cm_anon_type = 0; /* never anonymous */
762 msg->cm_format_type = FMT_RFC822; /* internet message */
764 pos = ChrPtr(*rfc822);
765 totalend = pos + StrLength(*rfc822);
767 OtherHeaders = NewStrBufPlain(NULL, StrLength(*rfc822));
771 /* Locate beginning and end of field, keeping in mind that
772 * some fields might be multiline
776 while ((end < totalend) &&
781 if ( (*pos=='\n') && ((*(pos+1))!=0x20) && ((*(pos+1))!=0x09) )
786 /* done with headers? */
788 ( (*(pos+1)=='\n') ||
794 if (pos >= (totalend - 1) )
804 /* At this point we have a field. Are we interested in it? */
805 converted = convert_field(msg, beg, end);
807 /* Strip the field out of the RFC822 header if we used it */
809 StrBufAppendBufPlain(OtherHeaders, beg, end - beg, 0);
810 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
813 /* If we've hit the end of the message, bail out */
817 StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
819 StrBufAppendBufPlain(OtherHeaders, pos, totalend - pos, 0);
821 msg->cm_fields['M'] = SmashStrBuf(&OtherHeaders);
823 /* Follow-up sanity checks... */
825 /* If there's no timestamp on this message, set it to now. */
826 if (msg->cm_fields['T'] == NULL) {
827 snprintf(buf, sizeof buf, "%ld", (long)time(NULL));
828 msg->cm_fields['T'] = strdup(buf);
831 /* If a W (references, or rather, Wefewences) field is present, we
832 * have to convert it from RFC822 format to Citadel format.
834 if (msg->cm_fields['W'] != NULL) {
835 convert_references_to_wefewences(msg->cm_fields['W']);
844 * Look for a particular header field in an RFC822 message text. If the
845 * requested field is found, it is unfolded (if necessary) and returned to
846 * the caller. The field name is stripped out, leaving only its contents.
847 * The caller is responsible for freeing the returned buffer. If the requested
848 * field is not present, or anything else goes wrong, it returns NULL.
850 char *rfc822_fetch_field(const char *rfc822, const char *fieldname) {
851 char *fieldbuf = NULL;
852 const char *end_of_headers;
853 const char *field_start;
858 /* Should never happen, but sometimes we get stupid */
859 if (rfc822 == NULL) return(NULL);
860 if (fieldname == NULL) return(NULL);
862 snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname);
864 /* Locate the end of the headers, so we don't run past that point */
865 end_of_headers = cbmstrcasestr(rfc822, "\n\r\n");
866 if (end_of_headers == NULL) {
867 end_of_headers = cbmstrcasestr(rfc822, "\n\n");
869 if (end_of_headers == NULL) return (NULL);
871 field_start = cbmstrcasestr(rfc822, fieldhdr);
872 if (field_start == NULL) return(NULL);
873 if (field_start > end_of_headers) return(NULL);
875 fieldbuf = malloc(SIZ);
876 strcpy(fieldbuf, "");
879 ptr = cmemreadline(ptr, fieldbuf, SIZ-strlen(fieldbuf) );
880 while ( (isspace(ptr[0])) && (ptr < end_of_headers) ) {
881 strcat(fieldbuf, " ");
882 cont = &fieldbuf[strlen(fieldbuf)];
883 ptr = cmemreadline(ptr, cont, SIZ-strlen(fieldbuf) );
887 strcpy(fieldbuf, &fieldbuf[strlen(fieldhdr)]);
895 /*****************************************************************************
896 * DIRECTORY MANAGEMENT FUNCTIONS *
897 *****************************************************************************/
900 * Generate the index key for an Internet e-mail address to be looked up
903 void directory_key(char *key, char *addr) {
907 for (i=0; !IsEmptyStr(&addr[i]); ++i) {
908 if (!isspace(addr[i])) {
909 key[keylen++] = tolower(addr[i]);
914 syslog(LOG_DEBUG, "Directory key is <%s>\n", key);
919 /* Return nonzero if the supplied address is in a domain we keep in
922 int IsDirectory(char *addr, int allow_masq_domains) {
926 extract_token(domain, addr, 1, '@', sizeof domain);
929 h = CtdlHostAlias(domain);
931 if ( (h == hostalias_masq) && allow_masq_domains)
934 if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
944 * Initialize the directory database (erasing anything already there)
946 void CtdlDirectoryInit(void) {
947 cdb_trunc(CDB_DIRECTORY);
952 * Add an Internet e-mail address to the directory for a user
954 int CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
957 if (IsDirectory(internet_addr, 0) == 0)
959 syslog(LOG_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 );
967 * Delete an Internet e-mail address from the directory.
969 * (NOTE: we don't actually use or need the citadel_addr variable; it's merely
970 * here because the callback API expects to be able to send it.)
972 int CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
975 syslog(LOG_DEBUG, "Delete directory entry: %s --> %s\n", internet_addr, citadel_addr);
976 directory_key(key, internet_addr);
977 return cdb_delete(CDB_DIRECTORY, key, strlen(key) ) == 0;
982 * Look up an Internet e-mail address in the directory.
983 * On success: returns 0, and Citadel address stored in 'target'
984 * On failure: returns nonzero
986 int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
987 struct cdbdata *cdbrec;
990 /* Dump it in there unchanged, just for kicks */
991 safestrncpy(target, internet_addr, targbuflen);
993 /* Only do lookups for addresses with hostnames in them */
994 if (num_tokens(internet_addr, '@') != 2) return(-1);
996 /* Only do lookups for domains in the directory */
997 if (IsDirectory(internet_addr, 0) == 0) return(-1);
999 directory_key(key, internet_addr);
1000 cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
1001 if (cdbrec != NULL) {
1002 safestrncpy(target, cdbrec->ptr, targbuflen);
1012 * Harvest any email addresses that someone might want to have in their
1013 * "collected addresses" book.
1015 char *harvest_collected_addresses(struct CtdlMessage *msg) {
1018 char user[256], node[256], name[256];
1023 if (msg == NULL) return(NULL);
1027 if (msg->cm_fields['A'] != NULL) {
1028 strcat(addr, msg->cm_fields['A']);
1030 if (msg->cm_fields['F'] != NULL) {
1032 strcat(addr, msg->cm_fields['F']);
1034 if (IsDirectory(msg->cm_fields['F'], 0)) {
1039 if (is_harvestable) {
1040 coll = strdup(addr);
1046 if (coll == NULL) return(NULL);
1048 /* Scan both the R (To) and Y (CC) fields */
1049 for (i = 0; i < 2; ++i) {
1050 if (i == 0) field = 'R' ;
1051 if (i == 1) field = 'Y' ;
1053 if (msg->cm_fields[field] != NULL) {
1054 for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
1055 extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
1056 if (strstr(addr, "=?") != NULL)
1057 utf8ify_rfc822_string(addr);
1058 process_rfc822_addr(addr, user, node, name);
1059 h = CtdlHostAlias(node);
1060 if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {
1061 coll = realloc(coll, strlen(coll) + strlen(addr) + 4);
1062 if (coll == NULL) return(NULL);
1063 if (!IsEmptyStr(coll)) {
1073 if (IsEmptyStr(coll)) {