fixed to not expand filenames until they are used inside of maildir_open(),

so that aliases are not required for simple filenames.
[re: http://bugs.debian.org/102255]
This commit is contained in:
Michael Elkins 2001-07-18 18:49:55 +00:00
parent 5eaa4e5512
commit 0f7823a4bf
3 changed files with 40 additions and 26 deletions

View File

@ -18,6 +18,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define _GNU_SOURCE 1
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
@ -52,13 +54,12 @@ config_defaults (config_t * conf)
#endif #endif
} }
/* `s' is destroyed by this call */ char *
static char * expand_strdup (const char *s)
expand_strdup (char *s)
{ {
char path[_POSIX_PATH_MAX]; char path[_POSIX_PATH_MAX];
struct passwd *pw; struct passwd *pw;
char *p; const char *p;
if (*s == '~') if (*s == '~')
{ {
@ -71,10 +72,15 @@ expand_strdup (char *s)
} }
else else
{ {
char *user;
p = strchr (s, '/'); p = strchr (s, '/');
if (p) if (p)
*p++ = 0; user = strndup (s, (int)(p - s));
pw = getpwnam (s); else
user = strdup (s);
pw = getpwnam (user);
free (user);
} }
if (!pw) if (!pw)
return 0; return 0;
@ -83,7 +89,8 @@ expand_strdup (char *s)
} }
else if (*s != '/') else if (*s != '/')
{ {
snprintf (path, sizeof (path), "%s/%s", global.maildir, s); snprintf (path, sizeof (path), "%s/%s",
global.maildir ? global.maildir : "", s);
s = path; s = path;
} }
return strdup (s); return strdup (s);
@ -131,7 +138,8 @@ 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 = expand_strdup (val); /* not expanded at this point */
(*cur)->path = strdup (val);
} }
else if (!strncasecmp ("maildir", cmd, 7)) else if (!strncasecmp ("maildir", cmd, 7))
{ {

View File

@ -167,6 +167,7 @@ int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int);
void config_defaults (config_t *); void config_defaults (config_t *);
void load_config (const char *); void load_config (const char *);
char * expand_strdup (const char *s);
config_t *find_box (const char *); config_t *find_box (const char *);
void imap_close (imap_t *); void imap_close (imap_t *);

View File

@ -136,25 +136,30 @@ maildir_open (const char *path, int fast)
char *s; char *s;
int count = 0; int count = 0;
/* check to make sure this looks like a valid maildir box */
snprintf (buf, sizeof (buf), "%s/new", path);
if (access (buf, F_OK))
{
perror ("access");
return 0;
}
snprintf (buf, sizeof (buf), "%s/cur", path);
if (access (buf, F_OK))
{
perror ("access");
return 0;
}
m = calloc (1, sizeof (mailbox_t)); m = calloc (1, sizeof (mailbox_t));
m->path = strdup (path); /* filename expansion happens here, not in the config parser */
m->path = expand_strdup (path);
/* check to make sure this looks like a valid maildir box */
snprintf (buf, sizeof (buf), "%s/new", m->path);
if (access (buf, F_OK))
{
free (m->path);
free (m);
perror ("access");
return 0;
}
snprintf (buf, sizeof (buf), "%s/cur", m->path);
if (access (buf, F_OK))
{
free (m->path);
free (m);
perror ("access");
return 0;
}
/* check for the uidvalidity value */ /* check for the uidvalidity value */
m->uidvalidity = read_uid (path, "isyncuidvalidity"); m->uidvalidity = read_uid (m->path, "isyncuidvalidity");
if (m->uidvalidity == (unsigned int) -1) if (m->uidvalidity == (unsigned int) -1)
{ {
free (m->path); free (m->path);
@ -163,7 +168,7 @@ maildir_open (const char *path, int fast)
} }
/* load the current maxuid */ /* load the current maxuid */
if ((m->maxuid = read_uid (path, "isyncmaxuid")) == (unsigned int) -1) if ((m->maxuid = read_uid (m->path, "isyncmaxuid")) == (unsigned int) -1)
{ {
free (m->path); free (m->path);
free (m); free (m);
@ -177,7 +182,7 @@ maildir_open (const char *path, int fast)
for (; count < 2; count++) for (; count < 2; count++)
{ {
/* read the msgs from the new subdir */ /* read the msgs from the new subdir */
snprintf (buf, sizeof (buf), "%s/%s", path, snprintf (buf, sizeof (buf), "%s/%s", m->path,
(count == 0) ? "new" : "cur"); (count == 0) ? "new" : "cur");
d = opendir (buf); d = opendir (buf);
if (!d) if (!d)