]> 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 2e36e57e3b1bcd130b25ee36386a1e0004b1ab5c..47a4042772027a7dfb8a4706b42cf55811e27338 100644 (file)
--- a/sink.c
+++ b/sink.c
@@ -262,7 +262,7 @@ static int send_bouncemail(struct query *ctl, struct msgblk *msg,
     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)
@@ -686,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);
@@ -708,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,
@@ -747,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);
     }
 
@@ -957,7 +963,6 @@ transient:
                    case PS_SUCCESS:
 #ifdef EXPLICIT_BOUNCE_ON_BAD_ADDRESS
                    from_responses[*bad_addresses] = xstrdup(smtp_response);
-                   strcpy(from_responses[*bad_addresses], smtp_response);
 #endif /* EXPLICIT_BOUNCE_ON_BAD_ADDRESS */
 
                    (*bad_addresses)++;
@@ -1317,14 +1322,14 @@ int close_sink(struct query *ctl, struct msgblk *msg, flag forward)
     {
        int rc,e,e2,err = 0;
 
-       if (ferror(sinkfp))
-           err = 1, e2 = errno;
-       if ((fflush(sinkfp)))
-           err = 1, e2 = errno;
-
        /* close the delivery pipe, we'll reopen before next message */
        if (sinkfp)
        {
+           if (ferror(sinkfp))
+               err = 1, e2 = errno;
+           if ((fflush(sinkfp)))
+               err = 1, e2 = errno;
+
            errno = 0;
            rc = pclose(sinkfp);
            e = errno;