Kaynağa Gözat

another message output cleanup, still not perfect (info messages will be
interleaved with progress dots).
support specifying -q twice to suppress warnings as well.

Oswald Buddenhagen 21 yıl önce
ebeveyn
işleme
b5307f0e16
6 değiştirilmiş dosya ile 29 ekleme ve 15 silme
  1. 2 1
      isync.1
  2. 4 5
      src/imap.c
  3. 1 0
      src/isync.h
  4. 2 2
      src/maildir.c
  5. 14 1
      src/main.c
  6. 6 6
      src/sync.c

+ 2 - 1
isync.1

@@ -92,7 +92,8 @@ Displays a summary of command line options
 Specifies the port on the IMAP server to connect to (default: 143)
 .TP
 \fB-q\fR, \fB--quiet\fR
-Supress feedback messages.
+Suppress informational messages.
+If specified twice, suppress warning messages as well.
 .TP
 \fB-r\fR, \fB--remote\fR \fIbox\fR
 Specifies the name of the remote IMAP mailbox to synchronize with

+ 4 - 5
src/imap.c

@@ -145,15 +145,14 @@ init_ssl (config_t * conf)
 
     SSLContext = SSL_CTX_new (method);
 
-    if (access (conf->cert_file, F_OK))
+    if (access (conf->cert_file, R_OK))
     {
 	if (errno != ENOENT)
 	{
 	    perror ("access");
 	    return -1;
 	}
-	fprintf (stderr, 
-	    "*** Warning, CertificateFile doesn't exist, can't verify server certificates\n");
+	warn ("*** Warning: CertificateFile doesn't exist, can't verify server certificates\n");
     }
     else
 	if (!SSL_CTX_load_verify_locations
@@ -775,7 +774,7 @@ imap_connect (config_t * cfg)
 	      goto bail;
 	    }
 	    else
-	      fprintf (stderr, "IMAP warning: SSL support not available\n");
+	      warn ("IMAP warning: SSL support not available\n");
 	  }
 	}
       }
@@ -836,7 +835,7 @@ imap_connect (config_t * cfg)
 #if HAVE_LIBSSL
 	  if (!use_ssl)
 #endif
-	    fprintf (stderr, "*** IMAP Warning *** Password is being sent in the clear\n");
+	    warn ("*** IMAP Warning *** Password is being sent in the clear\n");
 	  if (imap_exec (imap, "LOGIN \"%s\" \"%s\"", cfg->user, cfg->pass))
 	  {
 	    fprintf (stderr, "IMAP error: LOGIN failed\n");

+ 1 - 0
src/isync.h

@@ -184,6 +184,7 @@ extern int Verbose, Quiet;
 
 extern void info (const char *, ...);
 extern void infoc (char);
+extern void warn (const char *, ...);
 
 #if HAVE_LIBSSL
 extern SSL_CTX *SSLContext;

+ 2 - 2
src/maildir.c

@@ -255,7 +255,7 @@ maildir_open (const char *path, int flags)
 	    ret = m->db->get (m->db, 0, &key, &value, 0);
 	    if (ret == DB_NOTFOUND) {
 		/* Every locally generated message triggers this ... */
-		/*printf ("Warning, no UID for message %.*s\n",
+		/*warn ("Warning: no UID for message %.*s\n",
 			key.size, p->file);*/
 	    } else if (ret) {
 		fprintf (stderr, "Unexpected error (%d) from db_get(%.*s)\n", 
@@ -389,7 +389,7 @@ maildir_clean_tmp (const char *mbox)
 	    /* this should happen infrequently enough that it won't be
 	     * bothersome to the user to display when it occurs.
 	     */
-	    printf ("Warning: removing stale file %s\n", path);
+	    info ("Notice: removing stale file %s\n", path);
 	    if (unlink (path))
 		fprintf (stderr,
 			 "maildir_clean_tmp: unlink: %s: %s (errno %d)\n",

+ 14 - 1
src/main.c

@@ -59,6 +59,19 @@ infoc (char c)
 	putchar (c);
 }
 
+void
+warn (const char *msg, ...)
+{
+  va_list va;
+
+  if (Quiet < 2)
+  {
+    va_start (va, msg);
+    vfprintf (stderr, msg, va);
+    va_end (va);
+  }
+}
+
 #if HAVE_GETOPT_LONG
 # define _GNU_SOURCE
 # include <getopt.h>
@@ -265,7 +278,7 @@ main (int argc, char **argv)
 		global.port = atoi (optarg);
 		break;
 	    case 'q':
-		Quiet = 1;
+		Quiet++;
 		Verbose = 0;
 		break;
 	    case 'r':

+ 6 - 6
src/sync.c

@@ -148,8 +148,8 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 		if (imap->box->max_size > 0
 		    && sb.st_size > imap->box->max_size)
 		{
-		    info ("Warning, local message is too large (%lu), skipping...\n",
-			  (unsigned long) sb.st_size);
+		    info ("Local message %s is too large (%lu), skipping...\n",
+			  cur->file, (unsigned long) sb.st_size);
 		    continue;
 		}
 		fd = open (path, O_RDONLY);
@@ -166,7 +166,7 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 		    /* update the db */
 		    set_uid (mbox->db, cur->file, cur->uid);
 		    if (!cur->uid)
-			printf("warning: no uid for new messge %s\n", cur->file);
+			warn ("Warning: no UID for new messge %s\n", cur->file);
 		    else if (cur->uid > mbox->maxuid)
 		    	mbox->maxuid = cur->uid;
 		}
@@ -187,7 +187,7 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 	     * exist on the server, warn that such messages exist.
 	     */
 	    else
-		info ("Warning, uid %u doesn't exist on server\n", cur->uid);
+		info ("Local message %u doesn't exist on server\n", cur->uid);
 	    continue;
 	}
 	tmp->processed = 1;
@@ -312,8 +312,8 @@ sync_mailbox (mailbox_t * mbox, imap_t * imap, int flags,
 
 	    if (max_size && cur->size > max_size)
 	    {
-		info ("Warning, message skipped because it is too big (%u)\n",
-		      cur->size);
+		info ("Remote message %u skipped because it is too big (%u)\n",
+		      cur->uid, cur->size);
 		continue;
 	    }