Skip to content

Commit

Permalink
Do not send imip email to invalid recipients
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst authored and backportbot[bot] committed Feb 11, 2021
1 parent 47a3980 commit d540776
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public function schedule(Message $iTipMessage) {
// Strip off mailto:
$sender = substr($iTipMessage->sender, 7);
$recipient = substr($iTipMessage->recipient, 7);
if (!$this->mailer->validateMailAddress($recipient)) {
// Nothing to send if the recipient doesn't have a valid email address
$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
return;
}

$senderName = $iTipMessage->senderName ?: null;
$recipientName = $iTipMessage->recipientName ?: null;
Expand Down
14 changes: 14 additions & 0 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function testDelivery() {
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');
$this->mailer->method('validateMailAddress')->willReturn(true);

$message = $this->_testMessage();
$this->_expectSend();
Expand All @@ -153,6 +154,7 @@ public function testFailedDelivery() {
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');
$this->mailer->method('validateMailAddress')->willReturn(true);

$message = $this->_testMessage();
$this->mailer
Expand All @@ -163,12 +165,21 @@ public function testFailedDelivery() {
$this->assertEquals('5.0', $message->getScheduleStatus());
}

public function testInvalidEmailDelivery() {
$this->mailer->method('validateMailAddress')->willReturn(false);

$message = $this->_testMessage();
$this->plugin->schedule($message);
$this->assertEquals('5.0', $message->getScheduleStatus());
}

public function testDeliveryWithNoCommonName() {
$this->config
->expects($this->at(1))
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');
$this->mailer->method('validateMailAddress')->willReturn(true);

$message = $this->_testMessage();
$message->senderName = null;
Expand All @@ -193,6 +204,7 @@ public function testNoMessageSendForPastEvents(array $veventParams, bool $expect
$this->config
->method('getAppValue')
->willReturn('yes');
$this->mailer->method('validateMailAddress')->willReturn(true);

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

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

$this->_expectSend($recipient, true, $has_buttons);
$this->config
Expand Down Expand Up @@ -256,6 +269,7 @@ public function testMessageSendWhenEventWithoutName() {
$this->config
->method('getAppValue')
->willReturn('yes');
$this->mailer->method('validateMailAddress')->willReturn(true);

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

0 comments on commit d540776

Please sign in to comment.