2001-01-11 10:13:47 +00:00
|
|
|
/* $Id$
|
|
|
|
*
|
|
|
|
* isync - IMAP4 to maildir mailbox synchronizer
|
2001-01-24 07:09:28 +00:00
|
|
|
* Copyright (C) 2000-1 Michael R. Elkins <me@mutt.org>
|
2001-01-11 10:13:47 +00:00
|
|
|
*
|
|
|
|
* 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 <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
2001-02-28 01:02:50 +00:00
|
|
|
#include <stdlib.h>
|
2001-11-09 00:23:50 +00:00
|
|
|
#include <stdio.h>
|
2001-01-11 10:13:47 +00:00
|
|
|
#include "isync.h"
|
|
|
|
|
2001-06-18 17:49:08 +00:00
|
|
|
config_t *boxes = 0;
|
2001-01-11 10:13:47 +00:00
|
|
|
|
|
|
|
/* set defaults from the global configuration section */
|
2001-11-15 23:59:27 +00:00
|
|
|
static void
|
2001-01-11 10:13:47 +00:00
|
|
|
config_defaults (config_t * conf)
|
|
|
|
{
|
2001-11-15 23:59:27 +00:00
|
|
|
memcpy (conf, &global, sizeof (config_t));
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 17:40:10 +00:00
|
|
|
static char *
|
2001-11-19 19:41:14 +00:00
|
|
|
my_strndup (const char *s, size_t nchars)
|
2001-11-14 17:40:10 +00:00
|
|
|
{
|
|
|
|
char *r = malloc (sizeof (char) * (nchars + 1));
|
|
|
|
strncpy (r, s, nchars);
|
|
|
|
r[nchars] = 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-07-18 18:49:55 +00:00
|
|
|
char *
|
|
|
|
expand_strdup (const char *s)
|
2001-01-16 19:45:08 +00:00
|
|
|
{
|
|
|
|
char path[_POSIX_PATH_MAX];
|
|
|
|
struct passwd *pw;
|
2001-07-18 18:49:55 +00:00
|
|
|
const char *p;
|
2001-01-16 19:45:08 +00:00
|
|
|
|
|
|
|
if (*s == '~')
|
|
|
|
{
|
|
|
|
s++;
|
|
|
|
if (*s == '/')
|
|
|
|
{
|
|
|
|
/* current user */
|
|
|
|
pw = getpwuid (getuid ());
|
|
|
|
p = s + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-07-18 18:49:55 +00:00
|
|
|
char *user;
|
|
|
|
|
2001-01-16 19:45:08 +00:00
|
|
|
p = strchr (s, '/');
|
|
|
|
if (p)
|
2001-11-13 00:36:44 +00:00
|
|
|
{
|
2001-11-19 19:41:14 +00:00
|
|
|
user = my_strndup (s, (int)(p - s));
|
2001-11-13 00:36:44 +00:00
|
|
|
p++;
|
|
|
|
}
|
2001-07-18 18:49:55 +00:00
|
|
|
else
|
|
|
|
user = strdup (s);
|
|
|
|
pw = getpwnam (user);
|
|
|
|
free (user);
|
2001-01-16 19:45:08 +00:00
|
|
|
}
|
|
|
|
if (!pw)
|
|
|
|
return 0;
|
|
|
|
snprintf (path, sizeof (path), "%s/%s", pw->pw_dir, p ? p : "");
|
|
|
|
s = path;
|
|
|
|
}
|
|
|
|
else if (*s != '/')
|
|
|
|
{
|
2001-07-18 18:49:55 +00:00
|
|
|
snprintf (path, sizeof (path), "%s/%s",
|
|
|
|
global.maildir ? global.maildir : "", s);
|
2001-01-16 19:45:08 +00:00
|
|
|
s = path;
|
|
|
|
}
|
|
|
|
return strdup (s);
|
|
|
|
}
|
|
|
|
|
2001-01-11 10:13:47 +00:00
|
|
|
void
|
|
|
|
load_config (const char *where)
|
|
|
|
{
|
|
|
|
char path[_POSIX_PATH_MAX];
|
|
|
|
char buf[1024];
|
|
|
|
struct passwd *pw;
|
2001-06-18 17:49:08 +00:00
|
|
|
config_t **cur = &boxes;
|
2001-01-11 10:13:47 +00:00
|
|
|
int line = 0;
|
|
|
|
FILE *fp;
|
|
|
|
char *p, *cmd, *val;
|
|
|
|
|
|
|
|
if (!where)
|
|
|
|
{
|
|
|
|
pw = getpwuid (getuid ());
|
|
|
|
snprintf (path, sizeof (path), "%s/.isyncrc", pw->pw_dir);
|
|
|
|
where = path;
|
|
|
|
}
|
2001-02-14 20:46:41 +00:00
|
|
|
|
2001-01-11 10:13:47 +00:00
|
|
|
printf ("Reading %s\n", where);
|
|
|
|
|
|
|
|
fp = fopen (where, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
if (errno != ENOENT)
|
|
|
|
perror ("fopen");
|
2001-02-14 20:46:41 +00:00
|
|
|
return;
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
|
|
|
buf[sizeof buf - 1] = 0;
|
|
|
|
while ((fgets (buf, sizeof (buf) - 1, fp)))
|
|
|
|
{
|
|
|
|
p = buf;
|
|
|
|
cmd = next_arg (&p);
|
|
|
|
val = next_arg (&p);
|
|
|
|
line++;
|
|
|
|
if (!cmd || *cmd == '#')
|
|
|
|
continue;
|
2001-10-03 05:42:22 +00:00
|
|
|
if (!strcasecmp ("mailbox", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
cur = &(*cur)->next;
|
|
|
|
*cur = calloc (1, sizeof (config_t));
|
|
|
|
config_defaults (*cur);
|
2001-07-18 18:49:55 +00:00
|
|
|
/* not expanded at this point */
|
|
|
|
(*cur)->path = strdup (val);
|
2001-01-16 19:45:08 +00:00
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("maildir", cmd))
|
2001-01-16 19:45:08 +00:00
|
|
|
{
|
|
|
|
/* this only affects the global setting */
|
|
|
|
free (global.maildir);
|
|
|
|
global.maildir = expand_strdup (val);
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("host", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
#if HAVE_LIBSSL
|
|
|
|
if (!strncasecmp ("imaps:", val, 6))
|
|
|
|
{
|
|
|
|
val += 6;
|
|
|
|
if (*cur)
|
|
|
|
{
|
|
|
|
(*cur)->use_imaps = 1;
|
|
|
|
(*cur)->port = 993;
|
2001-02-14 20:46:41 +00:00
|
|
|
(*cur)->use_sslv2 = 1;
|
|
|
|
(*cur)->use_sslv3 = 1;
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
global.use_imaps = 1;
|
|
|
|
global.port = 993;
|
2001-02-14 20:46:41 +00:00
|
|
|
global.use_sslv2 = 1;
|
|
|
|
global.use_sslv3 = 1;
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->host = strdup (val);
|
|
|
|
else
|
|
|
|
global.host = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("user", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->user = strdup (val);
|
|
|
|
else
|
|
|
|
global.user = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("pass", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->pass = strdup (val);
|
|
|
|
else
|
|
|
|
global.pass = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("port", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->port = atoi (val);
|
|
|
|
else
|
|
|
|
global.port = atoi (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("box", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->box = strdup (val);
|
|
|
|
else
|
|
|
|
global.box = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("alias", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->alias = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("maxsize", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->max_size = atol (val);
|
|
|
|
else
|
|
|
|
global.max_size = atol (val);
|
|
|
|
}
|
2001-11-15 23:59:27 +00:00
|
|
|
else if (!strcasecmp ("MaxMessages", cmd))
|
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->max_messages = atol (val);
|
|
|
|
else
|
|
|
|
global.max_messages = atol (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("UseNamespace", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->use_namespace = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.use_namespace = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("CopyDeletedTo", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->copy_deleted_to = strdup (val);
|
|
|
|
else
|
|
|
|
global.copy_deleted_to = strdup (val);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("Expunge", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->expunge = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.expunge = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 06:32:16 +00:00
|
|
|
else if (!strcasecmp ("Delete", cmd))
|
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->delete = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.delete = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-01-11 10:13:47 +00:00
|
|
|
#if HAVE_LIBSSL
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("CertificateFile", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
2001-01-16 19:45:08 +00:00
|
|
|
(*cur)->cert_file = expand_strdup (val);
|
2001-01-11 10:13:47 +00:00
|
|
|
else
|
2001-01-16 19:45:08 +00:00
|
|
|
global.cert_file = expand_strdup (val);
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("RequireSSL", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->require_ssl = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.require_ssl = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("UseSSLv2", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->use_sslv2 = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.use_sslv2 = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("UseSSLv3", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->use_sslv3 = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.use_sslv3 = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("UseTLSv1", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->use_tlsv1 = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.use_tlsv1 = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
2001-10-03 05:42:22 +00:00
|
|
|
else if (!strcasecmp ("RequireCRAM", cmd))
|
2001-01-11 10:13:47 +00:00
|
|
|
{
|
|
|
|
if (*cur)
|
|
|
|
(*cur)->require_cram = (strcasecmp (val, "yes") == 0);
|
|
|
|
else
|
|
|
|
global.require_cram = (strcasecmp (val, "yes") == 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (buf[0])
|
2001-11-15 23:59:27 +00:00
|
|
|
printf ("%s:%d:unknown keyword:%s\n", path, line, cmd);
|
2001-01-11 10:13:47 +00:00
|
|
|
}
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
config_t *
|
|
|
|
find_box (const char *s)
|
|
|
|
{
|
2001-06-18 17:49:08 +00:00
|
|
|
config_t *p = boxes;
|
2001-01-11 10:13:47 +00:00
|
|
|
|
|
|
|
for (; p; p = p->next)
|
2001-07-18 18:56:11 +00:00
|
|
|
{
|
2001-01-11 10:13:47 +00:00
|
|
|
if (!strcmp (s, p->path) || (p->alias && !strcmp (s, p->alias)))
|
|
|
|
return p;
|
2001-07-18 18:56:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check to see if the full pathname was specified on the
|
|
|
|
* command line.
|
|
|
|
*/
|
|
|
|
char *t = expand_strdup (p->path);
|
|
|
|
|
|
|
|
if (!strcmp (s, t))
|
|
|
|
{
|
|
|
|
free (t);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
free (t);
|
|
|
|
}
|
|
|
|
}
|
2001-01-11 10:13:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-11-19 19:41:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
free_config (void)
|
|
|
|
{
|
|
|
|
free (global.user);
|
|
|
|
free (global.maildir);
|
|
|
|
free (global.host);
|
|
|
|
free (global.pass);
|
|
|
|
}
|