]> Pileus Git - ~andy/fetchmail/blobdiff - sink.c
BerliOS #10972 contains insufficient information, but it looks like the problem
[~andy/fetchmail] / sink.c
diff --git a/sink.c b/sink.c
index afd1439efb9778709f2b79df9c04bbbce1e2b7dc..47a4042772027a7dfb8a4706b42cf55811e27338 100644 (file)
--- a/sink.c
+++ b/sink.c
@@ -258,12 +258,11 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg,
     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)
@@ -277,37 +276,10 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg,
                                        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)
@@ -714,7 +686,7 @@ int stuffline(struct query *ctl, char *buf)
 
     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);
@@ -736,6 +708,12 @@ static int open_bsmtp_sink(struct query *ctl, struct msgblk *msg,
     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,
@@ -775,9 +753,9 @@ static int open_bsmtp_sink(struct query *ctl, struct msgblk *msg,
 
     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);
     }