isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit a7eddc6ede4d52589aae2626885dc6793836bf9c
parent 7489ff8613bea88efa0d5987689063773d1f9078
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Sat, 17 Jan 2015 15:27:08 +0100

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.

Diffstat:
Msrc/drv_maildir.c | 41++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)

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