diff options
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/IMipPlugin.php | 12 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php | 19 |
2 files changed, 27 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php index edb52c3ad89..5e103bfc5c0 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php @@ -26,6 +26,7 @@ namespace OCA\DAV\CalDAV\Schedule; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -79,6 +80,9 @@ class IMipPlugin extends SabreIMipPlugin { /** @var IURLGenerator */ private $urlGenerator; + /** @var Defaults */ + private $defaults; + const MAX_DATE = '2038-01-01'; const METHOD_REQUEST = 'request'; @@ -92,9 +96,10 @@ class IMipPlugin extends SabreIMipPlugin { * @param ITimeFactory $timeFactory * @param L10NFactory $l10nFactory * @param IUrlGenerator $urlGenerator + * @param Defaults $defaults * @param string $userId */ - public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, IURLGenerator $urlGenerator, $userId) { + public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, IURLGenerator $urlGenerator, Defaults $defaults, $userId) { parent::__construct(''); $this->userId = $userId; $this->config = $config; @@ -103,6 +108,7 @@ class IMipPlugin extends SabreIMipPlugin { $this->timeFactory = $timeFactory; $this->l10nFactory = $l10nFactory; $this->urlGenerator = $urlGenerator; + $this->defaults = $defaults; } /** @@ -202,7 +208,11 @@ class IMipPlugin extends SabreIMipPlugin { 'meeting_url' => (string)$meetingUrl ?: $defaultVal, ); + $fromEMail = \OCP\Util::getDefaultEmailAddress('invitations-noreply'); + $fromName = $l10n->t('%s via %s', [$senderName, $this->defaults->getName()]); + $message = $this->mailer->createMessage() + ->setFrom([$fromEMail => $fromName]) ->setReplyTo([$sender => $senderName]) ->setTo([$recipient => $recipientName]); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index ee52cab2814..3f89002ab98 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -29,6 +29,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\Schedule; use OC\Mail\Mailer; use OCA\DAV\CalDAV\Schedule\IMipPlugin; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Defaults; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -46,6 +47,7 @@ class IMipPluginTest extends TestCase { public function testDelivery() { $mailMessage = $this->createMock(IMessage::class); + $mailMessage->method('setFrom')->willReturn($mailMessage); $mailMessage->method('setReplyTo')->willReturn($mailMessage); $mailMessage->method('setTo')->willReturn($mailMessage); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ @@ -68,8 +70,13 @@ class IMipPluginTest extends TestCase { $l10nFactory->method('get')->willReturn($l10n); /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */ $urlGenerator = $this->createMock(IURLGenerator::class); + /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */ + $defaults = $this->createMock(Defaults::class); + $defaults->expects($this->once()) + ->method('getName') + ->will($this->returnValue('Instance Name 123')); - $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123'); + $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123'); $message = new Message(); $message->method = 'REQUEST'; $message->message = new VCalendar(); @@ -98,6 +105,7 @@ class IMipPluginTest extends TestCase { public function testFailedDelivery() { $mailMessage = $this->createMock(IMessage::class); + $mailMessage->method('setFrom')->willReturn($mailMessage); $mailMessage->method('setReplyTo')->willReturn($mailMessage); $mailMessage->method('setTo')->willReturn($mailMessage); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ @@ -120,8 +128,10 @@ class IMipPluginTest extends TestCase { $l10nFactory->method('get')->willReturn($l10n); /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */ $urlGenerator = $this->createMock(IURLGenerator::class); + /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */ + $defaults = $this->createMock(Defaults::class); - $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123'); + $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123'); $message = new Message(); $message->method = 'REQUEST'; $message->message = new VCalendar(); @@ -153,6 +163,7 @@ class IMipPluginTest extends TestCase { */ public function testNoMessageSendForPastEvents($veventParams, $expectsMail) { $mailMessage = $this->createMock(IMessage::class); + $mailMessage->method('setFrom')->willReturn($mailMessage); $mailMessage->method('setReplyTo')->willReturn($mailMessage); $mailMessage->method('setTo')->willReturn($mailMessage); /** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */ @@ -179,8 +190,10 @@ class IMipPluginTest extends TestCase { $l10nFactory->method('get')->willReturn($l10n); /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */ $urlGenerator = $this->createMock(IURLGenerator::class); + /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */ + $defaults = $this->createMock(Defaults::class); - $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123'); + $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123'); $message = new Message(); $message->method = 'REQUEST'; $message->message = new VCalendar(); |