diff --git a/cassandane/Cassandane/Cyrus/List.pm b/cassandane/Cassandane/Cyrus/List.pm index bfda2b7d1e..12b1e64c09 100644 --- a/cassandane/Cassandane/Cyrus/List.pm +++ b/cassandane/Cassandane/Cyrus/List.pm @@ -2329,4 +2329,55 @@ sub test_list_return_subscribed_trash_nochildren }); } +sub test_scan + :min_version_3_9 +{ + my ($self) = @_; + + my $store = $self->{store}; + my $imaptalk = $store->get_client(); + + $self->setup_mailbox_structure($imaptalk, [ + [ 'create' => [qw( INBOX.a INBOX.b INBOX.c )] ], + ]); + + xlog $self, "listing..."; + my $res = $imaptalk->list("", "*"); +warn Dumper($res); + + $self->assert_mailbox_structure($res, '.', { + 'INBOX' => [qw( \\HasChildren )], + 'INBOX.a' => [qw( \\HasNoChildren )], + 'INBOX.b' => [qw( \\HasNoChildren )], + 'INBOX.c' => [qw( \\HasNoChildren )], + }, 'strict'); + + xlog $self, "Generate some messages"; + $store->set_folder('INBOX.a'); + $self->make_message("foo"); + + $store->set_folder('INBOX.b'); + $self->make_message("bar"); + + $store->set_folder('INBOX.c'); + $self->make_message("baz", body => 'foo\r\n'); + + my @results = {}; + xlog $self, "scan with a selected mailbox"; + $res = $imaptalk->_imap_cmd('SCAN', 0, "list", "", "*", "foo"); + + $self->assert_mailbox_structure($res, '.', { + 'INBOX.a' => [qw( \\HasNoChildren )], + 'INBOX.c' => [qw( \\HasNoChildren )], + }, 'strict'); + + xlog $self, "scan with NO selected mailbox"; + $res = $imaptalk->unselect(); + $res = $imaptalk->_imap_cmd('SCAN', 0, "list", "", "*", "bar"); + + $self->assert_mailbox_structure($res, '.', { + 'INBOX.b' => [qw( \\HasNoChildren )], + }, 'strict'); +} + 1; diff --git a/imap/imapd.c b/imap/imapd.c index 1aafbdad8a..161aece4ae 100644 --- a/imap/imapd.c +++ b/imap/imapd.c @@ -13582,8 +13582,10 @@ static void list_response(const char *extname, const mbentry_t *mbentry, if (!strcmpsafe(mbentry->name, index_mboxname(imapd_index))) { /* currently selected mailbox */ - if (!index_scan(imapd_index, listargs->scan)) + if (index_refresh(imapd_index) || + !index_scan(imapd_index, listargs->scan)) { return; /* no matching messages */ + } } else { /* other local mailbox */ @@ -13595,13 +13597,14 @@ static void list_response(const char *extname, const mbentry_t *mbentry, init.userid = imapd_userid; init.authstate = imapd_authstate; init.out = imapd_out; + init.examine_mode = 1; r = index_open(mbentry->name, &init, &state); if (!r) doclose = 1; - if (!r && index_hasrights(state, ACL_READ)) { + if (!r && !index_hasrights(state, ACL_READ)) { r = (imapd_userisadmin || index_hasrights(state, ACL_LOOKUP)) ? IMAP_PERMISSION_DENIED : IMAP_MAILBOX_NONEXISTENT; } diff --git a/imap/index.c b/imap/index.c index cc0da4ac7c..a45b5f52ff 100644 --- a/imap/index.c +++ b/imap/index.c @@ -1772,9 +1772,6 @@ EXPORTED int index_scan(struct index_state *state, const char *contents) if (!(contents && contents[0])) return(0); - if (index_check(state, 0)) - return 0; - if (state->exists <= 0) return 0; length = strlen(contents);