another message output cleanup, still not perfect (info messages will be

interleaved with progress dots).
support specifying -q twice to suppress warnings as well.
This commit is contained in:
Oswald Buddenhagen 2004-01-18 02:22:17 +00:00
parent 8c5a1d94de
commit b5307f0e16
6 changed files with 29 additions and 15 deletions

View File

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

View File

@ -145,15 +145,14 @@ init_ssl (config_t * conf)
SSLContext = SSL_CTX_new (method); SSLContext = SSL_CTX_new (method);
if (access (conf->cert_file, F_OK)) if (access (conf->cert_file, R_OK))
{ {
if (errno != ENOENT) if (errno != ENOENT)
{ {
perror ("access"); perror ("access");
return -1; return -1;
} }
fprintf (stderr, warn ("*** Warning: CertificateFile doesn't exist, can't verify server certificates\n");
"*** Warning, CertificateFile doesn't exist, can't verify server certificates\n");
} }
else else
if (!SSL_CTX_load_verify_locations if (!SSL_CTX_load_verify_locations
@ -775,7 +774,7 @@ imap_connect (config_t * cfg)
goto bail; goto bail;
} }
else 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 HAVE_LIBSSL
if (!use_ssl) if (!use_ssl)
#endif #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)) if (imap_exec (imap, "LOGIN \"%s\" \"%s\"", cfg->user, cfg->pass))
{ {
fprintf (stderr, "IMAP error: LOGIN failed\n"); fprintf (stderr, "IMAP error: LOGIN failed\n");

View File

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

View File

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

View File

@ -59,6 +59,19 @@ infoc (char c)
putchar (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 #if HAVE_GETOPT_LONG
# define _GNU_SOURCE # define _GNU_SOURCE
# include <getopt.h> # include <getopt.h>
@ -265,7 +278,7 @@ main (int argc, char **argv)
global.port = atoi (optarg); global.port = atoi (optarg);
break; break;
case 'q': case 'q':
Quiet = 1; Quiet++;
Verbose = 0; Verbose = 0;
break; break;
case 'r': case 'r':

View File

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