added support for tilde (~) expansion in the Mailbox' and CertificateFile'

configuration directives

added `Maildir' configuration command to specify the default location of the
user's mailboxes.  If a relative path is used in a `Mailbox' command, this
path is used as a prefix.
This commit is contained in:
Michael Elkins 2001-01-16 19:45:08 +00:00
parent b3672634e5
commit 7173d07192
6 changed files with 86 additions and 18 deletions

4
TODO
View File

@ -1,3 +1,3 @@
add upload support to mirror local msgs on the server
add support for syncing with other: and shared: via NAMESPACE add support for syncing with other: and shared: via NAMESPACE
finish implementing --quiet

View File

@ -51,6 +51,43 @@ config_defaults (config_t * conf)
#endif #endif
} }
/* `s' is destroyed by this call */
static char *
expand_strdup (char *s)
{
char path[_POSIX_PATH_MAX];
struct passwd *pw;
char *p;
if (*s == '~')
{
s++;
if (*s == '/')
{
/* current user */
pw = getpwuid (getuid ());
p = s + 1;
}
else
{
p = strchr (s, '/');
if (p)
*p++ = 0;
pw = getpwnam (s);
}
if (!pw)
return 0;
snprintf (path, sizeof (path), "%s/%s", pw->pw_dir, p ? p : "");
s = path;
}
else if (*s != '/')
{
snprintf (path, sizeof (path), "%s/%s", global.maildir, s);
s = path;
}
return strdup (s);
}
void void
load_config (const char *where) load_config (const char *where)
{ {
@ -94,7 +131,13 @@ load_config (const char *where)
cur = &(*cur)->next; cur = &(*cur)->next;
*cur = calloc (1, sizeof (config_t)); *cur = calloc (1, sizeof (config_t));
config_defaults (*cur); config_defaults (*cur);
(*cur)->path = strdup (val); (*cur)->path = expand_strdup (val);
}
else if (!strncasecmp ("maildir", cmd, 7))
{
/* this only affects the global setting */
free (global.maildir);
global.maildir = expand_strdup (val);
} }
else if (!strncasecmp ("host", cmd, 4)) else if (!strncasecmp ("host", cmd, 4))
{ {
@ -184,9 +227,9 @@ load_config (const char *where)
else if (!strncasecmp ("CertificateFile", cmd, 15)) else if (!strncasecmp ("CertificateFile", cmd, 15))
{ {
if (*cur) if (*cur)
(*cur)->cert_file = strdup (val); (*cur)->cert_file = expand_strdup (val);
else else
global.cert_file = strdup (val); global.cert_file = expand_strdup (val);
} }
else if (!strncasecmp ("RequireSSL", cmd, 10)) else if (!strncasecmp ("RequireSSL", cmd, 10))
{ {

1
imap.c
View File

@ -727,7 +727,6 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap)
void void
imap_close (imap_t * imap) imap_close (imap_t * imap)
{ {
puts ("Closing IMAP connection");
imap_exec (imap, "LOGOUT"); imap_exec (imap, "LOGOUT");
close (imap->sock->fd); close (imap->sock->fd);
free (imap->sock); free (imap->sock);

12
isync.1
View File

@ -16,7 +16,7 @@
\" along with this program; if not, write to the Free Software \" along with this program; if not, write to the Free Software
\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
.. ..
.TH isync 1 "2000 Dec 27" .TH isync 1 "2001 Jan 16"
.. ..
.SH NAME .SH NAME
isync - synchronize IMAP4 and maildir mailboxes isync - synchronize IMAP4 and maildir mailboxes
@ -168,6 +168,16 @@ command line option overrides this setting when set to
\fIno\fR. \fIno\fR.
.. ..
.TP .TP
\fBMailDir\fR \fIstring\fR
Specifies the location for your mailboxes if a relative path is
specified in a
.I Mailbox
command.
(Default:
.I ~
)
..
.TP
\fBMaxSize\fR \fIbytes\fR \fBMaxSize\fR \fIbytes\fR
Sets a threshold for the maximum message size (in bytes) for which Sets a threshold for the maximum message size (in bytes) for which
.B isync .B isync

View File

@ -47,7 +47,8 @@ typedef struct message message_t;
struct config struct config
{ {
char *path; char *maildir;
char *path; /* path relative to .maildir, or absolute path */
char *host; char *host;
int port; int port;
char *user; char *user;

35
main.c
View File

@ -41,6 +41,7 @@ struct option Opts[] = {
{"remote", 1, NULL, 'r'}, {"remote", 1, NULL, 'r'},
{"host", 1, NULL, 's'}, {"host", 1, NULL, 's'},
{"port", 1, NULL, 'p'}, {"port", 1, NULL, 'p'},
{"quiet", 0, NULL, 'q'},
{"user", 1, NULL, 'u'}, {"user", 1, NULL, 'u'},
{"version", 0, NULL, 'v'}, {"version", 0, NULL, 'v'},
{"verbose", 0, NULL, 'V'}, {"verbose", 0, NULL, 'V'},
@ -134,6 +135,7 @@ main (int argc, char **argv)
int delete = 0; int delete = 0;
char *config = 0; char *config = 0;
struct passwd *pw; struct passwd *pw;
int quiet = 0;
pw = getpwuid (getuid ()); pw = getpwuid (getuid ());
@ -142,6 +144,7 @@ main (int argc, char **argv)
global.port = 143; global.port = 143;
global.box = "INBOX"; global.box = "INBOX";
global.user = strdup (pw->pw_name); global.user = strdup (pw->pw_name);
global.maildir = strdup (pw->pw_dir);
global.max_size = 0; global.max_size = 0;
global.use_namespace = 1; global.use_namespace = 1;
#if HAVE_LIBSSL #if HAVE_LIBSSL
@ -155,9 +158,9 @@ main (int argc, char **argv)
#endif #endif
#if HAVE_GETOPT_LONG #if HAVE_GETOPT_LONG
while ((i = getopt_long (argc, argv, "c:defhp:u:r:s:vV", Opts, NULL)) != -1) while ((i = getopt_long (argc, argv, "c:defhp:qu:r:s:vV", Opts, NULL)) != -1)
#else #else
while ((i = getopt (argc, argv, "c:defhp:u:r:s:vV")) != -1) while ((i = getopt (argc, argv, "c:defhp:u:qr:s:vV")) != -1)
#endif #endif
{ {
switch (i) switch (i)
@ -177,6 +180,10 @@ main (int argc, char **argv)
case 'p': case 'p':
global.port = atoi (optarg); global.port = atoi (optarg);
break; break;
case 'q':
quiet = 1;
Verbose = 0;
break;
case 'r': case 'r':
global.box = optarg; global.box = optarg;
break; break;
@ -241,7 +248,8 @@ main (int argc, char **argv)
box->pass = strdup (global.pass); box->pass = strdup (global.pass);
} }
printf ("Reading %s\n", box->path); if(!quiet)
printf ("Reading %s\n", box->path);
mail = maildir_open (box->path, fast); mail = maildir_open (box->path, fast);
if (!mail) if (!mail)
{ {
@ -253,7 +261,8 @@ main (int argc, char **argv)
if (!imap) if (!imap)
exit (1); exit (1);
puts ("Synchronizing"); if (!quiet)
puts ("Synchronizing");
i = delete ? SYNC_DELETE : 0; i = delete ? SYNC_DELETE : 0;
i |= (expunge || box->expunge) ? SYNC_EXPUNGE : 0; i |= (expunge || box->expunge) ? SYNC_EXPUNGE : 0;
if (sync_mailbox (mail, imap, i, box->max_size)) if (sync_mailbox (mail, imap, i, box->max_size))
@ -264,11 +273,13 @@ main (int argc, char **argv)
if (expunge && (imap->deleted || mail->deleted)) if (expunge && (imap->deleted || mail->deleted))
{ {
/* remove messages marked for deletion */ /* remove messages marked for deletion */
printf ("Expunging %d messages from server\n", imap->deleted); if (!quiet)
printf ("Expunging %d messages from server\n", imap->deleted);
if (imap_expunge (imap)) if (imap_expunge (imap))
exit (1); exit (1);
printf ("Expunging %d messages from local mailbox\n", if (!quiet)
mail->deleted); printf ("Expunging %d messages from local mailbox\n",
mail->deleted);
if (maildir_expunge (mail, 0)) if (maildir_expunge (mail, 0))
exit (1); exit (1);
} }
@ -280,9 +291,13 @@ main (int argc, char **argv)
maildir_expunge (mail, 1); maildir_expunge (mail, 1);
/* write changed flags back to the mailbox */ /* write changed flags back to the mailbox */
printf ("Committing changes to %s\n", mail->path); if (mail->changed)
if (maildir_sync (mail)) {
exit (1); if (!quiet)
printf ("Committing changes to %s\n", mail->path);
if (maildir_sync (mail))
exit (1);
}
} }
maildir_close (mail); maildir_close (mail);