]> Pileus Git - ~andy/fetchmail/commitdiff
Major progress ticker bugfix/overhaul.
authorMatthias Andree <matthias.andree@gmx.de>
Mon, 4 May 2009 21:52:32 +0000 (21:52 -0000)
committerMatthias Andree <matthias.andree@gmx.de>
Mon, 4 May 2009 21:52:32 +0000 (21:52 -0000)
Progress tickers had been used inconsistently for a long time, and
documentation was outdated, too. Factor out common code to ease
maintenance, use the report_flush() function, and add and use a macro
(want_progress()) to determine if progress ticker output is desired.

This makes for a much more consistent look on screen and in logfiles and
should be much easier to fix later on.

TODO: test syslog output.

svn path=/branches/BRANCH_6-3/; revision=5290

NEWS
driver.c
fetchmail.c
fetchmail.h
fetchmail.man
transact.c

diff --git a/NEWS b/NEWS
index 98147a43456a31e75cd115e4958bef30ed2afdf7..9868a4ef1648bdd233eed17187a219dbbfeb2db3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,11 @@ fetchmail 6.3.10 (not yet released):
   termination signal properly through sys/wait.h macros.
 * When acquiring a body, understand NIL ("no such data item"), as returned by
   some MS Exchange versions. Fixes BerliOS Bug #11980 by KB Sriram.
+* Make progress tickers (-v/--showdots) consistent, and update documentation 
+  accordingly ("." for each 1024 octets read, "#" for a header written, and "*" 
+  for each body line written.)
+  The conditions under which these had been printed were inconsistent, 
+  illogical, and documentation hadn't matched real behaviour for long.
 
 # CHANGES
 * Make the comparison of the SSL fingerprints case insensitive, to
index 335da6acdfdd3599c91c56266f6bdd27896c1bf2..bf4c7b5c6ad55c27b31b9005e80745f3a520970e 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -418,6 +418,14 @@ static void mark_oversized(struct query *ctl, int size)
     }
 }
 
+static int eat_trailer(int sock, struct query *ctl)
+{
+    /* we only need this LF if we're printing ticker dots
+     * AND we are dumping protocol traces. */
+    if (outlevel >= O_VERBOSE && want_progress()) fputc('\n', stdout);
+    return (ctl->server.base_protocol->trail)(sock, ctl, tag);
+}
+
 static int fetch_messages(int mailserver_socket, struct query *ctl, 
                          int count, int **msgsizes, int maxfetch,
                          int *fetches, int *dispatches, int *deletions)
@@ -615,8 +623,11 @@ static int fetch_messages(int mailserver_socket, struct query *ctl,
                if (len > 0)
                    report_build(stdout, wholesize ? GT_(" (%d octets)")
                                 : GT_(" (%d header octets)"), len);
-               if (outlevel >= O_VERBOSE)
-                   report_complete(stdout, "\n");
+               if (want_progress()) {
+                   /* flush and add a blank to append ticker dots */
+                   report_flush(stdout);
+                   putchar(' ');
+               }
            }
 
            /* 
@@ -628,6 +639,7 @@ static int fetch_messages(int mailserver_socket, struct query *ctl,
                             /* pass the suppress_readbody flag only if the underlying
                              * protocol does not fetch the body separately */
                             separatefetchbody ? 0 : &suppress_readbody);
+
            if (err == PS_RETAINED)
                suppress_forward = suppress_delete = retained = TRUE;
            else if (err == PS_TRANSIENT)
@@ -640,14 +652,8 @@ static int fetch_messages(int mailserver_socket, struct query *ctl,
            /* tell server we got it OK and resynchronize */
            if (separatefetchbody && ctl->server.base_protocol->trail)
            {
-               if (outlevel >= O_VERBOSE && !is_a_file(1) && !run.use_syslog)
-               {
-                   fputc('\n', stdout);
-                   fflush(stdout);
-               }
-
-               if ((err = (ctl->server.base_protocol->trail)(mailserver_socket, ctl, tag)))
-                   return(err);
+               err = eat_trailer(mailserver_socket, ctl);
+               if (err) return(err);
            }
 
            /* do not read the body which is not being forwarded only if
@@ -680,9 +686,15 @@ static int fetch_messages(int mailserver_socket, struct query *ctl,
                     */
                    if (len == -1)
                        len = msgsize - msgblk.msglen;
-                   if (outlevel > O_SILENT && !wholesize)
-                       report_build(stdout,
-                                       GT_(" (%d body octets)"), len);
+                   if (!wholesize) {
+                       if (outlevel > O_SILENT)
+                           report_build(stdout,
+                                   GT_(" (%d body octets)"), len);
+                       if (want_progress()) {
+                           report_flush(stdout);
+                           putchar(' ');
+                       }
+                   }
                }
 
                /* process the body now */
