]> Pileus Git - ~andy/fetchmail/blobdiff - driver.c
Cosmetic cleanup.
[~andy/fetchmail] / driver.c
index 4692f009723cbca6403596d2940875f282386f5c..26ff2879f0edd277545dd391ba3c3913a6fc5a6c 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -82,6 +82,7 @@ flag peek_capable;    /* can we peek for better error recovery? */
 int pass;              /* how many times have we re-polled? */
 int stage;             /* where are we? */
 int phase;             /* where are we, for error-logging purposes? */
+int mytimeout;         /* value of nonreponse timeout */
 
 static const struct method *protocol;
 static jmp_buf restart;
@@ -91,7 +92,6 @@ static int tagnum;
 #define GENSYM (sprintf(tag, "A%04d", ++tagnum % TAGMOD), tag)
 
 static char shroud[PASSWORDLEN];       /* string to shroud in debug output */
-static int mytimeout;                  /* value of nonreponse timeout */
 static int timeoutcount;               /* count consecutive timeouts */
 static int msglen;                     /* actual message length */
 
@@ -529,7 +529,7 @@ static int readheaders(int sock,
            sizeticker += linelen;
            while (sizeticker >= SIZETICKER)
            {
-               if (!run.use_syslog)
+               if (!run.use_syslog && isatty(1))
                {
                    fputc('.', stdout);
                    fflush(stdout);
@@ -725,14 +725,15 @@ static int readheaders(int sock,
        else if (!strncasecmp("Resent-Sender:", line, 14))
            resent_sender_offs = (line - msgblk.headers);
 
-       else if (!strncasecmp("Message-Id:", buf, 11))
+#ifdef __UNUSED__
+       else if (!strncasecmp("Message-Id:", line, 11))
        {
            if (ctl->server.uidl)
            {
                char id[IDLEN+1];
 
-               buf[IDLEN+12] = 0;              /* prevent stack overflow */
-               sscanf(buf+12, "%s", id);
+               line[IDLEN+12] = 0;             /* prevent stack overflow */
+               sscanf(line+12, "%s", id);
                if (!str_find( &ctl->newsaved, num))
                {
                    struct idlist *new = save_str(&ctl->newsaved,id,UID_SEEN);
@@ -740,6 +741,7 @@ static int readheaders(int sock,
                }
            }
        }
+#endif /* __UNUSED__ */
 
        else if (!MULTIDROP(ctl))
            continue;
@@ -1045,7 +1047,7 @@ static int readheaders(int sock,
        free_str_list(&msgblk.recipients);
        return(PS_IOERR);
     }
-    else if ((run.poll_interval == 0 || nodetach) && outlevel >= O_VERBOSE)
+    else if ((run.poll_interval == 0 || nodetach) && outlevel >= O_VERBOSE && isatty(2))
        fputs("#", stderr);
 
     /* write error notifications */
@@ -1155,7 +1157,7 @@ static int readbody(int sock, struct query *ctl, flag forward, int len)
            sizeticker += linelen;
            while (sizeticker >= SIZETICKER)
            {
-               if ((run.poll_interval == 0 || nodetach) && outlevel > O_SILENT)
+               if ((run.poll_interval == 0 || nodetach) && outlevel > O_SILENT && isatty(1))
                {
                    fputc('.', stdout);
                    fflush(stdout);
@@ -1213,7 +1215,7 @@ static int readbody(int sock, struct query *ctl, flag forward, int len)
                release_sink(ctl);
                return(PS_IOERR);
            }
-           else if (outlevel >= O_VERBOSE)
+           else if (outlevel >= O_VERBOSE && isatty(1))
            {
                fputc('*', stdout);
                fflush(stdout);
@@ -1415,7 +1417,7 @@ static void send_size_warnings(struct query *ctl)
            nbr = current->val.status.mark;
            size = atoi(current->id);
            stuff_warning(ctl, 
-                   _("\t%d msg %d octets long skipped by fetchmail.\n"),
+                   _("\t%d msg %d octets long skipped by fetchmail.\r\n"),
                    nbr, size);
        }
        current->val.status.num++;
@@ -1482,8 +1484,9 @@ const int maxfetch;               /* maximum number of messages to fetch */
        if (js == THROW_SIGPIPE)
        {
            report(stdout,
-                  _("SIGPIPE thrown from an MDA or a stream socket error"));
+                  _("SIGPIPE thrown from an MDA or a stream socket error\n"));
            ok = PS_SOCKET;
+           goto cleanUp;
        }
        else if (js == THROW_TIMEOUT)
        {
@@ -1502,7 +1505,7 @@ const int maxfetch;               /* maximum number of messages to fetch */
                       ctl->mda ? "MDA" : "SMTP");
            else if (phase == LISTENER_WAIT)
                report(stdout,
-                      _("timeout after %d seconds waiting for listener to respond.\n"));
+                      _("timeout after %d seconds waiting for listener to respond.\n"), ctl->server.timeout);
            else
                report(stdout, 
                       _("timeout after %d seconds.\n"), ctl->server.timeout);
@@ -1510,6 +1513,8 @@ const int maxfetch;               /* maximum number of messages to fetch */
            /*
             * If we've exceeded our threshold for consecutive timeouts, 
             * try to notify the user, then mark the connection wedged.
+            * Don't do this if the connection can idle, though; idle
+            * timeouts just mean the frequency of mail is low.
             */
            if (timeoutcount > MAX_TIMEOUTS 
                && !open_warning_by_mail(ctl, (struct msgblk *)NULL))
@@ -1543,7 +1548,7 @@ const int maxfetch;               /* maximum number of messages to fetch */
     }
     else
     {
-       char buf[POPBUFSIZE+1], *realhost;
+       char buf[MSGBUFSIZE+1], *realhost;
        int len, num, count, new, bytes, deletions = 0, *msgsizes = NULL;
 #if INET6_ENABLE
        int fetches, dispatches, oldphase;
@@ -1585,6 +1590,7 @@ const int maxfetch;               /* maximum number of messages to fetch */
        if ((mailserver_socket = SockOpen(realhost, port, NULL, ctl->server.plugin)) == -1)
 #endif /* INET6_ENABLE */
        {
+           char        errbuf[BUFSIZ];
 #if !INET6_ENABLE
            int err_no = errno;
 #ifdef HAVE_RES_SEARCH
@@ -1596,7 +1602,8 @@ const int maxfetch;               /* maximum number of messages to fetch */
             * in daemon mode but the connection to the outside world
             * is down.
             */
-           if (!(err_no == EHOSTUNREACH && run.poll_interval))
+           if (!((err_no == EHOSTUNREACH || err_no == ENETUNREACH) 
+                 && run.poll_interval))
            {
                report_build(stderr, _("fetchmail: %s connection to %s failed"), 
                             protocol->name, ctl->server.pollname);
@@ -1604,25 +1611,38 @@ const int maxfetch;             /* maximum number of messages to fetch */
                if (h_errno != 0)
                {
                    if (h_errno == HOST_NOT_FOUND)
-                       report_complete(stderr,
-                               _(": host is unknown\n"));
+                       strcpy(errbuf, _("host is unknown."));
                    else if (h_errno == NO_ADDRESS)
-                       report_complete(stderr, 
-                               _(": name is valid but has no IP address\n"));
+                       strcpy(errbuf, _("name is valid but has no IP address."));
                    else if (h_errno == NO_RECOVERY)
-                       report_complete(stderr,
-                               _(": unrecoverable name server error\n"));
+                       strcpy(errbuf, _("unrecoverable name server error."));
                    else if (h_errno == TRY_AGAIN)
-                       report_complete(stderr,
-                               _(": temporary name server error\n"));
+                       strcpy(errbuf, _("temporary name server error."));
                    else
-                       report_complete(stderr,
-                               _(": unknown DNS error %d\n"), h_errno);
+                       sprintf(errbuf, _("unknown DNS error %d."), h_errno);
                }
                else
 #endif /* HAVE_RES_SEARCH */
-                   report_complete(stderr, ": %s\n", strerror(err_no));
-
+                   strcpy(errbuf, strerror(err_no));
+               report_complete(stderr, ": %s\n", errbuf);
+
+#ifdef __UNUSED
+               /* 
+                * Don't use this.  It was an attempt to address Debian bug
+                * #47143 (Notify user by mail when pop server nonexistent).
+                * Trouble is, that doesn't work; you trip over the case 
+                * where your SLIP or PPP link is down...
+                */
+               /* warn the system administrator */
+               if (open_warning_by_mail(ctl, (struct msgblk *)NULL) == 0)
+               {
+#define OPENFAIL       "Subject: Fetchmail unreachable-server warning.\r\n\r\nFetchmail could not reach the mail server %s:"
+                   stuff_warning(ctl, OPENFAIL, ctl->server.pollname);
+                   stuff_warning(ctl, errbuf, ctl->server.pollname);
+                   close_warning_by_mail(ctl, (struct msgblk *)NULL);
+#undef OPENFAIL
+               }
+#endif
            }
 #endif /* INET6_ENABLE */
            ok = PS_SOCKET;
@@ -1737,6 +1757,9 @@ const int maxfetch;               /* maximum number of messages to fetch */
                dispatches = 0;
                ++pass;
 
+               /* reset timeout, in case we did an IDLE */
+               mytimeout = ctl->server.timeout;
+
                if (outlevel >= O_DEBUG)
                {
                    if (idp->id)
@@ -1795,7 +1818,12 @@ const int maxfetch;              /* maximum number of messages to fetch */
                    if (new == -1 || ctl->fetchall)
                        new = count;
                    fetches = new;      /* set error status ccorrectly */
-                   goto no_error;
+                   /*
+                    * There used to be a `got noerror' here, but this
+                    * prevneted checking of multiple folders.  This
+                    * comment is a reminder in case I introduced some
+                    * subtle bug by removing it...
+                    */
                }
                else if (count > 0)
                {    
@@ -2006,7 +2034,7 @@ const int maxfetch;               /* maximum number of messages to fetch */
                             */
                            if (protocol->fetch_body && !suppress_readbody) 
                            {
-                               if (outlevel >= O_VERBOSE)
+                               if (outlevel >= O_VERBOSE && isatty(1))
                                {
                                    fputc('\n', stdout);
                                    fflush(stdout);
@@ -2060,7 +2088,7 @@ const int maxfetch;               /* maximum number of messages to fetch */
                                /* tell server we got it OK and resynchronize */
                                if (protocol->trail)
                                {
-                                   if (outlevel >= O_VERBOSE)
+                                   if (outlevel >= O_VERBOSE && isatty(1))
                                    {
                                        fputc('\n', stdout);
                                        fflush(stdout);
@@ -2178,8 +2206,8 @@ const int maxfetch;               /* maximum number of messages to fetch */
                }
            } while
                  /*
-                  * Only re-poll if we had some actual forwards, allowed
-                  * deletions and had no errors.
+                  * Only re-poll if we either had some actual forwards and 
+                  * either allowed deletions and had no errors.
                   * Otherwise it is far too easy to get into infinite loops.
                   */
                  (dispatches && protocol->retry && !ctl->keep && !ctl->errcount);