diff --git a/src/common.h b/src/common.h index a2f80de..b3d36ad 100644 --- a/src/common.h +++ b/src/common.h @@ -167,6 +167,7 @@ int map_name( const char *arg, char **result, int reserve, const char *in, const DEFINE_ARRAY_TYPE(int) void sort_int_array( int_array_t array ); +int find_int_array( const int_array_t array, int value ); void arc4_init( void ); uchar arc4_getbyte( void ); diff --git a/src/drv_imap.c b/src/drv_imap.c index e2ae985..c33f8a3 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -2305,7 +2305,6 @@ imap_load_box( store_t *gctx, int minuid, int maxuid, int newuid, int_array_t ex } else { struct imap_cmd_refcounted_state *sts = imap_refcounted_new_state( cb, aux ); - sort_int_array( excs ); for (i = 0; i < excs.size; ) { for (bl = 0; i < excs.size && bl < 960; i++) { if (bl) diff --git a/src/drv_maildir.c b/src/drv_maildir.c index 6e99d22..1518099 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -831,7 +831,7 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) DBC *dbc; #endif /* USE_DB */ msg_t *entry; - int i, j, uid, bl, fnl, ret; + int i, uid, bl, fnl, ret; time_t now, stamps[2]; struct stat st; char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX]; @@ -922,13 +922,8 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) uid = INT_MAX; } if (uid <= ctx->maxuid) { - if (uid < ctx->minuid) { - for (j = 0; j < ctx->excs.size; j++) - if (ctx->excs.data[j] == uid) - goto oke; + if (uid < ctx->minuid && !find_int_array( ctx->excs, uid )) continue; - oke: ; - } entry = msg_t_array_append( msglist ); entry->base = nfstrdup( e->d_name ); entry->uid = uid; diff --git a/src/sync.c b/src/sync.c index a6ebea8..f74f384 100644 --- a/src/sync.c +++ b/src/sync.c @@ -1276,6 +1276,7 @@ box_opened2( sync_vars_t *svars, int t ) minwuid = INT_MAX; } sync_ref( svars ); + sort_int_array( mexcs.array ); load_box( svars, M, minwuid, mexcs.array ); if (!check_cancel( svars )) load_box( svars, S, (ctx[S]->opts & OPEN_OLD) ? 1 : INT_MAX, (int_array_t){ 0, 0 } ); diff --git a/src/util.c b/src/util.c index 726054f..6e3cb97 100644 --- a/src/util.c +++ b/src/util.c @@ -545,6 +545,23 @@ sort_int_array( int_array_t array ) qsort( array.data, array.size, sizeof(int), compare_ints ); } +int +find_int_array( int_array_t array, int value ) +{ + int bot = 0, top = array.size - 1; + while (bot <= top) { + int i = (bot + top) / 2; + int elt = array.data[i]; + if (elt == value) + return 1; + if (elt < value) + bot = i + 1; + else + top = i - 1; + } + return 0; +} + static struct { uchar i, j, s[256];