Skip to content

Commit

Permalink
jmap_mail_submission.c: properly handle onSuccessDestroyEmail:null
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Jan 2, 2024
1 parent c78ab7b commit b3510e6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
87 changes: 87 additions & 0 deletions cassandane/Cassandane/Cyrus/JMAPEmailSubmission.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2138,5 +2138,92 @@ sub test_emailsubmission_scheduled_send_null_onsend
$self->assert_num_equals(0, scalar @$alarmdata);
}

sub test_emailsubmission_onsuccessdestroy
:min_version_3_9 :needs_component_jmap
{
my ($self) = @_;
my $jmap = $self->{jmap};

my $res = $jmap->CallMethods( [ [ 'Identity/get', {}, "R1" ] ] );
my $identityid = $res->[0][1]->{list}[0]->{id};
$self->assert_not_null($identityid);

xlog $self, "Generate an email via IMAP";
$self->make_message("foo", body => "an email") or die;

xlog $self, "get email id";
$res = $jmap->CallMethods( [ [ 'Email/query', {}, "R1" ] ] );
my $emailid = $res->[0][1]->{ids}[0];

xlog $self, "create email submission with bad onSuccess";
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
create => {
'1' => {
identityId => $identityid,
emailId => $emailid,
}
},
onSuccessDestroyEmail => {}
}, "R1" ] ] );
$self->assert_str_equals("error", $res->[0][0]);
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
$self->assert_str_equals("onSuccessDestroyEmail",
$res->[0][1]{arguments}[0]);

xlog $self, "create email submission with bad onSuccess";
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
create => {
'1' => {
identityId => $identityid,
emailId => $emailid,
}
},
onSuccessDestroyEmail => "foo"
}, "R1" ] ] );
$self->assert_str_equals("error", $res->[0][0]);
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
$self->assert_str_equals("onSuccessDestroyEmail",
$res->[0][1]{arguments}[0]);

xlog $self, "create email submission with bad onSuccess";
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
create => {
'1' => {
identityId => $identityid,
emailId => $emailid,
}
},
onSuccessDestroyEmail => [ 1 ]
}, "R1" ] ] );
$self->assert_str_equals("error", $res->[0][0]);
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
$self->assert_str_equals("onSuccessDestroyEmail[0]",
$res->[0][1]{arguments}[0]);

xlog $self, "create email submission with no onSuccess";
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
create => {
'1' => {
identityId => $identityid,
emailId => $emailid,
}
},
}, "R1" ] ] );
my $msgsubid = $res->[0][1]->{created}{1}{id};
$self->assert_not_null($msgsubid);

xlog $self, "create email submission with NULL onSuccess";
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
create => {
'2' => {
identityId => $identityid,
emailId => $emailid,
}
},
onSuccessDestroyEmail => JSON::null
}, "R1" ] ] );
$msgsubid = $res->[0][1]->{created}{2}{id};
$self->assert_not_null($msgsubid);
}

1;
8 changes: 5 additions & 3 deletions imap/jmap_mail_submission.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,11 +1415,13 @@ static int _submission_setargs_parse(jmap_req_t *req,
else if (JNOTNULL(arg)) r = 0;
}

else if (!strcmp(key, "onSuccessDestroyEmail") && JNOTNULL(arg)) {
else if (!strcmp(key, "onSuccessDestroyEmail")) {
// need urn:ietf:params:jmap:mail to destroy emails
if (!jmap_is_using(req, JMAP_URN_MAIL)) return 0;
jmap_parse_strings(arg, parser, "onSuccessDestroyEmail");
set->onSuccessDestroy = arg;
if (JNOTNULL(arg)) {
if (jmap_parse_strings(arg, parser, "onSuccessDestroyEmail"))
set->onSuccessDestroy = arg;
}
}

else r = 0;
Expand Down

0 comments on commit b3510e6

Please sign in to comment.