Skip to content

Commit a31c9f6

Browse files
authored
Merge pull request #4779 from cyrusimap/onSuccessDestroyEmail
jmap_mail_submission.c: properly handle onSuccessDestroyEmail:null
2 parents 9a89959 + b3510e6 commit a31c9f6

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

Diff for: cassandane/Cassandane/Cyrus/JMAPEmailSubmission.pm

+87
Original file line numberDiff line numberDiff line change
@@ -2138,5 +2138,92 @@ sub test_emailsubmission_scheduled_send_null_onsend
21382138
$self->assert_num_equals(0, scalar @$alarmdata);
21392139
}
21402140

2141+
sub test_emailsubmission_onsuccessdestroy
2142+
:min_version_3_9 :needs_component_jmap
2143+
{
2144+
my ($self) = @_;
2145+
my $jmap = $self->{jmap};
2146+
2147+
my $res = $jmap->CallMethods( [ [ 'Identity/get', {}, "R1" ] ] );
2148+
my $identityid = $res->[0][1]->{list}[0]->{id};
2149+
$self->assert_not_null($identityid);
2150+
2151+
xlog $self, "Generate an email via IMAP";
2152+
$self->make_message("foo", body => "an email") or die;
2153+
2154+
xlog $self, "get email id";
2155+
$res = $jmap->CallMethods( [ [ 'Email/query', {}, "R1" ] ] );
2156+
my $emailid = $res->[0][1]->{ids}[0];
2157+
2158+
xlog $self, "create email submission with bad onSuccess";
2159+
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
2160+
create => {
2161+
'1' => {
2162+
identityId => $identityid,
2163+
emailId => $emailid,
2164+
}
2165+
},
2166+
onSuccessDestroyEmail => {}
2167+
}, "R1" ] ] );
2168+
$self->assert_str_equals("error", $res->[0][0]);
2169+
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
2170+
$self->assert_str_equals("onSuccessDestroyEmail",
2171+
$res->[0][1]{arguments}[0]);
2172+
2173+
xlog $self, "create email submission with bad onSuccess";
2174+
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
2175+
create => {
2176+
'1' => {
2177+
identityId => $identityid,
2178+
emailId => $emailid,
2179+
}
2180+
},
2181+
onSuccessDestroyEmail => "foo"
2182+
}, "R1" ] ] );
2183+
$self->assert_str_equals("error", $res->[0][0]);
2184+
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
2185+
$self->assert_str_equals("onSuccessDestroyEmail",
2186+
$res->[0][1]{arguments}[0]);
2187+
2188+
xlog $self, "create email submission with bad onSuccess";
2189+
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
2190+
create => {
2191+
'1' => {
2192+
identityId => $identityid,
2193+
emailId => $emailid,
2194+
}
2195+
},
2196+
onSuccessDestroyEmail => [ 1 ]
2197+
}, "R1" ] ] );
2198+
$self->assert_str_equals("error", $res->[0][0]);
2199+
$self->assert_str_equals("invalidArguments", $res->[0][1]{type});
2200+
$self->assert_str_equals("onSuccessDestroyEmail[0]",
2201+
$res->[0][1]{arguments}[0]);
2202+
2203+
xlog $self, "create email submission with no onSuccess";
2204+
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
2205+
create => {
2206+
'1' => {
2207+
identityId => $identityid,
2208+
emailId => $emailid,
2209+
}
2210+
},
2211+
}, "R1" ] ] );
2212+
my $msgsubid = $res->[0][1]->{created}{1}{id};
2213+
$self->assert_not_null($msgsubid);
2214+
2215+
xlog $self, "create email submission with NULL onSuccess";
2216+
$res = $jmap->CallMethods( [ [ 'EmailSubmission/set', {
2217+
create => {
2218+
'2' => {
2219+
identityId => $identityid,
2220+
emailId => $emailid,
2221+
}
2222+
},
2223+
onSuccessDestroyEmail => JSON::null
2224+
}, "R1" ] ] );
2225+
$msgsubid = $res->[0][1]->{created}{2}{id};
2226+
$self->assert_not_null($msgsubid);
2227+
}
21412228

21422229
1;

Diff for: imap/jmap_mail_submission.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1415,11 +1415,13 @@ static int _submission_setargs_parse(jmap_req_t *req,
14151415
else if (JNOTNULL(arg)) r = 0;
14161416
}
14171417

1418-
else if (!strcmp(key, "onSuccessDestroyEmail") && JNOTNULL(arg)) {
1418+
else if (!strcmp(key, "onSuccessDestroyEmail")) {
14191419
// need urn:ietf:params:jmap:mail to destroy emails
14201420
if (!jmap_is_using(req, JMAP_URN_MAIL)) return 0;
1421-
jmap_parse_strings(arg, parser, "onSuccessDestroyEmail");
1422-
set->onSuccessDestroy = arg;
1421+
if (JNOTNULL(arg)) {
1422+
if (jmap_parse_strings(arg, parser, "onSuccessDestroyEmail"))
1423+
set->onSuccessDestroy = arg;
1424+
}
14231425
}
14241426

14251427
else r = 0;

0 commit comments

Comments
 (0)