don't make intermediate directories proper maildirs

"phantom" mailboxes waste time on syncing. furthermore, mutt's mailbox
navigator provides no means to enter subfolders of maildirs.
This commit is contained in:
Oswald Buddenhagen 2015-01-17 15:27:08 +01:00
parent 7489ff8613
commit a7eddc6ede

View File

@ -214,22 +214,22 @@ maildir_list_recurse( store_t *gctx, int isBox, int *flags, const char *inbox, i
char *path, int pathLen, char *name, int nameLen ) char *path, int pathLen, char *name, int nameLen )
{ {
DIR *dir; DIR *dir;
int pl, nl, missing; int pl, nl;
struct dirent *de; struct dirent *de;
struct stat st; struct stat st;
if (isBox) { if (isBox) {
path[pathLen++] = '/'; path[pathLen++] = '/';
nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "cur" ); if (isBox > 1 ||
missing = stat( path, &st ) || !S_ISDIR(st.st_mode); (nfsnprintf( path + pathLen, _POSIX_PATH_MAX - pathLen, "cur" ),
if (!missing || isBox > 1) !stat( path, &st ) && S_ISDIR(st.st_mode)))
add_string_list( &gctx->boxes, name ); add_string_list( &gctx->boxes, name );
if (missing)
return 0;
path[pathLen] = 0; path[pathLen] = 0;
name[nameLen++] = '/'; name[nameLen++] = '/';
} }
if (!(dir = opendir( path ))) { if (!(dir = opendir( path ))) {
if (isBox && (errno == ENOENT || errno == ENOTDIR))
return 0;
sys_error( "Maildir error: cannot list %s", path ); sys_error( "Maildir error: cannot list %s", path );
return -1; return -1;
} }
@ -369,9 +369,27 @@ maildir_clear_tmp( char *buf, int bufsz, int bl )
} }
static int static int
maildir_validate( const char *box, int create, maildir_store_t *ctx ) make_box_dir( char *buf, int bl )
{ {
char *p; char *p;
if (!mkdir( buf, 0700 ) || errno == EEXIST)
return 0;
p = memrchr( buf, '/', bl - 1 );
if (*(p + 1) != '.') {
errno = ENOENT;
return -1;
}
*p = 0;
if (make_box_dir( buf, (int)(p - buf) ))
return -1;
*p = '/';
return mkdir( buf, 0700 );
}
static int
maildir_validate( const char *box, int create, maildir_store_t *ctx )
{
int i, bl, ret; int i, bl, ret;
struct stat st; struct stat st;
char buf[_POSIX_PATH_MAX]; char buf[_POSIX_PATH_MAX];
@ -384,14 +402,7 @@ maildir_validate( const char *box, int create, maildir_store_t *ctx )
} }
if (!create) if (!create)
return DRV_BOX_BAD; return DRV_BOX_BAD;
p = memrchr( buf, '/', bl - 1 ); if (make_box_dir( buf, bl )) {
if (*(p + 1) == '.') {
*p = 0;
if ((ret = maildir_validate( buf, 1, ctx )) != DRV_OK)
return ret;
*p = '/';
}
if (mkdir( buf, 0700 )) {
sys_error( "Maildir error: cannot create mailbox '%s'", box ); sys_error( "Maildir error: cannot create mailbox '%s'", box );
maildir_invoke_bad_callback( &ctx->gen ); maildir_invoke_bad_callback( &ctx->gen );
return DRV_CANCELED; return DRV_CANCELED;