commit a8e145e589fc41087862bd0b11d7ede79e1789ea
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Wed Jun 1 19:55:24 2022 +0200

    split OPEN_PAIRED from OPEN_OLD, and rename OPEN_OLD_IDS accordingly
    
    this emphasizes the non-complementarity to OPEN_NEW.
    the "real" OPEN_OLD is currently used only for trashing.

 src/driver.h      |  9 +++++----
 src/drv_imap.c    |  4 ++--
 src/drv_maildir.c |  6 +++---
 src/sync.c        | 42 +++++++++++++++++++++++++++++-------------
 4 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/src/driver.h b/src/driver.h
index 2de793c6..62fe15b9 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -82,16 +82,17 @@ static_assert_bits(F, message_t, flags);
 static_assert_bits(M, message_t, status);
 
 // For driver_t->prepare_load_box(), which may amend the passed flags.
-// The drivers don't use the first two, but may set them if loading the
+// The drivers don't use the first three, but may set them if loading the
 // particular range is required to handle some other flag; note that these
 // ranges may overlap.
 BIT_ENUM(
-       OPEN_OLD,         // Paired messages *in* this store.
+       OPEN_PAIRED,      // Paired messages *in* this store.
+       OPEN_OLD,         // Messages that should be already propagated *from* 
this store.
        OPEN_NEW,         // Messages (possibly) not yet propagated *from* this 
store.
        OPEN_FIND,
        OPEN_FLAGS,       // Note that fetch_msg() gets the flags regardless.
        OPEN_NEW_SIZE,
-       OPEN_OLD_IDS,
+       OPEN_PAIRED_IDS,
        OPEN_APPEND,
        OPEN_SETFLAGS,
        OPEN_EXPUNGE,
@@ -235,7 +236,7 @@ struct driver {
         * and those named in the excs array (smaller than minuid).
         * The driver takes ownership of the excs array.
         * Messages starting with finduid need to have the TUID populated when 
OPEN_FIND is set.
-        * Messages up to pairuid need to have the Message-Id populated when 
OPEN_OLD_IDS is set.
+        * Messages up to pairuid need to have the Message-Id populated when 
OPEN_PAIRED_IDS is set.
         * Messages up to newuid need to have the size populated when 
OPEN_OLD_SIZE is set;
         * likewise messages above newuid when OPEN_NEW_SIZE is set.
         * The returned message list remains owned by the driver. */
diff --git a/src/drv_imap.c b/src/drv_imap.c
index 43705b97..45160239 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -2885,7 +2885,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, 
uint finduid, uint pairu
                                if (i != j)
                                        bl += sprintf( buf + bl, ":%u", 
excs.data[i] );
                        }
-                       imap_submit_load( ctx, buf, shifted_bit( ctx->opts, 
OPEN_OLD_IDS, WantMsgids ), sts );
+                       imap_submit_load( ctx, buf, shifted_bit( ctx->opts, 
OPEN_PAIRED_IDS, WantMsgids ), sts );
                }
                if (maxuid == UINT_MAX)
                        maxuid = ctx->uidnext - 1;
@@ -2899,7 +2899,7 @@ imap_load_box( store_t *gctx, uint minuid, uint maxuid, 
uint finduid, uint pairu
                                imap_set_range( ranges, &nranges, 0, WantSize, 
newuid );
                        if (ctx->opts & OPEN_FIND)
                                imap_set_range( ranges, &nranges, 0, WantTuids, 
finduid - 1 );
-                       if (ctx->opts & OPEN_OLD_IDS)
+                       if (ctx->opts & OPEN_PAIRED_IDS)
                                imap_set_range( ranges, &nranges, WantMsgids, 
0, pairuid );
                        for (uint r = 0; r < nranges; r++) {
                                sprintf( buf, "%u:%u", ranges[r].first, 
ranges[r].last );
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 9d29336f..3ea03483 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -1113,7 +1113,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t 
*msglist )
                        }
                        int want_size = ((ctx->opts & OPEN_NEW_SIZE) && uid > 
ctx->newuid);
                        int want_tuid = ((ctx->opts & OPEN_FIND) && uid >= 
ctx->finduid);
-                       int want_msgid = ((ctx->opts & OPEN_OLD_IDS) && uid <= 
ctx->pairuid);
+                       int want_msgid = ((ctx->opts & OPEN_PAIRED_IDS) && uid 
<= ctx->pairuid);
                        if (!want_size && !want_tuid && !want_msgid)
                                continue;
                        if (!fnl)
@@ -1401,9 +1401,9 @@ maildir_prepare_load_box( store_t *gctx, uint opts )
        maildir_store_t *ctx = (maildir_store_t *)gctx;
 
        if (opts & OPEN_SETFLAGS)
-               opts |= OPEN_OLD;
+               opts |= OPEN_PAIRED;
        if (opts & OPEN_EXPUNGE)
-               opts |= OPEN_OLD|OPEN_NEW|OPEN_FLAGS;
+               opts |= OPEN_PAIRED | OPEN_OLD | OPEN_NEW | OPEN_FLAGS;
        ctx->opts = opts;
        return opts;
 }
diff --git a/src/sync.c b/src/sync.c
index 70dd160d..42b7dc1e 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -741,7 +741,7 @@ box_opened2( sync_vars_t *svars, int t )
 
        opts[F] = opts[N] = 0;
        if (fails)
