Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriptions bump folderstate #4712

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions cassandane/Cassandane/Cyrus/JMAPMailbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,9 @@ sub test_mailbox_query_name
}

sub test_mailbox_query_filteroperator
:min_version_3_1 :needs_component_jmap
:min_version_3_1 :needs_component_jmap :NoAltNameSpace
{
my ($self) = @_;
return;

my $jmap = $self->{jmap};
my $imaptalk = $self->{store}->get_client();
Expand Down Expand Up @@ -947,6 +946,15 @@ sub test_mailbox_query_filteroperator
]);
$self->assert(exists $res->[0][1]{updated}{$mboxids{'Ham'}});

xlog $self, "make sure subscribing changed state";
$self->assert_not_equals($res->[0][1]{oldState}, $res->[0][1]{newState});

my $state = $res->[0][1]{oldState};
$res = $jmap->CallMethods([['Mailbox/changes', { sinceState => $state }, "R1"]]);
$self->assert_num_equals(1, scalar @{$res->[0][1]{updated}});
$self->assert_equals($res->[0][1]{updated}[0], $mboxids{'Ham'});
$self->assert_null($res->[0][1]{updatedProperties});

xlog $self, "list mailboxes filtered by parentId OR role";
$res = $jmap->CallMethods([['Mailbox/query', {
filter => {
Expand All @@ -959,10 +967,11 @@ sub test_mailbox_query_filteroperator
},
sort => [{ property => "name" }],
}, "R1"]]);
$self->assert_num_equals(3, scalar @{$res->[0][1]->{ids}});
$self->assert_num_equals(4, scalar @{$res->[0][1]->{ids}});
$self->assert_str_equals($mboxids{'Bonk'}, $res->[0][1]{ids}[0]);
$self->assert_str_equals($mboxids{'Spam'}, $res->[0][1]{ids}[1]);
$self->assert_str_equals($mboxids{'Zonk'}, $res->[0][1]{ids}[2]);
$self->assert_str_equals($mboxids{'Inbox'}, $res->[0][1]{ids}[1]);
$self->assert_str_equals($mboxids{'Spam'}, $res->[0][1]{ids}[2]);
$self->assert_str_equals($mboxids{'Zonk'}, $res->[0][1]{ids}[3]);

xlog $self, "list mailboxes filtered by name";
$res = $jmap->CallMethods([['Mailbox/query', {
Expand All @@ -978,9 +987,10 @@ sub test_mailbox_query_filteroperator
filter => {
isSubscribed => JSON::true,
},
sort => [{ property => "name" }],
}, "R1"]]);
$self->assert_num_equals(1, scalar @{$res->[0][1]->{ids}});
$self->assert_str_equals($mboxids{'Zonk'}, $res->[0][1]{ids}[0]);
$self->assert_str_equals($mboxids{'Ham'}, $res->[0][1]{ids}[0]);

xlog $self, "list mailboxes filtered by isSubscribed is false";
$res = $jmap->CallMethods([['Mailbox/query', {
Expand All @@ -1000,7 +1010,7 @@ sub test_mailbox_query_filteroperator
filter => {
operator => "AND",
conditions => [{
parentId => $mboxids{'Inbox'},
parentId => JSON::null,
}, {
hasAnyRole => JSON::false,
}],
Expand All @@ -1014,22 +1024,21 @@ sub test_mailbox_query_filteroperator
$res = $jmap->CallMethods([['Mailbox/query', {
filter => {
operator => "NOT",
conditions => [
conditions => [{
operator => "AND",
conditions => [{
parentId => $mboxids{'Inbox'},
parentId => JSON::null,
}, {
hasAnyRole => JSON::true,
}],
],
}],
},
sort => [{ property => "name" }],
}, "R1"]]);
$self->assert_num_equals(4, scalar @{$res->[0][1]->{ids}});
$self->assert_num_equals(3, scalar @{$res->[0][1]->{ids}});
$self->assert_str_equals($mboxids{'Bonk'}, $res->[0][1]{ids}[0]);
$self->assert_str_equals($mboxids{'Inbox'}, $res->[0][1]{ids}[1]);
$self->assert_str_equals($mboxids{'Spam'}, $res->[0][1]{ids}[2]);
$self->assert_str_equals($mboxids{'Zonk'}, $res->[0][1]{ids}[3]);
$self->assert_str_equals($mboxids{'Ham'}, $res->[0][1]{ids}[1]);
$self->assert_str_equals($mboxids{'Zonk'}, $res->[0][1]{ids}[2]);
}

sub test_mailbox_query_issue2286
Expand Down
1 change: 1 addition & 0 deletions imap/jmap_mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ static int _mboxquery_eval_filter(mboxquery_t *query,
int want_subscribed = json_boolean_value(filter->is_subscribed);
int is_subscribed = strarray_find(query->sublist, rec->mboxname, 0);
if (want_subscribed && is_subscribed < 0) return 0;
if (!want_subscribed && is_subscribed >= 0) return 0;
}
return 1;
}
Expand Down
30 changes: 21 additions & 9 deletions imap/mboxlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5141,7 +5141,6 @@ EXPORTED int mboxlist_changesub(const char *name, const char *userid,
mbentry_t *mbentry = NULL;
int r;
struct db *subs;
struct mboxevent *mboxevent;

init_internal();

Expand All @@ -5151,15 +5150,12 @@ EXPORTED int mboxlist_changesub(const char *name, const char *userid,

char *dbname = mboxname_to_dbname(name);

mboxlist_mylookup(dbname, &mbentry, NULL, 0, 0);

if (add && !force) {
/* Ensure mailbox exists and can be seen by user */
if ((r = mboxlist_mylookup(dbname, &mbentry, NULL, 0, 0))!=0) {
if (!mbentry || (cyrus_acl_myrights(auth_state, mbentry->acl) & ACL_LOOKUP) == 0) {
mboxlist_closesubs(subs);
goto done;
}
if ((cyrus_acl_myrights(auth_state, mbentry->acl) & ACL_LOOKUP) == 0) {
mboxlist_closesubs(subs);
mboxlist_entry_free(&mbentry);
r = IMAP_MAILBOX_NONEXISTENT;
goto done;
}
Expand All @@ -5186,11 +5182,26 @@ EXPORTED int mboxlist_changesub(const char *name, const char *userid,

sync_log_subscribe(userid, name);
mboxlist_closesubs(subs);
mboxlist_entry_free(&mbentry);
buf_free(&key);

if (r) goto done;

// bump the modseq on the folder if one exists
if (mbentry && !(mbentry->mbtype & MBTYPE_REMOTE)) {
struct mailbox *mailbox = NULL;
r = mailbox_open_iwl(name, &mailbox);
if (!r) {
mailbox_modseq_dirty(mailbox);
mboxlist_update_foldermodseq(name, mailbox->i.highestmodseq);
r = mailbox_commit(mailbox);
mailbox_close(&mailbox);
}
if (r) goto done;
}

/* prepare a MailboxSubscribe or MailboxUnSubscribe event notification */
if (notify && r == 0) {
if (notify) {
struct mboxevent *mboxevent;
mboxevent = mboxevent_new(add ? EVENT_MAILBOX_SUBSCRIBE :
EVENT_MAILBOX_UNSUBSCRIBE);

Expand All @@ -5200,6 +5211,7 @@ EXPORTED int mboxlist_changesub(const char *name, const char *userid,
}

done:
mboxlist_entry_free(&mbentry);
free(dbname);
return r;
}
Expand Down
Loading