Skip to content

Commit 32a49e2

Browse files
authored
Merge pull request #25591 from nextcloud/backport/25582/stable21
[stable21] Do not send imip email to invalid recipients
2 parents a15066b + 3878bcb commit 32a49e2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public function schedule(Message $iTipMessage) {
178178
// Strip off mailto:
179179
$sender = substr($iTipMessage->sender, 7);
180180
$recipient = substr($iTipMessage->recipient, 7);
181+
if (!$this->mailer->validateMailAddress($recipient)) {
182+
// Nothing to send if the recipient doesn't have a valid email address
183+
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
184+
return;
185+
}
181186

182187
$senderName = $iTipMessage->senderName ?: null;
183188
$recipientName = $iTipMessage->recipientName ?: null;

apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public function testDelivery() {
140140
->method('getAppValue')
141141
->with('dav', 'invitation_link_recipients', 'yes')
142142
->willReturn('yes');
143+
$this->mailer->method('validateMailAddress')->willReturn(true);
143144

144145
$message = $this->_testMessage();
145146
$this->_expectSend();
@@ -153,6 +154,7 @@ public function testFailedDelivery() {
153154
->method('getAppValue')
154155
->with('dav', 'invitation_link_recipients', 'yes')
155156
->willReturn('yes');
157+
$this->mailer->method('validateMailAddress')->willReturn(true);
156158

157159
$message = $this->_testMessage();
158160
$this->mailer
@@ -163,12 +165,21 @@ public function testFailedDelivery() {
163165
$this->assertEquals('5.0', $message->getScheduleStatus());
164166
}
165167

168+
public function testInvalidEmailDelivery() {
169+
$this->mailer->method('validateMailAddress')->willReturn(false);
170+
171+
$message = $this->_testMessage();
172+
$this->plugin->schedule($message);
173+
$this->assertEquals('5.0', $message->getScheduleStatus());
174+
}
175+
166176
public function testDeliveryWithNoCommonName() {
167177
$this->config
168178
->expects($this->at(1))
169179
->method('getAppValue')
170180
->with('dav', 'invitation_link_recipients', 'yes')
171181
->willReturn('yes');
182+
$this->mailer->method('validateMailAddress')->willReturn(true);
172183

173184
$message = $this->_testMessage();
174185
$message->senderName = null;
@@ -193,6 +204,7 @@ public function testNoMessageSendForPastEvents(array $veventParams, bool $expect
193204
$this->config
194205
->method('getAppValue')
195206
->willReturn('yes');
207+
$this->mailer->method('validateMailAddress')->willReturn(true);
196208

197209
$message = $this->_testMessage($veventParams);
198210

@@ -227,6 +239,7 @@ public function dataNoMessageSendForPastEvents() {
227239
*/
228240
public function testIncludeResponseButtons(string $config_setting, string $recipient, bool $has_buttons) {
229241
$message = $this->_testMessage([],$recipient);
242+
$this->mailer->method('validateMailAddress')->willReturn(true);
230243

231244
$this->_expectSend($recipient, true, $has_buttons);
232245
$this->config
@@ -256,6 +269,7 @@ public function testMessageSendWhenEventWithoutName() {
256269
$this->config
257270
->method('getAppValue')
258271
->willReturn('yes');
272+
$this->mailer->method('validateMailAddress')->willReturn(true);
259273

260274
$message = $this->_testMessage(['SUMMARY' => '']);
261275
$this->_expectSend('frodo@hobb.it', true, true,'Invitation: Untitled event');

0 commit comments

Comments
 (0)