Oswald Buddenhagen
2017-04-22 09:28:18 UTC
commit 683e581340773ad135d7296ced6ae023ea6d55f8
Author: Oswald Buddenhagen <***@users.sf.net>
Date: Sun Mar 26 18:44:43 2017 +0200
let driver_t::find_new_msgs() return the list of messages
consistently with driver_t::load_box().
src/driver.h | 5 +++--
src/drv_imap.c | 38 +++++++++++++++++++++++++++-----------
src/drv_maildir.c | 2 +-
src/sync.c | 12 ++++++------
4 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/src/driver.h b/src/driver.h
index e8edb59..fc3cc28 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -216,9 +216,10 @@ struct driver {
/* 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
- * 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 (*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
* a pre-fetched one (in which case the in-memory representation is updated),
diff --git a/src/drv_imap.c b/src/drv_imap.c
index f00470c..a837c4f 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -184,7 +184,10 @@ typedef struct {
} imap_cmd_out_uid_t;
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;
} 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_p3( imap_store_t *, imap_cmd_t *, int );
+static void imap_find_new_msgs_p4( imap_store_t *, imap_cmd_t *, int );
static void
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_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;
// 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
@@ -2885,10 +2890,11 @@ imap_find_new_msgs_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response )
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->gen.gen.param.lastuid = 1;
- imap_exec( ctx, &cmd->gen.gen, imap_find_new_msgs_p3,
+ cmd->gen.param.lastuid = 1;
+ imap_exec( ctx, &cmd->gen, imap_find_new_msgs_p3,
"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_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) {
- imap_done_simple_box( ctx, gcmd, response );
+ imap_find_new_msgs_p4( ctx, gcmd, response );
return;
}
- INIT_IMAP_CMD(imap_cmd_simple_t, cmd, cmdp->gen.callback, cmdp->gen.callback_aux)
- imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_done_simple_box,
+ INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cmdp->callback, cmdp->callback_aux)
+ 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 );
}
+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 *******************/
typedef struct {
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 4d2e25c..4cc8f7e 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -1645,7 +1645,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
static void
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" );
}
diff --git a/src/sync.c b/src/sync.c
index cca339f..3db7bb3 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -217,7 +217,7 @@ jFprintf( sync_vars_t *svars, const char *msg, ... )
}
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;
message_t *tmsg, *ntmsg = 0;
@@ -237,7 +237,7 @@ match_tuids( sync_vars_t *svars, int t )
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)
continue;
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) {
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] );
@@ -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 sync_close( sync_vars_t *svars, int t );
@@ -1928,7 +1928,7 @@ msgs_copied( sync_vars_t *svars, int t )
}
static void
-msgs_found_new( int sts, void *aux )
+msgs_found_new( int sts, message_t *msgs, void *aux )
{
SVARS_CHECK_RET;
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] );
break;
}
- match_tuids( svars, t );
+ match_tuids( svars, t, msgs );
msgs_new_done( svars, t );
}
Author: Oswald Buddenhagen <***@users.sf.net>
Date: Sun Mar 26 18:44:43 2017 +0200
let driver_t::find_new_msgs() return the list of messages
consistently with driver_t::load_box().
src/driver.h | 5 +++--
src/drv_imap.c | 38 +++++++++++++++++++++++++++-----------
src/drv_maildir.c | 2 +-
src/sync.c | 12 ++++++------
4 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/src/driver.h b/src/driver.h
index e8edb59..fc3cc28 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -216,9 +216,10 @@ struct driver {
/* 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
- * 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 (*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
* a pre-fetched one (in which case the in-memory representation is updated),
diff --git a/src/drv_imap.c b/src/drv_imap.c
index f00470c..a837c4f 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -184,7 +184,10 @@ typedef struct {
} imap_cmd_out_uid_t;
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;
} 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_p3( imap_store_t *, imap_cmd_t *, int );
+static void imap_find_new_msgs_p4( imap_store_t *, imap_cmd_t *, int );
static void
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_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;
// 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
@@ -2885,10 +2890,11 @@ imap_find_new_msgs_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response )
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->gen.gen.param.lastuid = 1;
- imap_exec( ctx, &cmd->gen.gen, imap_find_new_msgs_p3,
+ cmd->gen.param.lastuid = 1;
+ imap_exec( ctx, &cmd->gen, imap_find_new_msgs_p3,
"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_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) {
- imap_done_simple_box( ctx, gcmd, response );
+ imap_find_new_msgs_p4( ctx, gcmd, response );
return;
}
- INIT_IMAP_CMD(imap_cmd_simple_t, cmd, cmdp->gen.callback, cmdp->gen.callback_aux)
- imap_exec( (imap_store_t *)ctx, &cmd->gen, imap_done_simple_box,
+ INIT_IMAP_CMD(imap_cmd_find_new_t, cmd, cmdp->callback, cmdp->callback_aux)
+ 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 );
}
+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 *******************/
typedef struct {
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 4d2e25c..4cc8f7e 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -1645,7 +1645,7 @@ maildir_store_msg( store_t *gctx, msg_data_t *data, int to_trash,
static void
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" );
}
diff --git a/src/sync.c b/src/sync.c
index cca339f..3db7bb3 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -217,7 +217,7 @@ jFprintf( sync_vars_t *svars, const char *msg, ... )
}
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;
message_t *tmsg, *ntmsg = 0;
@@ -237,7 +237,7 @@ match_tuids( sync_vars_t *svars, int t )
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)
continue;
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) {
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] );
@@ -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 sync_close( sync_vars_t *svars, int t );
@@ -1928,7 +1928,7 @@ msgs_copied( sync_vars_t *svars, int t )
}
static void
-msgs_found_new( int sts, void *aux )
+msgs_found_new( int sts, message_t *msgs, void *aux )
{
SVARS_CHECK_RET;
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] );
break;
}
- match_tuids( svars, t );
+ match_tuids( svars, t, msgs );
msgs_new_done( svars, t );
}