@@ -690,23 +702,16 @@ static int fetch_messages(int mailserver_socket, struct query *ctl,
                              ctl,
                              !suppress_forward,
                              len);
+
                if (err == PS_TRANSIENT)
                    suppress_delete = suppress_forward = TRUE;
                else if (err)
                    return(err);
 
                /* tell server we got it OK and resynchronize */
-               if (ctl->server.base_protocol->trail)
-               {
-                   if (outlevel >= O_VERBOSE && !is_a_file(1) && !run.use_syslog)
-                   {
-                       fputc('\n', stdout);
-                       fflush(stdout);
-                   }
-
-                   err = (ctl->server.base_protocol->trail)(mailserver_socket, ctl, tag);
-                   if (err != 0)
-                       return(err);
+               if (ctl->server.base_protocol->trail) {
+                   err = eat_trailer(mailserver_socket, ctl);
+                   if (err) return(err);
                }
            }
 
index e7f486688c198cb30975f5a59d49579d06f2ba66..aff4877b1d278221913052b39653c4b9755a226a 100644 (file)
@@ -1150,8 +1150,6 @@ static int load_params(int argc, char **argv, int optind)
                                        flag = FALSE;\
                                else\
                                        flag = (dflt)
-    /* one global gets treated specially */
-    DEFAULT(run.showdots, run.poll_interval==0 || nodetach);
 
     /* merge in wired defaults, do sanity checks and prepare internal fields */
     for (ctl = querylist; ctl; ctl = ctl->next)
index 4b32a88918af95242d4fc65c82181e9ccb9221d8..bb3b09bf050ab996aa6f46eebb3d6d7f73663963 100644 (file)
@@ -764,5 +764,11 @@ int must_tls(struct query *ctl);
 /* prototype from rfc822valid.c */
 int rfc822_valid_msgid(const unsigned char *);
 
+/* macro to determine if we want to spam progress to stdout */
+#define want_progress() \
+       ((outlevel >= O_VERBOSE || (outlevel > O_SILENT && run.showdots)) \
+       && !run.use_syslog \
+       && (run.showdots || !is_a_file(1)))
+
 #endif
 /* fetchmail.h ends here */
index e66da7d003284d87a488fd74d7f278cf1bb8a98d..e2e933afaa05240e25b9113acf0c8be663bd8361 100644 (file)
@@ -1315,9 +1315,9 @@ mailserver host.
 The
 .B \-\-showdots
 option (keyword: set showdots) forces fetchmail to show progress dots
-even if the current tty is not stdout (for example logfiles).
-Fetchmail shows the dots by default when run in nodetach mode or when
-daemon mode is not enabled.
+even if the output goes to a file or fetchmail is not in verbose mode.
+Fetchmail shows the dots by default when run in \-\-verbose mode 
+\fIand\fP output goes to console. This option is ignored in \-\-silent mode.
 .PP
 By specifying the
 .B \-\-tracepolls
index d66d27588966f5266eda1ab1ffe5be9e4424a245..7f658bc88dc2db1eb575ffd34b87e147b9d17255 100644 (file)
@@ -367,7 +367,7 @@ static void print_ticker(int *tickervar, int bytes)
     *tickervar += bytes;
     while (*tickervar >= SIZETICKER)
     {
-       if (outlevel > O_SILENT && run.showdots && !run.use_syslog)
+       if (want_progress())
        {
            fputc('.', stdout);
            fflush(stdout);
@@ -1265,7 +1265,7 @@ int readheaders(int sock,
        return(PS_IOERR);
     }
     
-    if ((run.poll_interval == 0 || nodetach) && outlevel >= O_VERBOSE && !is_a_file(1) && !run.use_syslog)
+    if (want_progress())
        fputc('#', stdout);
 
     /* write error notifications */
@@ -1446,7 +1446,7 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
                release_sink(ctl);
                return(PS_IOERR);
            }
-           else if (outlevel >= O_VERBOSE && !is_a_file(1) && !run.use_syslog)
+           else if (want_progress())
            {
                fputc('*', stdout);
                fflush(stdout);