let driver_t::find_new_msgs() return the list of messages

consistently with driver_t::load_box().
This commit is contained in:
Oswald Buddenhagen 2017-03-26 18:44:43 +02:00
parent 74e9368121
commit 683e581340
4 changed files with 37 additions and 20 deletions

View File

@ -216,9 +216,10 @@ struct driver {
/* Index the messages which have newly appeared in the mailbox, including their /* Index the messages which have newly appeared in the mailbox, including their
* temporary UID headers. This is needed if store_msg() does not guarantee returning * temporary UID headers. This is needed if store_msg() does not guarantee returning
* a UID; otherwise the driver needs to implement only the OPEN_FIND flag. */ * a UID; otherwise the driver needs to implement only the OPEN_FIND flag.
* The returned message list remains owned by the driver. */
void (*find_new_msgs)( store_t *ctx, int newuid, void (*find_new_msgs)( store_t *ctx, int newuid,
void (*cb)( int sts, void *aux ), void *aux ); void (*cb)( int sts, message_t *msgs, void *aux ), void *aux );
/* Add/remove the named flags to/from the given message. The message may be either /* Add/remove the named flags to/from the given message. The message may be either
* a pre-fetched one (in which case the in-memory representation is updated), * a pre-fetched one (in which case the in-memory representation is updated),

View File

@ -184,7 +184,10 @@ typedef struct {
} imap_cmd_out_uid_t; } imap_cmd_out_uid_t;
typedef struct { typedef struct {
imap_cmd_simple_t gen; imap_cmd_t gen;
void (*callback)( int sts, message_t *msgs, void *aux );
void *callback_aux;
message_t **out_msgs;
int uid; int uid;
} imap_cmd_find_new_t; } imap_cmd_find_new_t;
@ -2858,18 +2861,20 @@ imap_store_msg_p2( imap_store_t *ctx ATTR_UNUSED, imap_cmd_t *cmd, int response
static void imap_find_new_msgs_p2( imap_store_t *, imap_cmd_t *, int ); static void imap_find_new_msgs_p2( imap_store_t *, imap_cmd_t *, int );
static void imap_find_new_msgs_p3( imap_store_t *, imap_cmd_t *, int ); static void imap_find_new_msgs_p3( imap_store_t *, imap_cmd_t *, int );
static void imap_find_new_msgs_p4( imap_store_t *, imap_cmd_t *, int );
static void static void
imap_find_new_msgs( store_t *gctx, int newuid, imap_find_new_msgs( store_t *gctx, int newuid,
void (*cb)( int sts, void *aux ), void *aux ) void (*cb)( int sts, message_t *msgs, void *aux ), void *aux )
{ {
imap_store_t *ctx = (imap_store_t *)gctx; imap_store_t *ctx = (imap_store_t *)gctx;
imap_cmd_find_new_t *cmd; imap_cmd_find_new_t *cmd;
INIT_IMAP_CMD_X(imap_cmd_find_new_t, cmd, cb, aux) INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cb, aux)
cmd->out_msgs = ctx->msgapp;
cmd->uid = newuid; cmd->uid = newuid;
// Some servers fail to enumerate recently STOREd messages without syncing first. // Some servers fail to enumerate recently STOREd messages without syncing first.
imap_exec( (imap_store_t *)ctx, &cmd->gen.gen, imap_find_new_msgs_p2, "CHECK" ); imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_find_new_msgs_p2, "CHECK" );
} }
static void static void
@ -2885,10 +2890,11 @@ imap_find_new_msgs_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response )
ctx->gen.uidnext = 0; ctx->gen.uidnext = 0;
INIT_IMAP_CMD_X(imap_cmd_find_new_t, cmd, cmdp->gen.callback, cmdp->gen.callback_aux) INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cmdp->callback, cmdp->callback_aux)
cmd->out_msgs = cmdp->out_msgs;
cmd->uid = cmdp->uid; cmd->uid = cmdp->uid;
cmd->gen.gen.param.lastuid = 1; cmd->gen.param.lastuid = 1;
imap_exec( ctx, &cmd->gen.gen, imap_find_new_msgs_p3, imap_exec( ctx, &cmd->gen, imap_find_new_msgs_p3,
"UID FETCH *:* (UID)" ); "UID FETCH *:* (UID)" );
} }
@ -2896,17 +2902,27 @@ static void
imap_find_new_msgs_p3( imap_store_t *ctx, imap_cmd_t *gcmd, int response ) imap_find_new_msgs_p3( imap_store_t *ctx, imap_cmd_t *gcmd, int response )
{ {
imap_cmd_find_new_t *cmdp = (imap_cmd_find_new_t *)gcmd; imap_cmd_find_new_t *cmdp = (imap_cmd_find_new_t *)gcmd;
imap_cmd_simple_t *cmd; imap_cmd_find_new_t *cmd;
if (response != RESP_OK || ctx->gen.uidnext <= cmdp->uid) { if (response != RESP_OK || ctx->gen.uidnext <= cmdp->uid) {
imap_done_simple_box( ctx, gcmd, response ); imap_find_new_msgs_p4( ctx, gcmd, response );
return; return;
} }
INIT_IMAP_CMD(imap_cmd_simple_t, cmd, cmdp->gen.callback, cmdp->gen.callback_aux) INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cmdp->callback, cmdp->callback_aux)
imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_done_simple_box, cmd->out_msgs = cmdp->out_msgs;
imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_find_new_msgs_p4,
"UID FETCH %d:%d (UID BODY.PEEK[HEADER.FIELDS (X-TUID)])", cmdp->uid, ctx->gen.uidnext - 1 ); "UID FETCH %d:%d (UID BODY.PEEK[HEADER.FIELDS (X-TUID)])", cmdp->uid, ctx->gen.uidnext - 1 );
} }
static void
imap_find_new_msgs_p4( imap_store_t *ctx ATTR_UNUSED, imap_cmd_t *gcmd, int response )
{
imap_cmd_find_new_t *cmdp = (imap_cmd_find_new_t *)gcmd;
transform_box_response( &response );
cmdp->callback( response, *cmdp->out_msgs, cmdp->callback_aux );
}
/******************* imap_list_store *******************/ /******************* imap_list_store *******************/
typedef struct { typedef struct {

View File

@ -1645,7 +1645,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
static void static void
maildir_find_new_msgs( store_t *gctx ATTR_UNUSED, int newuid ATTR_UNUSED, maildir_find_new_msgs( store_t *gctx ATTR_UNUSED, int newuid ATTR_UNUSED,
void (*cb)( int sts, void *aux ) ATTR_UNUSED, void *aux ATTR_UNUSED ) void (*cb)( int sts, message_t *msgs, void *aux ) ATTR_UNUSED, void *aux ATTR_UNUSED )
{ {
assert( !"maildir_find_new_msgs is not supposed to be called" ); assert( !"maildir_find_new_msgs is not supposed to be called" );
} }

View File

@ -217,7 +217,7 @@ jFprintf( sync_vars_t *svars, const char *msg, ... )
} }
static void static void
match_tuids( sync_vars_t *svars, int t ) match_tuids( sync_vars_t *svars, int t, message_t *msgs )
{ {
sync_rec_t *srec; sync_rec_t *srec;
message_t *tmsg, *ntmsg = 0; message_t *tmsg, *ntmsg = 0;
@ -237,7 +237,7 @@ match_tuids( sync_vars_t *svars, int t )
goto mfound; goto mfound;
} }
} }
for (tmsg = svars->msgs[t]; tmsg != ntmsg; tmsg = tmsg->next) { for (tmsg = msgs; tmsg != ntmsg; tmsg = tmsg->next) {
if (tmsg->status & M_DEAD) if (tmsg->status & M_DEAD)
continue; continue;
if (tmsg->tuid[0] && !memcmp( tmsg->tuid, srec->tuid, TUIDL )) { if (tmsg->tuid[0] && !memcmp( tmsg->tuid, srec->tuid, TUIDL )) {
@ -1380,7 +1380,7 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int recent_msgs, void *aux
if (svars->state[t] & ST_FIND_OLD) { if (svars->state[t] & ST_FIND_OLD) {
debug( "matching previously copied messages on %s\n", str_ms[t] ); debug( "matching previously copied messages on %s\n", str_ms[t] );
match_tuids( svars, t ); match_tuids( svars, t, msgs );
} }
debug( "matching messages on %s against sync records\n", str_ms[t] ); debug( "matching messages on %s against sync records\n", str_ms[t] );
@ -1864,7 +1864,7 @@ msg_copied_p2( sync_vars_t *svars, sync_rec_t *srec, int t, int uid )
} }
} }
static void msgs_found_new( int sts, void *aux ); static void msgs_found_new( int sts, message_t *msgs, void *aux );
static void msgs_new_done( sync_vars_t *svars, int t ); static void msgs_new_done( sync_vars_t *svars, int t );
static void sync_close( sync_vars_t *svars, int t ); static void sync_close( sync_vars_t *svars, int t );
@ -1928,7 +1928,7 @@ msgs_copied( sync_vars_t *svars, int t )
} }
static void static void
msgs_found_new( int sts, void *aux ) msgs_found_new( int sts, message_t *msgs, void *aux )
{ {
SVARS_CHECK_RET; SVARS_CHECK_RET;
switch (sts) { switch (sts) {
@ -1939,7 +1939,7 @@ msgs_found_new( int sts, void *aux )
warn( "Warning: cannot find newly stored messages on %s.\n", str_ms[t] ); warn( "Warning: cannot find newly stored messages on %s.\n", str_ms[t] );
break; break;
} }
match_tuids( svars, t ); match_tuids( svars, t, msgs );
msgs_new_done( svars, t ); msgs_new_done( svars, t );
} }