aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fetchmail.h1
-rw-r--r--sink.c92
-rw-r--r--transact.c19
3 files changed, 50 insertions, 62 deletions
diff --git a/fetchmail.h b/fetchmail.h
index 394ed269..8bdfbc57 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -485,6 +485,7 @@ int interruptible_idle(int interval);
/* sink.c: forwarding */
void smtp_close(struct query *, int);
int smtp_open(struct query *);
+char *rcpt_address(struct query *, const char *, int);
int stuffline(struct query *, char *);
int open_sink(struct query*, struct msgblk *, int*, int*);
void release_sink(struct query *);
diff --git a/sink.c b/sink.c
index 8d487b6c..3595aa85 100644
--- a/sink.c
+++ b/sink.c
@@ -216,6 +216,37 @@ static void sanitize(char *s)
*cp = '_';
}
+char *rcpt_address(struct query *ctl, const char *id,
+ int usesmtpname)
+{
+ static char addr[HOSTLEN+USERNAMELEN+1];
+ if (strchr(id, '@'))
+ {
+#ifdef HAVE_SNPRINTF
+ snprintf(addr, sizeof (addr), "%s", id);
+#else
+ sprintf(addr, "%s", id);
+#endif /* HAVE_SNPRINTF */
+ }
+ else if (usesmtpname && ctl->smtpname)
+ {
+#ifdef HAVE_SNPRINTF
+ snprintf(addr, sizeof (addr), "%s", ctl->smtpname);
+#else
+ sprintf(addr, "%s", ctl->smtpname);
+#endif /* HAVE_SNPRINTF */
+ }
+ else
+ {
+#ifdef HAVE_SNPRINTF
+ snprintf(addr, sizeof (addr), "%s@%s", id, ctl->destaddr);
+#else
+ sprintf(addr, "%s@%s", id, ctl->destaddr);
+#endif /* HAVE_SNPRINTF */
+ }
+ return addr;
+}
+
static int send_bouncemail(struct query *ctl, struct msgblk *msg,
int userclass, char *message,
int nerrors, char *errors[])
@@ -306,8 +337,8 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg,
char *error;
/* Minimum RFC1894 compliance + Diagnostic-Code field */
SockPrintf(sock, "\r\n");
- SockPrintf(sock, "Final-Recipient: rfc822; %s@%s\r\n",
- idp->id, fetchmailhost);
+ SockPrintf(sock, "Final-Recipient: rfc822; %s\r\n",
+ rcpt_address (ctl, idp->id, 1));
SockPrintf(sock, "Last-Attempt-Date: %s\r\n", rfc822timestamp());
SockPrintf(sock, "Action: failed\r\n");
@@ -458,7 +489,7 @@ static int handle_smtp_report(struct query *ctl, struct msgblk *msg)
#ifdef __DONT_FEED_THE_SPAMMERS__
if (run.bouncemail)
send_bouncemail(ctl, msg, XMIT_ACCEPT,
- "Invalid address in MAIL FROM/RCPT TO (SMTP error 553).\r\n",
+ "Invalid address in MAIL FROM (SMTP error 553).\r\n",
1, responses);
#endif /* __DONT_FEED_THE_SPAMMERS__ */
return(PS_REFUSED);
@@ -647,15 +678,9 @@ static int open_bsmtp_sink(struct query *ctl, struct msgblk *msg,
for (idp = msg->recipients; idp; idp = idp->next)
if (idp->val.status.mark == XMIT_ACCEPT)
{
- if (ctl->smtpname)
- fprintf(sinkfp, "RCPT TO: %s\r\n", ctl->smtpname);
- else if (strchr(idp->id, '@'))
- fprintf(sinkfp,
- "RCPT TO: %s\r\n", idp->id);
- else
- fprintf(sinkfp,
- "RCPT TO: %s@%s\r\n", idp->id, ctl->destaddr);
- *good_addresses = 0;
+ fprintf(sinkfp, "RCPT TO: %s\r\n",
+ rcpt_address (ctl, idp->id, 1));
+ (*good_addresses)++;
}
fputs("DATA\r\n", sinkfp);
@@ -845,25 +870,9 @@ static int open_smtp_sink(struct query *ctl, struct msgblk *msg,
for (idp = msg->recipients; idp; idp = idp->next)
if (idp->val.status.mark == XMIT_ACCEPT)
{
- if (strchr(idp->id, '@'))
- strcpy(addr, idp->id);
- else {
- if (ctl->smtpname) {
-#ifdef HAVE_SNPRINTF
- snprintf(addr, sizeof(addr), "%s", ctl->smtpname);
-#else
- sprintf(addr, "%s", ctl->smtpname);
-#endif /* HAVE_SNPRINTF */
-
- } else {
-#ifdef HAVE_SNPRINTF
- snprintf(addr, sizeof(addr), "%s@%s", idp->id, ctl->destaddr);
-#else
- sprintf(addr, "%s@%s", idp->id, ctl->destaddr);
-#endif /* HAVE_SNPRINTF */
- }
- }
- if (SMTP_rcpt(ctl->smtp_socket, addr) == SM_OK)
+ const char *address;
+ address = rcpt_address (ctl, idp->id, 1);
+ if (SMTP_rcpt(ctl->smtp_socket, address) == SM_OK)
(*good_addresses)++;
else
{
@@ -886,14 +895,14 @@ static int open_smtp_sink(struct query *ctl, struct msgblk *msg,
if (outlevel >= O_VERBOSE)
report(stderr,
GT_("%cMTP listener doesn't like recipient address `%s'\n"),
- ctl->listener, addr);
+ ctl->listener, address);
break;
case PS_REFUSED:
if (outlevel >= O_VERBOSE)
report(stderr,
GT_("%cMTP listener doesn't really like recipient address `%s'\n"),
- ctl->listener, addr);
+ ctl->listener, address);
break;
}
}
@@ -934,18 +943,8 @@ static int open_smtp_sink(struct query *ctl, struct msgblk *msg,
SMTP_rset(ctl->smtp_socket); /* required by RFC1870 */
return(PS_REFUSED);
}
- if (strchr(run.postmaster, '@'))
- strncpy(addr, run.postmaster, sizeof(addr));
- else
- {
-#ifdef HAVE_SNPRINTF
- snprintf(addr, sizeof(addr), "%s@%s", run.postmaster, ctl->destaddr);
-#else
- sprintf(addr, "%s@%s", run.postmaster, ctl->destaddr);
-#endif /* HAVE_SNPRINTF */
- }
-
- if (SMTP_rcpt(ctl->smtp_socket, addr) != SM_OK)
+ if (SMTP_rcpt(ctl->smtp_socket,
+ rcpt_address (ctl, run.postmaster, 0)) != SM_OK)
{
report(stderr, GT_("can't even send to %s!\n"), run.postmaster);
SMTP_rset(ctl->smtp_socket); /* required by RFC1870 */
@@ -962,8 +961,9 @@ static int open_smtp_sink(struct query *ctl, struct msgblk *msg,
*/
if (SMTP_data(ctl->smtp_socket) != SM_OK)
{
+ int err = handle_smtp_report(ctl, msg);
SMTP_rset(ctl->smtp_socket); /* stay on the safe side */
- return(handle_smtp_report(ctl, msg));
+ return(err);
}
/*
diff --git a/transact.c b/transact.c
index d20cf28c..77a2b29f 100644
--- a/transact.c
+++ b/transact.c
@@ -1097,33 +1097,20 @@ int readheaders(int sock,
#else
sprintf(buf+1,
#endif /* HAVE_SNPRINTF */
- "for %s@%s (by default); ",
- user, ctl->destaddr);
+ "for %s (by default); ",
+ rcpt_address (ctl, run.postmaster, 0));
}
else if (good_addresses == 1)
{
for (idp = msgblk.recipients; idp; idp = idp->next)
if (idp->val.status.mark == XMIT_ACCEPT)
break; /* only report first address */
- if (strchr(idp->id, '@'))
#ifdef HAVE_SNPRINTF
snprintf(buf+1, sizeof(buf)-1,
#else
sprintf(buf+1,
#endif /* HAVE_SNPRINTF */
- "for %s", idp->id);
- else
- /*
- * This could be a bit misleading, as destaddr is
- * the forwarding host rather than the actual
- * destination. Most of the time they coincide.
- */
-#ifdef HAVE_SNPRINTF
- snprintf(buf+1, sizeof(buf)-1,
-#else
- sprintf(buf+1,
-#endif /* HAVE_SNPRINTF */
- "for %s@%s", idp->id, ctl->destaddr);
+ "for %s", rcpt_address (ctl, idp->id, 1));
sprintf(buf+strlen(buf), " (%s); ",
MULTIDROP(ctl) ? "multi-drop" : "single-drop");
}