From 7519dbaa2327580d528ad0393fd3f3c68e7721ed Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 16 May 2021 17:18:44 +0200 Subject: [PATCH 1/3] Fix: Mail sender name Displays the configured sender name and no longer just the email address. Behaviour has been adapted to the Activity App. --- lib/Mailer/NotificationMailer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Mailer/NotificationMailer.php b/lib/Mailer/NotificationMailer.php index ca41372..8315dc3 100644 --- a/lib/Mailer/NotificationMailer.php +++ b/lib/Mailer/NotificationMailer.php @@ -27,6 +27,8 @@ use OCP\Template; use OCA\Notifications\Configuration\OptionsStorage; use OCP\IURLGenerator; +use OCP\Defaults; +use OCP\Util; /** * The class will focus on sending notifications via email. In addition, some email-related @@ -51,7 +53,22 @@ public function __construct(IManager $manager, IMailer $mailer, OptionsStorage $ $this->optionsStorage = $optionsStorage; $this->urlGenerator = $urlGenerator; } + + protected function getSenderData($setting) { + if (empty($this->senderAddress)) { + $this->senderAddress = Util::getDefaultEmailAddress('no-reply'); + } + if (empty($this->senderName)) { + $defaults = new Defaults(); + $this->senderName = $defaults->getName(); + } + if ($setting === 'email') { + return $this->senderAddress; + } + return $this->senderName; + } + /** * Send a notification via email to the list of email addresses passed as parameter * @param INotification $notification the notification to be sent @@ -74,6 +91,7 @@ public function sendNotification(INotification $notification, $serverUrl, $email $emailMessage = $this->mailer->createMessage(); $emailMessage->setTo([$emailAddress]); + $emailMessage->setFrom([$this->getSenderData('email') => $this->getSenderData('name')]); $notificationLink = $notification->getLink(); $urlComponents = \parse_url($notificationLink); From d8c8cb0141e7dd76110fd429a80489501120d65e Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 16 May 2021 17:22:26 +0200 Subject: [PATCH 2/3] Additional comments for fix --- lib/Mailer/NotificationMailer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Mailer/NotificationMailer.php b/lib/Mailer/NotificationMailer.php index 8315dc3..5ecd948 100644 --- a/lib/Mailer/NotificationMailer.php +++ b/lib/Mailer/NotificationMailer.php @@ -54,6 +54,11 @@ public function __construct(IManager $manager, IMailer $mailer, OptionsStorage $ $this->urlGenerator = $urlGenerator; } + /** + * Get the sender data + * @param string $setting Either `email` or `name` + * @return string + */ protected function getSenderData($setting) { if (empty($this->senderAddress)) { $this->senderAddress = Util::getDefaultEmailAddress('no-reply'); From a31b2aa691b88e727f0cd28d2354a55c0e58ab30 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 16 May 2021 17:35:12 +0200 Subject: [PATCH 3/3] Fix phpstan error --- lib/Mailer/NotificationMailer.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Mailer/NotificationMailer.php b/lib/Mailer/NotificationMailer.php index 5ecd948..b2187e8 100644 --- a/lib/Mailer/NotificationMailer.php +++ b/lib/Mailer/NotificationMailer.php @@ -46,6 +46,12 @@ class NotificationMailer { /** @var IURLGenerator */ private $urlGenerator; + + /** @var string */ + protected $senderAddress; + + /** @var string */ + protected $senderName; public function __construct(IManager $manager, IMailer $mailer, OptionsStorage $optionsStorage, IURLGenerator $urlGenerator) { $this->manager = $manager;