/*
* The first two checks are optimizations that will catch a good
- * many cases. First, check against the hostname the user specified.
- * Odds are good this will either be the mailserver's FQDN or a
- * suffix of it with the mailserver's domain's default host name
- * omitted. Next, check against the mailserver's FQDN, in case
+ * many cases. (1) check against the hostname the user
+ * specified. Odds are good this will either be the mailserver's
+ * FQDN or a suffix of it with the mailserver's domain's default
+ * host name omitted. Then check the rest of the `also known as'
+ * cache accumulated by previous DNS checks. This cache is primed
+ * by the aka list option.
+ *
+ * (2) check against the mailserver's FQDN, in case
* it's not the same as the declared hostname.
*
* Either of these on a mail address is definitive. Only if the
* name doesn't match either is it time to call the bind library.
* If this happens odds are good we're looking at an MX name.
*/
- if (strcmp(name, ctl->servername) == 0)
+ if (str_in_list(&ctl->lead_server->servernames, name))
return(TRUE);
else if (strcmp(name, ctl->canonical_name) == 0)
return(TRUE);
- /*
- * Is it in the `also known as' cache accumulated by previous DNS checks?
- * This cache may someday be primed by an aka option.
- */
- else if (uid_in_list(&ctl->lead_server->aka, name))
- return(TRUE);
-
/*
* We know DNS service was up at the beginning of this poll cycle.
* If it's down, our nameserver has crashed. We don't want to try
putchar('\n'); /* terminate the progress message */
fprintf(stderr,
"fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
- name, ctl->servername);
+ name, ctl->servernames->id);
ctl->errcount++;
longjmp(restart, 2); /* try again next poll cycle */
break;
default:
fprintf(stderr,
"fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
- name, ctl->servername);
+ name, ctl->servernames->id);
ctl->errcount++;
longjmp(restart, 2); /* try again next poll cycle */
break;
match:
/* add this name to relevant server's `also known as' list */
- save_uid(&ctl->lead_server->aka, -1, name);
+ save_str(&ctl->lead_server->servernames, -1, name);
return(TRUE);
}
+static void map_name(name, ctl, xmit_names)
+/* add given name to xmit_names if it matches declared localnames */
+const char *name; /* name to map */
+struct query *ctl; /* list of permissible aliases */
+struct idlist **xmit_names; /* list of recipient names parsed out */
+{
+ const char *lname;
+
+ lname = idpair_find(&ctl->localnames, name);
+ if (!lname && ctl->wildcard)
+ lname = name;
+
+ if (lname != (char *)NULL)
+ {
+ if (outlevel == O_VERBOSE)
+ fprintf(stderr,
+ "fetchmail: mapped %s to local %s\n",
+ name, lname);
+ save_str(xmit_names, -1, lname);
+ }
+}
+
void find_server_names(hdr, ctl, xmit_names)
/* parse names out of a RFC822 header into an ID list */
const char *hdr; /* RFC822 header in question */
atsign[0] = '\0';
}
- lname = idpair_find(&ctl->localnames, cp);
- if (lname != (char *)NULL)
- {
- if (outlevel == O_VERBOSE)
- fprintf(stderr,
- "fetchmail: mapped %s to local %s\n",
- cp, lname);
- save_uid(xmit_names, -1, lname);
- }
+ map_name(cp, ctl, xmit_names);
} while
((cp = nxtaddr((char *)NULL)) != (char *)NULL);
}
if ((ctl->smtp_sockfp = Socket(ctl->smtphost, SMTP_PORT)) == (FILE *)NULL)
return((FILE *)NULL);
else if (SMTP_ok(ctl->smtp_sockfp) != SM_OK
- || SMTP_helo(ctl->smtp_sockfp, ctl->servername) != SM_OK)
+ || SMTP_helo(ctl->smtp_sockfp, ctl->servernames->id) != SM_OK)
{
fclose(ctl->smtp_sockfp);
ctl->smtp_sockfp = (FILE *)NULL;
if (inheaders)
{
if (!ctl->norewrite)
- reply_hack(bufp, ctl->servername);
+ reply_hack(bufp, ctl->servernames->id);
if (!lines)
{
char *sp, *tp;
tp = rbuf;
- for (sp = ok + 5; *sp && *sp != '>' && *sp != '@'; sp++)
- *tp++ = *sp;
+ sp = ok + 4;
+ if (*sp == '<')
+ sp++;
+ while (*sp && *sp != '>' && *sp != '@' && *sp != ';')
+ if (!isspace(*sp))
+ *tp++ = *sp++;
+ else
+ {
+ /* uh oh -- whitespace here can't be right! */
+ ok = (char *)NULL;
+ break;
+ }
*tp = '\0';
- if (*sp != ';' && *sp != '@')
- ok = (char *)NULL;
}
if (ok)
* It has to be a mailserver address, or we
* wouldn't have got here.
*/
- find_server_names(received_for, ctl, &xmit_names);
+ map_name(received_for, ctl, &xmit_names);
else
{
/*
if (!xmit_names)
{
no_local_matches = TRUE;
- save_uid(&xmit_names, -1, user);
+ save_str(&xmit_names, -1, user);
if (outlevel == O_VERBOSE)
fprintf(stderr,
"fetchmail: no local matches, forwarding to %s\n",
}
else /* it's a single-drop box, use first localname */
#endif /* HAVE_RES_SEARCH */
- save_uid(&xmit_names, -1, ctl->localnames->id);
+ save_str(&xmit_names, -1, ctl->localnames->id);
/* time to address the message */
if (ctl->mda[0]) /* we have a declared MDA */
/* build a connection to the SMTP listener */
if (ctl->mda[0] == '\0' && ((sinkfp = smtp_open(ctl)) == NULL))
{
- free_uid_list(&xmit_names);
+ free_str_list(&xmit_names);
fprintf(stderr, "fetchmail: SMTP connect failed\n");
return(PS_SMTP);
}
SockWrite(errmsg, strlen(errmsg), sinkfp);
}
- free_uid_list(&xmit_names);
+ free_str_list(&xmit_names);
}
/* SMTP byte-stuffing */
{
fprintf(stderr,
"fetchmail: timeout after %d seconds waiting for %s.\n",
- ctl->timeout, ctl->servername);
+ ctl->timeout, ctl->servernames->id);
ok = PS_ERROR;
}
else if (js == 2)
FILE *sockfp;
/* open a socket to the mail server */
- if ((sockfp = Socket(ctl->servername,
+ if ((sockfp = Socket(ctl->servernames->id,
ctl->port ? ctl->port : protocol->port)) == NULL)
{
perror("fetchmail, connecting to host");
if (count == 0)
fprintf(stderr, "No mail from %s@%s\n",
ctl->remotename,
- ctl->servername);
+ ctl->servernames->id);
else
{
fprintf(stderr, "%d message%s", count, count > 1 ? "s" : "");
fprintf(stderr,
" from %s@%s.\n",
ctl->remotename,
- ctl->servername);
+ ctl->servernames->id);
}
/* we may need to get sizes in order to check message limits */
vtalarm(ctl->timeout);
if (ok != 0)
goto cleanUp;
- delete_uid(&ctl->newsaved, num);
+ delete_str(&ctl->newsaved, num);
}
else if (outlevel > O_SILENT)
fprintf(stderr, " not flushed\n");
}
if (ok==PS_SOCKET || ok==PS_AUTHFAIL || ok==PS_SYNTAX || ok==PS_IOERR
|| ok==PS_ERROR || ok==PS_PROTOCOL || ok==PS_SMTP)
- fprintf(stderr, " error while talking to %s\n", ctl->servername);
+ fprintf(stderr, " error while talking to %s\n", ctl->servernames->id);
closeUp:
signal(SIGVTALRM, sigsave);