char daemon_name[15 + HOSTLEN] = "MAILER-DAEMON@";
char boundary[BUFSIZ], *bounce_to;
int sock;
- struct idlist *ish;
static char *fqdn_of_host = NULL;
const char *md1 = "MAILER-DAEMON", *md2 = "MAILER-DAEMON@";
/* don't bounce in reply to undeliverable bounces */
- if (!msg->return_path[0] ||
+ if (!msg || !msg->return_path[0] ||
strcmp(msg->return_path, "<>") == 0 ||
strcasecmp(msg->return_path, md1) == 0 ||
strncasecmp(msg->return_path, md2, strlen(md2)) == 0)
lose the NDN here */
strlcat(daemon_name, fqdn_of_host, sizeof(daemon_name));
- /* XXX FIXME: we blindly assume that any host on our smtphunt list
- * and offers SMTP will accept our bounce; however, in global lmtp
- * mode we'll just try localhost instead. */
/* we need only SMTP for this purpose */
- sock = -1;
- if (ctl->smtphunt && ctl->listener == SMTP_MODE) {
- for (ish = ctl->smtphunt ; ish; ish = ish->next) {
- char *x = xstrdup(ish->id), *y, *port;
-
- /* skip over LMTP entries */
- if (x[0] == '/') {
- free(x);
- continue;
- }
-
- if ((y = strrchr(x, '/'))) {
- *y = '\0';
- port = y + 1;
- } else {
- port = SMTP_PORT;
- }
- sock = SockOpen(x, port, NULL, &ai1);
- free(x);
- if (sock != -1)
- break;
- }
- } else {
- sock = SockOpen("localhost", SMTP_PORT, NULL, &ai1);
- }
-
- if (sock == -1)
+ /* XXX FIXME: hardcoding localhost is nonsense if smtphost can be
+ * configured */
+ if ((sock = SockOpen("localhost", SMTP_PORT, NULL, &ai1)) == -1)
return(FALSE);
if (SMTP_ok(sock, SMTP_MODE) != SM_OK)
n = 0;
if (ctl->mda || ctl->bsmtp) {
- n = fwrite(buf, last - buf, 1, sinkfp);
+ n = fwrite(buf, 1, last - buf, sinkfp);
if (ferror(sinkfp)) n = -1;
} else if (ctl->smtp_socket != -1)
n = SockWrite(ctl->smtp_socket, buf, last - buf);
else
sinkfp = fopen(ctl->bsmtp, "a");
+ if (!sinkfp || ferror(sinkfp)) {
+ report(stderr, GT_("BSMTP file open failed: %s\n"),
+ strerror(errno));
+ return(PS_BSMTP);
+ }
+
/* see the ap computation under the SMTP branch */
need_anglebrs = (msg->return_path[0] != '<');
fprintf(sinkfp,
fputs("DATA\r\n", sinkfp);
- if (ferror(sinkfp))
+ if (fflush(sinkfp) || ferror(sinkfp))
{
- report(stderr, GT_("BSMTP file open or preamble write failed\n"));
+ report(stderr, GT_("BSMTP preamble write failed.\n"));
return(PS_BSMTP);
}