Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ private function getAllEMailAddressesFromEvent(VEvent $vevent):array {
$emailAddressesOfDelegates = $delegates->getParts();
foreach ($emailAddressesOfDelegates as $addressesOfDelegate) {
if (strcasecmp($addressesOfDelegate, 'mailto:') === 0) {
$emailAddresses[substr($addressesOfDelegate, 7)] = [];
$delegateEmail = substr($addressesOfDelegate, 7);
if ($delegateEmail !== false && $this->mailer->validateMailAddress($delegateEmail)) {
$emailAddresses[$delegateEmail] = [];
}
}
}

Expand Down Expand Up @@ -344,8 +347,12 @@ private function getEMailAddressOfAttendee(VObject\Property $attendee):?string {
if (!$this->hasAttendeeMailURI($attendee)) {
return null;
}
$attendeeEMail = substr($attendee->getValue(), 7);
if ($attendeeEMail === false || !$this->mailer->validateMailAddress($attendeeEMail)) {
return null;
}

return substr($attendee->getValue(), 7);
return $attendeeEMail;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author Christoph Wurst <[email protected]>
* @author Georg Ehrke <[email protected]>
* @author Joas Schilling <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Thomas Citharel <[email protected]>
*
Expand Down Expand Up @@ -40,27 +41,28 @@
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Mail\IMessage;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VCalendar;

class EmailProviderTest extends AbstractNotificationProviderTest {
public const USER_EMAIL = '[email protected]';

/** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
/** @var ILogger|MockObject */
protected $logger;

/** @var L10NFactory|\PHPUnit\Framework\MockObject\MockObject */
/** @var L10NFactory|MockObject */
protected $l10nFactory;

/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
/** @var IL10N|MockObject */
protected $l10n;

/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
/** @var IURLGenerator|MockObject */
protected $urlGenerator;

/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig|MockObject */
protected $config;

/** @var IMailer|\PHPUnit\Framework\MockObject\MockObject */
/** @var IMailer|MockObject */
private $mailer;

protected function setUp(): void {
Expand All @@ -78,22 +80,7 @@ protected function setUp(): void {
}

public function testSendWithoutAttendees():void {
$this->config->expects($this->at(0))
->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(3))
->method('getUserValue')
->with('uid5', 'core', 'lang', null)
->willReturn('de');
list($user1, $user2, $user3, , $user5) = $users = $this->getUsers();

$enL10N = $this->createMock(IL10N::class);
$enL10N->method('t')
Expand All @@ -107,30 +94,32 @@ public function testSendWithoutAttendees():void {
$deL10N->method('l')
->willReturnArgument(0);

$this->l10nFactory->expects($this->at(0))
$this->l10nFactory
->method('getUserLanguage')
->willReturnMap([
[$user1, 'en'],
[$user2, 'de'],
[$user3, 'de'],
[$user5, 'de'],
]);

$this->l10nFactory
->method('findLanguage')
->with()
->willReturn('en');

$this->l10nFactory->expects($this->at(1))
$this->l10nFactory
->method('languageExists')
->with('dav', 'en')
->willReturn(true);
->willReturnMap([
['dav', 'en', true],
['dav', 'de', true],
]);

$this->l10nFactory->expects($this->at(2))
$this->l10nFactory
->method('get')
->with('dav', 'en')
->willReturn($enL10N);

$this->l10nFactory->expects($this->at(3))
->method('languageExists')
->with('dav', 'de')
->willReturn(true);

$this->l10nFactory->expects($this->at(4))
->method('get')
->with('dav', 'de')
->willReturn($deL10N);
->willReturnMap([
['dav', 'en', null, $enL10N],
['dav', 'de', null, $deL10N],
]);

$template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('[email protected]', $template1);
Expand Down Expand Up @@ -197,26 +186,11 @@ public function testSendWithoutAttendees():void {
$this->setupURLGeneratorMock(2);

$vcalendar = $this->getNoAttendeeVCalendar();
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $this->getUsers());
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users);
}

public function testSendWithAttendees(): void {
$this->config->expects($this->at(0))
->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(3))
->method('getUserValue')
->with('uid5', 'core', 'lang', null)
->willReturn('de');
list($user1, $user2, $user3, , $user5) = $users = $this->getUsers();

$enL10N = $this->createMock(IL10N::class);
$enL10N->method('t')
Expand All @@ -230,138 +204,85 @@ public function testSendWithAttendees(): void {
$deL10N->method('l')
->willReturnArgument(0);

$this->l10nFactory->expects($this->at(0))
$this->l10nFactory
->method('getUserLanguage')
->willReturnMap([
[$user1, 'en'],
[$user2, 'de'],
[$user3, 'de'],
[$user5, 'de'],
]);

$this->l10nFactory
->method('findLanguage')
->with()
->willReturn('en');

$this->l10nFactory->expects($this->at(1))
$this->l10nFactory
->method('languageExists')
->with('dav', 'de')
->willReturn(true);
->willReturnMap([
['dav', 'en', true],
['dav', 'de', true],
]);

$this->l10nFactory->expects($this->at(2))
$this->l10nFactory
->method('get')
->with('dav', 'de')
->willReturn($enL10N);

$this->l10nFactory->expects($this->at(3))
->method('languageExists')
->with('dav', 'en')
->willReturn(true);
->willReturnMap([
['dav', 'en', null, $enL10N],
['dav', 'de', null, $deL10N],
]);

$this->l10nFactory->expects($this->at(4))
->method('get')
->with('dav', 'en')
->willReturn($deL10N);

// German
$template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('[email protected]', $template1);
$message12 = $this->getMessageMock('[email protected]', $template1);
$message13 = $this->getMessageMock('[email protected]', $template1);
// English
$template2 = $this->getTemplateMock();
$message21 = $this->getMessageMock('[email protected]', $template2);
$message22 = $this->getMessageMock('[email protected]', $template2);
$message23 = $this->getMessageMock('[email protected]', $template2);

$this->mailer->expects($this->at(0))
->method('createEMailTemplate')
->with('dav.calendarReminder')
->willReturn($template1);

$this->mailer->expects($this->at(1))
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);

$this->mailer->expects($this->at(2))
->method('createMessage')
->with()
->willReturn($message11);
$this->mailer->expects($this->at(3))
->method('send')
->with($message11)
->willReturn([]);
$this->mailer->expects($this->at(4))
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);

$this->mailer->expects($this->at(5))
->method('createMessage')
->with()
->willReturn($message12);
$this->mailer->expects($this->at(6))
->method('send')
->with($message12)
->willReturn([]);
$this->mailer->expects($this->at(7))
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);
$this->mailer->expects($this->at(8))
->method('createMessage')
->with()
->willReturn($message13);
$this->mailer->expects($this->at(9))
->method('send')
->with($message13)
->willReturn([]);
$this->mailer->expects($this->at(10))
->method('validateMailAddress')
->with('invalid')
->willReturn(false);

$this->mailer->expects($this->at(11))
$this->mailer->expects(self::exactly(2))
->method('createEMailTemplate')
->with('dav.calendarReminder')
->willReturn($template2);

$this->mailer->expects($this->at(12))
->willReturnOnConsecutiveCalls(
$template1,
$template2
);
$this->mailer->expects($this->atLeastOnce())
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);
$this->mailer->expects($this->at(13))
->willReturnMap([
['[email protected]', true],
['[email protected]', true],
['[email protected]', true],
['[email protected]', true],
['[email protected]', true],
['[email protected]', true],
['invalid', false]
]);
$this->mailer->expects($this->exactly(6))
->method('createMessage')
->with()
->willReturn($message21);
$this->mailer->expects($this->at(14))
->willReturnOnConsecutiveCalls(
$message11,
$message12,
$message13,
$message21,
$message22,
$message23
);
$this->mailer->expects($this->exactly(6))
->method('send')
->with($message21)
->willReturn([]);

$this->mailer->expects($this->at(15))
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);
$this->mailer->expects($this->at(16))
->method('createMessage')
->with()
->willReturn($message22);
$this->mailer->expects($this->at(17))
->method('send')
->with($message22)
->willReturn([]);

$this->mailer->expects($this->at(18))
->method('validateMailAddress')
->with('[email protected]')
->willReturn(true);
$this->mailer->expects($this->at(19))
->method('createMessage')
->with()
->willReturn($message23);
$this->mailer->expects($this->at(20))
->method('send')
->with($message23)
->willReturn([]);

->withConsecutive(
[$message11],
[$message12],
[$message13],
[$message21],
[$message22],
[$message23]
)->willReturn([]);
$this->setupURLGeneratorMock(2);

$vcalendar = $this->getAttendeeVCalendar();
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $this->getUsers());
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users);
}

/**
Expand Down