-               opts[F] = opts[N] = OPEN_OLD|OPEN_OLD_IDS;
+               opts[F] = opts[N] = OPEN_PAIRED | OPEN_PAIRED_IDS;
        for (t = 0; t < 2; t++) {
                if (any_purges[t]) {
                        debug( "resuming %d %s purge(s)\n", any_purges[t], 
str_fn[t] );
@@ -754,7 +754,7 @@ box_opened2( sync_vars_t *svars, int t )
                }
                if (chan->ops[t] & (OP_GONE | OP_FLAGS)) {
                        opts[t] |= OPEN_SETFLAGS;
-                       opts[t^1] |= OPEN_OLD;
+                       opts[t^1] |= OPEN_PAIRED;
                        if (chan->ops[t] & OP_FLAGS)
                                opts[t^1] |= OPEN_FLAGS;
                }
@@ -773,8 +773,8 @@ box_opened2( sync_vars_t *svars, int t )
                        if ((chan->ops[t] & OP_UPGRADE) || any_upgrades[t]) {
                                debug( "resuming %s of %d upgrade(s)\n", 
str_hl[t], any_upgrades[t] );
                                if (chan->ops[t] & OP_UPGRADE)
-                                       opts[t] |= OPEN_OLD | OPEN_FLAGS | 
OPEN_SETFLAGS;
-                               opts[t^1] |= OPEN_OLD;
+                                       opts[t] |= OPEN_PAIRED | OPEN_FLAGS | 
OPEN_SETFLAGS;
+                               opts[t^1] |= OPEN_PAIRED;
                        }
                        if ((chan->ops[t] | chan->ops[t^1]) & OP_EXPUNGE)  // 
Don't propagate doomed msgs
                                opts[t^1] |= OPEN_FLAGS;
@@ -798,9 +798,9 @@ box_opened2( sync_vars_t *svars, int t )
        if ((chan->ops[N] & (OP_NEW | OP_UPGRADE | OP_FLAGS)) && 
chan->max_messages)
                svars->any_expiring = 1;
        if (svars->any_expiring) {
-               opts[N] |= OPEN_OLD | OPEN_FLAGS;
+               opts[N] |= OPEN_PAIRED | OPEN_FLAGS;
                if (any_dummies[N])
-                       opts[F] |= OPEN_OLD | OPEN_FLAGS;
+                       opts[F] |= OPEN_PAIRED | OPEN_FLAGS;
                else if (chan->ops[N] & (OP_NEW | OP_UPGRADE))
                        opts[F] |= OPEN_FLAGS;
        }
@@ -808,7 +808,7 @@ box_opened2( sync_vars_t *svars, int t )
        svars->opts[N] = svars->drv[N]->prepare_load_box( ctx[N], opts[N] );
 
        ARRAY_INIT( &mexcs );
-       if ((svars->opts[F] & OPEN_OLD) && chan->max_messages) {
+       if ((svars->opts[F] & OPEN_PAIRED) && !(svars->opts[F] & OPEN_OLD) && 
chan->max_messages) {
                /* When messages have been expired on the near side, the far 
side fetch is split into
                 * two ranges: The bulk fetch which corresponds with the most 
recent messages, and an
                 * exception list of messages which would have been expired if 
they weren't important. */
@@ -859,13 +859,29 @@ load_box( sync_vars_t *svars, int t, uint minwuid, 
uint_array_t mexcs )
        uint maxwuid = 0, pairuid = UINT_MAX;
 
        if (svars->opts[t] & OPEN_NEW) {
-               if (!(svars->opts[t] & OPEN_OLD) || (minwuid > svars->maxuid[t] 
+ 1))
+               if (svars->opts[t] & OPEN_OLD) {
+                       svars->opts[t] |= OPEN_PAIRED;
+                       minwuid = 1;
+               } else if (!(svars->opts[t] & OPEN_PAIRED) || (minwuid > 
svars->maxuid[t] + 1)) {
                        minwuid = svars->maxuid[t] + 1;
+               }
                maxwuid = UINT_MAX;
-               if (svars->opts[t] & OPEN_OLD_IDS)  // Implies OPEN_OLD
+               if (svars->opts[t] & OPEN_PAIRED_IDS)  // Implies OPEN_PAIRED
                        pairuid = get_seenuid( svars, t );
-       } else if (svars->opts[t] & OPEN_OLD) {
-               maxwuid = get_seenuid( svars, t );
+       } else if (svars->opts[t] & (OPEN_PAIRED | OPEN_OLD)) {
+               uint seenuid = get_seenuid( svars, t );
+               if (svars->opts[t] & OPEN_OLD) {
+                       minwuid = 1;
+                       maxwuid = svars->maxuid[t];
+                       if (maxwuid < seenuid) {
+                               if (svars->opts[t] & OPEN_PAIRED)
+                                       maxwuid = seenuid;
+                       } else {
+                               svars->opts[t] |= OPEN_PAIRED;
+                       }
+               } else {  // OPEN_PAIRED
+                       maxwuid = seenuid;
+               }
        } else {
                minwuid = UINT_MAX;
        }
@@ -1030,8 +1046,8 @@ box_loaded( int sts, message_t *msgs, int total_msgs, int 
recent_msgs, void *aux
                debug( "pair (%u,%u)\n", srec->uid[F], srec->uid[N] );
                assert( !srec->tuid[0] );
                // no[] means that a message is known to be not there.
-               no[F] = !srec->msg[F] && (svars->opts[F] & OPEN_OLD);
-               no[N] = !srec->msg[N] && (svars->opts[N] & OPEN_OLD);
+               no[F] = !srec->msg[F] && (svars->opts[F] & OPEN_PAIRED);
+               no[N] = !srec->msg[N] && (svars->opts[N] & OPEN_PAIRED);
                if (no[F] && no[N]) {
                        // It does not matter whether one side was already 
known to be missing
                        // (never stored [skipped or failed] or expunged 
[possibly expired]) -


_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to