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"
57 * Wrapper around iconv_open()
58 * Our version adds aliases for non-standard Microsoft charsets
59 * such as 'MS950', aliasing them to names like 'CP950'
61 * tocode Target encoding
62 * fromcode Source encoding
64 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
66 iconv_t ic = (iconv_t)(-1) ;
67 ic = iconv_open(tocode, fromcode);
68 if (ic == (iconv_t)(-1) ) {
69 char alias_fromcode[64];
70 if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
71 safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
72 alias_fromcode[0] = 'C';
73 alias_fromcode[1] = 'P';
74 ic = iconv_open(tocode, alias_fromcode);
81 /* This is the non-define version in case of s.b. needing to debug */
82 inline void FindNextEnd (char *bptr, char *end)
84 /* Find the next ?Q? */
85 end = strchr(bptr + 2, '?');
86 if (end == NULL) return NULL;
87 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) &&
88 (*(end + 2) == '?')) {
89 /* skip on to the end of the cluster, the next ?= */
90 end = strstr(end + 3, "?=");
93 /* sort of half valid encoding, try to find an end. */
94 end = strstr(bptr, "?=");
98 #define FindNextEnd(bptr, end) { \
99 end = strchr(bptr + 2, '?'); \
101 if (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) && (*(end + 2) == '?')) { \
102 end = strstr(end + 3, "?="); \
103 } else end = strstr(bptr, "?="); \
108 * Handle subjects with RFC2047 encoding such as:
109 * =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=
111 void utf8ify_rfc822_string(char *buf) {
112 char *start, *end, *next, *nextend, *ptr;
117 iconv_t ic = (iconv_t)(-1) ;
118 char *ibuf; /**< Buffer of characters to be converted */
119 char *obuf; /**< Buffer for converted characters */
120 size_t ibuflen; /**< Length of input buffer */
121 size_t obuflen; /**< Length of output buffer */
122 char *isav; /**< Saved pointer to input buffer */
123 char *osav; /**< Saved pointer to output buffer */
126 int illegal_non_rfc2047_encoding = 0;
128 /* Sometimes, badly formed messages contain strings which were simply
129 * written out directly in some foreign character set instead of
130 * using RFC2047 encoding. This is illegal but we will attempt to
131 * handle it anyway by converting from a user-specified default
132 * charset to UTF-8 if we see any nonprintable characters.
135 for (i=0; i<len; ++i) {
136 if ((buf[i] < 32) || (buf[i] > 126)) {
137 illegal_non_rfc2047_encoding = 1;
138 i = len; ///< take a shortcut, it won't be more than one.
141 if (illegal_non_rfc2047_encoding) {
142 const char *default_header_charset = "iso-8859-1";
143 if ( (strcasecmp(default_header_charset, "UTF-8")) && (strcasecmp(default_header_charset, "us-ascii")) ) {
144 ic = ctdl_iconv_open("UTF-8", default_header_charset);
145 if (ic != (iconv_t)(-1) ) {
148 safestrncpy(ibuf, buf, 1024);
149 ibuflen = strlen(ibuf);
151 obuf = (char *) malloc(obuflen);
153 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
154 osav[1024-obuflen] = 0;
163 /* pre evaluate the first pair */
164 nextend = end = NULL;
166 start = strstr(buf, "=?");
168 FindNextEnd (start, end);
170 while ((start != NULL) && (end != NULL))
172 next = strstr(end, "=?");
174 FindNextEnd(next, nextend);
178 /* did we find two partitions */
179 if ((next != NULL) &&
183 while ((ptr < next) &&
189 /* did we find a gab just filled with blanks? */
194 len - (next - start));
196 /* now terminate the gab at the end */
197 delta = (next - end) - 2;
201 /* move next to its new location. */
206 /* our next-pair is our new first pair now. */
211 /* Now we handle foreign character sets properly encoded
214 start = strstr(buf, "=?");
215 FindNextEnd((start != NULL)? start : buf, end);
216 while (start != NULL && end != NULL && end > start)
218 extract_token(charset, start, 1, '?', sizeof charset);
219 extract_token(encoding, start, 2, '?', sizeof encoding);
220 extract_token(istr, start, 3, '?', sizeof istr);
224 if (!strcasecmp(encoding, "B")) { /**< base64 */
225 ibuflen = CtdlDecodeBase64(ibuf, istr, strlen(istr));
227 else if (!strcasecmp(encoding, "Q")) { /**< quoted-printable */
235 if (istr[pos] == '_') istr[pos] = ' ';
239 ibuflen = CtdlDecodeQuotedPrintable(ibuf, istr, len);
242 strcpy(ibuf, istr); /**< unknown encoding */
243 ibuflen = strlen(istr);
246 ic = ctdl_iconv_open("UTF-8", charset);
247 if (ic != (iconv_t)(-1) ) {
249 obuf = (char *) malloc(obuflen);
251 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
252 osav[1024-obuflen] = 0;
257 remove_token(end, 0, '?');
258 remove_token(end, 0, '?');
259 remove_token(end, 0, '?');
260 remove_token(end, 0, '?');
261 strcpy(end, &end[1]);
263 snprintf(newbuf, sizeof newbuf, "%s%s%s", buf, osav, end);
272 remove_token(end, 0, '?');
273 remove_token(end, 0, '?');
274 remove_token(end, 0, '?');
275 remove_token(end, 0, '?');
276 strcpy(end, &end[1]);
278 snprintf(newbuf, sizeof newbuf, "%s(unreadable)%s", buf, end);
285 * Since spammers will go to all sorts of absurd lengths to get their
286 * messages through, there are LOTS of corrupt headers out there.
287 * So, prevent a really badly formed RFC2047 header from throwing
288 * this function into an infinite loop.
291 if (passes > 20) return;
293 start = strstr(buf, "=?");
294 FindNextEnd((start != NULL)? start : buf, end);
299 inline void utf8ify_rfc822_string(char *a){};
310 char *inetcfg = NULL;
311 struct spamstrings_t *spamstrings = NULL;
315 * Return nonzero if the supplied name is an alias for this host.
317 int CtdlHostAlias(char *fqdn) {
321 char host[256], type[256];
323 if (fqdn == NULL) return(hostalias_nomatch);
324 if (IsEmptyStr(fqdn)) return(hostalias_nomatch);
325 if (!strcasecmp(fqdn, "localhost")) return(hostalias_localhost);
326 if (!strcasecmp(fqdn, config.c_fqdn)) return(hostalias_localhost);
327 if (!strcasecmp(fqdn, config.c_nodename)) return(hostalias_localhost);
328 if (inetcfg == NULL) return(hostalias_nomatch);
330 config_lines = num_tokens(inetcfg, '\n');
331 for (i=0; i<config_lines; ++i) {
332 extract_token(buf, inetcfg, i, '\n', sizeof buf);
333 extract_token(host, buf, 0, '|', sizeof host);
334 extract_token(type, buf, 1, '|', sizeof type);
336 if ( (!strcasecmp(type, "localhost"))
337 && (!strcasecmp(fqdn, host)))
338 return(hostalias_localhost);
340 if ( (!strcasecmp(type, "directory"))
341 && (!strcasecmp(fqdn, host)))
342 return(hostalias_directory);
344 if ( (!strcasecmp(type, "masqdomain"))
345 && (!strcasecmp(fqdn, host)))
346 return(hostalias_masq);
350 return(hostalias_nomatch);
360 * Return 0 if a given string fuzzy-matches a Citadel user account
362 * FIXME ... this needs to be updated to handle aliases.
364 int fuzzy_match(struct ctdluser *us, char *matchstring) {
368 if ( (!strncasecmp(matchstring, "cit", 3))
369 && (atol(&matchstring[3]) == us->usernum)) {
373 len = strlen(matchstring);
374 for (a=0; !IsEmptyStr(&us->fullname[a]); ++a) {
375 if (!strncasecmp(&us->fullname[a],
385 * Unfold a multi-line field into a single line, removing multi-whitespaces
387 void unfold_rfc822_field(char *field) {
391 striplt(field); /* remove leading/trailing whitespace */
393 /* convert non-space whitespace to spaces, and remove double blanks */
394 for (i=0; i<strlen(field); ++i) {
395 if (field[i]=='\"') quote = 1 - quote;
397 if (isspace(field[i])) field[i] = ' ';
398 while (isspace(field[i]) && isspace(field[i+1])) {
399 strcpy(&field[i+1], &field[i+2]);
408 * Split an RFC822-style address into userid, host, and full name
411 void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name)
416 strcpy(node, config.c_fqdn);
419 if (rfc822 == NULL) return;
421 /* extract full name - first, it's From minus <userid> */
422 strcpy(name, rfc822);
423 stripout(name, '<', '>');
425 /* strip anything to the left of a bang */
426 while ((!IsEmptyStr(name)) && (haschar(name, '!') > 0))
427 strcpy(name, &name[1]);
429 /* and anything to the right of a @ or % */
430 for (a = 0; a < strlen(name); ++a) {
437 /* but if there are parentheses, that changes the rules... */
438 if ((haschar(rfc822, '(') == 1) && (haschar(rfc822, ')') == 1)) {
439 strcpy(name, rfc822);
440 stripallbut(name, '(', ')');
443 /* but if there are a set of quotes, that supersedes everything */
444 if (haschar(rfc822, 34) == 2) {
445 strcpy(name, rfc822);
446 while ((!IsEmptyStr(name)) && (name[0] != 34)) {
447 strcpy(&name[0], &name[1]);
449 strcpy(&name[0], &name[1]);
450 for (a = 0; a < strlen(name); ++a)
454 /* extract user id */
455 strcpy(user, rfc822);
457 /* first get rid of anything in parens */
458 stripout(user, '(', ')');
460 /* if there's a set of angle brackets, strip it down to that */
461 if ((haschar(user, '<') == 1) && (haschar(user, '>') == 1)) {
462 stripallbut(user, '<', '>');
465 /* strip anything to the left of a bang */
466 while ((!IsEmptyStr(user)) && (haschar(user, '!') > 0))
467 strcpy(user, &user[1]);
469 /* and anything to the right of a @ or % */
470 for (a = 0; a < strlen(user); ++a) {
478 /* extract node name */
479 strcpy(node, rfc822);
481 /* first get rid of anything in parens */
482 stripout(node, '(', ')');
484 /* if there's a set of angle brackets, strip it down to that */
485 if ((haschar(node, '<') == 1) && (haschar(node, '>') == 1)) {
486 stripallbut(node, '<', '>');
489 /* If no node specified, tack ours on instead */
491 (haschar(node, '@')==0)
492 && (haschar(node, '%')==0)
493 && (haschar(node, '!')==0)
495 strcpy(node, config.c_nodename);
500 /* strip anything to the left of a @ */
501 while ((!IsEmptyStr(node)) && (haschar(node, '@') > 0))
502 strcpy(node, &node[1]);
504 /* strip anything to the left of a % */
505 while ((!IsEmptyStr(node)) && (haschar(node, '%') > 0))
506 strcpy(node, &node[1]);
508 /* reduce multiple system bang paths to node!user */
509 while ((!IsEmptyStr(node)) && (haschar(node, '!') > 1))
510 strcpy(node, &node[1]);
512 /* now get rid of the user portion of a node!user string */
513 for (a = 0; a < strlen(node); ++a)
518 /* strip leading and trailing spaces in all strings */
523 /* If we processed a string that had the address in angle brackets
524 * but no name outside the brackets, we now have an empty name. In
525 * this case, use the user portion of the address as the name.
527 if ((IsEmptyStr(name)) && (!IsEmptyStr(user))) {
535 * convert_field() is a helper function for convert_internet_message().
536 * Given start/end positions for an rfc822 field, it converts it to a Citadel
537 * field if it wants to, and unfolds it if necessary.
539 * Returns 1 if the field was converted and inserted into the Citadel message
540 * structure, implying that the source field should be removed from the
543 int convert_field(struct CtdlMessage *msg, int beg, int end) {
556 rfc822 = msg->cm_fields['M']; /* M field contains rfc822 text */
557 for (i = end; i >= beg; --i) {
558 if (rfc822[i] == ':') colonpos = i;
561 if (colonpos < 0) return(0); /* no colon? not a valid header line */
563 key = malloc((end - beg) + 2);
564 safestrncpy(key, &rfc822[beg], (end-beg)+1);
565 key[colonpos - beg] = 0;
566 value = &key[(colonpos - beg) + 1];
567 unfold_rfc822_field(value);
570 * Here's the big rfc822-to-citadel loop.
573 /* Date/time is converted into a unix timestamp. If the conversion
574 * fails, we replace it with the time the message arrived locally.
576 if (!strcasecmp(key, "Date")) {
577 parsed_date = parsedate(value);
578 if (parsed_date < 0L) parsed_date = time(NULL);
579 snprintf(buf, sizeof buf, "%ld", (long)parsed_date );
580 if (msg->cm_fields['T'] == NULL)
581 msg->cm_fields['T'] = strdup(buf);
585 else if (!strcasecmp(key, "From")) {
586 process_rfc822_addr(value, user, node, name);
587 CtdlLogPrintf(CTDL_DEBUG, "Converted to <%s@%s> (%s)\n", user, node, name);
588 snprintf(addr, sizeof addr, "%s@%s", user, node);
589 if (msg->cm_fields['A'] == NULL)
590 msg->cm_fields['A'] = strdup(name);
592 if (msg->cm_fields['F'] == NULL)
593 msg->cm_fields['F'] = strdup(addr);
597 else if (!strcasecmp(key, "Subject")) {
598 if (msg->cm_fields['U'] == NULL)
599 msg->cm_fields['U'] = strdup(value);
603 else if (!strcasecmp(key, "List-ID")) {
604 if (msg->cm_fields['L'] == NULL)
605 msg->cm_fields['L'] = strdup(value);
609 else if (!strcasecmp(key, "To")) {
610 if (msg->cm_fields['R'] == NULL)
611 msg->cm_fields['R'] = strdup(value);
615 else if (!strcasecmp(key, "CC")) {
616 if (msg->cm_fields['Y'] == NULL)
617 msg->cm_fields['Y'] = strdup(value);
621 else if (!strcasecmp(key, "Message-ID")) {
622 if (msg->cm_fields['I'] != NULL) {
623 CtdlLogPrintf(CTDL_WARNING, "duplicate message id\n");
626 if (msg->cm_fields['I'] == NULL) {
627 msg->cm_fields['I'] = strdup(value);
629 /* Strip angle brackets */
630 while (haschar(msg->cm_fields['I'], '<') > 0) {
631 strcpy(&msg->cm_fields['I'][0],
632 &msg->cm_fields['I'][1]);
634 for (i = 0; i<strlen(msg->cm_fields['I']); ++i)
635 if (msg->cm_fields['I'][i] == '>')
636 msg->cm_fields['I'][i] = 0;
642 else if (!strcasecmp(key, "Return-Path")) {
643 if (msg->cm_fields['P'] == NULL)
644 msg->cm_fields['P'] = strdup(value);
648 else if (!strcasecmp(key, "Envelope-To")) {
649 if (msg->cm_fields['V'] == NULL)
650 msg->cm_fields['V'] = strdup(value);
654 else if (!strcasecmp(key, "References")) {
655 if (msg->cm_fields['W'] != NULL) {
656 free(msg->cm_fields['W']);
658 msg->cm_fields['W'] = strdup(value);
662 else if (!strcasecmp(key, "In-reply-to")) {
663 if (msg->cm_fields['W'] == NULL) { /* References: supersedes In-reply-to: */
664 msg->cm_fields['W'] = strdup(value);
671 /* Clean up and move on. */
672 free(key); /* Don't free 'value', it's actually the same buffer */
678 * Convert RFC822 references format (References) to Citadel references format (Weferences)
680 void convert_references_to_wefewences(char *str) {
681 int bracket_nesting = 0;
683 char *moveptr = NULL;
690 if (bracket_nesting < 0) bracket_nesting = 0;
692 if ((ch == '>') && (bracket_nesting == 0) && (*(ptr+1)) && (ptr>str) ) {
696 else if (bracket_nesting > 0) {
702 *moveptr = *(moveptr+1);
706 if (ch == '<') ++bracket_nesting;
713 * Convert an RFC822 message (headers + body) to a CtdlMessage structure.
714 * NOTE: the supplied buffer becomes part of the CtdlMessage structure, and
715 * will be deallocated when CtdlFreeMessage() is called. Therefore, the
716 * supplied buffer should be DEREFERENCED. It should not be freed or used
719 struct CtdlMessage *convert_internet_message(char *rfc822) {
721 struct CtdlMessage *msg;
722 int pos, beg, end, msglen;
727 msg = malloc(sizeof(struct CtdlMessage));
728 if (msg == NULL) return msg;
730 memset(msg, 0, sizeof(struct CtdlMessage));
731 msg->cm_magic = CTDLMESSAGE_MAGIC; /* self check */
732 msg->cm_anon_type = 0; /* never anonymous */
733 msg->cm_format_type = FMT_RFC822; /* internet message */
734 msg->cm_fields['M'] = rfc822;
741 /* Locate beginning and end of field, keeping in mind that
742 * some fields might be multiline
747 msglen = strlen(rfc822);
748 while ( (end < 0) && (done == 0) ) {
750 if ((rfc822[pos]=='\n')
751 && (!isspace(rfc822[pos+1]))) {
755 /* done with headers? */
756 if ( (rfc822[pos]=='\n')
757 && ( (rfc822[pos+1]=='\n')
758 ||(rfc822[pos+1]=='\r')) ) {
763 if (pos >= (msglen-1) ) {
772 /* At this point we have a field. Are we interested in it? */
773 converted = convert_field(msg, beg, end);
775 /* Strip the field out of the RFC822 header if we used it */
777 strcpy(&rfc822[beg], &rfc822[pos]);
781 /* If we've hit the end of the message, bail out */
782 if (pos > strlen(rfc822)) done = 1;
785 /* Follow-up sanity checks... */
787 /* If there's no timestamp on this message, set it to now. */
788 if (msg->cm_fields['T'] == NULL) {
789 snprintf(buf, sizeof buf, "%ld", (long)time(NULL));
790 msg->cm_fields['T'] = strdup(buf);
793 /* If a W (references, or rather, Wefewences) field is present, we
794 * have to convert it from RFC822 format to Citadel format.
796 if (msg->cm_fields['W'] != NULL) {
797 convert_references_to_wefewences(msg->cm_fields['W']);
806 * Look for a particular header field in an RFC822 message text. If the
807 * requested field is found, it is unfolded (if necessary) and returned to
808 * the caller. The field name is stripped out, leaving only its contents.
809 * The caller is responsible for freeing the returned buffer. If the requested
810 * field is not present, or anything else goes wrong, it returns NULL.
812 char *rfc822_fetch_field(char *rfc822, char *fieldname) {
813 char *fieldbuf = NULL;
814 char *end_of_headers;
820 /* Should never happen, but sometimes we get stupid */
821 if (rfc822 == NULL) return(NULL);
822 if (fieldname == NULL) return(NULL);
824 snprintf(fieldhdr, sizeof fieldhdr, "%s:", fieldname);
826 /* Locate the end of the headers, so we don't run past that point */
827 end_of_headers = bmstrcasestr(rfc822, "\n\r\n");
828 if (end_of_headers == NULL) {
829 end_of_headers = bmstrcasestr(rfc822, "\n\n");
831 if (end_of_headers == NULL) return (NULL);
833 field_start = bmstrcasestr(rfc822, fieldhdr);
834 if (field_start == NULL) return(NULL);
835 if (field_start > end_of_headers) return(NULL);
837 fieldbuf = malloc(SIZ);
838 strcpy(fieldbuf, "");
841 ptr = memreadline(ptr, fieldbuf, SIZ-strlen(fieldbuf) );
842 while ( (isspace(ptr[0])) && (ptr < end_of_headers) ) {
843 strcat(fieldbuf, " ");
844 cont = &fieldbuf[strlen(fieldbuf)];
845 ptr = memreadline(ptr, cont, SIZ-strlen(fieldbuf) );
849 strcpy(fieldbuf, &fieldbuf[strlen(fieldhdr)]);
857 /*****************************************************************************
858 * DIRECTORY MANAGEMENT FUNCTIONS *
859 *****************************************************************************/
862 * Generate the index key for an Internet e-mail address to be looked up
865 void directory_key(char *key, char *addr) {
869 for (i=0; !IsEmptyStr(&addr[i]); ++i) {
870 if (!isspace(addr[i])) {
871 key[keylen++] = tolower(addr[i]);
876 CtdlLogPrintf(CTDL_DEBUG, "Directory key is <%s>\n", key);
881 /* Return nonzero if the supplied address is in a domain we keep in
884 int IsDirectory(char *addr, int allow_masq_domains) {
888 extract_token(domain, addr, 1, '@', sizeof domain);
891 h = CtdlHostAlias(domain);
893 if ( (h == hostalias_masq) && allow_masq_domains)
896 if ( (h == hostalias_localhost) || (h == hostalias_directory) ) {
906 * Initialize the directory database (erasing anything already there)
908 void CtdlDirectoryInit(void) {
909 cdb_trunc(CDB_DIRECTORY);
914 * Add an Internet e-mail address to the directory for a user
916 void CtdlDirectoryAddUser(char *internet_addr, char *citadel_addr) {
919 CtdlLogPrintf(CTDL_DEBUG, "Dir: %s --> %s\n",
920 internet_addr, citadel_addr);
921 if (IsDirectory(internet_addr, 0) == 0) return;
923 directory_key(key, internet_addr);
925 cdb_store(CDB_DIRECTORY, key, strlen(key),
926 citadel_addr, strlen(citadel_addr)+1 );
931 * Delete an Internet e-mail address from the directory.
933 * (NOTE: we don't actually use or need the citadel_addr variable; it's merely
934 * here because the callback API expects to be able to send it.)
936 void CtdlDirectoryDelUser(char *internet_addr, char *citadel_addr) {
939 directory_key(key, internet_addr);
940 cdb_delete(CDB_DIRECTORY, key, strlen(key) );
945 * Look up an Internet e-mail address in the directory.
946 * On success: returns 0, and Citadel address stored in 'target'
947 * On failure: returns nonzero
949 int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
950 struct cdbdata *cdbrec;
953 /* Dump it in there unchanged, just for kicks */
954 safestrncpy(target, internet_addr, targbuflen);
956 /* Only do lookups for addresses with hostnames in them */
957 if (num_tokens(internet_addr, '@') != 2) return(-1);
959 /* Only do lookups for domains in the directory */
960 if (IsDirectory(internet_addr, 0) == 0) return(-1);
962 directory_key(key, internet_addr);
963 cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) );
964 if (cdbrec != NULL) {
965 safestrncpy(target, cdbrec->ptr, targbuflen);
975 * Harvest any email addresses that someone might want to have in their
976 * "collected addresses" book.
978 char *harvest_collected_addresses(struct CtdlMessage *msg) {
981 char user[256], node[256], name[256];
986 if (msg == NULL) return(NULL);
990 if (msg->cm_fields['A'] != NULL) {
991 strcat(addr, msg->cm_fields['A']);
993 if (msg->cm_fields['F'] != NULL) {
995 strcat(addr, msg->cm_fields['F']);
997 if (IsDirectory(msg->cm_fields['F'], 0)) {
1002 if (is_harvestable) {
1003 coll = strdup(addr);
1009 if (coll == NULL) return(NULL);
1011 /* Scan both the R (To) and Y (CC) fields */
1012 for (i = 0; i < 2; ++i) {
1013 if (i == 0) field = 'R' ;
1014 if (i == 1) field = 'Y' ;
1016 if (msg->cm_fields[field] != NULL) {
1017 for (j=0; j<num_tokens(msg->cm_fields[field], ','); ++j) {
1018 extract_token(addr, msg->cm_fields[field], j, ',', sizeof addr);
1019 if (strstr(addr, "=?") != NULL)
1020 utf8ify_rfc822_string(addr);
1021 process_rfc822_addr(addr, user, node, name);
1022 h = CtdlHostAlias(node);
1023 if ( (h != hostalias_localhost) && (h != hostalias_directory) ) {
1024 coll = realloc(coll, strlen(coll) + strlen(addr) + 4);
1025 if (coll == NULL) return(NULL);
1026 if (!IsEmptyStr(coll)) {
1036 if (IsEmptyStr(coll)) {