isync

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

commit fb19d644f7ac7e449061c7fdd4bfeb1a39ab01cc
parent 97a42cd825be28f4b042a9b649845c8b954f9ea9
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Sat, 27 Dec 2014 23:39:55 +0100

split off open_box() from select_box()

aka prepare_paths() reloaded. we'll need it in a moment.

Diffstat:
Msrc/driver.h | 9++++++---
Msrc/drv_imap.c | 21+++++++++++++++------
Msrc/drv_maildir.c | 29++++++++++++++++++-----------
Msrc/main.c | 2+-
Msrc/sync.c | 14++++++++++----
5 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/src/driver.h b/src/driver.h @@ -161,10 +161,13 @@ struct driver { void (*list_store)( store_t *ctx, int flags, void (*cb)( int sts, void *aux ), void *aux ); - /* Open the mailbox name. Optionally create missing boxes. + /* Invoked before open_box(), this informs the driver which box is to be opened. * As a side effect, this should resolve ctx->path if applicable. */ - void (*select_box)( store_t *ctx, const char *name, int create, - void (*cb)( int sts, void *aux ), void *aux ); + int (*select_box)( store_t *ctx, const char *name ); + + /* Open the selected mailbox. Optionally create missing boxes. */ + void (*open_box)( store_t *ctx, int create, + void (*cb)( int sts, void *aux ), void *aux ); /* Invoked before load_box(), this informs the driver which operations (OP_*) * will be performed on the mailbox. The driver may extend the set by implicitly diff --git a/src/drv_imap.c b/src/drv_imap.c @@ -2108,21 +2108,29 @@ imap_open_store_bail( imap_store_t *ctx ) cb( 0, aux ); } -/******************* imap_select_box *******************/ +/******************* imap_open_box *******************/ -static void -imap_select_box( store_t *gctx, const char *name, int create, - void (*cb)( int sts, void *aux ), void *aux ) +static int +imap_select_box( store_t *gctx, const char *name ) { imap_store_t *ctx = (imap_store_t *)gctx; - struct imap_cmd_simple *cmd; - char *buf; free_generic_messages( gctx->msgs ); gctx->msgs = 0; ctx->msgapp = &gctx->msgs; ctx->name = name; + return DRV_OK; +} + +static void +imap_open_box( store_t *gctx, int create, + void (*cb)( int sts, void *aux ), void *aux ) +{ + imap_store_t *ctx = (imap_store_t *)gctx; + struct imap_cmd_simple *cmd; + char *buf; + if (prepare_box( &buf, ctx ) < 0) { cb( DRV_BOX_BAD, aux ); return; @@ -2780,6 +2788,7 @@ struct driver imap_driver = { imap_cancel_store, imap_list_store, imap_select_box, + imap_open_box, imap_prepare_load_box, imap_load_box, imap_fetch_msg, diff --git a/src/drv_maildir.c b/src/drv_maildir.c @@ -926,16 +926,10 @@ maildir_app_msg( maildir_store_t *ctx, message_t ***msgapp, msg_t *entry ) maildir_init_msg( ctx, msg, entry ); } -static void -maildir_select_box( store_t *gctx, const char *name, int create, - void (*cb)( int sts, void *aux ), void *aux ) +static int +maildir_select_box( store_t *gctx, const char *name ) { maildir_store_t *ctx = (maildir_store_t *)gctx; - int ret; -#ifdef USE_DB - struct stat st; -#endif /* USE_DB */ - char uvpath[_POSIX_PATH_MAX]; maildir_cleanup( gctx ); gctx->msgs = 0; @@ -948,12 +942,24 @@ maildir_select_box( store_t *gctx, const char *name, int create, gctx->path = maildir_join_path( ((maildir_store_conf_t *)gctx->conf)->inbox, name + 5 ); } else { if (maildir_validate_path( gctx->conf ) < 0) { - maildir_invoke_bad_callback( gctx ); - cb( DRV_CANCELED, aux ); - return; + gctx->path = 0; + return DRV_CANCELED; } gctx->path = maildir_join_path( gctx->conf->path, name ); } + return DRV_OK; +} + +static void +maildir_open_box( store_t *gctx, int create, + void (*cb)( int sts, void *aux ), void *aux ) +{ + maildir_store_t *ctx = (maildir_store_t *)gctx; + int ret; +#ifdef USE_DB + struct stat st; +#endif /* USE_DB */ + char uvpath[_POSIX_PATH_MAX]; if ((ret = maildir_validate( gctx->path, create, ctx )) != DRV_OK) { cb( ret, aux ); @@ -1532,6 +1538,7 @@ struct driver maildir_driver = { maildir_disown_store, /* _cancel_, but it's the same */ maildir_list_store, maildir_select_box, + maildir_open_box, maildir_prepare_load_box, maildir_load_box, maildir_fetch_msg, diff --git a/src/main.c b/src/main.c @@ -599,7 +599,7 @@ sync_chans( main_vars_t *mvars, int ent ) else labels[M] = labels[S] = ""; for (t = 0; ; t++) { - info( "Opening %s %s...\n", str_ms[t], mvars->chan->stores[t]->name ); + info( "Opening %s store %s...\n", str_ms[t], mvars->chan->stores[t]->name ); mvars->drv[t] = mvars->chan->stores[t]->driver; mvars->drv[t]->open_store( mvars->chan->stores[t], labels[t], store_opened, AUX ); if (t) diff --git a/src/sync.c b/src/sync.c @@ -919,7 +919,7 @@ load_state( sync_vars_t *svars ) return 1; } -static void box_selected( int sts, void *aux ); +static void box_opened( int sts, void *aux ); void sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan, @@ -957,10 +957,16 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan, } /* Both boxes must be fully set up at this point, so that error exit paths * don't run into uninitialized variables. */ + for (t = 0; t < 2; t++) { + if (svars->drv[t]->select_box( ctx[t], svars->box_name[t] ) == DRV_CANCELED) { + store_bad( AUX ); + return; + } + } sync_ref( svars ); for (t = 0; t < 2; t++) { - info( "Selecting %s %s...\n", str_ms[t], svars->orig_name[t] ); - svars->drv[t]->select_box( ctx[t], svars->box_name[t], (chan->ops[t] & OP_CREATE) != 0, box_selected, AUX ); + info( "Opening %s box %s...\n", str_ms[t], svars->orig_name[t] ); + svars->drv[t]->open_box( ctx[t], (chan->ops[t] & OP_CREATE) != 0, box_opened, AUX ); if (check_cancel( svars )) break; } @@ -970,7 +976,7 @@ sync_boxes( store_t *ctx[], const char *names[], channel_conf_t *chan, static void load_box( sync_vars_t *svars, int t, int minwuid, int *mexcs, int nmexcs ); static void -box_selected( int sts, void *aux ) +box_opened( int sts, void *aux ) { DECL_SVARS; sync_rec_t *srec;