2000-12-21 00:30:53 +00:00
|
|
|
/* $Id$
|
|
|
|
*
|
|
|
|
* isync - IMAP4 to maildir mailbox synchronizer
|
2000-12-20 21:41:21 +00:00
|
|
|
* Copyright (C) 2000 Michael R. Elkins <me@mutt.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "isync.h"
|
|
|
|
|
|
|
|
#if HAVE_GETOPT_LONG
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
struct option Opts[] = {
|
|
|
|
{"config", 1, NULL, 'c'},
|
|
|
|
{"delete", 0, NULL, 'd'},
|
|
|
|
{"expunge", 0, NULL, 'e'},
|
|
|
|
{"fast", 0, NULL, 'f'},
|
|
|
|
{"help", 0, NULL, 'h'},
|
|
|
|
{"remote", 1, NULL, 'r'},
|
|
|
|
{"host", 1, NULL, 's'},
|
|
|
|
{"port", 1, NULL, 'p'},
|
|
|
|
{"user", 1, NULL, 'u'},
|
|
|
|
{"version", 0, NULL, 'v'},
|
|
|
|
{"verbose", 0, NULL, 'V'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
config_t global;
|
|
|
|
unsigned int Tag = 0;
|
|
|
|
static config_t *box = 0;
|
|
|
|
char Hostname[256];
|
|
|
|
int Verbose = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
version (void)
|
|
|
|
{
|
|
|
|
printf ("%s %s\n", PACKAGE, VERSION);
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage (void)
|
|
|
|
{
|
|
|
|
printf ("%s %s IMAP4 to maildir synchronizer\n", PACKAGE, VERSION);
|
|
|
|
puts ("Copyright (C) 2000 Michael R. Elkins <me@mutt.org>");
|
2000-12-27 21:14:22 +00:00
|
|
|
printf ("usage: %s [ flags ] mailbox [mailbox ...]\n", PACKAGE);
|
2000-12-20 21:41:21 +00:00
|
|
|
puts
|
|
|
|
(" -c, --config CONFIG read an alternate config file (default: ~/.isyncrc)");
|
|
|
|
puts
|
|
|
|
(" -d, --delete delete local msgs that don't exist on the server");
|
|
|
|
puts
|
|
|
|
(" -e, --expunge expunge deleted messages from the server");
|
|
|
|
puts (" -f, --fast only fetch new messages");
|
|
|
|
puts (" -h, --help display this help message");
|
|
|
|
puts (" -p, --port PORT server IMAP port");
|
|
|
|
puts (" -r, --remote BOX remote mailbox");
|
|
|
|
puts (" -s, --host HOST IMAP server address");
|
|
|
|
puts (" -u, --user USER IMAP user name");
|
|
|
|
puts (" -v, --version display version");
|
|
|
|
puts
|
|
|
|
(" -V, --verbose verbose mode (display network traffic)");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2000-12-21 06:27:05 +00:00
|
|
|
/* set defaults from the global configuration section */
|
|
|
|
static void
|
|
|
|
config_defaults (config_t * conf)
|
|
|
|
{
|
|
|
|
conf->user = global.user;
|
|
|
|
conf->pass = global.pass;
|
|
|
|
conf->port = global.port;
|
|
|
|
conf->box = global.box;
|
|
|
|
conf->host = global.host;
|
2000-12-22 07:14:32 +00:00
|
|
|
conf->max_size = global.max_size;
|
2000-12-22 21:22:24 +00:00
|
|
|
conf->use_namespace = global.use_namespace;
|
2000-12-21 06:27:05 +00:00
|
|
|
#if HAVE_LIBSSL
|
|
|
|
conf->require_ssl = global.require_ssl;
|
|
|
|
conf->use_imaps = global.use_imaps;
|
|
|
|
conf->cert_file = global.cert_file;
|
2000-12-22 21:22:24 +00:00
|
|
|
conf->use_sslv2 = global.use_sslv2;
|
|
|
|
conf->use_sslv3 = global.use_sslv3;
|
|
|
|
conf->use_tlsv1 = global.use_tlsv1;
|
2000-12-21 06:27:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-12-20 21:41:21 +00:00
|
|
|
static void
|
|
|
|
load_config (char *where)
|
|
|
|
{
|
|
|
|
char path[_POSIX_PATH_MAX];
|
|
|
|
char buf[1024];
|
|
|
|
struct passwd *pw;
|
|
|
|
config_t **cur = &box;
|
|
|
|
int line = 0;
|
|
|
|
FILE *fp;
|
2000-12-28 18:44:06 +00:00
|
|
|
char *p, *cmd, *val;
|
2000-12-20 21:41:21 +00:00
|
|
|
|
|
|
|
if (!where)
|
|
|
|
{
|
|
|
|
pw = getpwuid (getuid ());
|
|
|
|
snprintf (path, sizeof (path), "%s/.isyncrc", pw->pw_dir);
|
|
|
|
where = path;
|
|
|
|
}
|
|
|
|
printf ("Reading %s\n", where);
|
|
|
|
|
|
|
|
fp = fopen (where, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT)
|
|
|
|
{
|
|
|
|
perror ("fopen");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
buf[sizeof buf - 1] = 0;
|
2000-12-20 21:41:21 +00:00
|
|
|
while ((fgets (buf, sizeof (buf) - 1, fp)))
|
|
|
|
{
|
2000-12-27 21:14:22 +00:00
|
|
|
p = buf;
|
2000-12-28 18:44:06 +00:00
|
|
|
cmd = next_arg (&p);
|
|
|
|
val = next_arg (&p);
|
2000-12-20 21:41:21 +00:00
|
|
|
line++;
|
2000-12-28 18:44:06 +00:00
|
|
|
if (!cmd || *cmd == '#')
|
2000-12-20 21:41:21 +00:00
|
|
|
continue;
|
2000-12-28 18:44:06 +00:00
|
|
|
if (!strncasecmp ("mailbox", cmd, 7))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
cur = &(*cur)->next;
|
|
|
|
*cur = calloc (1, sizeof (config_t));
|
2000-12-21 06:27:05 +00:00
|
|
|
config_defaults (*cur);
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->path = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("host", cmd, 4))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2000-12-21 06:51:14 +00:00
|
|
|
#if HAVE_LIBSSL
|
2000-12-28 18:44:06 +00:00
|
|
|
if (!strncasecmp ("imaps:", val, 6))
|
2000-12-21 06:27:05 +00:00
|
|
|
{
|
2000-12-28 18:44:06 +00:00
|
|
|
val += 6;
|
2000-12-21 06:27:05 +00:00
|
|
|
if (*cur)
|
|
|
|
{
|
|
|
|
(*cur)->use_imaps = 1;
|
|
|
|
(*cur)->port = 993;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global.use_imaps = 1;
|
|
|
|
global.port = 993;
|
|
|
|
}
|
|
|
|
}
|
2000-12-21 06:51:14 +00:00
|
|
|
#endif
|
2000-12-20 21:41:21 +00:00
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->host = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.host = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("user", cmd, 4))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->user = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.user = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("pass", cmd, 4))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->pass = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.pass = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("port", cmd, 4))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->port = atoi (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.port = atoi (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("box", cmd, 3))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->box = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.box = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("alias", cmd, 5))
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->alias = strdup (val);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("maxsize", cmd, 7))
|
2000-12-22 07:14:32 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->max_size = atol (val);
|
2000-12-22 07:14:32 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.max_size = atol (val);
|
2000-12-22 07:14:32 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("UseNamespace", cmd, 12))
|
2000-12-22 21:22:24 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->use_namespace = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.use_namespace = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
}
|
2000-12-21 06:27:05 +00:00
|
|
|
#if HAVE_LIBSSL
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("CertificateFile", cmd, 15))
|
2000-12-21 06:27:05 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->cert_file = strdup (val);
|
2000-12-21 06:27:05 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.cert_file = strdup (val);
|
2000-12-21 06:27:05 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("RequireSSL", cmd, 10))
|
2000-12-21 06:27:05 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->require_ssl = (strcasecmp (val, "yes") == 0);
|
2000-12-21 06:27:05 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.require_ssl = (strcasecmp (val, "yes") == 0);
|
2000-12-21 06:27:05 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("UseSSLv2", cmd, 8))
|
2000-12-22 21:22:24 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->use_sslv2 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.use_sslv2 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("UseSSLv3", cmd, 8))
|
2000-12-22 21:22:24 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->use_sslv3 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.use_sslv3 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("UseTLSv1", cmd, 8))
|
2000-12-22 21:22:24 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->use_tlsv1 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.use_tlsv1 = (strcasecmp (val, "yes") == 0);
|
2000-12-22 21:22:24 +00:00
|
|
|
}
|
2000-12-28 18:44:06 +00:00
|
|
|
else if (!strncasecmp ("RequireCRAM", cmd, 11))
|
2000-12-27 21:14:22 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2000-12-28 18:44:06 +00:00
|
|
|
(*cur)->require_cram = (strcasecmp (val, "yes") == 0);
|
2000-12-27 21:14:22 +00:00
|
|
|
else
|
2000-12-28 18:44:06 +00:00
|
|
|
global.require_cram = (strcasecmp (val, "yes") == 0);
|
2000-12-27 21:14:22 +00:00
|
|
|
}
|
2000-12-21 06:27:05 +00:00
|
|
|
#endif
|
2000-12-20 21:41:21 +00:00
|
|
|
else if (buf[0])
|
2000-12-28 18:44:06 +00:00
|
|
|
printf ("%s:%d:unknown command:%s", path, line, cmd);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static config_t *
|
|
|
|
find_box (const char *s)
|
|
|
|
{
|
|
|
|
config_t *p = box;
|
|
|
|
|
|
|
|
for (; p; p = p->next)
|
|
|
|
if (!strcmp (s, p->path) || (p->alias && !strcmp (s, p->alias)))
|
|
|
|
return p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
next_arg (char **s)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return 0;
|
|
|
|
if (!*s)
|
|
|
|
return 0;
|
2000-12-22 21:22:24 +00:00
|
|
|
while (isspace ((unsigned char) **s))
|
2000-12-20 21:41:21 +00:00
|
|
|
(*s)++;
|
|
|
|
if (!**s)
|
|
|
|
{
|
|
|
|
*s = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ret = *s;
|
2000-12-22 21:22:24 +00:00
|
|
|
while (**s && !isspace ((unsigned char) **s))
|
2000-12-20 21:41:21 +00:00
|
|
|
(*s)++;
|
|
|
|
if (**s)
|
|
|
|
*(*s)++ = 0;
|
|
|
|
if (!**s)
|
|
|
|
*s = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
config_t *box;
|
|
|
|
mailbox_t *mail;
|
2000-12-27 21:14:22 +00:00
|
|
|
imap_t *imap = 0;
|
2000-12-20 21:41:21 +00:00
|
|
|
int expunge = 0; /* by default, don't delete anything */
|
|
|
|
int fast = 0;
|
|
|
|
int delete = 0;
|
|
|
|
char *config = 0;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
pw = getpwuid (getuid ());
|
|
|
|
|
|
|
|
/* defaults */
|
|
|
|
memset (&global, 0, sizeof (global));
|
|
|
|
global.port = 143;
|
|
|
|
global.box = "INBOX";
|
|
|
|
global.user = strdup (pw->pw_name);
|
2000-12-22 15:24:55 +00:00
|
|
|
global.max_size = 0;
|
2000-12-22 21:22:24 +00:00
|
|
|
global.use_namespace = 1;
|
2000-12-21 06:27:05 +00:00
|
|
|
#if HAVE_LIBSSL
|
|
|
|
/* this will probably annoy people, but its the best default just in
|
|
|
|
* case people forget to turn it on
|
|
|
|
*/
|
|
|
|
global.require_ssl = 1;
|
2000-12-22 21:22:24 +00:00
|
|
|
global.use_sslv2 = 1;
|
|
|
|
global.use_sslv3 = 1;
|
|
|
|
global.use_tlsv1 = 1;
|
2000-12-21 06:27:05 +00:00
|
|
|
#endif
|
2000-12-20 21:41:21 +00:00
|
|
|
|
|
|
|
#if HAVE_GETOPT_LONG
|
2001-01-08 09:45:35 +00:00
|
|
|
while ((i = getopt_long (argc, argv, "c:defhp:u:r:s:vV", Opts, NULL)) != -1)
|
2000-12-20 21:41:21 +00:00
|
|
|
#else
|
2001-01-08 09:45:35 +00:00
|
|
|
while ((i = getopt (argc, argv, "c:defhp:u:r:s:vV")) != -1)
|
2000-12-20 21:41:21 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
config = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
delete = 1;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
expunge = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fast = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
global.port = atoi (optarg);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
global.box = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
global.host = optarg;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
free (global.user);
|
|
|
|
global.user = optarg;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
Verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
version ();
|
|
|
|
default:
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv[optind])
|
|
|
|
{
|
|
|
|
puts ("No box specified");
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gethostname (Hostname, sizeof (Hostname));
|
|
|
|
|
|
|
|
load_config (config);
|
|
|
|
|
2000-12-27 21:14:22 +00:00
|
|
|
for (; argv[optind]; optind++)
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2000-12-27 21:14:22 +00:00
|
|
|
box = find_box (argv[optind]);
|
|
|
|
if (!box)
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2000-12-27 21:14:22 +00:00
|
|
|
/* if enough info is given on the command line, don't worry if
|
|
|
|
* the mailbox isn't defined.
|
|
|
|
*/
|
|
|
|
if (!global.host)
|
|
|
|
{
|
|
|
|
puts ("No such mailbox");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
global.path = argv[optind];
|
|
|
|
box = &global;
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
|
|
|
|
2000-12-27 21:14:22 +00:00
|
|
|
if (!box->pass)
|
|
|
|
{
|
2001-01-08 09:45:35 +00:00
|
|
|
/* if we don't have a global password set, prompt the user for
|
|
|
|
* it now.
|
|
|
|
*/
|
|
|
|
if (!global.pass)
|
2000-12-27 21:14:22 +00:00
|
|
|
{
|
2001-01-08 09:45:35 +00:00
|
|
|
global.pass = getpass ("Password:");
|
|
|
|
if (!global.pass)
|
|
|
|
{
|
|
|
|
puts ("Aborting, no password");
|
|
|
|
exit (1);
|
|
|
|
}
|
2000-12-27 21:14:22 +00:00
|
|
|
}
|
2001-01-08 09:45:35 +00:00
|
|
|
box->pass = strdup (global.pass);
|
2000-12-27 21:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf ("Reading %s\n", box->path);
|
|
|
|
mail = maildir_open (box->path, fast);
|
|
|
|
if (!mail)
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2000-12-27 21:14:22 +00:00
|
|
|
puts ("Unable to load mailbox");
|
2000-12-21 06:27:05 +00:00
|
|
|
exit (1);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
|
|
|
|
2000-12-27 21:14:22 +00:00
|
|
|
imap = imap_open (box, fast ? mail->maxuid + 1 : 1, imap);
|
|
|
|
if (!imap)
|
|
|
|
exit (1);
|
2000-12-20 21:41:21 +00:00
|
|
|
|
2000-12-27 21:14:22 +00:00
|
|
|
puts ("Synchronizing");
|
|
|
|
i = delete ? SYNC_DELETE : 0;
|
|
|
|
i |= expunge ? SYNC_EXPUNGE : 0;
|
|
|
|
if (sync_mailbox (mail, imap, i, box->max_size))
|
|
|
|
exit (1);
|
2000-12-20 21:41:21 +00:00
|
|
|
|
2000-12-27 21:14:22 +00:00
|
|
|
if (!fast)
|
2000-12-20 21:41:21 +00:00
|
|
|
{
|
2000-12-27 21:14:22 +00:00
|
|
|
if (expunge && (imap->deleted || mail->deleted))
|
|
|
|
{
|
|
|
|
/* remove messages marked for deletion */
|
|
|
|
printf ("Expunging %d messages from server\n", imap->deleted);
|
|
|
|
if (imap_expunge (imap))
|
|
|
|
exit (1);
|
|
|
|
printf ("Expunging %d messages from local mailbox\n",
|
|
|
|
mail->deleted);
|
|
|
|
if (maildir_expunge (mail, 0))
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
/* remove messages deleted from server. this can safely be an
|
|
|
|
* `else' clause since dead messages are marked as deleted by
|
|
|
|
* sync_mailbox.
|
|
|
|
*/
|
|
|
|
else if (delete)
|
|
|
|
maildir_expunge (mail, 1);
|
|
|
|
|
|
|
|
/* write changed flags back to the mailbox */
|
|
|
|
printf ("Committing changes to %s\n", mail->path);
|
|
|
|
if (maildir_sync (mail))
|
2000-12-20 21:41:21 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
2000-12-27 21:14:22 +00:00
|
|
|
|
|
|
|
maildir_close (mail);
|
2000-12-20 21:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* gracefully close connection to the IMAP server */
|
|
|
|
imap_close (imap);
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|