diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-11-20 00:09:25 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-11-20 00:09:25 +0000 |
commit | c4d8cbb6ca64ab55ceb58667f256d937b560409a (patch) | |
tree | c26040e6b2aee98516f48f9b326d8696a0a3bcbc | |
parent | 5e8fa01c2753fc4bceb8b69b1c2a603759b43fca (diff) | |
download | fetchmail-c4d8cbb6ca64ab55ceb58667f256d937b560409a.tar.gz fetchmail-c4d8cbb6ca64ab55ceb58667f256d937b560409a.tar.bz2 fetchmail-c4d8cbb6ca64ab55ceb58667f256d937b560409a.zip |
Process Received lines.
svn path=/trunk/; revision=559
-rw-r--r-- | driver.c | 66 |
1 files changed, 60 insertions, 6 deletions
@@ -260,14 +260,17 @@ int delimited; /* does the protocol use a message delimiter? */ struct query *ctl; /* query control record */ { char buf [MSGBUFSIZE+1]; - char *bufp, *headers, *fromhdr, *tohdr, *cchdr, *bcchdr; + char *bufp, *headers, *fromhdr, *tohdr, *cchdr, *bcchdr, *received_for; int n, oldlen, mboxfd; int inheaders,lines,sizeticker; FILE *sinkfp; +#ifdef HAVE_GETHOSTBYNAME + char rbuf[HOSTLEN + USERNAMELEN + 4]; +#endif /* HAVE_GETHOSTBYNAME */ /* read the message content from the server */ inheaders = 1; - headers = fromhdr = tohdr = cchdr = bcchdr = NULL; + headers = fromhdr = tohdr = cchdr = bcchdr = received_for = NULL; lines = 0; sizeticker = 0; oldlen = 0; @@ -350,6 +353,44 @@ struct query *ctl; /* query control record */ cchdr = bufp; else if (!strncasecmp("Bcc:", bufp, 4)) bcchdr = bufp; +#ifdef HAVE_GETHOSTBYNAME + else if (MULTIDROP(ctl) && !strncasecmp("Received:", bufp, 9)) + { + char *ok; + + /* + * Try to extract the real envelope addressee. We look here + * specifically for the mailserver's Received line. + * Note: this will only work for sendmail, or an MTA that + * shares sendmail's convention of embedding the envelope + * address in the Received line. + */ + strcpy(rbuf, "by "); + strcat(rbuf, ctl->canonical_name); + if ((ok = strstr(bufp, rbuf))) + ok = strstr(bufp, "for "); + if (ok) + { + char *sp, *tp; + + tp = rbuf; + for (sp = ok + 4; *sp && *sp != ';'; sp++) + *tp++ = *sp; + *tp = '\0'; + if (*sp != ';') + ok = (char *)NULL; + } + + if (ok) + { + received_for = rbuf; + if (outlevel == O_VERBOSE) + fprintf(stderr, + "fetchmail: found Received address `%s'\n", + received_for); + } + } +#endif /* HAVE_GETHOSTBYNAME */ goto skipwrite; } @@ -369,10 +410,23 @@ struct query *ctl; /* query control record */ /* is this a multidrop box? */ if (MULTIDROP(ctl)) { - /* compute the local address list */ - find_server_names(tohdr, ctl, &xmit_names); - find_server_names(cchdr, ctl, &xmit_names); - find_server_names(bcchdr, ctl, &xmit_names); + if (received_for) + /* + * We have the actual envelope addressee. + * It has to be a mailserver address, or we + * wouldn't have got here. + */ + save_uid(&xmit_names, -1, received_for); + else + { + /* + * We haven't extracted the envelope address. + * So check all the header addresses. + */ + find_server_names(tohdr, ctl, &xmit_names); + find_server_names(cchdr, ctl, &xmit_names); + find_server_names(bcchdr, ctl, &xmit_names); + } if (!xmit_names) { no_local_matches = TRUE; |