diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | rfc822.c | 30 |
2 files changed, 21 insertions, 11 deletions
@@ -12,6 +12,8 @@ fetchmail-4.4.9 (): * Fix man-page installation (thanks to Kevin Hawkins <khawkins@ncsa.uiuc.edu>). * Should build on SunOS again (__STDC__ conditions changed to STDC_HEADERS). * CompuServe RPA and idfile fixes from Rich Beerman <rbeerman@pobox.com>. +* Hajimu UMEMOTO <ume@calm.imasy.or.jp> patched the address-rewrite logic to + deal with addresses of the form "John Smith (foo) <jsmith@bar.com>" better. There are 278 people on fetchmail-friends and 216 on fetchmail-announce. @@ -18,6 +18,7 @@ #ifdef TESTMAIN static int verbose; +char *program_name = "rfc822"; #endif /* TESTMAIN */ char *reply_hack(buf, host) @@ -25,7 +26,7 @@ char *reply_hack(buf, host) char *buf; /* header to be hacked */ const char *host; /* server hostname */ { - char *from, *cp, last_nws = '\0'; + char *from, *cp, last_nws = '\0', *parens_from = NULL; int parendepth, state, has_bare_name_part, has_host_part; int addresscount = 1; @@ -56,13 +57,8 @@ const char *host; /* server hostname */ #endif /* TESTMAIN */ /* - * This is going to foo up on some ill-formed addresses. For example, - * "From: John Smith (Systems) <jsmith@domain>" will get rewritten as - * "From: John Smith@my.pop.server (Systems) <jsmith@domain>" because - * the state machine can't look ahead to the <> part past the comment - * and instead treats `John Smith' as a bareword address. - * - * Also note that we don't rewrite the fake address <> in order to + * This is going to foo up on some ill-formed addresses. + * Note that we don't rewrite the fake address <> in order to * avoid screwing up bounce suppression with a null Return-Path. */ @@ -105,13 +101,17 @@ const char *host; /* server hostname */ * an obscure misfeature described in sections * 6.1, 6.2.6, and A.1.5 of the RFC822 standard. */ - else if ((*from == ',' || HEADER_END(from) || from[1] == '(') + else if ((*from == ',' || HEADER_END(from)) && has_bare_name_part && !has_host_part - && last_nws != ';' && last_nws != ')') + && last_nws != ';') { int hostlen; + char *p; + p = from; + if (parens_from) + from = parens_from; while (isspace(*from) || (*from == ',')) --from; from++; @@ -120,9 +120,16 @@ const char *host; /* server hostname */ cp[hostlen+1] = *cp; *from++ = '@'; memcpy(from, host, hostlen); - from += hostlen; + from = p + hostlen + 1; has_host_part = TRUE; } + else if (from[1] == '(' + && has_bare_name_part + && !has_host_part + && last_nws != ';' && last_nws != ')') + { + parens_from = from; + } else if (!isspace(*from)) has_bare_name_part = TRUE; break; @@ -159,6 +166,7 @@ const char *host; /* server hostname */ */ if (from[-1] == ',' && !parendepth) { has_host_part = has_bare_name_part = FALSE; + parens_from = NULL; } } |