|
|
@ -33,6 +33,7 @@ |
|
|
|
#include <getopt.h> |
|
|
|
#include <getopt.h> |
|
|
|
|
|
|
|
|
|
|
|
struct option Opts[] = { |
|
|
|
struct option Opts[] = { |
|
|
|
|
|
|
|
{"all", 0, NULL, 'a'}, |
|
|
|
{"config", 1, NULL, 'c'}, |
|
|
|
{"config", 1, NULL, 'c'}, |
|
|
|
{"delete", 0, NULL, 'd'}, |
|
|
|
{"delete", 0, NULL, 'd'}, |
|
|
|
{"expunge", 0, NULL, 'e'}, |
|
|
|
{"expunge", 0, NULL, 'e'}, |
|
|
@ -67,12 +68,10 @@ usage (void) |
|
|
|
printf ("%s %s IMAP4 to maildir synchronizer\n", PACKAGE, VERSION); |
|
|
|
printf ("%s %s IMAP4 to maildir synchronizer\n", PACKAGE, VERSION); |
|
|
|
puts ("Copyright (C) 2000 Michael R. Elkins <me@mutt.org>"); |
|
|
|
puts ("Copyright (C) 2000 Michael R. Elkins <me@mutt.org>"); |
|
|
|
printf ("usage: %s [ flags ] mailbox [mailbox ...]\n", PACKAGE); |
|
|
|
printf ("usage: %s [ flags ] mailbox [mailbox ...]\n", PACKAGE); |
|
|
|
puts |
|
|
|
puts (" -a, --all Synchronize all defined mailboxes"); |
|
|
|
(" -c, --config CONFIG read an alternate config file (default: ~/.isyncrc)"); |
|
|
|
puts (" -c, --config CONFIG read an alternate config file (default: ~/.isyncrc)"); |
|
|
|
puts |
|
|
|
puts (" -d, --delete delete local msgs that don't exist on the server"); |
|
|
|
(" -d, --delete delete local msgs that don't exist on the server"); |
|
|
|
puts (" -e, --expunge expunge deleted messages from the server"); |
|
|
|
puts |
|
|
|
|
|
|
|
(" -e, --expunge expunge deleted messages from the server"); |
|
|
|
|
|
|
|
puts (" -f, --fast only fetch new messages"); |
|
|
|
puts (" -f, --fast only fetch new messages"); |
|
|
|
puts (" -h, --help display this help message"); |
|
|
|
puts (" -h, --help display this help message"); |
|
|
|
puts (" -p, --port PORT server IMAP port"); |
|
|
|
puts (" -p, --port PORT server IMAP port"); |
|
|
@ -80,8 +79,7 @@ usage (void) |
|
|
|
puts (" -s, --host HOST IMAP server address"); |
|
|
|
puts (" -s, --host HOST IMAP server address"); |
|
|
|
puts (" -u, --user USER IMAP user name"); |
|
|
|
puts (" -u, --user USER IMAP user name"); |
|
|
|
puts (" -v, --version display version"); |
|
|
|
puts (" -v, --version display version"); |
|
|
|
puts |
|
|
|
puts (" -V, --verbose verbose mode (display network traffic)"); |
|
|
|
(" -V, --verbose verbose mode (display network traffic)"); |
|
|
|
|
|
|
|
exit (0); |
|
|
|
exit (0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -127,7 +125,7 @@ int |
|
|
|
main (int argc, char **argv) |
|
|
|
main (int argc, char **argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
config_t *box; |
|
|
|
config_t *box = 0; |
|
|
|
mailbox_t *mail; |
|
|
|
mailbox_t *mail; |
|
|
|
imap_t *imap = 0; |
|
|
|
imap_t *imap = 0; |
|
|
|
int expunge = 0; /* by default, don't delete anything */ |
|
|
|
int expunge = 0; /* by default, don't delete anything */ |
|
|
@ -136,6 +134,7 @@ main (int argc, char **argv) |
|
|
|
char *config = 0; |
|
|
|
char *config = 0; |
|
|
|
struct passwd *pw; |
|
|
|
struct passwd *pw; |
|
|
|
int quiet = 0; |
|
|
|
int quiet = 0; |
|
|
|
|
|
|
|
int all = 0; |
|
|
|
|
|
|
|
|
|
|
|
pw = getpwuid (getuid ()); |
|
|
|
pw = getpwuid (getuid ()); |
|
|
|
|
|
|
|
|
|
|
@ -157,56 +156,61 @@ main (int argc, char **argv) |
|
|
|
global.use_tlsv1 = 1; |
|
|
|
global.use_tlsv1 = 1; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define FLAGS "ac:defhp:qu:r:s:vV" |
|
|
|
|
|
|
|
|
|
|
|
#if HAVE_GETOPT_LONG |
|
|
|
#if HAVE_GETOPT_LONG |
|
|
|
while ((i = getopt_long (argc, argv, "c:defhp:qu:r:s:vV", Opts, NULL)) != -1) |
|
|
|
while ((i = getopt_long (argc, argv, FLAGS, Opts, NULL)) != -1) |
|
|
|
#else |
|
|
|
#else |
|
|
|
while ((i = getopt (argc, argv, "c:defhp:u:qr:s:vV")) != -1) |
|
|
|
while ((i = getopt (argc, argv, FLAGS)) != -1) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (i) |
|
|
|
switch (i) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case 'c': |
|
|
|
case 'a': |
|
|
|
config = optarg; |
|
|
|
all = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'd': |
|
|
|
case 'c': |
|
|
|
delete = 1; |
|
|
|
config = optarg; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'e': |
|
|
|
case 'd': |
|
|
|
expunge = 1; |
|
|
|
delete = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'f': |
|
|
|
case 'e': |
|
|
|
fast = 1; |
|
|
|
expunge = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'p': |
|
|
|
case 'f': |
|
|
|
global.port = atoi (optarg); |
|
|
|
fast = 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'q': |
|
|
|
case 'p': |
|
|
|
quiet = 1; |
|
|
|
global.port = atoi (optarg); |
|
|
|
Verbose = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'q': |
|
|
|
case 'r': |
|
|
|
quiet = 1; |
|
|
|
global.box = optarg; |
|
|
|
Verbose = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 's': |
|
|
|
case 'r': |
|
|
|
global.host = optarg; |
|
|
|
global.box = optarg; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'u': |
|
|
|
case 's': |
|
|
|
free (global.user); |
|
|
|
global.host = optarg; |
|
|
|
global.user = optarg; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'u': |
|
|
|
case 'V': |
|
|
|
free (global.user); |
|
|
|
Verbose = 1; |
|
|
|
global.user = optarg; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'v': |
|
|
|
case 'V': |
|
|
|
version (); |
|
|
|
Verbose = 1; |
|
|
|
default: |
|
|
|
break; |
|
|
|
usage (); |
|
|
|
case 'v': |
|
|
|
|
|
|
|
version (); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
usage (); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!argv[optind]) |
|
|
|
if (!argv[optind] && !all) |
|
|
|
{ |
|
|
|
{ |
|
|
|
puts ("No box specified"); |
|
|
|
puts ("No mailbox specified"); |
|
|
|
usage (); |
|
|
|
usage (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -214,21 +218,24 @@ main (int argc, char **argv) |
|
|
|
|
|
|
|
|
|
|
|
load_config (config); |
|
|
|
load_config (config); |
|
|
|
|
|
|
|
|
|
|
|
for (; argv[optind]; optind++) |
|
|
|
for (box = boxes; (all && box) || (!all && argv[optind]); |
|
|
|
|
|
|
|
box = box->next, optind++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
box = find_box (argv[optind]); |
|
|
|
if (!all) |
|
|
|
if (!box) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
/* if enough info is given on the command line, don't worry if
|
|
|
|
if (NULL == (box = find_box (argv[optind]))) |
|
|
|
* the mailbox isn't defined. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if (!global.host) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
puts ("No such mailbox"); |
|
|
|
/* if enough info is given on the command line, don't worry if
|
|
|
|
exit (1); |
|
|
|
* the mailbox isn't defined. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if (!global.host) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fprintf (stderr, "%s: no such mailbox\n", argv[optind]); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
global.path = argv[optind]; |
|
|
|
|
|
|
|
box = &global; |
|
|
|
} |
|
|
|
} |
|
|
|
global.path = argv[optind]; |
|
|
|
|
|
|
|
box = &global; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!box->pass) |
|
|
|
if (!box->pass) |
|
|
@ -248,18 +255,22 @@ main (int argc, char **argv) |
|
|
|
box->pass = strdup (global.pass); |
|
|
|
box->pass = strdup (global.pass); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!quiet) |
|
|
|
if (!quiet) |
|
|
|
printf ("Reading %s\n", box->path); |
|
|
|
printf ("Reading %s\n", box->path); |
|
|
|
mail = maildir_open (box->path, fast); |
|
|
|
mail = maildir_open (box->path, fast); |
|
|
|
if (!mail) |
|
|
|
if (!mail) |
|
|
|
{ |
|
|
|
{ |
|
|
|
puts ("Unable to load mailbox"); |
|
|
|
fprintf (stderr, "%s: unable to load mailbox\n", box->path); |
|
|
|
exit (1); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap); |
|
|
|
imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap); |
|
|
|
if (!imap) |
|
|
|
if (!imap) |
|
|
|
exit (1); |
|
|
|
{ |
|
|
|
|
|
|
|
fprintf (stderr, "%s: skipping mailbox due to IMAP error\n", |
|
|
|
|
|
|
|
box->path); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!quiet) |
|
|
|
if (!quiet) |
|
|
|
puts ("Synchronizing"); |
|
|
|
puts ("Synchronizing"); |
|
|
@ -274,7 +285,8 @@ main (int argc, char **argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* remove messages marked for deletion */ |
|
|
|
/* remove messages marked for deletion */ |
|
|
|
if (!quiet) |
|
|
|
if (!quiet) |
|
|
|
printf ("Expunging %d messages from server\n", imap->deleted); |
|
|
|
printf ("Expunging %d messages from server\n", |
|
|
|
|
|
|
|
imap->deleted); |
|
|
|
if (imap_expunge (imap)) |
|
|
|
if (imap_expunge (imap)) |
|
|
|
exit (1); |
|
|
|
exit (1); |
|
|
|
if (!quiet) |
|
|
|
if (!quiet) |
|
|
|