Skip to content

Commit

Permalink
Merge pull request #5023 from ksmurchison/jmap_email_copy_as_update
Browse files Browse the repository at this point in the history
jmap_email.c: refactor Email/copy to use _email_bulkupdate
  • Loading branch information
ksmurchison committed Sep 16, 2024
2 parents fb1d371 + ab7a7d0 commit f6b964d
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 520 deletions.
45 changes: 43 additions & 2 deletions cassandane/tiny-tests/JMAPEmail/email_copy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sub test_email_copy
my $imaptalk = $self->{store}->get_client();
my $admintalk = $self->{adminstore}->get_client();

xlog $self, "Create user and share mailbox";
xlog $self, "Create user and share mailbox read-only";
$self->{instance}->create_user("other");
$admintalk->setacl("user.other", "cassandane", "lrsiwntex") or die;
$admintalk->setacl("user.other", "cassandane", "lrs") or die;

my $srcInboxId = $self->getinbox()->{id};
$self->assert_not_null($srcInboxId);
Expand Down Expand Up @@ -59,6 +59,32 @@ sub test_email_copy
# Safeguard receivedAt asserts.
sleep 1;

xlog $self, "attempt to move email - fail to copy and no /set sub-request";
$res = $jmap->CallMethods([
['Email/copy', {
fromAccountId => 'cassandane',
accountId => 'other',
create => {
1 => {
id => $emailId,
mailboxIds => {
$dstInboxId => JSON::true,
},
keywords => {
'bar' => JSON::true,
},
},
},
onSuccessDestroyOriginal => JSON::true,
}, 'R1'],
]);

$self->assert_num_equals(1, scalar @{$res});
$self->assert_not_null($res->[0][1]->{notCreated}{1});

xlog $self, "share mailbox read-write";
$admintalk->setacl("user.other", "cassandane", "lrsiwntex") or die;

xlog $self, "move email";
$res = $jmap->CallMethods([
['Email/copy', {
Expand Down Expand Up @@ -97,6 +123,7 @@ sub test_email_copy
$self->assert_str_equals($receivedAt, $res->[0][1]{list}[0]{receivedAt});

xlog $self, "copy email back";
$receivedAt = '2020-02-01T00:00:00Z';
$res = $jmap->CallMethods([
['Email/copy', {
accountId => 'cassandane',
Expand All @@ -110,13 +137,27 @@ sub test_email_copy
keywords => {
'bar' => JSON::true,
},
receivedAt => $receivedAt
},
},
}, 'R1'],
]);

$self->assert_str_equals($copiedEmailId, $res->[0][1]->{created}{1}{id});

xlog $self, "get copied email";
$res = $jmap->CallMethods([
['Email/get', {
accountId => 'cassandane',
ids => [$copiedEmailId],
properties => ['keywords', 'receivedAt'],
}, 'R1']
]);

my $wantKeywords = { 'bar' => JSON::true };
$self->assert_deep_equals($wantKeywords, $res->[0][1]{list}[0]{keywords});
$self->assert_str_equals($receivedAt, $res->[0][1]{list}[0]{receivedAt});

xlog $self, "copy email back (again)";
$res = $jmap->CallMethods([
['Email/copy', {
Expand Down
6 changes: 6 additions & 0 deletions imap/jmap_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3205,6 +3205,12 @@ EXPORTED const mbentry_t *jmap_mbentry_by_uniqueid(jmap_req_t *req,
return _mbentry_by_uniqueid(req, id, 1/*scope*/);
}

EXPORTED const mbentry_t *jmap_mbentry_by_uniqueid_all(jmap_req_t *req,
const char *id)
{
return _mbentry_by_uniqueid(req, id, 0/*scope*/);
}

EXPORTED mbentry_t *jmap_mbentry_by_uniqueid_copy(jmap_req_t *req, const char *id)
{
const mbentry_t *mbentry = _mbentry_by_uniqueid(req, id, 1/*scope*/);
Expand Down
1 change: 1 addition & 0 deletions imap/jmap_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ extern void jmap_parse_sharewith_patch(json_t *arg, json_t **shareWith);

extern void jmap_mbentry_cache_free(jmap_req_t *req);
extern const mbentry_t *jmap_mbentry_by_uniqueid(jmap_req_t *req, const char *id);
extern const mbentry_t *jmap_mbentry_by_uniqueid_all(jmap_req_t *req, const char *id);
extern mbentry_t *jmap_mbentry_by_uniqueid_copy(jmap_req_t *req, const char *id);
extern mbentry_t *jmap_mbentry_from_dav(jmap_req_t *req, struct dav_data *dav);

Expand Down
Loading

0 comments on commit f6b964d

Please sign in to comment.