Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-08-01 12:01:34 +0300
committerdartcafe <github@dartcafe.de>2020-08-01 12:01:34 +0300
commitc145b5e4beb4f7ff34e5ebe230b8683ba19d6ca5 (patch)
treee88a8fed435c264e759fa646e36a9b6e8921040b /lib
parente857f1450b8e916b675a907fe75f236ad5cd9c99 (diff)
implement sending to a share's mail address
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/MailService.php38
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php
index 2456fb84..543bafa0 100644
--- a/lib/Service/MailService.php
+++ b/lib/Service/MailService.php
@@ -122,28 +122,28 @@ class MailService {
/**
* sendMail - Send eMail and evaluate recipient's mail address
- * and displayname if $toUserId is a site user
+ * and displayname if $userId is a site user
* @param IEmailTemplate $emailTemplate
- * @param String $toUserId
- * @param String $toEmail
- * @param String $toDisplayName
+ * @param String $userId
+ * @param String $emailAddress, ignored, when $userId is set
+ * @param String $displayName, ignored, when $userId is set
* @return String
*/
- private function sendMail($emailTemplate, $toUserId = '', $toEmail = '', $toDisplayName = '') {
+ private function sendMail($emailTemplate, $userId = '', $emailAddress = '', $displayName = '') {
- if ($this->userManager->get($toUserId) instanceof IUser && !$toEmail) {
- $toEmail = \OC::$server->getConfig()->getUserValue($toUserId, 'settings', 'email');
- $toDisplayName = $this->userManager->get($toUserId)->getDisplayName();
+ if ($this->userManager->get($userId) instanceof IUser) {
+ $emailAddress = \OC::$server->getConfig()->getUserValue($userId, 'settings', 'email');
+ $displayName = $this->userManager->get($userId)->getDisplayName();
}
- if (!$toEmail || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) {
- throw new Exception('Invalid email address (' . $toEmail . ')');
+ if (!$emailAddress || !filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
+ throw new Exception('Invalid email address (' . $emailAddress . ')');
}
try {
$message = $this->mailer->createMessage();
- $message->setTo([$toEmail => $toDisplayName]);
+ $message->setTo([$emailAddress => $displayName]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
@@ -363,15 +363,23 @@ class MailService {
$log = $this->logMapper->findUnprocessed();
foreach ($subscriptions as $subscription) {
+ $poll = $this->pollMapper->find($subscription->getPollId());
+ $emailAddress = '';
+ $displayName = '';
if ($this->userManager->get($subscription->getUserId()) instanceof IUser) {
$lang = $this->config->getUserValue($subscription->getUserId(), 'core', 'lang');
} else {
- $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang');
- continue;
+ try {
+ $emailAddress = $this->shareMapper->findByPollAndUser($subscription->getPollId(), $subscription->getUserId())->getUserEmail();
+ $displayName = $subscription->getUserId();
+ $lang = $this->config->getUserValue($poll->getOwner(), 'core', 'lang');
+ } catch (\Exception $e) {
+ continue;
+ }
+
}
- $poll = $this->pollMapper->find($subscription->getPollId());
$trans = $this->transFactory->get('polls', $lang);
$url = $this->urlGenerator->getAbsoluteURL(
@@ -468,7 +476,7 @@ class MailService {
$emailTemplate->addFooter($trans->t('This email is sent to you, because you subscribed to notifications of this poll. To opt out, visit the poll and remove your subscription.'));
try {
- $this->sendMail($emailTemplate, $subscription->getUserId());
+ $this->sendMail($emailTemplate, $subscription->getUserId(), $emailAddress, $displayName);
} catch (Exception $e) {
\OC::$server->getLogger()->alert('Error sending Mail to ' . $subscription->getUserId());
}