Skip to content

Commit

Permalink
Merge pull request #4401 from cyrusimap/jmap-move-deleted-parent
Browse files Browse the repository at this point in the history
Jmap move deleted parent
  • Loading branch information
brong committed Feb 7, 2023
2 parents 5e77f60 + 9e34e7b commit e386eec
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
73 changes: 73 additions & 0 deletions cassandane/Cassandane/Cyrus/JMAPMailbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,79 @@ sub test_mailbox_set_order
$self->assert_null($res->[0][1]{notDestroyed});
}

sub test_mailbox_move_to_deleted_parent
:min_version_3_6 :needs_component_jmap
{
my ($self) = @_;

my $jmap = $self->{jmap};

# Assert mailboxes are created in the right order.
my $RawRequest = {
headers => {
'Authorization' => $jmap->auth_header(),
'Content-Type' => 'application/json',
'Accept' => 'application/json',
},
content => '{
"using" : ["urn:ietf:params:jmap:mail"],
"methodCalls" : [["Mailbox/set", {
"create" : {
"C" : {
"name" : "C", "parentId" : "#B", "role" : null
},
"B" : {
"name" : "B", "parentId" : null, "role" : null
},
"A" : {
"name" : "A", "parentId" : null, "role" : null
}
}
}, "R1"]]
}',
};
my $RawResponse = $jmap->ua->post($jmap->uri(), $RawRequest);
if ($ENV{DEBUGJMAP}) {
warn "JMAP " . Dumper($RawRequest, $RawResponse);
}
$self->assert($RawResponse->{success});

my $res = eval { decode_json($RawResponse->{content}) };
$res = $res->{methodResponses};
$self->assert_not_null($res->[0][1]{created}{A});
$self->assert_not_null($res->[0][1]{created}{B});
$self->assert_not_null($res->[0][1]{created}{C});
my $idA = $res->[0][1]{created}{A}{id};
my $idB = $res->[0][1]{created}{B}{id};
my $idC = $res->[0][1]{created}{C}{id};

# Destroy "A"
$res = $jmap->CallMethods([['Mailbox/set', {
destroy => [ $idA ],
}, "R1"]]);
$self->assert_num_equals(1, scalar @{$res->[0][1]{destroyed}});
$self->assert_null($res->[0][1]{notDestroyed});

# Try to move "B" under a non-existant mailbox
$res = $jmap->CallMethods([['Mailbox/set', {
update => {
$idB => { parentId => "nosuchid" },
}
}, "R1"]]);
$self->assert_null($res->[0][1]{updated});
$self->assert_not_null($res->[0][1]{notUpdated});

# Try to move "B" under "A"
$res = $jmap->CallMethods([['Mailbox/set', {
update => {
$idB => { parentId => $idA },
}
}, "R1"]]);
$self->assert_null($res->[0][1]{updated});
$self->assert_not_null($res->[0][1]{notUpdated});

}

sub test_mailbox_set_inbox_children
:min_version_3_1 :needs_component_jmap :NoAltNameSpace
{
Expand Down
1 change: 1 addition & 0 deletions imap/jmap_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3224,6 +3224,7 @@ static const mbentry_t *_mbentry_by_uniqueid(jmap_req_t *req,
if (!mbentry) {
int r = mboxlist_lookup_by_uniqueid(id, &mbentry, NULL);
if (r || !mbentry || (mbentry->mbtype & MBTYPE_DELETED) ||
mboxname_isdeletedmailbox(mbentry->name, NULL) ||
/* make sure the user can "see" the mailbox */
!(jmap_myrights_mbentry(req, mbentry) & JACL_LOOKUP) ||
/* keep the lookup scoped to accountid */
Expand Down

0 comments on commit e386eec

Please sign in to comment.