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
*/
#define _GNU_SOURCE 1
#include <unistd.h>
#include <limits.h>
#include <errno.h>
@ -52,13 +54,12 @@ config_defaults (config_t * conf)
#endif
}
/* `s' is destroyed by this call */
static char *
expand_strdup (char *s)
char *
expand_strdup (const char *s)
{
char path[_POSIX_PATH_MAX];
struct passwd *pw;
char *p;
const char *p;
if (*s == '~')
{
@ -71,10 +72,15 @@ expand_strdup (char *s)
}
else
{
char *user;
p = strchr (s, '/');
if (p)
*p++ = 0;
pw = getpwnam (s);
user = strndup (s, (int)(p - s));
else
user = strdup (s);
pw = getpwnam (user);
free (user);
}
if (!pw)
return 0;
@ -83,7 +89,8 @@ expand_strdup (char *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;
}
return strdup (s);
@ -131,7 +138,8 @@ load_config (const char *where)
cur = &(*cur)->next;
*cur = calloc (1, sizeof (config_t));
config_defaults (*cur);
(*cur)->path = expand_strdup (val);
/* not expanded at this point */
(*cur)->path = strdup (val);
}
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 load_config (const char *);
char * expand_strdup (const char *s);
config_t *find_box (const char *);
void imap_close (imap_t *);

View File

@ -136,25 +136,30 @@ maildir_open (const char *path, int fast)
char *s;
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->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 */
m->uidvalidity = read_uid (path, "isyncuidvalidity");
m->uidvalidity = read_uid (m->path, "isyncuidvalidity");
if (m->uidvalidity == (unsigned int) -1)
{
free (m->path);
@ -163,7 +168,7 @@ maildir_open (const char *path, int fast)
}
/* 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);
@ -177,7 +182,7 @@ maildir_open (const char *path, int fast)
for (; count < 2; count++)
{
/* 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");
d = opendir (buf);
if (!d)