calculate trash box path already in maildir_open_store()
this gives us some cleaner code paths later on, as we can treat the trash box like a regular mailbox.
This commit is contained in:
parent
8121224744
commit
4f94197e41
|
@ -64,6 +64,7 @@ typedef struct maildir_store {
|
||||||
store_t gen;
|
store_t gen;
|
||||||
int uvfd, uvok, nuid;
|
int uvfd, uvok, nuid;
|
||||||
int minuid, maxuid, newuid, nexcs, *excs;
|
int minuid, maxuid, newuid, nexcs, *excs;
|
||||||
|
char *trash;
|
||||||
#ifdef USE_DB
|
#ifdef USE_DB
|
||||||
DB *db;
|
DB *db;
|
||||||
#endif /* USE_DB */
|
#endif /* USE_DB */
|
||||||
|
@ -108,6 +109,7 @@ maildir_open_store( store_conf_t *conf,
|
||||||
ctx = nfcalloc( sizeof(*ctx) );
|
ctx = nfcalloc( sizeof(*ctx) );
|
||||||
ctx->gen.conf = conf;
|
ctx->gen.conf = conf;
|
||||||
ctx->uvfd = -1;
|
ctx->uvfd = -1;
|
||||||
|
nfasprintf( &ctx->trash, "%s%s", conf->path, conf->trash );
|
||||||
cb( &ctx->gen, aux );
|
cb( &ctx->gen, aux );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +135,7 @@ maildir_cleanup( store_t *gctx )
|
||||||
if (ctx->db)
|
if (ctx->db)
|
||||||
ctx->db->close( ctx->db, 0 );
|
ctx->db->close( ctx->db, 0 );
|
||||||
#endif /* USE_DB */
|
#endif /* USE_DB */
|
||||||
|
free( ctx->trash );
|
||||||
free( gctx->path );
|
free( gctx->path );
|
||||||
free( ctx->excs );
|
free( ctx->excs );
|
||||||
if (ctx->uvfd >= 0)
|
if (ctx->uvfd >= 0)
|
||||||
|
@ -230,7 +233,7 @@ maildir_free_scan( msglist_t *msglist )
|
||||||
#define _24_HOURS (3600 * 24)
|
#define _24_HOURS (3600 * 24)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
maildir_validate( const char *prefix, const char *box, int create, maildir_store_t *ctx )
|
maildir_validate( const char *box, int create, maildir_store_t *ctx )
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
@ -239,7 +242,7 @@ maildir_validate( const char *prefix, const char *box, int create, maildir_store
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char buf[_POSIX_PATH_MAX];
|
char buf[_POSIX_PATH_MAX];
|
||||||
|
|
||||||
bl = nfsnprintf( buf, sizeof(buf) - 4, "%s%s/", prefix, box );
|
bl = nfsnprintf( buf, sizeof(buf) - 4, "%s/", box );
|
||||||
if (stat( buf, &st )) {
|
if (stat( buf, &st )) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
if (create) {
|
if (create) {
|
||||||
|
@ -824,7 +827,7 @@ maildir_select( store_t *gctx, int create,
|
||||||
else
|
else
|
||||||
nfasprintf( &gctx->path, "%s%s", gctx->conf->path, gctx->name );
|
nfasprintf( &gctx->path, "%s%s", gctx->conf->path, gctx->name );
|
||||||
|
|
||||||
if ((ret = maildir_validate( gctx->path, "", create, ctx )) != DRV_OK) {
|
if ((ret = maildir_validate( gctx->path, create, ctx )) != DRV_OK) {
|
||||||
cb( ret, aux );
|
cb( ret, aux );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1066,7 +1069,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
|
||||||
void (*cb)( int sts, int uid, void *aux ), void *aux )
|
void (*cb)( int sts, int uid, void *aux ), void *aux )
|
||||||
{
|
{
|
||||||
maildir_store_t *ctx = (maildir_store_t *)gctx;
|
maildir_store_t *ctx = (maildir_store_t *)gctx;
|
||||||
const char *prefix, *box;
|
const char *box;
|
||||||
int ret, fd, bl, uid;
|
int ret, fd, bl, uid;
|
||||||
char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX], fbuf[NUM_FLAGS + 3], base[128];
|
char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX], fbuf[NUM_FLAGS + 3], base[128];
|
||||||
|
|
||||||
|
@ -1091,15 +1094,13 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
|
||||||
maildir_uidval_unlock( ctx );
|
maildir_uidval_unlock( ctx );
|
||||||
nfsnprintf( base + bl, sizeof(base) - bl, ",U=%d", uid );
|
nfsnprintf( base + bl, sizeof(base) - bl, ",U=%d", uid );
|
||||||
}
|
}
|
||||||
prefix = gctx->path;
|
box = gctx->path;
|
||||||
box = "";
|
|
||||||
} else {
|
} else {
|
||||||
prefix = gctx->conf->path;
|
box = ctx->trash;
|
||||||
box = gctx->conf->trash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maildir_make_flags( data->flags, fbuf );
|
maildir_make_flags( data->flags, fbuf );
|
||||||
nfsnprintf( buf, sizeof(buf), "%s%s/tmp/%s%s", prefix, box, base, fbuf );
|
nfsnprintf( buf, sizeof(buf), "%s/tmp/%s%s", box, base, fbuf );
|
||||||
if ((fd = open( buf, O_WRONLY|O_CREAT|O_EXCL, 0600 )) < 0) {
|
if ((fd = open( buf, O_WRONLY|O_CREAT|O_EXCL, 0600 )) < 0) {
|
||||||
if (errno != ENOENT || !to_trash) {
|
if (errno != ENOENT || !to_trash) {
|
||||||
sys_error( "Maildir error: cannot create %s", buf );
|
sys_error( "Maildir error: cannot create %s", buf );
|
||||||
|
@ -1107,7 +1108,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
|
||||||
cb( DRV_BOX_BAD, 0, aux );
|
cb( DRV_BOX_BAD, 0, aux );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((ret = maildir_validate( gctx->conf->path, gctx->conf->trash, 1, ctx )) != DRV_OK) {
|
if ((ret = maildir_validate( box, 1, ctx )) != DRV_OK) {
|
||||||
free( data->data );
|
free( data->data );
|
||||||
cb( ret, 0, aux );
|
cb( ret, 0, aux );
|
||||||
return;
|
return;
|
||||||
|
@ -1137,7 +1138,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Moving seen messages to cur/ is strictly speaking incorrect, but makes mutt happy. */
|
/* Moving seen messages to cur/ is strictly speaking incorrect, but makes mutt happy. */
|
||||||
nfsnprintf( nbuf, sizeof(nbuf), "%s%s/%s/%s%s", prefix, box, subdirs[!(data->flags & F_SEEN)], base, fbuf );
|
nfsnprintf( nbuf, sizeof(nbuf), "%s/%s/%s%s", box, subdirs[!(data->flags & F_SEEN)], base, fbuf );
|
||||||
if (rename( buf, nbuf )) {
|
if (rename( buf, nbuf )) {
|
||||||
sys_error( "Maildir error: cannot rename %s to %s", buf, nbuf );
|
sys_error( "Maildir error: cannot rename %s to %s", buf, nbuf );
|
||||||
cb( DRV_BOX_BAD, 0, aux );
|
cb( DRV_BOX_BAD, 0, aux );
|
||||||
|
@ -1241,12 +1242,12 @@ maildir_trash_msg( store_t *gctx, message_t *gmsg,
|
||||||
for (;;) {
|
for (;;) {
|
||||||
nfsnprintf( buf, sizeof(buf), "%s/%s/%s", gctx->path, subdirs[gmsg->status & M_RECENT], msg->base );
|
nfsnprintf( buf, sizeof(buf), "%s/%s/%s", gctx->path, subdirs[gmsg->status & M_RECENT], msg->base );
|
||||||
s = strstr( msg->base, ":2," );
|
s = strstr( msg->base, ":2," );
|
||||||
nfsnprintf( nbuf, sizeof(nbuf), "%s%s/%s/%ld.%d_%d.%s%s", gctx->conf->path, gctx->conf->trash,
|
nfsnprintf( nbuf, sizeof(nbuf), "%s/%s/%ld.%d_%d.%s%s", ctx->trash,
|
||||||
subdirs[gmsg->status & M_RECENT], time( 0 ), Pid, ++MaildirCount, Hostname, s ? s : "" );
|
subdirs[gmsg->status & M_RECENT], time( 0 ), Pid, ++MaildirCount, Hostname, s ? s : "" );
|
||||||
if (!rename( buf, nbuf ))
|
if (!rename( buf, nbuf ))
|
||||||
break;
|
break;
|
||||||
if (!stat( buf, &st )) {
|
if (!stat( buf, &st )) {
|
||||||
if ((ret = maildir_validate( gctx->conf->path, gctx->conf->trash, 1, ctx )) != DRV_OK) {
|
if ((ret = maildir_validate( ctx->trash, 1, ctx )) != DRV_OK) {
|
||||||
cb( ret, aux );
|
cb( ret, aux );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user