Skip to content

Commit

Permalink
imapd.c, index.c: actually fix and test SCAN command
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Jul 26, 2023
1 parent 789d955 commit dd3a777
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
51 changes: 51 additions & 0 deletions cassandane/Cassandane/Cyrus/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 5 additions & 2 deletions imap/imapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions imap/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dd3a777

Please sign in to comment.