Browse Source

fix updating cached message flags in imap_set_msg_flags()

while this (currently) doesn't really matter (as all flag changes are
calculated before any are actually submitted), msg's flags should not
be updated before set_msg_flags() has actually succeeded.

as a side effect, this does away with the redundancy elimination and
pulling uid from msg (which were both unused since 19128f158).
wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
a652043934
  1. 28
      src/drv_imap.c

28
src/drv_imap.c

@ -658,12 +658,16 @@ imap_refcounted_new_cmd( imap_cmd_refcounted_state_t *sts )
return &cmd->gen; return &cmd->gen;
} }
#define DONE_REFCOUNTED_STATE(sts) \ #define DONE_REFCOUNTED_STATE_FINALIZE(sts, finalize) \
if (!--sts->ref_count) { \ if (!--sts->ref_count) { \
finalize \
sts->callback( sts->ret_val, sts->callback_aux ); \ sts->callback( sts->ret_val, sts->callback_aux ); \
free( sts ); \ free( sts ); \
} }
#define DONE_REFCOUNTED_STATE(sts) \
DONE_REFCOUNTED_STATE_FINALIZE(sts, )
#define DONE_REFCOUNTED_STATE_ARGS(sts, finalize, ...) \ #define DONE_REFCOUNTED_STATE_ARGS(sts, finalize, ...) \
if (!--sts->ref_count) { \ if (!--sts->ref_count) { \
finalize \ finalize \
@ -3040,6 +3044,8 @@ typedef union {
IMAP_CMD_REFCOUNTED_STATE IMAP_CMD_REFCOUNTED_STATE
void (*callback)( int sts, void *aux ); void (*callback)( int sts, void *aux );
void *callback_aux; void *callback_aux;
message_t *msg;
int add, del;
}; };
} imap_set_msg_flags_state_t; } imap_set_msg_flags_state_t;
@ -3065,23 +3071,16 @@ imap_set_msg_flags( store_t *gctx, message_t *msg, uint uid, int add, int del,
{ {
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
if (msg) { assert( add || del );
uid = msg->uid;
add &= ~msg->flags;
del &= msg->flags;
msg->flags |= add;
msg->flags &= ~del;
}
if (add || del) {
INIT_REFCOUNTED_STATE(imap_set_msg_flags_state_t, sts, cb, aux) INIT_REFCOUNTED_STATE(imap_set_msg_flags_state_t, sts, cb, aux)
sts->msg = msg;
sts->add = add;
sts->del = del;
if (add) if (add)
imap_flags_helper( ctx, uid, '+', add, sts ); imap_flags_helper( ctx, uid, '+', add, sts );
if (del) if (del)
imap_flags_helper( ctx, uid, '-', del, sts ); imap_flags_helper( ctx, uid, '-', del, sts );
imap_set_flags_p3( sts ); imap_set_flags_p3( sts );
} else {
cb( DRV_OK, aux );
}
} }
static void static void
@ -3096,7 +3095,10 @@ imap_set_flags_p2( imap_store_t *ctx ATTR_UNUSED, imap_cmd_t *cmd, int response
static void static void
imap_set_flags_p3( imap_set_msg_flags_state_t *sts ) imap_set_flags_p3( imap_set_msg_flags_state_t *sts )
{ {
DONE_REFCOUNTED_STATE(sts) DONE_REFCOUNTED_STATE_FINALIZE(sts, {
if (sts->msg)
sts->msg->flags = (sts->msg->flags & ~sts->del) | sts->add;
})
} }
/******************* imap_close_box *******************/ /******************* imap_close_box *******************/

Loading…
Cancel
Save