@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
127 | 127 | $template->addHeader(); |
128 | 128 | $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
129 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
129 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | 130 | $template->addFooter(); |
131 | 131 | |
132 | 132 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
197 | 197 | $template->addHeader(); |
198 | 198 | $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
199 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
199 | + $template->addBodyText($text.' '.$this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | 200 | if ($user->getEMailAddress()) { |
201 | 201 | $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
202 | 202 | } |
@@ -34,179 +34,179 @@ |
||
34 | 34 | |
35 | 35 | class Hooks { |
36 | 36 | |
37 | - /** @var IActivityManager */ |
|
38 | - protected $activityManager; |
|
39 | - /** @var IUserManager */ |
|
40 | - protected $userManager; |
|
41 | - /** @var IUserSession */ |
|
42 | - protected $userSession; |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $urlGenerator; |
|
45 | - /** @var IMailer */ |
|
46 | - protected $mailer; |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - /** @var IFactory */ |
|
50 | - protected $languageFactory; |
|
51 | - /** @var IL10N */ |
|
52 | - protected $l; |
|
53 | - |
|
54 | - public function __construct(IActivityManager $activityManager, |
|
55 | - IUserManager $userManager, |
|
56 | - IUserSession $userSession, |
|
57 | - IURLGenerator $urlGenerator, |
|
58 | - IMailer $mailer, |
|
59 | - IConfig $config, |
|
60 | - IFactory $languageFactory, |
|
61 | - IL10N $l) { |
|
62 | - $this->activityManager = $activityManager; |
|
63 | - $this->userManager = $userManager; |
|
64 | - $this->userSession = $userSession; |
|
65 | - $this->urlGenerator = $urlGenerator; |
|
66 | - $this->mailer = $mailer; |
|
67 | - $this->config = $config; |
|
68 | - $this->languageFactory = $languageFactory; |
|
69 | - $this->l = $l; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param string $uid |
|
74 | - * @throws \InvalidArgumentException |
|
75 | - * @throws \BadMethodCallException |
|
76 | - * @throws \Exception |
|
77 | - */ |
|
78 | - public function onChangePassword($uid) { |
|
79 | - $user = $this->userManager->get($uid); |
|
80 | - |
|
81 | - if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
82 | - // User didn't login, so don't create activities and emails. |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - $event = $this->activityManager->generateEvent(); |
|
87 | - $event->setApp('settings') |
|
88 | - ->setType('personal_settings') |
|
89 | - ->setAffectedUser($user->getUID()); |
|
90 | - |
|
91 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
92 | - |
|
93 | - $actor = $this->userSession->getUser(); |
|
94 | - if ($actor instanceof IUser) { |
|
95 | - if ($actor->getUID() !== $user->getUID()) { |
|
96 | - $this->l = $this->languageFactory->get( |
|
97 | - 'settings', |
|
98 | - $this->config->getUserValue( |
|
99 | - $user->getUID(), 'core', 'lang', |
|
100 | - $this->config->getSystemValue('default_language', 'en') |
|
101 | - ) |
|
102 | - ); |
|
103 | - |
|
104 | - $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
105 | - $event->setAuthor($actor->getUID()) |
|
106 | - ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
107 | - } else { |
|
108 | - $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
109 | - $event->setAuthor($actor->getUID()) |
|
110 | - ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
111 | - } |
|
112 | - } else { |
|
113 | - $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
114 | - $event->setSubject(Provider::PASSWORD_RESET); |
|
115 | - } |
|
116 | - |
|
117 | - $this->activityManager->publish($event); |
|
118 | - |
|
119 | - if ($user->getEMailAddress() !== null) { |
|
120 | - $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
121 | - 'displayname' => $user->getDisplayName(), |
|
122 | - 'emailAddress' => $user->getEMailAddress(), |
|
123 | - 'instanceUrl' => $instanceUrl, |
|
124 | - ]); |
|
125 | - |
|
126 | - $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
127 | - $template->addHeader(); |
|
128 | - $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
129 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | - $template->addFooter(); |
|
131 | - |
|
132 | - |
|
133 | - $message = $this->mailer->createMessage(); |
|
134 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
135 | - $message->useTemplate($template); |
|
136 | - $this->mailer->send($message); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param IUser $user |
|
142 | - * @param string|null $oldMailAddress |
|
143 | - * @throws \InvalidArgumentException |
|
144 | - * @throws \BadMethodCallException |
|
145 | - */ |
|
146 | - public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
147 | - |
|
148 | - if ($oldMailAddress === $user->getEMailAddress() || |
|
149 | - $user->getLastLogin() === 0) { |
|
150 | - // Email didn't really change or user didn't login, |
|
151 | - // so don't create activities and emails. |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $event = $this->activityManager->generateEvent(); |
|
156 | - $event->setApp('settings') |
|
157 | - ->setType('personal_settings') |
|
158 | - ->setAffectedUser($user->getUID()); |
|
159 | - |
|
160 | - $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
161 | - |
|
162 | - $actor = $this->userSession->getUser(); |
|
163 | - if ($actor instanceof IUser) { |
|
164 | - if ($actor->getUID() !== $user->getUID()) { |
|
165 | - $this->l = $this->languageFactory->get( |
|
166 | - 'settings', |
|
167 | - $this->config->getUserValue( |
|
168 | - $user->getUID(), 'core', 'lang', |
|
169 | - $this->config->getSystemValue('default_language', 'en') |
|
170 | - ) |
|
171 | - ); |
|
172 | - |
|
173 | - $text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
174 | - $event->setAuthor($actor->getUID()) |
|
175 | - ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); |
|
176 | - } else { |
|
177 | - $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
178 | - $event->setAuthor($actor->getUID()) |
|
179 | - ->setSubject(Provider::EMAIL_CHANGED_SELF); |
|
180 | - } |
|
181 | - } else { |
|
182 | - $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
183 | - $event->setSubject(Provider::EMAIL_CHANGED); |
|
184 | - } |
|
185 | - $this->activityManager->publish($event); |
|
186 | - |
|
187 | - |
|
188 | - if ($oldMailAddress !== null) { |
|
189 | - $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
190 | - 'displayname' => $user->getDisplayName(), |
|
191 | - 'newEMailAddress' => $user->getEMailAddress(), |
|
192 | - 'oldEMailAddress' => $oldMailAddress, |
|
193 | - 'instanceUrl' => $instanceUrl, |
|
194 | - ]); |
|
195 | - |
|
196 | - $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
197 | - $template->addHeader(); |
|
198 | - $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
199 | - $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | - if ($user->getEMailAddress()) { |
|
201 | - $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
202 | - } |
|
203 | - $template->addFooter(); |
|
204 | - |
|
205 | - |
|
206 | - $message = $this->mailer->createMessage(); |
|
207 | - $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
208 | - $message->useTemplate($template); |
|
209 | - $this->mailer->send($message); |
|
210 | - } |
|
211 | - } |
|
37 | + /** @var IActivityManager */ |
|
38 | + protected $activityManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + protected $userManager; |
|
41 | + /** @var IUserSession */ |
|
42 | + protected $userSession; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $urlGenerator; |
|
45 | + /** @var IMailer */ |
|
46 | + protected $mailer; |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + /** @var IFactory */ |
|
50 | + protected $languageFactory; |
|
51 | + /** @var IL10N */ |
|
52 | + protected $l; |
|
53 | + |
|
54 | + public function __construct(IActivityManager $activityManager, |
|
55 | + IUserManager $userManager, |
|
56 | + IUserSession $userSession, |
|
57 | + IURLGenerator $urlGenerator, |
|
58 | + IMailer $mailer, |
|
59 | + IConfig $config, |
|
60 | + IFactory $languageFactory, |
|
61 | + IL10N $l) { |
|
62 | + $this->activityManager = $activityManager; |
|
63 | + $this->userManager = $userManager; |
|
64 | + $this->userSession = $userSession; |
|
65 | + $this->urlGenerator = $urlGenerator; |
|
66 | + $this->mailer = $mailer; |
|
67 | + $this->config = $config; |
|
68 | + $this->languageFactory = $languageFactory; |
|
69 | + $this->l = $l; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param string $uid |
|
74 | + * @throws \InvalidArgumentException |
|
75 | + * @throws \BadMethodCallException |
|
76 | + * @throws \Exception |
|
77 | + */ |
|
78 | + public function onChangePassword($uid) { |
|
79 | + $user = $this->userManager->get($uid); |
|
80 | + |
|
81 | + if (!$user instanceof IUser || $user->getLastLogin() === 0) { |
|
82 | + // User didn't login, so don't create activities and emails. |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + $event = $this->activityManager->generateEvent(); |
|
87 | + $event->setApp('settings') |
|
88 | + ->setType('personal_settings') |
|
89 | + ->setAffectedUser($user->getUID()); |
|
90 | + |
|
91 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
92 | + |
|
93 | + $actor = $this->userSession->getUser(); |
|
94 | + if ($actor instanceof IUser) { |
|
95 | + if ($actor->getUID() !== $user->getUID()) { |
|
96 | + $this->l = $this->languageFactory->get( |
|
97 | + 'settings', |
|
98 | + $this->config->getUserValue( |
|
99 | + $user->getUID(), 'core', 'lang', |
|
100 | + $this->config->getSystemValue('default_language', 'en') |
|
101 | + ) |
|
102 | + ); |
|
103 | + |
|
104 | + $text = $this->l->t('%1$s changed your password on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
105 | + $event->setAuthor($actor->getUID()) |
|
106 | + ->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]); |
|
107 | + } else { |
|
108 | + $text = $this->l->t('Your password on %s was changed.', [$instanceUrl]); |
|
109 | + $event->setAuthor($actor->getUID()) |
|
110 | + ->setSubject(Provider::PASSWORD_CHANGED_SELF); |
|
111 | + } |
|
112 | + } else { |
|
113 | + $text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]); |
|
114 | + $event->setSubject(Provider::PASSWORD_RESET); |
|
115 | + } |
|
116 | + |
|
117 | + $this->activityManager->publish($event); |
|
118 | + |
|
119 | + if ($user->getEMailAddress() !== null) { |
|
120 | + $template = $this->mailer->createEMailTemplate('settings.PasswordChanged', [ |
|
121 | + 'displayname' => $user->getDisplayName(), |
|
122 | + 'emailAddress' => $user->getEMailAddress(), |
|
123 | + 'instanceUrl' => $instanceUrl, |
|
124 | + ]); |
|
125 | + |
|
126 | + $template->setSubject($this->l->t('Password for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
127 | + $template->addHeader(); |
|
128 | + $template->addHeading($this->l->t('Password changed for %s', [$user->getDisplayName()]), false); |
|
129 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
130 | + $template->addFooter(); |
|
131 | + |
|
132 | + |
|
133 | + $message = $this->mailer->createMessage(); |
|
134 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
135 | + $message->useTemplate($template); |
|
136 | + $this->mailer->send($message); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param IUser $user |
|
142 | + * @param string|null $oldMailAddress |
|
143 | + * @throws \InvalidArgumentException |
|
144 | + * @throws \BadMethodCallException |
|
145 | + */ |
|
146 | + public function onChangeEmail(IUser $user, $oldMailAddress) { |
|
147 | + |
|
148 | + if ($oldMailAddress === $user->getEMailAddress() || |
|
149 | + $user->getLastLogin() === 0) { |
|
150 | + // Email didn't really change or user didn't login, |
|
151 | + // so don't create activities and emails. |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $event = $this->activityManager->generateEvent(); |
|
156 | + $event->setApp('settings') |
|
157 | + ->setType('personal_settings') |
|
158 | + ->setAffectedUser($user->getUID()); |
|
159 | + |
|
160 | + $instanceUrl = $this->urlGenerator->getAbsoluteURL('/'); |
|
161 | + |
|
162 | + $actor = $this->userSession->getUser(); |
|
163 | + if ($actor instanceof IUser) { |
|
164 | + if ($actor->getUID() !== $user->getUID()) { |
|
165 | + $this->l = $this->languageFactory->get( |
|
166 | + 'settings', |
|
167 | + $this->config->getUserValue( |
|
168 | + $user->getUID(), 'core', 'lang', |
|
169 | + $this->config->getSystemValue('default_language', 'en') |
|
170 | + ) |
|
171 | + ); |
|
172 | + |
|
173 | + $text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]); |
|
174 | + $event->setAuthor($actor->getUID()) |
|
175 | + ->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]); |
|
176 | + } else { |
|
177 | + $text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]); |
|
178 | + $event->setAuthor($actor->getUID()) |
|
179 | + ->setSubject(Provider::EMAIL_CHANGED_SELF); |
|
180 | + } |
|
181 | + } else { |
|
182 | + $text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]); |
|
183 | + $event->setSubject(Provider::EMAIL_CHANGED); |
|
184 | + } |
|
185 | + $this->activityManager->publish($event); |
|
186 | + |
|
187 | + |
|
188 | + if ($oldMailAddress !== null) { |
|
189 | + $template = $this->mailer->createEMailTemplate('settings.EmailChanged', [ |
|
190 | + 'displayname' => $user->getDisplayName(), |
|
191 | + 'newEMailAddress' => $user->getEMailAddress(), |
|
192 | + 'oldEMailAddress' => $oldMailAddress, |
|
193 | + 'instanceUrl' => $instanceUrl, |
|
194 | + ]); |
|
195 | + |
|
196 | + $template->setSubject($this->l->t('Email address for %1$s changed on %2$s', [$user->getDisplayName(), $instanceUrl])); |
|
197 | + $template->addHeader(); |
|
198 | + $template->addHeading($this->l->t('Email address changed for %s', [$user->getDisplayName()]), false); |
|
199 | + $template->addBodyText($text . ' ' . $this->l->t('If you did not request this, please contact an administrator.')); |
|
200 | + if ($user->getEMailAddress()) { |
|
201 | + $template->addBodyText($this->l->t('The new email address is %s', [$user->getEMailAddress()])); |
|
202 | + } |
|
203 | + $template->addFooter(); |
|
204 | + |
|
205 | + |
|
206 | + $message = $this->mailer->createMessage(); |
|
207 | + $message->setTo([$oldMailAddress => $user->getDisplayName()]); |
|
208 | + $message->useTemplate($template); |
|
209 | + $this->mailer->send($message); |
|
210 | + } |
|
211 | + } |
|
212 | 212 | } |
@@ -39,33 +39,33 @@ discard block |
||
39 | 39 | * @package OC\Mail |
40 | 40 | */ |
41 | 41 | class EMailTemplate implements IEMailTemplate { |
42 | - /** @var Defaults */ |
|
43 | - protected $themingDefaults; |
|
44 | - /** @var IURLGenerator */ |
|
45 | - protected $urlGenerator; |
|
46 | - /** @var IL10N */ |
|
47 | - protected $l10n; |
|
48 | - /** @var string */ |
|
49 | - protected $emailId; |
|
50 | - /** @var array */ |
|
51 | - protected $data; |
|
52 | - |
|
53 | - /** @var string */ |
|
54 | - protected $subject = ''; |
|
55 | - /** @var string */ |
|
56 | - protected $htmlBody = ''; |
|
57 | - /** @var string */ |
|
58 | - protected $plainBody = ''; |
|
59 | - /** @var bool indicated if the footer is added */ |
|
60 | - protected $headerAdded = false; |
|
61 | - /** @var bool indicated if the body is already opened */ |
|
62 | - protected $bodyOpened = false; |
|
63 | - /** @var bool indicated if there is a list open in the body */ |
|
64 | - protected $bodyListOpened = false; |
|
65 | - /** @var bool indicated if the footer is added */ |
|
66 | - protected $footerAdded = false; |
|
67 | - |
|
68 | - protected $head = <<<EOF |
|
42 | + /** @var Defaults */ |
|
43 | + protected $themingDefaults; |
|
44 | + /** @var IURLGenerator */ |
|
45 | + protected $urlGenerator; |
|
46 | + /** @var IL10N */ |
|
47 | + protected $l10n; |
|
48 | + /** @var string */ |
|
49 | + protected $emailId; |
|
50 | + /** @var array */ |
|
51 | + protected $data; |
|
52 | + |
|
53 | + /** @var string */ |
|
54 | + protected $subject = ''; |
|
55 | + /** @var string */ |
|
56 | + protected $htmlBody = ''; |
|
57 | + /** @var string */ |
|
58 | + protected $plainBody = ''; |
|
59 | + /** @var bool indicated if the footer is added */ |
|
60 | + protected $headerAdded = false; |
|
61 | + /** @var bool indicated if the body is already opened */ |
|
62 | + protected $bodyOpened = false; |
|
63 | + /** @var bool indicated if there is a list open in the body */ |
|
64 | + protected $bodyListOpened = false; |
|
65 | + /** @var bool indicated if the footer is added */ |
|
66 | + protected $footerAdded = false; |
|
67 | + |
|
68 | + protected $head = <<<EOF |
|
69 | 69 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
70 | 70 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
71 | 71 | <head> |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | <center data-parsed="" style="min-width:580px;width:100%"> |
84 | 84 | EOF; |
85 | 85 | |
86 | - protected $tail = <<<EOF |
|
86 | + protected $tail = <<<EOF |
|
87 | 87 | </center> |
88 | 88 | </td> |
89 | 89 | </tr> |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | </html> |
95 | 95 | EOF; |
96 | 96 | |
97 | - protected $header = <<<EOF |
|
97 | + protected $header = <<<EOF |
|
98 | 98 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
99 | 99 | <tr style="padding:0;text-align:left;vertical-align:top"> |
100 | 100 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | </table> |
128 | 128 | EOF; |
129 | 129 | |
130 | - protected $heading = <<<EOF |
|
130 | + protected $heading = <<<EOF |
|
131 | 131 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
132 | 132 | <tbody> |
133 | 133 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | </table> |
147 | 147 | EOF; |
148 | 148 | |
149 | - protected $bodyBegin = <<<EOF |
|
149 | + protected $bodyBegin = <<<EOF |
|
150 | 150 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
151 | 151 | <tr style="padding:0;text-align:left;vertical-align:top"> |
152 | 152 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | </table> |
164 | 164 | EOF; |
165 | 165 | |
166 | - protected $bodyText = <<<EOF |
|
166 | + protected $bodyText = <<<EOF |
|
167 | 167 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
168 | 168 | <tbody> |
169 | 169 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | </table> |
183 | 183 | EOF; |
184 | 184 | |
185 | - protected $listBegin = <<<EOF |
|
185 | + protected $listBegin = <<<EOF |
|
186 | 186 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
187 | 187 | <tbody> |
188 | 188 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
191 | 191 | EOF; |
192 | 192 | |
193 | - protected $listItem = <<<EOF |
|
193 | + protected $listItem = <<<EOF |
|
194 | 194 | <tr style="padding:0;text-align:left;vertical-align:top"> |
195 | 195 | <td style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;"> |
196 | 196 | <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p> |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | </tr> |
203 | 203 | EOF; |
204 | 204 | |
205 | - protected $listEnd = <<<EOF |
|
205 | + protected $listEnd = <<<EOF |
|
206 | 206 | </table> |
207 | 207 | </th> |
208 | 208 | </tr> |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | </table> |
211 | 211 | EOF; |
212 | 212 | |
213 | - protected $buttonGroup = <<<EOF |
|
213 | + protected $buttonGroup = <<<EOF |
|
214 | 214 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
215 | 215 | <tbody> |
216 | 216 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | </table> |
264 | 264 | EOF; |
265 | 265 | |
266 | - protected $button = <<<EOF |
|
266 | + protected $button = <<<EOF |
|
267 | 267 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
268 | 268 | <tbody> |
269 | 269 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | </table> |
304 | 304 | EOF; |
305 | 305 | |
306 | - protected $bodyEnd = <<<EOF |
|
306 | + protected $bodyEnd = <<<EOF |
|
307 | 307 | |
308 | 308 | </td> |
309 | 309 | </tr> |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | </table> |
315 | 315 | EOF; |
316 | 316 | |
317 | - protected $footer = <<<EOF |
|
317 | + protected $footer = <<<EOF |
|
318 | 318 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
319 | 319 | <tbody> |
320 | 320 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -340,306 +340,306 @@ discard block |
||
340 | 340 | </table> |
341 | 341 | EOF; |
342 | 342 | |
343 | - /** |
|
344 | - * @param Defaults $themingDefaults |
|
345 | - * @param IURLGenerator $urlGenerator |
|
346 | - * @param IL10N $l10n |
|
347 | - * @param string $emailId |
|
348 | - * @param array $data |
|
349 | - */ |
|
350 | - public function __construct(Defaults $themingDefaults, |
|
351 | - IURLGenerator $urlGenerator, |
|
352 | - IL10N $l10n, |
|
353 | - $emailId, |
|
354 | - array $data) { |
|
355 | - $this->themingDefaults = $themingDefaults; |
|
356 | - $this->urlGenerator = $urlGenerator; |
|
357 | - $this->l10n = $l10n; |
|
358 | - $this->htmlBody .= $this->head; |
|
359 | - $this->emailId = $emailId; |
|
360 | - $this->data = $data; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Sets the subject of the email |
|
365 | - * |
|
366 | - * @param string $subject |
|
367 | - */ |
|
368 | - public function setSubject($subject) { |
|
369 | - $this->subject = $subject; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Adds a header to the email |
|
374 | - */ |
|
375 | - public function addHeader() { |
|
376 | - if ($this->headerAdded) { |
|
377 | - return; |
|
378 | - } |
|
379 | - $this->headerAdded = true; |
|
380 | - |
|
381 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
382 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Adds a heading to the email |
|
387 | - * |
|
388 | - * @param string $title |
|
389 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
390 | - * if empty the $title is used, if false none will be used |
|
391 | - */ |
|
392 | - public function addHeading($title, $plainTitle = '') { |
|
393 | - if ($this->footerAdded) { |
|
394 | - return; |
|
395 | - } |
|
396 | - if ($plainTitle === '') { |
|
397 | - $plainTitle = $title; |
|
398 | - } |
|
399 | - |
|
400 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
401 | - if ($plainTitle !== false) { |
|
402 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Open the HTML body when it is not already |
|
408 | - */ |
|
409 | - protected function ensureBodyIsOpened() { |
|
410 | - if ($this->bodyOpened) { |
|
411 | - return; |
|
412 | - } |
|
413 | - |
|
414 | - $this->htmlBody .= $this->bodyBegin; |
|
415 | - $this->bodyOpened = true; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Adds a paragraph to the body of the email |
|
420 | - * |
|
421 | - * @param string $text |
|
422 | - * @param string|bool $plainText Text that is used in the plain text email |
|
423 | - * if empty the $text is used, if false none will be used |
|
424 | - */ |
|
425 | - public function addBodyText($text, $plainText = '') { |
|
426 | - if ($this->footerAdded) { |
|
427 | - return; |
|
428 | - } |
|
429 | - if ($plainText === '') { |
|
430 | - $plainText = $text; |
|
431 | - } |
|
432 | - |
|
433 | - $this->ensureBodyIsOpened(); |
|
434 | - |
|
435 | - $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
436 | - if ($plainText !== false) { |
|
437 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
438 | - } |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Adds a list item to the body of the email |
|
443 | - * |
|
444 | - * @param string $text |
|
445 | - * @param string $metaInfo |
|
446 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
447 | - * @param string $plainText Text that is used in the plain text email |
|
448 | - * if empty the $text is used, if false none will be used |
|
449 | - * @param string $plainMetaInfo Meta info that is used in the plain text email |
|
450 | - * if empty the $metaInfo is used, if false none will be used |
|
451 | - * @since 12.0.0 |
|
452 | - */ |
|
453 | - public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
454 | - $this->ensureBodyListOpened(); |
|
455 | - |
|
456 | - if ($plainText === '') { |
|
457 | - $plainText = $text; |
|
458 | - } |
|
459 | - if ($plainMetaInfo === '') { |
|
460 | - $plainMetaInfo = $metaInfo; |
|
461 | - } |
|
462 | - |
|
463 | - $htmlText = htmlspecialchars($text); |
|
464 | - if ($metaInfo) { |
|
465 | - $htmlText = '<em style="color:#777;">' . htmlspecialchars($metaInfo) . '</em><br>' . $htmlText; |
|
466 | - } |
|
467 | - if ($icon !== '') { |
|
468 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
469 | - } else { |
|
470 | - $icon = '•'; |
|
471 | - } |
|
472 | - $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
473 | - if ($plainText !== false) { |
|
474 | - $this->plainBody .= ' * ' . $plainText; |
|
475 | - if ($plainMetaInfo !== false) { |
|
476 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
477 | - } |
|
478 | - $this->plainBody .= PHP_EOL; |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - protected function ensureBodyListOpened() { |
|
483 | - if ($this->bodyListOpened) { |
|
484 | - return; |
|
485 | - } |
|
486 | - |
|
487 | - $this->ensureBodyIsOpened(); |
|
488 | - $this->bodyListOpened = true; |
|
489 | - $this->htmlBody .= $this->listBegin; |
|
490 | - } |
|
491 | - |
|
492 | - protected function ensureBodyListClosed() { |
|
493 | - if (!$this->bodyListOpened) { |
|
494 | - return; |
|
495 | - } |
|
496 | - |
|
497 | - $this->bodyListOpened = false; |
|
498 | - $this->htmlBody .= $this->listEnd; |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * Adds a button group of two buttons to the body of the email |
|
503 | - * |
|
504 | - * @param string $textLeft Text of left button |
|
505 | - * @param string $urlLeft URL of left button |
|
506 | - * @param string $textRight Text of right button |
|
507 | - * @param string $urlRight URL of right button |
|
508 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
509 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
510 | - */ |
|
511 | - public function addBodyButtonGroup($textLeft, |
|
512 | - $urlLeft, |
|
513 | - $textRight, |
|
514 | - $urlRight, |
|
515 | - $plainTextLeft = '', |
|
516 | - $plainTextRight = '') { |
|
517 | - if ($this->footerAdded) { |
|
518 | - return; |
|
519 | - } |
|
520 | - if ($plainTextLeft === '') { |
|
521 | - $plainTextLeft = $textLeft; |
|
522 | - } |
|
523 | - |
|
524 | - if ($plainTextRight === '') { |
|
525 | - $plainTextRight = $textRight; |
|
526 | - } |
|
527 | - |
|
528 | - $this->ensureBodyIsOpened(); |
|
529 | - $this->ensureBodyListClosed(); |
|
530 | - |
|
531 | - $color = $this->themingDefaults->getColorPrimary(); |
|
532 | - |
|
533 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
534 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
535 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
536 | - |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Adds a button to the body of the email |
|
541 | - * |
|
542 | - * @param string $text Text of button |
|
543 | - * @param string $url URL of button |
|
544 | - * @param string $plainText Text of button in plain text version |
|
545 | - * if empty the $text is used, if false none will be used |
|
546 | - * |
|
547 | - * @since 12.0.0 |
|
548 | - */ |
|
549 | - public function addBodyButton($text, $url, $plainText = '') { |
|
550 | - if ($this->footerAdded) { |
|
551 | - return; |
|
552 | - } |
|
553 | - |
|
554 | - $this->ensureBodyIsOpened(); |
|
555 | - $this->ensureBodyListClosed(); |
|
556 | - |
|
557 | - if ($plainText === '') { |
|
558 | - $plainText = $text; |
|
559 | - } |
|
560 | - |
|
561 | - $color = $this->themingDefaults->getColorPrimary(); |
|
562 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
563 | - |
|
564 | - if ($plainText !== false) { |
|
565 | - $this->plainBody .= $plainText . ': '; |
|
566 | - } |
|
567 | - |
|
568 | - $this->plainBody .= $url . PHP_EOL; |
|
569 | - |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Close the HTML body when it is open |
|
574 | - */ |
|
575 | - protected function ensureBodyIsClosed() { |
|
576 | - if (!$this->bodyOpened) { |
|
577 | - return; |
|
578 | - } |
|
579 | - |
|
580 | - $this->ensureBodyListClosed(); |
|
581 | - |
|
582 | - $this->htmlBody .= $this->bodyEnd; |
|
583 | - $this->bodyOpened = false; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
588 | - * |
|
589 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
590 | - */ |
|
591 | - public function addFooter($text = '') { |
|
592 | - if($text === '') { |
|
593 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
594 | - } |
|
595 | - |
|
596 | - if ($this->footerAdded) { |
|
597 | - return; |
|
598 | - } |
|
599 | - $this->footerAdded = true; |
|
600 | - |
|
601 | - $this->ensureBodyIsClosed(); |
|
602 | - |
|
603 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
604 | - $this->htmlBody .= $this->tail; |
|
605 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
606 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Returns the rendered email subject as string |
|
611 | - * |
|
612 | - * @return string |
|
613 | - */ |
|
614 | - public function renderSubject() { |
|
615 | - return $this->subject; |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * Returns the rendered HTML email as string |
|
620 | - * |
|
621 | - * @return string |
|
622 | - */ |
|
623 | - public function renderHtml() { |
|
624 | - if (!$this->footerAdded) { |
|
625 | - $this->footerAdded = true; |
|
626 | - $this->ensureBodyIsClosed(); |
|
627 | - $this->htmlBody .= $this->tail; |
|
628 | - } |
|
629 | - return $this->htmlBody; |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Returns the rendered plain text email as string |
|
634 | - * |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function renderText() { |
|
638 | - if (!$this->footerAdded) { |
|
639 | - $this->footerAdded = true; |
|
640 | - $this->ensureBodyIsClosed(); |
|
641 | - $this->htmlBody .= $this->tail; |
|
642 | - } |
|
643 | - return $this->plainBody; |
|
644 | - } |
|
343 | + /** |
|
344 | + * @param Defaults $themingDefaults |
|
345 | + * @param IURLGenerator $urlGenerator |
|
346 | + * @param IL10N $l10n |
|
347 | + * @param string $emailId |
|
348 | + * @param array $data |
|
349 | + */ |
|
350 | + public function __construct(Defaults $themingDefaults, |
|
351 | + IURLGenerator $urlGenerator, |
|
352 | + IL10N $l10n, |
|
353 | + $emailId, |
|
354 | + array $data) { |
|
355 | + $this->themingDefaults = $themingDefaults; |
|
356 | + $this->urlGenerator = $urlGenerator; |
|
357 | + $this->l10n = $l10n; |
|
358 | + $this->htmlBody .= $this->head; |
|
359 | + $this->emailId = $emailId; |
|
360 | + $this->data = $data; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Sets the subject of the email |
|
365 | + * |
|
366 | + * @param string $subject |
|
367 | + */ |
|
368 | + public function setSubject($subject) { |
|
369 | + $this->subject = $subject; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Adds a header to the email |
|
374 | + */ |
|
375 | + public function addHeader() { |
|
376 | + if ($this->headerAdded) { |
|
377 | + return; |
|
378 | + } |
|
379 | + $this->headerAdded = true; |
|
380 | + |
|
381 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
382 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Adds a heading to the email |
|
387 | + * |
|
388 | + * @param string $title |
|
389 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
390 | + * if empty the $title is used, if false none will be used |
|
391 | + */ |
|
392 | + public function addHeading($title, $plainTitle = '') { |
|
393 | + if ($this->footerAdded) { |
|
394 | + return; |
|
395 | + } |
|
396 | + if ($plainTitle === '') { |
|
397 | + $plainTitle = $title; |
|
398 | + } |
|
399 | + |
|
400 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
401 | + if ($plainTitle !== false) { |
|
402 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Open the HTML body when it is not already |
|
408 | + */ |
|
409 | + protected function ensureBodyIsOpened() { |
|
410 | + if ($this->bodyOpened) { |
|
411 | + return; |
|
412 | + } |
|
413 | + |
|
414 | + $this->htmlBody .= $this->bodyBegin; |
|
415 | + $this->bodyOpened = true; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Adds a paragraph to the body of the email |
|
420 | + * |
|
421 | + * @param string $text |
|
422 | + * @param string|bool $plainText Text that is used in the plain text email |
|
423 | + * if empty the $text is used, if false none will be used |
|
424 | + */ |
|
425 | + public function addBodyText($text, $plainText = '') { |
|
426 | + if ($this->footerAdded) { |
|
427 | + return; |
|
428 | + } |
|
429 | + if ($plainText === '') { |
|
430 | + $plainText = $text; |
|
431 | + } |
|
432 | + |
|
433 | + $this->ensureBodyIsOpened(); |
|
434 | + |
|
435 | + $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); |
|
436 | + if ($plainText !== false) { |
|
437 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
438 | + } |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Adds a list item to the body of the email |
|
443 | + * |
|
444 | + * @param string $text |
|
445 | + * @param string $metaInfo |
|
446 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
447 | + * @param string $plainText Text that is used in the plain text email |
|
448 | + * if empty the $text is used, if false none will be used |
|
449 | + * @param string $plainMetaInfo Meta info that is used in the plain text email |
|
450 | + * if empty the $metaInfo is used, if false none will be used |
|
451 | + * @since 12.0.0 |
|
452 | + */ |
|
453 | + public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
454 | + $this->ensureBodyListOpened(); |
|
455 | + |
|
456 | + if ($plainText === '') { |
|
457 | + $plainText = $text; |
|
458 | + } |
|
459 | + if ($plainMetaInfo === '') { |
|
460 | + $plainMetaInfo = $metaInfo; |
|
461 | + } |
|
462 | + |
|
463 | + $htmlText = htmlspecialchars($text); |
|
464 | + if ($metaInfo) { |
|
465 | + $htmlText = '<em style="color:#777;">' . htmlspecialchars($metaInfo) . '</em><br>' . $htmlText; |
|
466 | + } |
|
467 | + if ($icon !== '') { |
|
468 | + $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
469 | + } else { |
|
470 | + $icon = '•'; |
|
471 | + } |
|
472 | + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
473 | + if ($plainText !== false) { |
|
474 | + $this->plainBody .= ' * ' . $plainText; |
|
475 | + if ($plainMetaInfo !== false) { |
|
476 | + $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
477 | + } |
|
478 | + $this->plainBody .= PHP_EOL; |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + protected function ensureBodyListOpened() { |
|
483 | + if ($this->bodyListOpened) { |
|
484 | + return; |
|
485 | + } |
|
486 | + |
|
487 | + $this->ensureBodyIsOpened(); |
|
488 | + $this->bodyListOpened = true; |
|
489 | + $this->htmlBody .= $this->listBegin; |
|
490 | + } |
|
491 | + |
|
492 | + protected function ensureBodyListClosed() { |
|
493 | + if (!$this->bodyListOpened) { |
|
494 | + return; |
|
495 | + } |
|
496 | + |
|
497 | + $this->bodyListOpened = false; |
|
498 | + $this->htmlBody .= $this->listEnd; |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * Adds a button group of two buttons to the body of the email |
|
503 | + * |
|
504 | + * @param string $textLeft Text of left button |
|
505 | + * @param string $urlLeft URL of left button |
|
506 | + * @param string $textRight Text of right button |
|
507 | + * @param string $urlRight URL of right button |
|
508 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
509 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
510 | + */ |
|
511 | + public function addBodyButtonGroup($textLeft, |
|
512 | + $urlLeft, |
|
513 | + $textRight, |
|
514 | + $urlRight, |
|
515 | + $plainTextLeft = '', |
|
516 | + $plainTextRight = '') { |
|
517 | + if ($this->footerAdded) { |
|
518 | + return; |
|
519 | + } |
|
520 | + if ($plainTextLeft === '') { |
|
521 | + $plainTextLeft = $textLeft; |
|
522 | + } |
|
523 | + |
|
524 | + if ($plainTextRight === '') { |
|
525 | + $plainTextRight = $textRight; |
|
526 | + } |
|
527 | + |
|
528 | + $this->ensureBodyIsOpened(); |
|
529 | + $this->ensureBodyListClosed(); |
|
530 | + |
|
531 | + $color = $this->themingDefaults->getColorPrimary(); |
|
532 | + |
|
533 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); |
|
534 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
535 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
536 | + |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Adds a button to the body of the email |
|
541 | + * |
|
542 | + * @param string $text Text of button |
|
543 | + * @param string $url URL of button |
|
544 | + * @param string $plainText Text of button in plain text version |
|
545 | + * if empty the $text is used, if false none will be used |
|
546 | + * |
|
547 | + * @since 12.0.0 |
|
548 | + */ |
|
549 | + public function addBodyButton($text, $url, $plainText = '') { |
|
550 | + if ($this->footerAdded) { |
|
551 | + return; |
|
552 | + } |
|
553 | + |
|
554 | + $this->ensureBodyIsOpened(); |
|
555 | + $this->ensureBodyListClosed(); |
|
556 | + |
|
557 | + if ($plainText === '') { |
|
558 | + $plainText = $text; |
|
559 | + } |
|
560 | + |
|
561 | + $color = $this->themingDefaults->getColorPrimary(); |
|
562 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); |
|
563 | + |
|
564 | + if ($plainText !== false) { |
|
565 | + $this->plainBody .= $plainText . ': '; |
|
566 | + } |
|
567 | + |
|
568 | + $this->plainBody .= $url . PHP_EOL; |
|
569 | + |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Close the HTML body when it is open |
|
574 | + */ |
|
575 | + protected function ensureBodyIsClosed() { |
|
576 | + if (!$this->bodyOpened) { |
|
577 | + return; |
|
578 | + } |
|
579 | + |
|
580 | + $this->ensureBodyListClosed(); |
|
581 | + |
|
582 | + $this->htmlBody .= $this->bodyEnd; |
|
583 | + $this->bodyOpened = false; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
588 | + * |
|
589 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
590 | + */ |
|
591 | + public function addFooter($text = '') { |
|
592 | + if($text === '') { |
|
593 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
594 | + } |
|
595 | + |
|
596 | + if ($this->footerAdded) { |
|
597 | + return; |
|
598 | + } |
|
599 | + $this->footerAdded = true; |
|
600 | + |
|
601 | + $this->ensureBodyIsClosed(); |
|
602 | + |
|
603 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
604 | + $this->htmlBody .= $this->tail; |
|
605 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
606 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Returns the rendered email subject as string |
|
611 | + * |
|
612 | + * @return string |
|
613 | + */ |
|
614 | + public function renderSubject() { |
|
615 | + return $this->subject; |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * Returns the rendered HTML email as string |
|
620 | + * |
|
621 | + * @return string |
|
622 | + */ |
|
623 | + public function renderHtml() { |
|
624 | + if (!$this->footerAdded) { |
|
625 | + $this->footerAdded = true; |
|
626 | + $this->ensureBodyIsClosed(); |
|
627 | + $this->htmlBody .= $this->tail; |
|
628 | + } |
|
629 | + return $this->htmlBody; |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Returns the rendered plain text email as string |
|
634 | + * |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function renderText() { |
|
638 | + if (!$this->footerAdded) { |
|
639 | + $this->footerAdded = true; |
|
640 | + $this->ensureBodyIsClosed(); |
|
641 | + $this->htmlBody .= $this->tail; |
|
642 | + } |
|
643 | + return $this->plainBody; |
|
644 | + } |
|
645 | 645 | } |
@@ -50,220 +50,220 @@ |
||
50 | 50 | * @package OC\Mail |
51 | 51 | */ |
52 | 52 | class Mailer implements IMailer { |
53 | - /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ |
|
54 | - private $instance = null; |
|
55 | - /** @var IConfig */ |
|
56 | - private $config; |
|
57 | - /** @var ILogger */ |
|
58 | - private $logger; |
|
59 | - /** @var Defaults */ |
|
60 | - private $defaults; |
|
61 | - /** @var IURLGenerator */ |
|
62 | - private $urlGenerator; |
|
63 | - /** @var IL10N */ |
|
64 | - private $l10n; |
|
53 | + /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ |
|
54 | + private $instance = null; |
|
55 | + /** @var IConfig */ |
|
56 | + private $config; |
|
57 | + /** @var ILogger */ |
|
58 | + private $logger; |
|
59 | + /** @var Defaults */ |
|
60 | + private $defaults; |
|
61 | + /** @var IURLGenerator */ |
|
62 | + private $urlGenerator; |
|
63 | + /** @var IL10N */ |
|
64 | + private $l10n; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param IConfig $config |
|
68 | - * @param ILogger $logger |
|
69 | - * @param Defaults $defaults |
|
70 | - * @param IURLGenerator $urlGenerator |
|
71 | - * @param IL10N $l10n |
|
72 | - */ |
|
73 | - public function __construct(IConfig $config, |
|
74 | - ILogger $logger, |
|
75 | - Defaults $defaults, |
|
76 | - IURLGenerator $urlGenerator, |
|
77 | - IL10N $l10n) { |
|
78 | - $this->config = $config; |
|
79 | - $this->logger = $logger; |
|
80 | - $this->defaults = $defaults; |
|
81 | - $this->urlGenerator = $urlGenerator; |
|
82 | - $this->l10n = $l10n; |
|
83 | - } |
|
66 | + /** |
|
67 | + * @param IConfig $config |
|
68 | + * @param ILogger $logger |
|
69 | + * @param Defaults $defaults |
|
70 | + * @param IURLGenerator $urlGenerator |
|
71 | + * @param IL10N $l10n |
|
72 | + */ |
|
73 | + public function __construct(IConfig $config, |
|
74 | + ILogger $logger, |
|
75 | + Defaults $defaults, |
|
76 | + IURLGenerator $urlGenerator, |
|
77 | + IL10N $l10n) { |
|
78 | + $this->config = $config; |
|
79 | + $this->logger = $logger; |
|
80 | + $this->defaults = $defaults; |
|
81 | + $this->urlGenerator = $urlGenerator; |
|
82 | + $this->l10n = $l10n; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Creates a new message object that can be passed to send() |
|
87 | - * |
|
88 | - * @return IMessage |
|
89 | - */ |
|
90 | - public function createMessage() { |
|
91 | - return new Message(new \Swift_Message()); |
|
92 | - } |
|
85 | + /** |
|
86 | + * Creates a new message object that can be passed to send() |
|
87 | + * |
|
88 | + * @return IMessage |
|
89 | + */ |
|
90 | + public function createMessage() { |
|
91 | + return new Message(new \Swift_Message()); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Creates a new email template object |
|
96 | - * |
|
97 | - * @param string $emailId |
|
98 | - * @param array $data |
|
99 | - * @return IEMailTemplate |
|
100 | - * @since 12.0.0 |
|
101 | - */ |
|
102 | - public function createEMailTemplate($emailId, array $data = []) { |
|
103 | - $class = $this->config->getSystemValue('mail_template_class', ''); |
|
94 | + /** |
|
95 | + * Creates a new email template object |
|
96 | + * |
|
97 | + * @param string $emailId |
|
98 | + * @param array $data |
|
99 | + * @return IEMailTemplate |
|
100 | + * @since 12.0.0 |
|
101 | + */ |
|
102 | + public function createEMailTemplate($emailId, array $data = []) { |
|
103 | + $class = $this->config->getSystemValue('mail_template_class', ''); |
|
104 | 104 | |
105 | - if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
106 | - return new $class( |
|
107 | - $this->defaults, |
|
108 | - $this->urlGenerator, |
|
109 | - $this->l10n, |
|
110 | - $emailId, |
|
111 | - $data |
|
112 | - ); |
|
113 | - } |
|
105 | + if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
106 | + return new $class( |
|
107 | + $this->defaults, |
|
108 | + $this->urlGenerator, |
|
109 | + $this->l10n, |
|
110 | + $emailId, |
|
111 | + $data |
|
112 | + ); |
|
113 | + } |
|
114 | 114 | |
115 | - return new EMailTemplate( |
|
116 | - $this->defaults, |
|
117 | - $this->urlGenerator, |
|
118 | - $this->l10n, |
|
119 | - $emailId, |
|
120 | - $data |
|
121 | - ); |
|
122 | - } |
|
115 | + return new EMailTemplate( |
|
116 | + $this->defaults, |
|
117 | + $this->urlGenerator, |
|
118 | + $this->l10n, |
|
119 | + $emailId, |
|
120 | + $data |
|
121 | + ); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
126 | - * if no-one has been passed. |
|
127 | - * |
|
128 | - * @param IMessage|Message $message Message to send |
|
129 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
130 | - * therefore should be considered |
|
131 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
132 | - * has been supplied.) |
|
133 | - */ |
|
134 | - public function send(IMessage $message) { |
|
135 | - $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
124 | + /** |
|
125 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
126 | + * if no-one has been passed. |
|
127 | + * |
|
128 | + * @param IMessage|Message $message Message to send |
|
129 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
130 | + * therefore should be considered |
|
131 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
132 | + * has been supplied.) |
|
133 | + */ |
|
134 | + public function send(IMessage $message) { |
|
135 | + $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
136 | 136 | |
137 | - if (empty($message->getFrom())) { |
|
138 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
139 | - } |
|
137 | + if (empty($message->getFrom())) { |
|
138 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
139 | + } |
|
140 | 140 | |
141 | - $failedRecipients = []; |
|
141 | + $failedRecipients = []; |
|
142 | 142 | |
143 | - $mailer = $this->getInstance(); |
|
143 | + $mailer = $this->getInstance(); |
|
144 | 144 | |
145 | - // Enable logger if debug mode is enabled |
|
146 | - if($debugMode) { |
|
147 | - $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
148 | - $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
149 | - } |
|
145 | + // Enable logger if debug mode is enabled |
|
146 | + if($debugMode) { |
|
147 | + $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
148 | + $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
149 | + } |
|
150 | 150 | |
151 | - $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
151 | + $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
152 | 152 | |
153 | - // Debugging logging |
|
154 | - $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
155 | - $this->logger->debug($logMessage, ['app' => 'core']); |
|
156 | - if($debugMode && isset($mailLogger)) { |
|
157 | - $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
158 | - } |
|
153 | + // Debugging logging |
|
154 | + $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
155 | + $this->logger->debug($logMessage, ['app' => 'core']); |
|
156 | + if($debugMode && isset($mailLogger)) { |
|
157 | + $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
158 | + } |
|
159 | 159 | |
160 | - return $failedRecipients; |
|
161 | - } |
|
160 | + return $failedRecipients; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Checks if an e-mail address is valid |
|
165 | - * |
|
166 | - * @param string $email Email address to be validated |
|
167 | - * @return bool True if the mail address is valid, false otherwise |
|
168 | - */ |
|
169 | - public function validateMailAddress($email) { |
|
170 | - return \Swift_Validate::email($this->convertEmail($email)); |
|
171 | - } |
|
163 | + /** |
|
164 | + * Checks if an e-mail address is valid |
|
165 | + * |
|
166 | + * @param string $email Email address to be validated |
|
167 | + * @return bool True if the mail address is valid, false otherwise |
|
168 | + */ |
|
169 | + public function validateMailAddress($email) { |
|
170 | + return \Swift_Validate::email($this->convertEmail($email)); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
175 | - * |
|
176 | - * FIXME: Remove this once SwiftMailer supports IDN |
|
177 | - * |
|
178 | - * @param string $email |
|
179 | - * @return string Converted mail address if `idn_to_ascii` exists |
|
180 | - */ |
|
181 | - protected function convertEmail($email) { |
|
182 | - if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) { |
|
183 | - return $email; |
|
184 | - } |
|
173 | + /** |
|
174 | + * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
175 | + * |
|
176 | + * FIXME: Remove this once SwiftMailer supports IDN |
|
177 | + * |
|
178 | + * @param string $email |
|
179 | + * @return string Converted mail address if `idn_to_ascii` exists |
|
180 | + */ |
|
181 | + protected function convertEmail($email) { |
|
182 | + if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) { |
|
183 | + return $email; |
|
184 | + } |
|
185 | 185 | |
186 | - list($name, $domain) = explode('@', $email, 2); |
|
187 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
188 | - return $name.'@'.$domain; |
|
189 | - } |
|
186 | + list($name, $domain) = explode('@', $email, 2); |
|
187 | + $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
188 | + return $name.'@'.$domain; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * Returns whatever transport is configured within the config |
|
193 | - * |
|
194 | - * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport |
|
195 | - */ |
|
196 | - protected function getInstance() { |
|
197 | - if (!is_null($this->instance)) { |
|
198 | - return $this->instance; |
|
199 | - } |
|
191 | + /** |
|
192 | + * Returns whatever transport is configured within the config |
|
193 | + * |
|
194 | + * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport |
|
195 | + */ |
|
196 | + protected function getInstance() { |
|
197 | + if (!is_null($this->instance)) { |
|
198 | + return $this->instance; |
|
199 | + } |
|
200 | 200 | |
201 | - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
202 | - case 'smtp': |
|
203 | - $this->instance = $this->getSmtpInstance(); |
|
204 | - break; |
|
205 | - case 'sendmail': |
|
206 | - // FIXME: Move into the return statement but requires proper testing |
|
207 | - // for SMTP and mail as well. Thus not really doable for a |
|
208 | - // minor release. |
|
209 | - $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); |
|
210 | - break; |
|
211 | - default: |
|
212 | - $this->instance = $this->getMailInstance(); |
|
213 | - break; |
|
214 | - } |
|
201 | + switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
202 | + case 'smtp': |
|
203 | + $this->instance = $this->getSmtpInstance(); |
|
204 | + break; |
|
205 | + case 'sendmail': |
|
206 | + // FIXME: Move into the return statement but requires proper testing |
|
207 | + // for SMTP and mail as well. Thus not really doable for a |
|
208 | + // minor release. |
|
209 | + $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); |
|
210 | + break; |
|
211 | + default: |
|
212 | + $this->instance = $this->getMailInstance(); |
|
213 | + break; |
|
214 | + } |
|
215 | 215 | |
216 | - return $this->instance; |
|
217 | - } |
|
216 | + return $this->instance; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Returns the SMTP transport |
|
221 | - * |
|
222 | - * @return \Swift_SmtpTransport |
|
223 | - */ |
|
224 | - protected function getSmtpInstance() { |
|
225 | - $transport = \Swift_SmtpTransport::newInstance(); |
|
226 | - $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
227 | - $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
228 | - $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
229 | - if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
230 | - $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
231 | - $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
232 | - $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
233 | - } |
|
234 | - $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
235 | - if (!empty($smtpSecurity)) { |
|
236 | - $transport->setEncryption($smtpSecurity); |
|
237 | - } |
|
238 | - $transport->start(); |
|
239 | - return $transport; |
|
240 | - } |
|
219 | + /** |
|
220 | + * Returns the SMTP transport |
|
221 | + * |
|
222 | + * @return \Swift_SmtpTransport |
|
223 | + */ |
|
224 | + protected function getSmtpInstance() { |
|
225 | + $transport = \Swift_SmtpTransport::newInstance(); |
|
226 | + $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
227 | + $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
228 | + $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
229 | + if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
230 | + $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
231 | + $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
232 | + $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
233 | + } |
|
234 | + $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
235 | + if (!empty($smtpSecurity)) { |
|
236 | + $transport->setEncryption($smtpSecurity); |
|
237 | + } |
|
238 | + $transport->start(); |
|
239 | + return $transport; |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Returns the sendmail transport |
|
244 | - * |
|
245 | - * @return \Swift_SendmailTransport |
|
246 | - */ |
|
247 | - protected function getSendMailInstance() { |
|
248 | - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
249 | - case 'qmail': |
|
250 | - $binaryPath = '/var/qmail/bin/sendmail'; |
|
251 | - break; |
|
252 | - default: |
|
253 | - $binaryPath = '/usr/sbin/sendmail'; |
|
254 | - break; |
|
255 | - } |
|
242 | + /** |
|
243 | + * Returns the sendmail transport |
|
244 | + * |
|
245 | + * @return \Swift_SendmailTransport |
|
246 | + */ |
|
247 | + protected function getSendMailInstance() { |
|
248 | + switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
249 | + case 'qmail': |
|
250 | + $binaryPath = '/var/qmail/bin/sendmail'; |
|
251 | + break; |
|
252 | + default: |
|
253 | + $binaryPath = '/usr/sbin/sendmail'; |
|
254 | + break; |
|
255 | + } |
|
256 | 256 | |
257 | - return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); |
|
258 | - } |
|
257 | + return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Returns the mail transport |
|
262 | - * |
|
263 | - * @return \Swift_MailTransport |
|
264 | - */ |
|
265 | - protected function getMailInstance() { |
|
266 | - return \Swift_MailTransport::newInstance(); |
|
267 | - } |
|
260 | + /** |
|
261 | + * Returns the mail transport |
|
262 | + * |
|
263 | + * @return \Swift_MailTransport |
|
264 | + */ |
|
265 | + protected function getMailInstance() { |
|
266 | + return \Swift_MailTransport::newInstance(); |
|
267 | + } |
|
268 | 268 | |
269 | 269 | } |
@@ -52,117 +52,117 @@ |
||
52 | 52 | */ |
53 | 53 | interface IEMailTemplate { |
54 | 54 | |
55 | - /** |
|
56 | - * Sets the subject of the email |
|
57 | - * |
|
58 | - * @param string $subject |
|
59 | - * |
|
60 | - * @since 13.0.0 |
|
61 | - */ |
|
62 | - public function setSubject($subject); |
|
55 | + /** |
|
56 | + * Sets the subject of the email |
|
57 | + * |
|
58 | + * @param string $subject |
|
59 | + * |
|
60 | + * @since 13.0.0 |
|
61 | + */ |
|
62 | + public function setSubject($subject); |
|
63 | 63 | |
64 | - /** |
|
65 | - * Adds a header to the email |
|
66 | - * |
|
67 | - * @since 12.0.0 |
|
68 | - */ |
|
69 | - public function addHeader(); |
|
64 | + /** |
|
65 | + * Adds a header to the email |
|
66 | + * |
|
67 | + * @since 12.0.0 |
|
68 | + */ |
|
69 | + public function addHeader(); |
|
70 | 70 | |
71 | - /** |
|
72 | - * Adds a heading to the email |
|
73 | - * |
|
74 | - * @param string $title |
|
75 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
76 | - * if empty the $title is used, if false none will be used |
|
77 | - * |
|
78 | - * @since 12.0.0 |
|
79 | - */ |
|
80 | - public function addHeading($title, $plainTitle = ''); |
|
71 | + /** |
|
72 | + * Adds a heading to the email |
|
73 | + * |
|
74 | + * @param string $title |
|
75 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
76 | + * if empty the $title is used, if false none will be used |
|
77 | + * |
|
78 | + * @since 12.0.0 |
|
79 | + */ |
|
80 | + public function addHeading($title, $plainTitle = ''); |
|
81 | 81 | |
82 | - /** |
|
83 | - * Adds a paragraph to the body of the email |
|
84 | - * |
|
85 | - * @param string $text |
|
86 | - * @param string|bool $plainText Text that is used in the plain text email |
|
87 | - * if empty the $text is used, if false none will be used |
|
88 | - * |
|
89 | - * @since 12.0.0 |
|
90 | - */ |
|
91 | - public function addBodyText($text, $plainText = ''); |
|
82 | + /** |
|
83 | + * Adds a paragraph to the body of the email |
|
84 | + * |
|
85 | + * @param string $text |
|
86 | + * @param string|bool $plainText Text that is used in the plain text email |
|
87 | + * if empty the $text is used, if false none will be used |
|
88 | + * |
|
89 | + * @since 12.0.0 |
|
90 | + */ |
|
91 | + public function addBodyText($text, $plainText = ''); |
|
92 | 92 | |
93 | - /** |
|
94 | - * Adds a list item to the body of the email |
|
95 | - * |
|
96 | - * @param string $text |
|
97 | - * @param string $metaInfo |
|
98 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
99 | - * @param string $plainText Text that is used in the plain text email |
|
100 | - * if empty the $text is used, if false none will be used |
|
101 | - * @param string $plainMetaInfo Meta info that is used in the plain text email |
|
102 | - * if empty the $metaInfo is used, if false none will be used |
|
103 | - * @since 12.0.0 |
|
104 | - */ |
|
105 | - public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
93 | + /** |
|
94 | + * Adds a list item to the body of the email |
|
95 | + * |
|
96 | + * @param string $text |
|
97 | + * @param string $metaInfo |
|
98 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
99 | + * @param string $plainText Text that is used in the plain text email |
|
100 | + * if empty the $text is used, if false none will be used |
|
101 | + * @param string $plainMetaInfo Meta info that is used in the plain text email |
|
102 | + * if empty the $metaInfo is used, if false none will be used |
|
103 | + * @since 12.0.0 |
|
104 | + */ |
|
105 | + public function addBodyListItem($text, $metaInfo = '', $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
106 | 106 | |
107 | - /** |
|
108 | - * Adds a button group of two buttons to the body of the email |
|
109 | - * |
|
110 | - * @param string $textLeft Text of left button |
|
111 | - * @param string $urlLeft URL of left button |
|
112 | - * @param string $textRight Text of right button |
|
113 | - * @param string $urlRight URL of right button |
|
114 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
115 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
116 | - * |
|
117 | - * @since 12.0.0 |
|
118 | - */ |
|
119 | - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
107 | + /** |
|
108 | + * Adds a button group of two buttons to the body of the email |
|
109 | + * |
|
110 | + * @param string $textLeft Text of left button |
|
111 | + * @param string $urlLeft URL of left button |
|
112 | + * @param string $textRight Text of right button |
|
113 | + * @param string $urlRight URL of right button |
|
114 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
115 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
116 | + * |
|
117 | + * @since 12.0.0 |
|
118 | + */ |
|
119 | + public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); |
|
120 | 120 | |
121 | - /** |
|
122 | - * Adds a button to the body of the email |
|
123 | - * |
|
124 | - * @param string $text Text of button |
|
125 | - * @param string $url URL of button |
|
126 | - * @param string $plainText Text of button in plain text version |
|
127 | - * if empty the $text is used, if false none will be used |
|
128 | - * |
|
129 | - * @since 12.0.0 |
|
130 | - */ |
|
131 | - public function addBodyButton($text, $url, $plainText = ''); |
|
121 | + /** |
|
122 | + * Adds a button to the body of the email |
|
123 | + * |
|
124 | + * @param string $text Text of button |
|
125 | + * @param string $url URL of button |
|
126 | + * @param string $plainText Text of button in plain text version |
|
127 | + * if empty the $text is used, if false none will be used |
|
128 | + * |
|
129 | + * @since 12.0.0 |
|
130 | + */ |
|
131 | + public function addBodyButton($text, $url, $plainText = ''); |
|
132 | 132 | |
133 | - /** |
|
134 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
135 | - * |
|
136 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
137 | - * |
|
138 | - * @since 12.0.0 |
|
139 | - */ |
|
140 | - public function addFooter($text = ''); |
|
133 | + /** |
|
134 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
135 | + * |
|
136 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
137 | + * |
|
138 | + * @since 12.0.0 |
|
139 | + */ |
|
140 | + public function addFooter($text = ''); |
|
141 | 141 | |
142 | - /** |
|
143 | - * Returns the rendered email subject as string |
|
144 | - * |
|
145 | - * @return string |
|
146 | - * |
|
147 | - * @since 13.0.0 |
|
148 | - */ |
|
149 | - public function renderSubject(); |
|
142 | + /** |
|
143 | + * Returns the rendered email subject as string |
|
144 | + * |
|
145 | + * @return string |
|
146 | + * |
|
147 | + * @since 13.0.0 |
|
148 | + */ |
|
149 | + public function renderSubject(); |
|
150 | 150 | |
151 | - /** |
|
152 | - * Returns the rendered HTML email as string |
|
153 | - * |
|
154 | - * @return string |
|
155 | - * |
|
156 | - * @since 12.0.0 |
|
157 | - */ |
|
158 | - public function renderHtml(); |
|
151 | + /** |
|
152 | + * Returns the rendered HTML email as string |
|
153 | + * |
|
154 | + * @return string |
|
155 | + * |
|
156 | + * @since 12.0.0 |
|
157 | + */ |
|
158 | + public function renderHtml(); |
|
159 | 159 | |
160 | - /** |
|
161 | - * Returns the rendered plain text email as string |
|
162 | - * |
|
163 | - * @return string |
|
164 | - * |
|
165 | - * @since 12.0.0 |
|
166 | - */ |
|
167 | - public function renderText(); |
|
160 | + /** |
|
161 | + * Returns the rendered plain text email as string |
|
162 | + * |
|
163 | + * @return string |
|
164 | + * |
|
165 | + * @since 12.0.0 |
|
166 | + */ |
|
167 | + public function renderText(); |
|
168 | 168 | } |
@@ -45,43 +45,43 @@ |
||
45 | 45 | * @since 8.1.0 |
46 | 46 | */ |
47 | 47 | interface IMailer { |
48 | - /** |
|
49 | - * Creates a new message object that can be passed to send() |
|
50 | - * |
|
51 | - * @return IMessage |
|
52 | - * @since 8.1.0 |
|
53 | - */ |
|
54 | - public function createMessage(); |
|
48 | + /** |
|
49 | + * Creates a new message object that can be passed to send() |
|
50 | + * |
|
51 | + * @return IMessage |
|
52 | + * @since 8.1.0 |
|
53 | + */ |
|
54 | + public function createMessage(); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Creates a new email template object |
|
58 | - * |
|
59 | - * @param string $emailId |
|
60 | - * @param array $data |
|
61 | - * @return IEMailTemplate |
|
62 | - * @since 12.0.0 Parameters added in 12.0.3 |
|
63 | - */ |
|
64 | - public function createEMailTemplate($emailId, array $data = []); |
|
56 | + /** |
|
57 | + * Creates a new email template object |
|
58 | + * |
|
59 | + * @param string $emailId |
|
60 | + * @param array $data |
|
61 | + * @return IEMailTemplate |
|
62 | + * @since 12.0.0 Parameters added in 12.0.3 |
|
63 | + */ |
|
64 | + public function createEMailTemplate($emailId, array $data = []); |
|
65 | 65 | |
66 | - /** |
|
67 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
68 | - * if no-one has been passed. |
|
69 | - * |
|
70 | - * @param IMessage $message Message to send |
|
71 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
72 | - * therefore should be considered |
|
73 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
74 | - * has been supplied.) |
|
75 | - * @since 8.1.0 |
|
76 | - */ |
|
77 | - public function send(IMessage $message); |
|
66 | + /** |
|
67 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
68 | + * if no-one has been passed. |
|
69 | + * |
|
70 | + * @param IMessage $message Message to send |
|
71 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
72 | + * therefore should be considered |
|
73 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
74 | + * has been supplied.) |
|
75 | + * @since 8.1.0 |
|
76 | + */ |
|
77 | + public function send(IMessage $message); |
|
78 | 78 | |
79 | - /** |
|
80 | - * Checks if an e-mail address is valid |
|
81 | - * |
|
82 | - * @param string $email Email address to be validated |
|
83 | - * @return bool True if the mail address is valid, false otherwise |
|
84 | - * @since 8.1.0 |
|
85 | - */ |
|
86 | - public function validateMailAddress($email); |
|
79 | + /** |
|
80 | + * Checks if an e-mail address is valid |
|
81 | + * |
|
82 | + * @param string $email Email address to be validated |
|
83 | + * @return bool True if the mail address is valid, false otherwise |
|
84 | + * @since 8.1.0 |
|
85 | + */ |
|
86 | + public function validateMailAddress($email); |
|
87 | 87 | } |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | $passwordPolicy = $this->getPasswordPolicy(); |
213 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
213 | + $passwordCharset = ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS; |
|
214 | 214 | $passwordLength = 8; |
215 | 215 | if (!empty($passwordPolicy)) { |
216 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
216 | + $passwordLength = (int) $passwordPolicy['minLength'] > 0 ? (int) $passwordPolicy['minLength'] : $passwordLength; |
|
217 | 217 | $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
218 | 218 | } |
219 | 219 | |
@@ -351,11 +351,11 @@ discard block |
||
351 | 351 | $share->getExpirationDate() |
352 | 352 | ); |
353 | 353 | } catch (HintException $hintException) { |
354 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
354 | + $this->logger->error('Failed to send share by mail: '.$hintException->getMessage()); |
|
355 | 355 | $this->removeShareFromTable($shareId); |
356 | 356 | throw $hintException; |
357 | 357 | } catch (\Exception $e) { |
358 | - $this->logger->error('Failed to send share by email: ' . $e->getMessage()); |
|
358 | + $this->logger->error('Failed to send share by email: '.$e->getMessage()); |
|
359 | 359 | $this->removeShareFromTable($shareId); |
360 | 360 | throw new HintException('Failed to send share by mail', |
361 | 361 | $this->l->t('Failed to send share by email')); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
397 | 397 | |
398 | 398 | $emailTemplate->addBodyText( |
399 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
399 | + $text.' '.$this->l->t('Click the button below to open it.'), |
|
400 | 400 | $text |
401 | 401 | ); |
402 | 402 | $emailTemplate->addBodyButton( |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | // The "Reply-To" is set to the sharer if an mail address is configured |
421 | 421 | // also the default footer contains a "Do not reply" which needs to be adjusted. |
422 | 422 | $initiatorEmail = $initiatorUser->getEMailAddress(); |
423 | - if($initiatorEmail !== null) { |
|
423 | + if ($initiatorEmail !== null) { |
|
424 | 424 | $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
425 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
425 | + $emailTemplate->addFooter($instanceName.($this->defaults->getSlogan() !== '' ? ' - '.$this->defaults->getSlogan() : '')); |
|
426 | 426 | } else { |
427 | 427 | $emailTemplate->addFooter(); |
428 | 428 | } |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
484 | 484 | if ($initiatorEmailAddress !== null) { |
485 | 485 | $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
486 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
486 | + $emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan()); |
|
487 | 487 | } else { |
488 | 488 | $emailTemplate->addFooter(); |
489 | 489 | } |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | ->orderBy('id'); |
579 | 579 | |
580 | 580 | $cursor = $qb->execute(); |
581 | - while($data = $cursor->fetch()) { |
|
581 | + while ($data = $cursor->fetch()) { |
|
582 | 582 | $children[] = $this->createShareObject($data); |
583 | 583 | } |
584 | 584 | $cursor->closeCursor(); |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | $qb->execute(); |
623 | 623 | $id = $qb->getLastInsertId(); |
624 | 624 | |
625 | - return (int)$id; |
|
625 | + return (int) $id; |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | /** |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | // a real password was given |
640 | 640 | $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
641 | 641 | |
642 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
642 | + if ($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
643 | 643 | $this->sendPassword($share, $plainTextPassword); |
644 | 644 | } |
645 | 645 | /* |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | |
734 | 734 | $cursor = $qb->execute(); |
735 | 735 | $shares = []; |
736 | - while($data = $cursor->fetch()) { |
|
736 | + while ($data = $cursor->fetch()) { |
|
737 | 737 | $shares[] = $this->createShareObject($data); |
738 | 738 | } |
739 | 739 | $cursor->closeCursor(); |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | ->execute(); |
786 | 786 | |
787 | 787 | $shares = []; |
788 | - while($data = $cursor->fetch()) { |
|
788 | + while ($data = $cursor->fetch()) { |
|
789 | 789 | $shares[] = $this->createShareObject($data); |
790 | 790 | } |
791 | 791 | $cursor->closeCursor(); |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | |
825 | 825 | $cursor = $qb->execute(); |
826 | 826 | |
827 | - while($data = $cursor->fetch()) { |
|
827 | + while ($data = $cursor->fetch()) { |
|
828 | 828 | $shares[] = $this->createShareObject($data); |
829 | 829 | } |
830 | 830 | $cursor->closeCursor(); |
@@ -887,15 +887,15 @@ discard block |
||
887 | 887 | protected function createShareObject($data) { |
888 | 888 | |
889 | 889 | $share = new Share($this->rootFolder, $this->userManager); |
890 | - $share->setId((int)$data['id']) |
|
891 | - ->setShareType((int)$data['share_type']) |
|
892 | - ->setPermissions((int)$data['permissions']) |
|
890 | + $share->setId((int) $data['id']) |
|
891 | + ->setShareType((int) $data['share_type']) |
|
892 | + ->setPermissions((int) $data['permissions']) |
|
893 | 893 | ->setTarget($data['file_target']) |
894 | - ->setMailSend((bool)$data['mail_send']) |
|
894 | + ->setMailSend((bool) $data['mail_send']) |
|
895 | 895 | ->setToken($data['token']); |
896 | 896 | |
897 | 897 | $shareTime = new \DateTime(); |
898 | - $shareTime->setTimestamp((int)$data['stime']); |
|
898 | + $shareTime->setTimestamp((int) $data['stime']); |
|
899 | 899 | $share->setShareTime($shareTime); |
900 | 900 | $share->setSharedWith($data['share_with']); |
901 | 901 | $share->setPassword($data['password']); |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | } else { |
907 | 907 | //OLD SHARE |
908 | 908 | $share->setSharedBy($data['uid_owner']); |
909 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
909 | + $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); |
|
910 | 910 | |
911 | 911 | $owner = $path->getOwner(); |
912 | 912 | $share->setShareOwner($owner->getUID()); |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | } |
920 | 920 | } |
921 | 921 | |
922 | - $share->setNodeId((int)$data['file_source']); |
|
922 | + $share->setNodeId((int) $data['file_source']); |
|
923 | 923 | $share->setNodeType($data['item_type']); |
924 | 924 | |
925 | 925 | $share->setProviderId($this->identifier()); |
@@ -1038,7 +1038,7 @@ discard block |
||
1038 | 1038 | ); |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1041 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1042 | 1042 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
1043 | 1043 | |
1044 | 1044 | $qb->orderBy('id'); |
@@ -53,1031 +53,1031 @@ |
||
53 | 53 | */ |
54 | 54 | class ShareByMailProvider implements IShareProvider { |
55 | 55 | |
56 | - /** @var IDBConnection */ |
|
57 | - private $dbConnection; |
|
58 | - |
|
59 | - /** @var ILogger */ |
|
60 | - private $logger; |
|
61 | - |
|
62 | - /** @var ISecureRandom */ |
|
63 | - private $secureRandom; |
|
64 | - |
|
65 | - /** @var IUserManager */ |
|
66 | - private $userManager; |
|
67 | - |
|
68 | - /** @var IRootFolder */ |
|
69 | - private $rootFolder; |
|
70 | - |
|
71 | - /** @var IL10N */ |
|
72 | - private $l; |
|
73 | - |
|
74 | - /** @var IMailer */ |
|
75 | - private $mailer; |
|
76 | - |
|
77 | - /** @var IURLGenerator */ |
|
78 | - private $urlGenerator; |
|
79 | - |
|
80 | - /** @var IManager */ |
|
81 | - private $activityManager; |
|
82 | - |
|
83 | - /** @var SettingsManager */ |
|
84 | - private $settingsManager; |
|
85 | - |
|
86 | - /** @var Defaults */ |
|
87 | - private $defaults; |
|
88 | - |
|
89 | - /** @var IHasher */ |
|
90 | - private $hasher; |
|
91 | - |
|
92 | - /** @var CapabilitiesManager */ |
|
93 | - private $capabilitiesManager; |
|
94 | - |
|
95 | - /** |
|
96 | - * Return the identifier of this provider. |
|
97 | - * |
|
98 | - * @return string Containing only [a-zA-Z0-9] |
|
99 | - */ |
|
100 | - public function identifier() { |
|
101 | - return 'ocMailShare'; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * DefaultShareProvider constructor. |
|
106 | - * |
|
107 | - * @param IDBConnection $connection |
|
108 | - * @param ISecureRandom $secureRandom |
|
109 | - * @param IUserManager $userManager |
|
110 | - * @param IRootFolder $rootFolder |
|
111 | - * @param IL10N $l |
|
112 | - * @param ILogger $logger |
|
113 | - * @param IMailer $mailer |
|
114 | - * @param IURLGenerator $urlGenerator |
|
115 | - * @param IManager $activityManager |
|
116 | - * @param SettingsManager $settingsManager |
|
117 | - * @param Defaults $defaults |
|
118 | - * @param IHasher $hasher |
|
119 | - * @param CapabilitiesManager $capabilitiesManager |
|
120 | - */ |
|
121 | - public function __construct( |
|
122 | - IDBConnection $connection, |
|
123 | - ISecureRandom $secureRandom, |
|
124 | - IUserManager $userManager, |
|
125 | - IRootFolder $rootFolder, |
|
126 | - IL10N $l, |
|
127 | - ILogger $logger, |
|
128 | - IMailer $mailer, |
|
129 | - IURLGenerator $urlGenerator, |
|
130 | - IManager $activityManager, |
|
131 | - SettingsManager $settingsManager, |
|
132 | - Defaults $defaults, |
|
133 | - IHasher $hasher, |
|
134 | - CapabilitiesManager $capabilitiesManager |
|
135 | - ) { |
|
136 | - $this->dbConnection = $connection; |
|
137 | - $this->secureRandom = $secureRandom; |
|
138 | - $this->userManager = $userManager; |
|
139 | - $this->rootFolder = $rootFolder; |
|
140 | - $this->l = $l; |
|
141 | - $this->logger = $logger; |
|
142 | - $this->mailer = $mailer; |
|
143 | - $this->urlGenerator = $urlGenerator; |
|
144 | - $this->activityManager = $activityManager; |
|
145 | - $this->settingsManager = $settingsManager; |
|
146 | - $this->defaults = $defaults; |
|
147 | - $this->hasher = $hasher; |
|
148 | - $this->capabilitiesManager = $capabilitiesManager; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Share a path |
|
153 | - * |
|
154 | - * @param IShare $share |
|
155 | - * @return IShare The share object |
|
156 | - * @throws ShareNotFound |
|
157 | - * @throws \Exception |
|
158 | - */ |
|
159 | - public function create(IShare $share) { |
|
160 | - |
|
161 | - $shareWith = $share->getSharedWith(); |
|
162 | - /* |
|
56 | + /** @var IDBConnection */ |
|
57 | + private $dbConnection; |
|
58 | + |
|
59 | + /** @var ILogger */ |
|
60 | + private $logger; |
|
61 | + |
|
62 | + /** @var ISecureRandom */ |
|
63 | + private $secureRandom; |
|
64 | + |
|
65 | + /** @var IUserManager */ |
|
66 | + private $userManager; |
|
67 | + |
|
68 | + /** @var IRootFolder */ |
|
69 | + private $rootFolder; |
|
70 | + |
|
71 | + /** @var IL10N */ |
|
72 | + private $l; |
|
73 | + |
|
74 | + /** @var IMailer */ |
|
75 | + private $mailer; |
|
76 | + |
|
77 | + /** @var IURLGenerator */ |
|
78 | + private $urlGenerator; |
|
79 | + |
|
80 | + /** @var IManager */ |
|
81 | + private $activityManager; |
|
82 | + |
|
83 | + /** @var SettingsManager */ |
|
84 | + private $settingsManager; |
|
85 | + |
|
86 | + /** @var Defaults */ |
|
87 | + private $defaults; |
|
88 | + |
|
89 | + /** @var IHasher */ |
|
90 | + private $hasher; |
|
91 | + |
|
92 | + /** @var CapabilitiesManager */ |
|
93 | + private $capabilitiesManager; |
|
94 | + |
|
95 | + /** |
|
96 | + * Return the identifier of this provider. |
|
97 | + * |
|
98 | + * @return string Containing only [a-zA-Z0-9] |
|
99 | + */ |
|
100 | + public function identifier() { |
|
101 | + return 'ocMailShare'; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * DefaultShareProvider constructor. |
|
106 | + * |
|
107 | + * @param IDBConnection $connection |
|
108 | + * @param ISecureRandom $secureRandom |
|
109 | + * @param IUserManager $userManager |
|
110 | + * @param IRootFolder $rootFolder |
|
111 | + * @param IL10N $l |
|
112 | + * @param ILogger $logger |
|
113 | + * @param IMailer $mailer |
|
114 | + * @param IURLGenerator $urlGenerator |
|
115 | + * @param IManager $activityManager |
|
116 | + * @param SettingsManager $settingsManager |
|
117 | + * @param Defaults $defaults |
|
118 | + * @param IHasher $hasher |
|
119 | + * @param CapabilitiesManager $capabilitiesManager |
|
120 | + */ |
|
121 | + public function __construct( |
|
122 | + IDBConnection $connection, |
|
123 | + ISecureRandom $secureRandom, |
|
124 | + IUserManager $userManager, |
|
125 | + IRootFolder $rootFolder, |
|
126 | + IL10N $l, |
|
127 | + ILogger $logger, |
|
128 | + IMailer $mailer, |
|
129 | + IURLGenerator $urlGenerator, |
|
130 | + IManager $activityManager, |
|
131 | + SettingsManager $settingsManager, |
|
132 | + Defaults $defaults, |
|
133 | + IHasher $hasher, |
|
134 | + CapabilitiesManager $capabilitiesManager |
|
135 | + ) { |
|
136 | + $this->dbConnection = $connection; |
|
137 | + $this->secureRandom = $secureRandom; |
|
138 | + $this->userManager = $userManager; |
|
139 | + $this->rootFolder = $rootFolder; |
|
140 | + $this->l = $l; |
|
141 | + $this->logger = $logger; |
|
142 | + $this->mailer = $mailer; |
|
143 | + $this->urlGenerator = $urlGenerator; |
|
144 | + $this->activityManager = $activityManager; |
|
145 | + $this->settingsManager = $settingsManager; |
|
146 | + $this->defaults = $defaults; |
|
147 | + $this->hasher = $hasher; |
|
148 | + $this->capabilitiesManager = $capabilitiesManager; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Share a path |
|
153 | + * |
|
154 | + * @param IShare $share |
|
155 | + * @return IShare The share object |
|
156 | + * @throws ShareNotFound |
|
157 | + * @throws \Exception |
|
158 | + */ |
|
159 | + public function create(IShare $share) { |
|
160 | + |
|
161 | + $shareWith = $share->getSharedWith(); |
|
162 | + /* |
|
163 | 163 | * Check if file is not already shared with the remote user |
164 | 164 | */ |
165 | - $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
166 | - if (!empty($alreadyShared)) { |
|
167 | - $message = 'Sharing %s failed, this item is already shared with %s'; |
|
168 | - $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
169 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
170 | - throw new \Exception($message_t); |
|
171 | - } |
|
172 | - |
|
173 | - // if the admin enforces a password for all mail shares we create a |
|
174 | - // random password and send it to the recipient |
|
175 | - $password = ''; |
|
176 | - $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
177 | - if ($passwordEnforced) { |
|
178 | - $password = $this->autoGeneratePassword($share); |
|
179 | - } |
|
180 | - |
|
181 | - $shareId = $this->createMailShare($share); |
|
182 | - $send = $this->sendPassword($share, $password); |
|
183 | - if ($passwordEnforced && $send === false) { |
|
184 | - $this->sendPasswordToOwner($share, $password); |
|
185 | - } |
|
186 | - |
|
187 | - $this->createShareActivity($share); |
|
188 | - $data = $this->getRawShare($shareId); |
|
189 | - |
|
190 | - return $this->createShareObject($data); |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * auto generate password in case of password enforcement on mail shares |
|
196 | - * |
|
197 | - * @param IShare $share |
|
198 | - * @return string |
|
199 | - * @throws \Exception |
|
200 | - */ |
|
201 | - protected function autoGeneratePassword($share) { |
|
202 | - $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
203 | - $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
204 | - $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
205 | - |
|
206 | - if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
207 | - throw new \Exception( |
|
208 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - $passwordPolicy = $this->getPasswordPolicy(); |
|
213 | - $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
214 | - $passwordLength = 8; |
|
215 | - if (!empty($passwordPolicy)) { |
|
216 | - $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
217 | - $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
218 | - } |
|
219 | - |
|
220 | - $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
221 | - |
|
222 | - $share->setPassword($this->hasher->hash($password)); |
|
223 | - |
|
224 | - return $password; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * get password policy |
|
229 | - * |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - protected function getPasswordPolicy() { |
|
233 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
234 | - if (isset($capabilities['password_policy'])) { |
|
235 | - return $capabilities['password_policy']; |
|
236 | - } |
|
237 | - |
|
238 | - return []; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * create activity if a file/folder was shared by mail |
|
243 | - * |
|
244 | - * @param IShare $share |
|
245 | - */ |
|
246 | - protected function createShareActivity(IShare $share) { |
|
247 | - |
|
248 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
249 | - |
|
250 | - $this->publishActivity( |
|
251 | - Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
252 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
253 | - $share->getSharedBy(), |
|
254 | - $share->getNode()->getId(), |
|
255 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
256 | - ); |
|
257 | - |
|
258 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
259 | - $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
260 | - $fileId = $share->getNode()->getId(); |
|
261 | - $nodes = $ownerFolder->getById($fileId); |
|
262 | - $ownerPath = $nodes[0]->getPath(); |
|
263 | - $this->publishActivity( |
|
264 | - Activity::SUBJECT_SHARED_EMAIL_BY, |
|
265 | - [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
266 | - $share->getShareOwner(), |
|
267 | - $fileId, |
|
268 | - $ownerFolder->getRelativePath($ownerPath) |
|
269 | - ); |
|
270 | - } |
|
271 | - |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * create activity if a file/folder was shared by mail |
|
276 | - * |
|
277 | - * @param IShare $share |
|
278 | - * @param string $sharedWith |
|
279 | - * @param bool $sendToSelf |
|
280 | - */ |
|
281 | - protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
282 | - |
|
283 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
284 | - |
|
285 | - if ($sendToSelf) { |
|
286 | - $this->publishActivity( |
|
287 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
288 | - [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
289 | - $share->getSharedBy(), |
|
290 | - $share->getNode()->getId(), |
|
291 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
292 | - ); |
|
293 | - } else { |
|
294 | - $this->publishActivity( |
|
295 | - Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
296 | - [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
297 | - $share->getSharedBy(), |
|
298 | - $share->getNode()->getId(), |
|
299 | - $userFolder->getRelativePath($share->getNode()->getPath()) |
|
300 | - ); |
|
301 | - } |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * publish activity if a file/folder was shared by mail |
|
307 | - * |
|
308 | - * @param $subject |
|
309 | - * @param $parameters |
|
310 | - * @param $affectedUser |
|
311 | - * @param $fileId |
|
312 | - * @param $filePath |
|
313 | - */ |
|
314 | - protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
315 | - $event = $this->activityManager->generateEvent(); |
|
316 | - $event->setApp('sharebymail') |
|
317 | - ->setType('shared') |
|
318 | - ->setSubject($subject, $parameters) |
|
319 | - ->setAffectedUser($affectedUser) |
|
320 | - ->setObject('files', $fileId, $filePath); |
|
321 | - $this->activityManager->publish($event); |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * @param IShare $share |
|
327 | - * @return int |
|
328 | - * @throws \Exception |
|
329 | - */ |
|
330 | - protected function createMailShare(IShare $share) { |
|
331 | - $share->setToken($this->generateToken()); |
|
332 | - $shareId = $this->addShareToDB( |
|
333 | - $share->getNodeId(), |
|
334 | - $share->getNodeType(), |
|
335 | - $share->getSharedWith(), |
|
336 | - $share->getSharedBy(), |
|
337 | - $share->getShareOwner(), |
|
338 | - $share->getPermissions(), |
|
339 | - $share->getToken(), |
|
340 | - $share->getPassword() |
|
341 | - ); |
|
342 | - |
|
343 | - try { |
|
344 | - $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
345 | - ['token' => $share->getToken()]); |
|
346 | - $this->sendMailNotification( |
|
347 | - $share->getNode()->getName(), |
|
348 | - $link, |
|
349 | - $share->getSharedBy(), |
|
350 | - $share->getSharedWith(), |
|
351 | - $share->getExpirationDate() |
|
352 | - ); |
|
353 | - } catch (HintException $hintException) { |
|
354 | - $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
355 | - $this->removeShareFromTable($shareId); |
|
356 | - throw $hintException; |
|
357 | - } catch (\Exception $e) { |
|
358 | - $this->logger->error('Failed to send share by email: ' . $e->getMessage()); |
|
359 | - $this->removeShareFromTable($shareId); |
|
360 | - throw new HintException('Failed to send share by mail', |
|
361 | - $this->l->t('Failed to send share by email')); |
|
362 | - } |
|
363 | - |
|
364 | - return $shareId; |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * @param string $filename |
|
370 | - * @param string $link |
|
371 | - * @param string $initiator |
|
372 | - * @param string $shareWith |
|
373 | - * @param \DateTime|null $expiration |
|
374 | - * @throws \Exception If mail couldn't be sent |
|
375 | - */ |
|
376 | - protected function sendMailNotification($filename, |
|
377 | - $link, |
|
378 | - $initiator, |
|
379 | - $shareWith, |
|
380 | - \DateTime $expiration = null) { |
|
381 | - $initiatorUser = $this->userManager->get($initiator); |
|
382 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
383 | - $message = $this->mailer->createMessage(); |
|
384 | - |
|
385 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientNotification', [ |
|
386 | - 'filename' => $filename, |
|
387 | - 'link' => $link, |
|
388 | - 'initiator' => $initiatorDisplayName, |
|
389 | - 'expiration' => $expiration, |
|
390 | - 'shareWith' => $shareWith, |
|
391 | - ]); |
|
392 | - |
|
393 | - $emailTemplate->setSubject($this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename))); |
|
394 | - $emailTemplate->addHeader(); |
|
395 | - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
396 | - $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
397 | - |
|
398 | - $emailTemplate->addBodyText( |
|
399 | - $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
400 | - $text |
|
401 | - ); |
|
402 | - $emailTemplate->addBodyButton( |
|
403 | - $this->l->t('Open »%s«', [$filename]), |
|
404 | - $link |
|
405 | - ); |
|
406 | - |
|
407 | - $message->setTo([$shareWith]); |
|
408 | - |
|
409 | - // The "From" contains the sharers name |
|
410 | - $instanceName = $this->defaults->getName(); |
|
411 | - $senderName = $this->l->t( |
|
412 | - '%s via %s', |
|
413 | - [ |
|
414 | - $initiatorDisplayName, |
|
415 | - $instanceName |
|
416 | - ] |
|
417 | - ); |
|
418 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
419 | - |
|
420 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
421 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
422 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
423 | - if($initiatorEmail !== null) { |
|
424 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
425 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
426 | - } else { |
|
427 | - $emailTemplate->addFooter(); |
|
428 | - } |
|
429 | - |
|
430 | - $message->useTemplate($emailTemplate); |
|
431 | - $this->mailer->send($message); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * send password to recipient of a mail share |
|
436 | - * |
|
437 | - * @param IShare $share |
|
438 | - * @param string $password |
|
439 | - * @return bool |
|
440 | - */ |
|
441 | - protected function sendPassword(IShare $share, $password) { |
|
442 | - |
|
443 | - $filename = $share->getNode()->getName(); |
|
444 | - $initiator = $share->getSharedBy(); |
|
445 | - $shareWith = $share->getSharedWith(); |
|
446 | - |
|
447 | - if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
448 | - return false; |
|
449 | - } |
|
450 | - |
|
451 | - $initiatorUser = $this->userManager->get($initiator); |
|
452 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
453 | - $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
454 | - |
|
455 | - $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
456 | - $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
457 | - |
|
458 | - $message = $this->mailer->createMessage(); |
|
459 | - |
|
460 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientPasswordNotification', [ |
|
461 | - 'filename' => $filename, |
|
462 | - 'password' => $password, |
|
463 | - 'initiator' => $initiatorDisplayName, |
|
464 | - 'initiatorEmail' => $initiatorEmailAddress, |
|
465 | - 'shareWith' => $shareWith, |
|
466 | - ]); |
|
467 | - |
|
468 | - $emailTemplate->setSubject($this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName])); |
|
469 | - $emailTemplate->addHeader(); |
|
470 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
471 | - $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
472 | - $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
473 | - |
|
474 | - // The "From" contains the sharers name |
|
475 | - $instanceName = $this->defaults->getName(); |
|
476 | - $senderName = $this->l->t( |
|
477 | - '%s via %s', |
|
478 | - [ |
|
479 | - $initiatorDisplayName, |
|
480 | - $instanceName |
|
481 | - ] |
|
482 | - ); |
|
483 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
484 | - if ($initiatorEmailAddress !== null) { |
|
485 | - $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
486 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
487 | - } else { |
|
488 | - $emailTemplate->addFooter(); |
|
489 | - } |
|
490 | - |
|
491 | - $message->setTo([$shareWith]); |
|
492 | - $message->useTemplate($emailTemplate); |
|
493 | - $this->mailer->send($message); |
|
494 | - |
|
495 | - $this->createPasswordSendActivity($share, $shareWith, false); |
|
496 | - |
|
497 | - return true; |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * send auto generated password to the owner. This happens if the admin enforces |
|
502 | - * a password for mail shares and forbid to send the password by mail to the recipient |
|
503 | - * |
|
504 | - * @param IShare $share |
|
505 | - * @param string $password |
|
506 | - * @return bool |
|
507 | - * @throws \Exception |
|
508 | - */ |
|
509 | - protected function sendPasswordToOwner(IShare $share, $password) { |
|
510 | - |
|
511 | - $filename = $share->getNode()->getName(); |
|
512 | - $initiator = $this->userManager->get($share->getSharedBy()); |
|
513 | - $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
514 | - $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
515 | - $shareWith = $share->getSharedWith(); |
|
516 | - |
|
517 | - if ($initiatorEMailAddress === null) { |
|
518 | - throw new \Exception( |
|
519 | - $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
520 | - ); |
|
521 | - } |
|
522 | - |
|
523 | - $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
524 | - |
|
525 | - $message = $this->mailer->createMessage(); |
|
526 | - $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [ |
|
527 | - 'filename' => $filename, |
|
528 | - 'password' => $password, |
|
529 | - 'initiator' => $initiatorDisplayName, |
|
530 | - 'initiatorEmail' => $initiatorEMailAddress, |
|
531 | - 'shareWith' => $shareWith, |
|
532 | - ]); |
|
533 | - |
|
534 | - $emailTemplate->setSubject($this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith])); |
|
535 | - $emailTemplate->addHeader(); |
|
536 | - $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
537 | - $emailTemplate->addBodyText($bodyPart); |
|
538 | - $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
539 | - $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
540 | - $emailTemplate->addFooter(); |
|
541 | - |
|
542 | - if ($initiatorEMailAddress) { |
|
543 | - $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
544 | - } |
|
545 | - $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
546 | - $message->useTemplate($emailTemplate); |
|
547 | - $this->mailer->send($message); |
|
548 | - |
|
549 | - $this->createPasswordSendActivity($share, $shareWith, true); |
|
550 | - |
|
551 | - return true; |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * generate share token |
|
556 | - * |
|
557 | - * @return string |
|
558 | - */ |
|
559 | - protected function generateToken($size = 15) { |
|
560 | - $token = $this->secureRandom->generate($size, ISecureRandom::CHAR_HUMAN_READABLE); |
|
561 | - return $token; |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Get all children of this share |
|
566 | - * |
|
567 | - * @param IShare $parent |
|
568 | - * @return IShare[] |
|
569 | - */ |
|
570 | - public function getChildren(IShare $parent) { |
|
571 | - $children = []; |
|
572 | - |
|
573 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
574 | - $qb->select('*') |
|
575 | - ->from('share') |
|
576 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
577 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
578 | - ->orderBy('id'); |
|
579 | - |
|
580 | - $cursor = $qb->execute(); |
|
581 | - while($data = $cursor->fetch()) { |
|
582 | - $children[] = $this->createShareObject($data); |
|
583 | - } |
|
584 | - $cursor->closeCursor(); |
|
585 | - |
|
586 | - return $children; |
|
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * add share to the database and return the ID |
|
591 | - * |
|
592 | - * @param int $itemSource |
|
593 | - * @param string $itemType |
|
594 | - * @param string $shareWith |
|
595 | - * @param string $sharedBy |
|
596 | - * @param string $uidOwner |
|
597 | - * @param int $permissions |
|
598 | - * @param string $token |
|
599 | - * @return int |
|
600 | - */ |
|
601 | - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
602 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
603 | - $qb->insert('share') |
|
604 | - ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
605 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
606 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
607 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
608 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
609 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
610 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
611 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
612 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
613 | - ->setValue('password', $qb->createNamedParameter($password)) |
|
614 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
615 | - |
|
616 | - /* |
|
165 | + $alreadyShared = $this->getSharedWith($shareWith, \OCP\Share::SHARE_TYPE_EMAIL, $share->getNode(), 1, 0); |
|
166 | + if (!empty($alreadyShared)) { |
|
167 | + $message = 'Sharing %s failed, this item is already shared with %s'; |
|
168 | + $message_t = $this->l->t('Sharing %s failed, this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
169 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
170 | + throw new \Exception($message_t); |
|
171 | + } |
|
172 | + |
|
173 | + // if the admin enforces a password for all mail shares we create a |
|
174 | + // random password and send it to the recipient |
|
175 | + $password = ''; |
|
176 | + $passwordEnforced = $this->settingsManager->enforcePasswordProtection(); |
|
177 | + if ($passwordEnforced) { |
|
178 | + $password = $this->autoGeneratePassword($share); |
|
179 | + } |
|
180 | + |
|
181 | + $shareId = $this->createMailShare($share); |
|
182 | + $send = $this->sendPassword($share, $password); |
|
183 | + if ($passwordEnforced && $send === false) { |
|
184 | + $this->sendPasswordToOwner($share, $password); |
|
185 | + } |
|
186 | + |
|
187 | + $this->createShareActivity($share); |
|
188 | + $data = $this->getRawShare($shareId); |
|
189 | + |
|
190 | + return $this->createShareObject($data); |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * auto generate password in case of password enforcement on mail shares |
|
196 | + * |
|
197 | + * @param IShare $share |
|
198 | + * @return string |
|
199 | + * @throws \Exception |
|
200 | + */ |
|
201 | + protected function autoGeneratePassword($share) { |
|
202 | + $initiatorUser = $this->userManager->get($share->getSharedBy()); |
|
203 | + $initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
204 | + $allowPasswordByMail = $this->settingsManager->sendPasswordByMail(); |
|
205 | + |
|
206 | + if ($initiatorEMailAddress === null && !$allowPasswordByMail) { |
|
207 | + throw new \Exception( |
|
208 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + $passwordPolicy = $this->getPasswordPolicy(); |
|
213 | + $passwordCharset = ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS; |
|
214 | + $passwordLength = 8; |
|
215 | + if (!empty($passwordPolicy)) { |
|
216 | + $passwordLength = (int)$passwordPolicy['minLength'] > 0 ? (int)$passwordPolicy['minLength'] : $passwordLength; |
|
217 | + $passwordCharset .= $passwordPolicy['enforceSpecialCharacters'] ? ISecureRandom::CHAR_SYMBOLS : ''; |
|
218 | + } |
|
219 | + |
|
220 | + $password = $this->secureRandom->generate($passwordLength, $passwordCharset); |
|
221 | + |
|
222 | + $share->setPassword($this->hasher->hash($password)); |
|
223 | + |
|
224 | + return $password; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * get password policy |
|
229 | + * |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + protected function getPasswordPolicy() { |
|
233 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
234 | + if (isset($capabilities['password_policy'])) { |
|
235 | + return $capabilities['password_policy']; |
|
236 | + } |
|
237 | + |
|
238 | + return []; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * create activity if a file/folder was shared by mail |
|
243 | + * |
|
244 | + * @param IShare $share |
|
245 | + */ |
|
246 | + protected function createShareActivity(IShare $share) { |
|
247 | + |
|
248 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
249 | + |
|
250 | + $this->publishActivity( |
|
251 | + Activity::SUBJECT_SHARED_EMAIL_SELF, |
|
252 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()], |
|
253 | + $share->getSharedBy(), |
|
254 | + $share->getNode()->getId(), |
|
255 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
256 | + ); |
|
257 | + |
|
258 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
259 | + $ownerFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
260 | + $fileId = $share->getNode()->getId(); |
|
261 | + $nodes = $ownerFolder->getById($fileId); |
|
262 | + $ownerPath = $nodes[0]->getPath(); |
|
263 | + $this->publishActivity( |
|
264 | + Activity::SUBJECT_SHARED_EMAIL_BY, |
|
265 | + [$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()], |
|
266 | + $share->getShareOwner(), |
|
267 | + $fileId, |
|
268 | + $ownerFolder->getRelativePath($ownerPath) |
|
269 | + ); |
|
270 | + } |
|
271 | + |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * create activity if a file/folder was shared by mail |
|
276 | + * |
|
277 | + * @param IShare $share |
|
278 | + * @param string $sharedWith |
|
279 | + * @param bool $sendToSelf |
|
280 | + */ |
|
281 | + protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) { |
|
282 | + |
|
283 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
284 | + |
|
285 | + if ($sendToSelf) { |
|
286 | + $this->publishActivity( |
|
287 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF, |
|
288 | + [$userFolder->getRelativePath($share->getNode()->getPath())], |
|
289 | + $share->getSharedBy(), |
|
290 | + $share->getNode()->getId(), |
|
291 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
292 | + ); |
|
293 | + } else { |
|
294 | + $this->publishActivity( |
|
295 | + Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND, |
|
296 | + [$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith], |
|
297 | + $share->getSharedBy(), |
|
298 | + $share->getNode()->getId(), |
|
299 | + $userFolder->getRelativePath($share->getNode()->getPath()) |
|
300 | + ); |
|
301 | + } |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * publish activity if a file/folder was shared by mail |
|
307 | + * |
|
308 | + * @param $subject |
|
309 | + * @param $parameters |
|
310 | + * @param $affectedUser |
|
311 | + * @param $fileId |
|
312 | + * @param $filePath |
|
313 | + */ |
|
314 | + protected function publishActivity($subject, $parameters, $affectedUser, $fileId, $filePath) { |
|
315 | + $event = $this->activityManager->generateEvent(); |
|
316 | + $event->setApp('sharebymail') |
|
317 | + ->setType('shared') |
|
318 | + ->setSubject($subject, $parameters) |
|
319 | + ->setAffectedUser($affectedUser) |
|
320 | + ->setObject('files', $fileId, $filePath); |
|
321 | + $this->activityManager->publish($event); |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * @param IShare $share |
|
327 | + * @return int |
|
328 | + * @throws \Exception |
|
329 | + */ |
|
330 | + protected function createMailShare(IShare $share) { |
|
331 | + $share->setToken($this->generateToken()); |
|
332 | + $shareId = $this->addShareToDB( |
|
333 | + $share->getNodeId(), |
|
334 | + $share->getNodeType(), |
|
335 | + $share->getSharedWith(), |
|
336 | + $share->getSharedBy(), |
|
337 | + $share->getShareOwner(), |
|
338 | + $share->getPermissions(), |
|
339 | + $share->getToken(), |
|
340 | + $share->getPassword() |
|
341 | + ); |
|
342 | + |
|
343 | + try { |
|
344 | + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', |
|
345 | + ['token' => $share->getToken()]); |
|
346 | + $this->sendMailNotification( |
|
347 | + $share->getNode()->getName(), |
|
348 | + $link, |
|
349 | + $share->getSharedBy(), |
|
350 | + $share->getSharedWith(), |
|
351 | + $share->getExpirationDate() |
|
352 | + ); |
|
353 | + } catch (HintException $hintException) { |
|
354 | + $this->logger->error('Failed to send share by mail: ' . $hintException->getMessage()); |
|
355 | + $this->removeShareFromTable($shareId); |
|
356 | + throw $hintException; |
|
357 | + } catch (\Exception $e) { |
|
358 | + $this->logger->error('Failed to send share by email: ' . $e->getMessage()); |
|
359 | + $this->removeShareFromTable($shareId); |
|
360 | + throw new HintException('Failed to send share by mail', |
|
361 | + $this->l->t('Failed to send share by email')); |
|
362 | + } |
|
363 | + |
|
364 | + return $shareId; |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * @param string $filename |
|
370 | + * @param string $link |
|
371 | + * @param string $initiator |
|
372 | + * @param string $shareWith |
|
373 | + * @param \DateTime|null $expiration |
|
374 | + * @throws \Exception If mail couldn't be sent |
|
375 | + */ |
|
376 | + protected function sendMailNotification($filename, |
|
377 | + $link, |
|
378 | + $initiator, |
|
379 | + $shareWith, |
|
380 | + \DateTime $expiration = null) { |
|
381 | + $initiatorUser = $this->userManager->get($initiator); |
|
382 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
383 | + $message = $this->mailer->createMessage(); |
|
384 | + |
|
385 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientNotification', [ |
|
386 | + 'filename' => $filename, |
|
387 | + 'link' => $link, |
|
388 | + 'initiator' => $initiatorDisplayName, |
|
389 | + 'expiration' => $expiration, |
|
390 | + 'shareWith' => $shareWith, |
|
391 | + ]); |
|
392 | + |
|
393 | + $emailTemplate->setSubject($this->l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename))); |
|
394 | + $emailTemplate->addHeader(); |
|
395 | + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
396 | + $text = $this->l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
397 | + |
|
398 | + $emailTemplate->addBodyText( |
|
399 | + $text . ' ' . $this->l->t('Click the button below to open it.'), |
|
400 | + $text |
|
401 | + ); |
|
402 | + $emailTemplate->addBodyButton( |
|
403 | + $this->l->t('Open »%s«', [$filename]), |
|
404 | + $link |
|
405 | + ); |
|
406 | + |
|
407 | + $message->setTo([$shareWith]); |
|
408 | + |
|
409 | + // The "From" contains the sharers name |
|
410 | + $instanceName = $this->defaults->getName(); |
|
411 | + $senderName = $this->l->t( |
|
412 | + '%s via %s', |
|
413 | + [ |
|
414 | + $initiatorDisplayName, |
|
415 | + $instanceName |
|
416 | + ] |
|
417 | + ); |
|
418 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
419 | + |
|
420 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
421 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
422 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
423 | + if($initiatorEmail !== null) { |
|
424 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
425 | + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
426 | + } else { |
|
427 | + $emailTemplate->addFooter(); |
|
428 | + } |
|
429 | + |
|
430 | + $message->useTemplate($emailTemplate); |
|
431 | + $this->mailer->send($message); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * send password to recipient of a mail share |
|
436 | + * |
|
437 | + * @param IShare $share |
|
438 | + * @param string $password |
|
439 | + * @return bool |
|
440 | + */ |
|
441 | + protected function sendPassword(IShare $share, $password) { |
|
442 | + |
|
443 | + $filename = $share->getNode()->getName(); |
|
444 | + $initiator = $share->getSharedBy(); |
|
445 | + $shareWith = $share->getSharedWith(); |
|
446 | + |
|
447 | + if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) { |
|
448 | + return false; |
|
449 | + } |
|
450 | + |
|
451 | + $initiatorUser = $this->userManager->get($initiator); |
|
452 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
453 | + $initiatorEmailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; |
|
454 | + |
|
455 | + $plainBodyPart = $this->l->t("%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n", [$initiatorDisplayName, $filename]); |
|
456 | + $htmlBodyPart = $this->l->t('%s shared »%s« with you. You should have already received a separate mail with a link to access it.', [$initiatorDisplayName, $filename]); |
|
457 | + |
|
458 | + $message = $this->mailer->createMessage(); |
|
459 | + |
|
460 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.RecipientPasswordNotification', [ |
|
461 | + 'filename' => $filename, |
|
462 | + 'password' => $password, |
|
463 | + 'initiator' => $initiatorDisplayName, |
|
464 | + 'initiatorEmail' => $initiatorEmailAddress, |
|
465 | + 'shareWith' => $shareWith, |
|
466 | + ]); |
|
467 | + |
|
468 | + $emailTemplate->setSubject($this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName])); |
|
469 | + $emailTemplate->addHeader(); |
|
470 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
471 | + $emailTemplate->addBodyText($htmlBodyPart, $plainBodyPart); |
|
472 | + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); |
|
473 | + |
|
474 | + // The "From" contains the sharers name |
|
475 | + $instanceName = $this->defaults->getName(); |
|
476 | + $senderName = $this->l->t( |
|
477 | + '%s via %s', |
|
478 | + [ |
|
479 | + $initiatorDisplayName, |
|
480 | + $instanceName |
|
481 | + ] |
|
482 | + ); |
|
483 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
484 | + if ($initiatorEmailAddress !== null) { |
|
485 | + $message->setReplyTo([$initiatorEmailAddress => $initiatorDisplayName]); |
|
486 | + $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
487 | + } else { |
|
488 | + $emailTemplate->addFooter(); |
|
489 | + } |
|
490 | + |
|
491 | + $message->setTo([$shareWith]); |
|
492 | + $message->useTemplate($emailTemplate); |
|
493 | + $this->mailer->send($message); |
|
494 | + |
|
495 | + $this->createPasswordSendActivity($share, $shareWith, false); |
|
496 | + |
|
497 | + return true; |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * send auto generated password to the owner. This happens if the admin enforces |
|
502 | + * a password for mail shares and forbid to send the password by mail to the recipient |
|
503 | + * |
|
504 | + * @param IShare $share |
|
505 | + * @param string $password |
|
506 | + * @return bool |
|
507 | + * @throws \Exception |
|
508 | + */ |
|
509 | + protected function sendPasswordToOwner(IShare $share, $password) { |
|
510 | + |
|
511 | + $filename = $share->getNode()->getName(); |
|
512 | + $initiator = $this->userManager->get($share->getSharedBy()); |
|
513 | + $initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null; |
|
514 | + $initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy(); |
|
515 | + $shareWith = $share->getSharedWith(); |
|
516 | + |
|
517 | + if ($initiatorEMailAddress === null) { |
|
518 | + throw new \Exception( |
|
519 | + $this->l->t("We can't send you the auto-generated password. Please set a valid email address in your personal settings and try again.") |
|
520 | + ); |
|
521 | + } |
|
522 | + |
|
523 | + $bodyPart = $this->l->t("You just shared »%s« with %s. The share was already send to the recipient. Due to the security policies defined by the administrator of %s each share needs to be protected by password and it is not allowed to send the password directly to the recipient. Therefore you need to forward the password manually to the recipient.", [$filename, $shareWith, $this->defaults->getName()]); |
|
524 | + |
|
525 | + $message = $this->mailer->createMessage(); |
|
526 | + $emailTemplate = $this->mailer->createEMailTemplate('sharebymail.OwnerPasswordNotification', [ |
|
527 | + 'filename' => $filename, |
|
528 | + 'password' => $password, |
|
529 | + 'initiator' => $initiatorDisplayName, |
|
530 | + 'initiatorEmail' => $initiatorEMailAddress, |
|
531 | + 'shareWith' => $shareWith, |
|
532 | + ]); |
|
533 | + |
|
534 | + $emailTemplate->setSubject($this->l->t('Password to access »%s« shared with %s', [$filename, $shareWith])); |
|
535 | + $emailTemplate->addHeader(); |
|
536 | + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename]), false); |
|
537 | + $emailTemplate->addBodyText($bodyPart); |
|
538 | + $emailTemplate->addBodyText($this->l->t('This is the password: %s', [$password])); |
|
539 | + $emailTemplate->addBodyText($this->l->t('You can choose a different password at any time in the share dialog.')); |
|
540 | + $emailTemplate->addFooter(); |
|
541 | + |
|
542 | + if ($initiatorEMailAddress) { |
|
543 | + $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); |
|
544 | + } |
|
545 | + $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); |
|
546 | + $message->useTemplate($emailTemplate); |
|
547 | + $this->mailer->send($message); |
|
548 | + |
|
549 | + $this->createPasswordSendActivity($share, $shareWith, true); |
|
550 | + |
|
551 | + return true; |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * generate share token |
|
556 | + * |
|
557 | + * @return string |
|
558 | + */ |
|
559 | + protected function generateToken($size = 15) { |
|
560 | + $token = $this->secureRandom->generate($size, ISecureRandom::CHAR_HUMAN_READABLE); |
|
561 | + return $token; |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Get all children of this share |
|
566 | + * |
|
567 | + * @param IShare $parent |
|
568 | + * @return IShare[] |
|
569 | + */ |
|
570 | + public function getChildren(IShare $parent) { |
|
571 | + $children = []; |
|
572 | + |
|
573 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
574 | + $qb->select('*') |
|
575 | + ->from('share') |
|
576 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
577 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
578 | + ->orderBy('id'); |
|
579 | + |
|
580 | + $cursor = $qb->execute(); |
|
581 | + while($data = $cursor->fetch()) { |
|
582 | + $children[] = $this->createShareObject($data); |
|
583 | + } |
|
584 | + $cursor->closeCursor(); |
|
585 | + |
|
586 | + return $children; |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * add share to the database and return the ID |
|
591 | + * |
|
592 | + * @param int $itemSource |
|
593 | + * @param string $itemType |
|
594 | + * @param string $shareWith |
|
595 | + * @param string $sharedBy |
|
596 | + * @param string $uidOwner |
|
597 | + * @param int $permissions |
|
598 | + * @param string $token |
|
599 | + * @return int |
|
600 | + */ |
|
601 | + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password) { |
|
602 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
603 | + $qb->insert('share') |
|
604 | + ->setValue('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
605 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
606 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
607 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
608 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
609 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
610 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
611 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
612 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
613 | + ->setValue('password', $qb->createNamedParameter($password)) |
|
614 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
615 | + |
|
616 | + /* |
|
617 | 617 | * Added to fix https://github.com/owncloud/core/issues/22215 |
618 | 618 | * Can be removed once we get rid of ajax/share.php |
619 | 619 | */ |
620 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
620 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
621 | 621 | |
622 | - $qb->execute(); |
|
623 | - $id = $qb->getLastInsertId(); |
|
622 | + $qb->execute(); |
|
623 | + $id = $qb->getLastInsertId(); |
|
624 | 624 | |
625 | - return (int)$id; |
|
626 | - } |
|
625 | + return (int)$id; |
|
626 | + } |
|
627 | 627 | |
628 | - /** |
|
629 | - * Update a share |
|
630 | - * |
|
631 | - * @param IShare $share |
|
632 | - * @param string|null $plainTextPassword |
|
633 | - * @return IShare The share object |
|
634 | - */ |
|
635 | - public function update(IShare $share, $plainTextPassword = null) { |
|
628 | + /** |
|
629 | + * Update a share |
|
630 | + * |
|
631 | + * @param IShare $share |
|
632 | + * @param string|null $plainTextPassword |
|
633 | + * @return IShare The share object |
|
634 | + */ |
|
635 | + public function update(IShare $share, $plainTextPassword = null) { |
|
636 | 636 | |
637 | - $originalShare = $this->getShareById($share->getId()); |
|
637 | + $originalShare = $this->getShareById($share->getId()); |
|
638 | 638 | |
639 | - // a real password was given |
|
640 | - $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
639 | + // a real password was given |
|
640 | + $validPassword = $plainTextPassword !== null && $plainTextPassword !== ''; |
|
641 | 641 | |
642 | - if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
643 | - $this->sendPassword($share, $plainTextPassword); |
|
644 | - } |
|
645 | - /* |
|
642 | + if($validPassword && $originalShare->getPassword() !== $share->getPassword()) { |
|
643 | + $this->sendPassword($share, $plainTextPassword); |
|
644 | + } |
|
645 | + /* |
|
646 | 646 | * We allow updating the permissions and password of mail shares |
647 | 647 | */ |
648 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
649 | - $qb->update('share') |
|
650 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
651 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
652 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
653 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
654 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
655 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
656 | - ->execute(); |
|
657 | - |
|
658 | - return $share; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * @inheritdoc |
|
663 | - */ |
|
664 | - public function move(IShare $share, $recipient) { |
|
665 | - /** |
|
666 | - * nothing to do here, mail shares are only outgoing shares |
|
667 | - */ |
|
668 | - return $share; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Delete a share (owner unShares the file) |
|
673 | - * |
|
674 | - * @param IShare $share |
|
675 | - */ |
|
676 | - public function delete(IShare $share) { |
|
677 | - $this->removeShareFromTable($share->getId()); |
|
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * @inheritdoc |
|
682 | - */ |
|
683 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
684 | - // nothing to do here, mail shares are only outgoing shares |
|
685 | - return; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @inheritdoc |
|
690 | - */ |
|
691 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
692 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
693 | - $qb->select('*') |
|
694 | - ->from('share'); |
|
695 | - |
|
696 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
697 | - |
|
698 | - /** |
|
699 | - * Reshares for this user are shares where they are the owner. |
|
700 | - */ |
|
701 | - if ($reshares === false) { |
|
702 | - //Special case for old shares created via the web UI |
|
703 | - $or1 = $qb->expr()->andX( |
|
704 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
705 | - $qb->expr()->isNull('uid_initiator') |
|
706 | - ); |
|
707 | - |
|
708 | - $qb->andWhere( |
|
709 | - $qb->expr()->orX( |
|
710 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
711 | - $or1 |
|
712 | - ) |
|
713 | - ); |
|
714 | - } else { |
|
715 | - $qb->andWhere( |
|
716 | - $qb->expr()->orX( |
|
717 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
718 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
719 | - ) |
|
720 | - ); |
|
721 | - } |
|
722 | - |
|
723 | - if ($node !== null) { |
|
724 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
725 | - } |
|
726 | - |
|
727 | - if ($limit !== -1) { |
|
728 | - $qb->setMaxResults($limit); |
|
729 | - } |
|
730 | - |
|
731 | - $qb->setFirstResult($offset); |
|
732 | - $qb->orderBy('id'); |
|
733 | - |
|
734 | - $cursor = $qb->execute(); |
|
735 | - $shares = []; |
|
736 | - while($data = $cursor->fetch()) { |
|
737 | - $shares[] = $this->createShareObject($data); |
|
738 | - } |
|
739 | - $cursor->closeCursor(); |
|
740 | - |
|
741 | - return $shares; |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * @inheritdoc |
|
746 | - */ |
|
747 | - public function getShareById($id, $recipientId = null) { |
|
748 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
749 | - |
|
750 | - $qb->select('*') |
|
751 | - ->from('share') |
|
752 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
753 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
754 | - |
|
755 | - $cursor = $qb->execute(); |
|
756 | - $data = $cursor->fetch(); |
|
757 | - $cursor->closeCursor(); |
|
758 | - |
|
759 | - if ($data === false) { |
|
760 | - throw new ShareNotFound(); |
|
761 | - } |
|
762 | - |
|
763 | - try { |
|
764 | - $share = $this->createShareObject($data); |
|
765 | - } catch (InvalidShare $e) { |
|
766 | - throw new ShareNotFound(); |
|
767 | - } |
|
768 | - |
|
769 | - return $share; |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Get shares for a given path |
|
774 | - * |
|
775 | - * @param \OCP\Files\Node $path |
|
776 | - * @return IShare[] |
|
777 | - */ |
|
778 | - public function getSharesByPath(Node $path) { |
|
779 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
780 | - |
|
781 | - $cursor = $qb->select('*') |
|
782 | - ->from('share') |
|
783 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
784 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
785 | - ->execute(); |
|
786 | - |
|
787 | - $shares = []; |
|
788 | - while($data = $cursor->fetch()) { |
|
789 | - $shares[] = $this->createShareObject($data); |
|
790 | - } |
|
791 | - $cursor->closeCursor(); |
|
792 | - |
|
793 | - return $shares; |
|
794 | - } |
|
795 | - |
|
796 | - /** |
|
797 | - * @inheritdoc |
|
798 | - */ |
|
799 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
800 | - /** @var IShare[] $shares */ |
|
801 | - $shares = []; |
|
802 | - |
|
803 | - //Get shares directly with this user |
|
804 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
805 | - $qb->select('*') |
|
806 | - ->from('share'); |
|
807 | - |
|
808 | - // Order by id |
|
809 | - $qb->orderBy('id'); |
|
810 | - |
|
811 | - // Set limit and offset |
|
812 | - if ($limit !== -1) { |
|
813 | - $qb->setMaxResults($limit); |
|
814 | - } |
|
815 | - $qb->setFirstResult($offset); |
|
816 | - |
|
817 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
818 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
819 | - |
|
820 | - // Filter by node if provided |
|
821 | - if ($node !== null) { |
|
822 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
823 | - } |
|
824 | - |
|
825 | - $cursor = $qb->execute(); |
|
826 | - |
|
827 | - while($data = $cursor->fetch()) { |
|
828 | - $shares[] = $this->createShareObject($data); |
|
829 | - } |
|
830 | - $cursor->closeCursor(); |
|
831 | - |
|
832 | - |
|
833 | - return $shares; |
|
834 | - } |
|
835 | - |
|
836 | - /** |
|
837 | - * Get a share by token |
|
838 | - * |
|
839 | - * @param string $token |
|
840 | - * @return IShare |
|
841 | - * @throws ShareNotFound |
|
842 | - */ |
|
843 | - public function getShareByToken($token) { |
|
844 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
845 | - |
|
846 | - $cursor = $qb->select('*') |
|
847 | - ->from('share') |
|
848 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
849 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
850 | - ->execute(); |
|
851 | - |
|
852 | - $data = $cursor->fetch(); |
|
853 | - |
|
854 | - if ($data === false) { |
|
855 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
856 | - } |
|
857 | - |
|
858 | - try { |
|
859 | - $share = $this->createShareObject($data); |
|
860 | - } catch (InvalidShare $e) { |
|
861 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
862 | - } |
|
863 | - |
|
864 | - return $share; |
|
865 | - } |
|
866 | - |
|
867 | - /** |
|
868 | - * remove share from table |
|
869 | - * |
|
870 | - * @param string $shareId |
|
871 | - */ |
|
872 | - protected function removeShareFromTable($shareId) { |
|
873 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
874 | - $qb->delete('share') |
|
875 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
876 | - $qb->execute(); |
|
877 | - } |
|
878 | - |
|
879 | - /** |
|
880 | - * Create a share object from an database row |
|
881 | - * |
|
882 | - * @param array $data |
|
883 | - * @return IShare |
|
884 | - * @throws InvalidShare |
|
885 | - * @throws ShareNotFound |
|
886 | - */ |
|
887 | - protected function createShareObject($data) { |
|
888 | - |
|
889 | - $share = new Share($this->rootFolder, $this->userManager); |
|
890 | - $share->setId((int)$data['id']) |
|
891 | - ->setShareType((int)$data['share_type']) |
|
892 | - ->setPermissions((int)$data['permissions']) |
|
893 | - ->setTarget($data['file_target']) |
|
894 | - ->setMailSend((bool)$data['mail_send']) |
|
895 | - ->setToken($data['token']); |
|
896 | - |
|
897 | - $shareTime = new \DateTime(); |
|
898 | - $shareTime->setTimestamp((int)$data['stime']); |
|
899 | - $share->setShareTime($shareTime); |
|
900 | - $share->setSharedWith($data['share_with']); |
|
901 | - $share->setPassword($data['password']); |
|
902 | - |
|
903 | - if ($data['uid_initiator'] !== null) { |
|
904 | - $share->setShareOwner($data['uid_owner']); |
|
905 | - $share->setSharedBy($data['uid_initiator']); |
|
906 | - } else { |
|
907 | - //OLD SHARE |
|
908 | - $share->setSharedBy($data['uid_owner']); |
|
909 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
910 | - |
|
911 | - $owner = $path->getOwner(); |
|
912 | - $share->setShareOwner($owner->getUID()); |
|
913 | - } |
|
914 | - |
|
915 | - if ($data['expiration'] !== null) { |
|
916 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
917 | - if ($expiration !== false) { |
|
918 | - $share->setExpirationDate($expiration); |
|
919 | - } |
|
920 | - } |
|
921 | - |
|
922 | - $share->setNodeId((int)$data['file_source']); |
|
923 | - $share->setNodeType($data['item_type']); |
|
924 | - |
|
925 | - $share->setProviderId($this->identifier()); |
|
926 | - |
|
927 | - return $share; |
|
928 | - } |
|
929 | - |
|
930 | - /** |
|
931 | - * Get the node with file $id for $user |
|
932 | - * |
|
933 | - * @param string $userId |
|
934 | - * @param int $id |
|
935 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
936 | - * @throws InvalidShare |
|
937 | - */ |
|
938 | - private function getNode($userId, $id) { |
|
939 | - try { |
|
940 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
941 | - } catch (NoUserException $e) { |
|
942 | - throw new InvalidShare(); |
|
943 | - } |
|
944 | - |
|
945 | - $nodes = $userFolder->getById($id); |
|
946 | - |
|
947 | - if (empty($nodes)) { |
|
948 | - throw new InvalidShare(); |
|
949 | - } |
|
950 | - |
|
951 | - return $nodes[0]; |
|
952 | - } |
|
953 | - |
|
954 | - /** |
|
955 | - * A user is deleted from the system |
|
956 | - * So clean up the relevant shares. |
|
957 | - * |
|
958 | - * @param string $uid |
|
959 | - * @param int $shareType |
|
960 | - */ |
|
961 | - public function userDeleted($uid, $shareType) { |
|
962 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
963 | - |
|
964 | - $qb->delete('share') |
|
965 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
966 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
967 | - ->execute(); |
|
968 | - } |
|
969 | - |
|
970 | - /** |
|
971 | - * This provider does not support group shares |
|
972 | - * |
|
973 | - * @param string $gid |
|
974 | - */ |
|
975 | - public function groupDeleted($gid) { |
|
976 | - return; |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * This provider does not support group shares |
|
981 | - * |
|
982 | - * @param string $uid |
|
983 | - * @param string $gid |
|
984 | - */ |
|
985 | - public function userDeletedFromGroup($uid, $gid) { |
|
986 | - return; |
|
987 | - } |
|
988 | - |
|
989 | - /** |
|
990 | - * get database row of a give share |
|
991 | - * |
|
992 | - * @param $id |
|
993 | - * @return array |
|
994 | - * @throws ShareNotFound |
|
995 | - */ |
|
996 | - protected function getRawShare($id) { |
|
997 | - |
|
998 | - // Now fetch the inserted share and create a complete share object |
|
999 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1000 | - $qb->select('*') |
|
1001 | - ->from('share') |
|
1002 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
1003 | - |
|
1004 | - $cursor = $qb->execute(); |
|
1005 | - $data = $cursor->fetch(); |
|
1006 | - $cursor->closeCursor(); |
|
1007 | - |
|
1008 | - if ($data === false) { |
|
1009 | - throw new ShareNotFound; |
|
1010 | - } |
|
1011 | - |
|
1012 | - return $data; |
|
1013 | - } |
|
1014 | - |
|
1015 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
1016 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1017 | - $qb->select('*') |
|
1018 | - ->from('share', 's') |
|
1019 | - ->andWhere($qb->expr()->orX( |
|
1020 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1021 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1022 | - )) |
|
1023 | - ->andWhere( |
|
1024 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
1025 | - ); |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Reshares for this user are shares where they are the owner. |
|
1029 | - */ |
|
1030 | - if ($reshares === false) { |
|
1031 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
1032 | - } else { |
|
1033 | - $qb->andWhere( |
|
1034 | - $qb->expr()->orX( |
|
1035 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
1036 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
1037 | - ) |
|
1038 | - ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1042 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1043 | - |
|
1044 | - $qb->orderBy('id'); |
|
1045 | - |
|
1046 | - $cursor = $qb->execute(); |
|
1047 | - $shares = []; |
|
1048 | - while ($data = $cursor->fetch()) { |
|
1049 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1050 | - } |
|
1051 | - $cursor->closeCursor(); |
|
1052 | - |
|
1053 | - return $shares; |
|
1054 | - } |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * @inheritdoc |
|
1058 | - */ |
|
1059 | - public function getAccessList($nodes, $currentAccess) { |
|
1060 | - $ids = []; |
|
1061 | - foreach ($nodes as $node) { |
|
1062 | - $ids[] = $node->getId(); |
|
1063 | - } |
|
1064 | - |
|
1065 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
1066 | - $qb->select('share_with') |
|
1067 | - ->from('share') |
|
1068 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1069 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1070 | - ->andWhere($qb->expr()->orX( |
|
1071 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1072 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1073 | - )) |
|
1074 | - ->setMaxResults(1); |
|
1075 | - $cursor = $qb->execute(); |
|
1076 | - |
|
1077 | - $mail = $cursor->fetch() !== false; |
|
1078 | - $cursor->closeCursor(); |
|
1079 | - |
|
1080 | - return ['public' => $mail]; |
|
1081 | - } |
|
648 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
649 | + $qb->update('share') |
|
650 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
651 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
652 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
653 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
654 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
655 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
656 | + ->execute(); |
|
657 | + |
|
658 | + return $share; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * @inheritdoc |
|
663 | + */ |
|
664 | + public function move(IShare $share, $recipient) { |
|
665 | + /** |
|
666 | + * nothing to do here, mail shares are only outgoing shares |
|
667 | + */ |
|
668 | + return $share; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Delete a share (owner unShares the file) |
|
673 | + * |
|
674 | + * @param IShare $share |
|
675 | + */ |
|
676 | + public function delete(IShare $share) { |
|
677 | + $this->removeShareFromTable($share->getId()); |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * @inheritdoc |
|
682 | + */ |
|
683 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
684 | + // nothing to do here, mail shares are only outgoing shares |
|
685 | + return; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @inheritdoc |
|
690 | + */ |
|
691 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
692 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
693 | + $qb->select('*') |
|
694 | + ->from('share'); |
|
695 | + |
|
696 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
697 | + |
|
698 | + /** |
|
699 | + * Reshares for this user are shares where they are the owner. |
|
700 | + */ |
|
701 | + if ($reshares === false) { |
|
702 | + //Special case for old shares created via the web UI |
|
703 | + $or1 = $qb->expr()->andX( |
|
704 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
705 | + $qb->expr()->isNull('uid_initiator') |
|
706 | + ); |
|
707 | + |
|
708 | + $qb->andWhere( |
|
709 | + $qb->expr()->orX( |
|
710 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
711 | + $or1 |
|
712 | + ) |
|
713 | + ); |
|
714 | + } else { |
|
715 | + $qb->andWhere( |
|
716 | + $qb->expr()->orX( |
|
717 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
718 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
719 | + ) |
|
720 | + ); |
|
721 | + } |
|
722 | + |
|
723 | + if ($node !== null) { |
|
724 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
725 | + } |
|
726 | + |
|
727 | + if ($limit !== -1) { |
|
728 | + $qb->setMaxResults($limit); |
|
729 | + } |
|
730 | + |
|
731 | + $qb->setFirstResult($offset); |
|
732 | + $qb->orderBy('id'); |
|
733 | + |
|
734 | + $cursor = $qb->execute(); |
|
735 | + $shares = []; |
|
736 | + while($data = $cursor->fetch()) { |
|
737 | + $shares[] = $this->createShareObject($data); |
|
738 | + } |
|
739 | + $cursor->closeCursor(); |
|
740 | + |
|
741 | + return $shares; |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * @inheritdoc |
|
746 | + */ |
|
747 | + public function getShareById($id, $recipientId = null) { |
|
748 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
749 | + |
|
750 | + $qb->select('*') |
|
751 | + ->from('share') |
|
752 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
753 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
754 | + |
|
755 | + $cursor = $qb->execute(); |
|
756 | + $data = $cursor->fetch(); |
|
757 | + $cursor->closeCursor(); |
|
758 | + |
|
759 | + if ($data === false) { |
|
760 | + throw new ShareNotFound(); |
|
761 | + } |
|
762 | + |
|
763 | + try { |
|
764 | + $share = $this->createShareObject($data); |
|
765 | + } catch (InvalidShare $e) { |
|
766 | + throw new ShareNotFound(); |
|
767 | + } |
|
768 | + |
|
769 | + return $share; |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Get shares for a given path |
|
774 | + * |
|
775 | + * @param \OCP\Files\Node $path |
|
776 | + * @return IShare[] |
|
777 | + */ |
|
778 | + public function getSharesByPath(Node $path) { |
|
779 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
780 | + |
|
781 | + $cursor = $qb->select('*') |
|
782 | + ->from('share') |
|
783 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
784 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
785 | + ->execute(); |
|
786 | + |
|
787 | + $shares = []; |
|
788 | + while($data = $cursor->fetch()) { |
|
789 | + $shares[] = $this->createShareObject($data); |
|
790 | + } |
|
791 | + $cursor->closeCursor(); |
|
792 | + |
|
793 | + return $shares; |
|
794 | + } |
|
795 | + |
|
796 | + /** |
|
797 | + * @inheritdoc |
|
798 | + */ |
|
799 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
800 | + /** @var IShare[] $shares */ |
|
801 | + $shares = []; |
|
802 | + |
|
803 | + //Get shares directly with this user |
|
804 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
805 | + $qb->select('*') |
|
806 | + ->from('share'); |
|
807 | + |
|
808 | + // Order by id |
|
809 | + $qb->orderBy('id'); |
|
810 | + |
|
811 | + // Set limit and offset |
|
812 | + if ($limit !== -1) { |
|
813 | + $qb->setMaxResults($limit); |
|
814 | + } |
|
815 | + $qb->setFirstResult($offset); |
|
816 | + |
|
817 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))); |
|
818 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
819 | + |
|
820 | + // Filter by node if provided |
|
821 | + if ($node !== null) { |
|
822 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
823 | + } |
|
824 | + |
|
825 | + $cursor = $qb->execute(); |
|
826 | + |
|
827 | + while($data = $cursor->fetch()) { |
|
828 | + $shares[] = $this->createShareObject($data); |
|
829 | + } |
|
830 | + $cursor->closeCursor(); |
|
831 | + |
|
832 | + |
|
833 | + return $shares; |
|
834 | + } |
|
835 | + |
|
836 | + /** |
|
837 | + * Get a share by token |
|
838 | + * |
|
839 | + * @param string $token |
|
840 | + * @return IShare |
|
841 | + * @throws ShareNotFound |
|
842 | + */ |
|
843 | + public function getShareByToken($token) { |
|
844 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
845 | + |
|
846 | + $cursor = $qb->select('*') |
|
847 | + ->from('share') |
|
848 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
849 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
850 | + ->execute(); |
|
851 | + |
|
852 | + $data = $cursor->fetch(); |
|
853 | + |
|
854 | + if ($data === false) { |
|
855 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
856 | + } |
|
857 | + |
|
858 | + try { |
|
859 | + $share = $this->createShareObject($data); |
|
860 | + } catch (InvalidShare $e) { |
|
861 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
862 | + } |
|
863 | + |
|
864 | + return $share; |
|
865 | + } |
|
866 | + |
|
867 | + /** |
|
868 | + * remove share from table |
|
869 | + * |
|
870 | + * @param string $shareId |
|
871 | + */ |
|
872 | + protected function removeShareFromTable($shareId) { |
|
873 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
874 | + $qb->delete('share') |
|
875 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
876 | + $qb->execute(); |
|
877 | + } |
|
878 | + |
|
879 | + /** |
|
880 | + * Create a share object from an database row |
|
881 | + * |
|
882 | + * @param array $data |
|
883 | + * @return IShare |
|
884 | + * @throws InvalidShare |
|
885 | + * @throws ShareNotFound |
|
886 | + */ |
|
887 | + protected function createShareObject($data) { |
|
888 | + |
|
889 | + $share = new Share($this->rootFolder, $this->userManager); |
|
890 | + $share->setId((int)$data['id']) |
|
891 | + ->setShareType((int)$data['share_type']) |
|
892 | + ->setPermissions((int)$data['permissions']) |
|
893 | + ->setTarget($data['file_target']) |
|
894 | + ->setMailSend((bool)$data['mail_send']) |
|
895 | + ->setToken($data['token']); |
|
896 | + |
|
897 | + $shareTime = new \DateTime(); |
|
898 | + $shareTime->setTimestamp((int)$data['stime']); |
|
899 | + $share->setShareTime($shareTime); |
|
900 | + $share->setSharedWith($data['share_with']); |
|
901 | + $share->setPassword($data['password']); |
|
902 | + |
|
903 | + if ($data['uid_initiator'] !== null) { |
|
904 | + $share->setShareOwner($data['uid_owner']); |
|
905 | + $share->setSharedBy($data['uid_initiator']); |
|
906 | + } else { |
|
907 | + //OLD SHARE |
|
908 | + $share->setSharedBy($data['uid_owner']); |
|
909 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
910 | + |
|
911 | + $owner = $path->getOwner(); |
|
912 | + $share->setShareOwner($owner->getUID()); |
|
913 | + } |
|
914 | + |
|
915 | + if ($data['expiration'] !== null) { |
|
916 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
917 | + if ($expiration !== false) { |
|
918 | + $share->setExpirationDate($expiration); |
|
919 | + } |
|
920 | + } |
|
921 | + |
|
922 | + $share->setNodeId((int)$data['file_source']); |
|
923 | + $share->setNodeType($data['item_type']); |
|
924 | + |
|
925 | + $share->setProviderId($this->identifier()); |
|
926 | + |
|
927 | + return $share; |
|
928 | + } |
|
929 | + |
|
930 | + /** |
|
931 | + * Get the node with file $id for $user |
|
932 | + * |
|
933 | + * @param string $userId |
|
934 | + * @param int $id |
|
935 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
936 | + * @throws InvalidShare |
|
937 | + */ |
|
938 | + private function getNode($userId, $id) { |
|
939 | + try { |
|
940 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
941 | + } catch (NoUserException $e) { |
|
942 | + throw new InvalidShare(); |
|
943 | + } |
|
944 | + |
|
945 | + $nodes = $userFolder->getById($id); |
|
946 | + |
|
947 | + if (empty($nodes)) { |
|
948 | + throw new InvalidShare(); |
|
949 | + } |
|
950 | + |
|
951 | + return $nodes[0]; |
|
952 | + } |
|
953 | + |
|
954 | + /** |
|
955 | + * A user is deleted from the system |
|
956 | + * So clean up the relevant shares. |
|
957 | + * |
|
958 | + * @param string $uid |
|
959 | + * @param int $shareType |
|
960 | + */ |
|
961 | + public function userDeleted($uid, $shareType) { |
|
962 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
963 | + |
|
964 | + $qb->delete('share') |
|
965 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
966 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
967 | + ->execute(); |
|
968 | + } |
|
969 | + |
|
970 | + /** |
|
971 | + * This provider does not support group shares |
|
972 | + * |
|
973 | + * @param string $gid |
|
974 | + */ |
|
975 | + public function groupDeleted($gid) { |
|
976 | + return; |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * This provider does not support group shares |
|
981 | + * |
|
982 | + * @param string $uid |
|
983 | + * @param string $gid |
|
984 | + */ |
|
985 | + public function userDeletedFromGroup($uid, $gid) { |
|
986 | + return; |
|
987 | + } |
|
988 | + |
|
989 | + /** |
|
990 | + * get database row of a give share |
|
991 | + * |
|
992 | + * @param $id |
|
993 | + * @return array |
|
994 | + * @throws ShareNotFound |
|
995 | + */ |
|
996 | + protected function getRawShare($id) { |
|
997 | + |
|
998 | + // Now fetch the inserted share and create a complete share object |
|
999 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1000 | + $qb->select('*') |
|
1001 | + ->from('share') |
|
1002 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
1003 | + |
|
1004 | + $cursor = $qb->execute(); |
|
1005 | + $data = $cursor->fetch(); |
|
1006 | + $cursor->closeCursor(); |
|
1007 | + |
|
1008 | + if ($data === false) { |
|
1009 | + throw new ShareNotFound; |
|
1010 | + } |
|
1011 | + |
|
1012 | + return $data; |
|
1013 | + } |
|
1014 | + |
|
1015 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
1016 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1017 | + $qb->select('*') |
|
1018 | + ->from('share', 's') |
|
1019 | + ->andWhere($qb->expr()->orX( |
|
1020 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1021 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1022 | + )) |
|
1023 | + ->andWhere( |
|
1024 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)) |
|
1025 | + ); |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Reshares for this user are shares where they are the owner. |
|
1029 | + */ |
|
1030 | + if ($reshares === false) { |
|
1031 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
1032 | + } else { |
|
1033 | + $qb->andWhere( |
|
1034 | + $qb->expr()->orX( |
|
1035 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
1036 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
1037 | + ) |
|
1038 | + ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
1042 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
1043 | + |
|
1044 | + $qb->orderBy('id'); |
|
1045 | + |
|
1046 | + $cursor = $qb->execute(); |
|
1047 | + $shares = []; |
|
1048 | + while ($data = $cursor->fetch()) { |
|
1049 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
1050 | + } |
|
1051 | + $cursor->closeCursor(); |
|
1052 | + |
|
1053 | + return $shares; |
|
1054 | + } |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * @inheritdoc |
|
1058 | + */ |
|
1059 | + public function getAccessList($nodes, $currentAccess) { |
|
1060 | + $ids = []; |
|
1061 | + foreach ($nodes as $node) { |
|
1062 | + $ids[] = $node->getId(); |
|
1063 | + } |
|
1064 | + |
|
1065 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
1066 | + $qb->select('share_with') |
|
1067 | + ->from('share') |
|
1068 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))) |
|
1069 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1070 | + ->andWhere($qb->expr()->orX( |
|
1071 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1072 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1073 | + )) |
|
1074 | + ->setMaxResults(1); |
|
1075 | + $cursor = $qb->execute(); |
|
1076 | + |
|
1077 | + $mail = $cursor->fetch() !== false; |
|
1078 | + $cursor->closeCursor(); |
|
1079 | + |
|
1080 | + return ['public' => $mail]; |
|
1081 | + } |
|
1082 | 1082 | |
1083 | 1083 | } |
@@ -33,135 +33,135 @@ |
||
33 | 33 | use OCP\Security\ISecureRandom; |
34 | 34 | |
35 | 35 | class NewUserMailHelper { |
36 | - /** @var Defaults */ |
|
37 | - private $themingDefaults; |
|
38 | - /** @var IURLGenerator */ |
|
39 | - private $urlGenerator; |
|
40 | - /** @var IL10N */ |
|
41 | - private $l10n; |
|
42 | - /** @var IMailer */ |
|
43 | - private $mailer; |
|
44 | - /** @var ISecureRandom */ |
|
45 | - private $secureRandom; |
|
46 | - /** @var ITimeFactory */ |
|
47 | - private $timeFactory; |
|
48 | - /** @var IConfig */ |
|
49 | - private $config; |
|
50 | - /** @var ICrypto */ |
|
51 | - private $crypto; |
|
52 | - /** @var string */ |
|
53 | - private $fromAddress; |
|
36 | + /** @var Defaults */ |
|
37 | + private $themingDefaults; |
|
38 | + /** @var IURLGenerator */ |
|
39 | + private $urlGenerator; |
|
40 | + /** @var IL10N */ |
|
41 | + private $l10n; |
|
42 | + /** @var IMailer */ |
|
43 | + private $mailer; |
|
44 | + /** @var ISecureRandom */ |
|
45 | + private $secureRandom; |
|
46 | + /** @var ITimeFactory */ |
|
47 | + private $timeFactory; |
|
48 | + /** @var IConfig */ |
|
49 | + private $config; |
|
50 | + /** @var ICrypto */ |
|
51 | + private $crypto; |
|
52 | + /** @var string */ |
|
53 | + private $fromAddress; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param Defaults $themingDefaults |
|
57 | - * @param IURLGenerator $urlGenerator |
|
58 | - * @param IL10N $l10n |
|
59 | - * @param IMailer $mailer |
|
60 | - * @param ISecureRandom $secureRandom |
|
61 | - * @param ITimeFactory $timeFactory |
|
62 | - * @param IConfig $config |
|
63 | - * @param ICrypto $crypto |
|
64 | - * @param string $fromAddress |
|
65 | - */ |
|
66 | - public function __construct(Defaults $themingDefaults, |
|
67 | - IURLGenerator $urlGenerator, |
|
68 | - IL10N $l10n, |
|
69 | - IMailer $mailer, |
|
70 | - ISecureRandom $secureRandom, |
|
71 | - ITimeFactory $timeFactory, |
|
72 | - IConfig $config, |
|
73 | - ICrypto $crypto, |
|
74 | - $fromAddress) { |
|
75 | - $this->themingDefaults = $themingDefaults; |
|
76 | - $this->urlGenerator = $urlGenerator; |
|
77 | - $this->l10n = $l10n; |
|
78 | - $this->mailer = $mailer; |
|
79 | - $this->secureRandom = $secureRandom; |
|
80 | - $this->timeFactory = $timeFactory; |
|
81 | - $this->config = $config; |
|
82 | - $this->crypto = $crypto; |
|
83 | - $this->fromAddress = $fromAddress; |
|
84 | - } |
|
55 | + /** |
|
56 | + * @param Defaults $themingDefaults |
|
57 | + * @param IURLGenerator $urlGenerator |
|
58 | + * @param IL10N $l10n |
|
59 | + * @param IMailer $mailer |
|
60 | + * @param ISecureRandom $secureRandom |
|
61 | + * @param ITimeFactory $timeFactory |
|
62 | + * @param IConfig $config |
|
63 | + * @param ICrypto $crypto |
|
64 | + * @param string $fromAddress |
|
65 | + */ |
|
66 | + public function __construct(Defaults $themingDefaults, |
|
67 | + IURLGenerator $urlGenerator, |
|
68 | + IL10N $l10n, |
|
69 | + IMailer $mailer, |
|
70 | + ISecureRandom $secureRandom, |
|
71 | + ITimeFactory $timeFactory, |
|
72 | + IConfig $config, |
|
73 | + ICrypto $crypto, |
|
74 | + $fromAddress) { |
|
75 | + $this->themingDefaults = $themingDefaults; |
|
76 | + $this->urlGenerator = $urlGenerator; |
|
77 | + $this->l10n = $l10n; |
|
78 | + $this->mailer = $mailer; |
|
79 | + $this->secureRandom = $secureRandom; |
|
80 | + $this->timeFactory = $timeFactory; |
|
81 | + $this->config = $config; |
|
82 | + $this->crypto = $crypto; |
|
83 | + $this->fromAddress = $fromAddress; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Set the IL10N object |
|
88 | - * |
|
89 | - * @param IL10N $l10n |
|
90 | - */ |
|
91 | - public function setL10N(IL10N $l10n) { |
|
92 | - $this->l10n = $l10n; |
|
93 | - } |
|
86 | + /** |
|
87 | + * Set the IL10N object |
|
88 | + * |
|
89 | + * @param IL10N $l10n |
|
90 | + */ |
|
91 | + public function setL10N(IL10N $l10n) { |
|
92 | + $this->l10n = $l10n; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param IUser $user |
|
97 | - * @param bool $generatePasswordResetToken |
|
98 | - * @return IEMailTemplate |
|
99 | - */ |
|
100 | - public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
101 | - if ($generatePasswordResetToken) { |
|
102 | - $token = $this->secureRandom->generate( |
|
103 | - 21, |
|
104 | - ISecureRandom::CHAR_DIGITS . |
|
105 | - ISecureRandom::CHAR_LOWER . |
|
106 | - ISecureRandom::CHAR_UPPER |
|
107 | - ); |
|
108 | - $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
109 | - $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
110 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
111 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
112 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
113 | - } else { |
|
114 | - $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
115 | - } |
|
116 | - $displayName = $user->getDisplayName(); |
|
117 | - $userId = $user->getUID(); |
|
95 | + /** |
|
96 | + * @param IUser $user |
|
97 | + * @param bool $generatePasswordResetToken |
|
98 | + * @return IEMailTemplate |
|
99 | + */ |
|
100 | + public function generateTemplate(IUser $user, $generatePasswordResetToken = false) { |
|
101 | + if ($generatePasswordResetToken) { |
|
102 | + $token = $this->secureRandom->generate( |
|
103 | + 21, |
|
104 | + ISecureRandom::CHAR_DIGITS . |
|
105 | + ISecureRandom::CHAR_LOWER . |
|
106 | + ISecureRandom::CHAR_UPPER |
|
107 | + ); |
|
108 | + $tokenValue = $this->timeFactory->getTime() . ':' . $token; |
|
109 | + $mailAddress = (null !== $user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
110 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $mailAddress . $this->config->getSystemValue('secret')); |
|
111 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
112 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
113 | + } else { |
|
114 | + $link = $this->urlGenerator->getAbsoluteURL('/'); |
|
115 | + } |
|
116 | + $displayName = $user->getDisplayName(); |
|
117 | + $userId = $user->getUID(); |
|
118 | 118 | |
119 | - $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ |
|
120 | - 'link' => $link, |
|
121 | - 'displayname' => $displayName, |
|
122 | - 'userid' => $userId, |
|
123 | - 'instancename' => $this->themingDefaults->getName(), |
|
124 | - 'resetTokenGenerated' => $generatePasswordResetToken, |
|
125 | - ]); |
|
119 | + $emailTemplate = $this->mailer->createEMailTemplate('settings.Welcome', [ |
|
120 | + 'link' => $link, |
|
121 | + 'displayname' => $displayName, |
|
122 | + 'userid' => $userId, |
|
123 | + 'instancename' => $this->themingDefaults->getName(), |
|
124 | + 'resetTokenGenerated' => $generatePasswordResetToken, |
|
125 | + ]); |
|
126 | 126 | |
127 | - $emailTemplate->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
128 | - $emailTemplate->addHeader(); |
|
129 | - if ($displayName === $userId) { |
|
130 | - $emailTemplate->addHeading($this->l10n->t('Welcome aboard')); |
|
131 | - } else { |
|
132 | - $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName])); |
|
133 | - } |
|
134 | - $emailTemplate->addBodyText($this->l10n->t('You now have an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
135 | - $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userId])); |
|
136 | - if ($generatePasswordResetToken) { |
|
137 | - $leftButtonText = $this->l10n->t('Set your password'); |
|
138 | - } else { |
|
139 | - $leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
140 | - } |
|
141 | - $emailTemplate->addBodyButtonGroup( |
|
142 | - $leftButtonText, |
|
143 | - $link, |
|
144 | - $this->l10n->t('Install Client'), |
|
145 | - 'https://nextcloud.com/install/#install-clients' |
|
146 | - ); |
|
147 | - $emailTemplate->addFooter(); |
|
127 | + $emailTemplate->setSubject($this->l10n->t('Your %s account was created', [$this->themingDefaults->getName()])); |
|
128 | + $emailTemplate->addHeader(); |
|
129 | + if ($displayName === $userId) { |
|
130 | + $emailTemplate->addHeading($this->l10n->t('Welcome aboard')); |
|
131 | + } else { |
|
132 | + $emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName])); |
|
133 | + } |
|
134 | + $emailTemplate->addBodyText($this->l10n->t('You now have an %s account, you can add, protect, and share your data.', [$this->themingDefaults->getName()])); |
|
135 | + $emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$userId])); |
|
136 | + if ($generatePasswordResetToken) { |
|
137 | + $leftButtonText = $this->l10n->t('Set your password'); |
|
138 | + } else { |
|
139 | + $leftButtonText = $this->l10n->t('Go to %s', [$this->themingDefaults->getName()]); |
|
140 | + } |
|
141 | + $emailTemplate->addBodyButtonGroup( |
|
142 | + $leftButtonText, |
|
143 | + $link, |
|
144 | + $this->l10n->t('Install Client'), |
|
145 | + 'https://nextcloud.com/install/#install-clients' |
|
146 | + ); |
|
147 | + $emailTemplate->addFooter(); |
|
148 | 148 | |
149 | - return $emailTemplate; |
|
150 | - } |
|
149 | + return $emailTemplate; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Sends a welcome mail to $user |
|
154 | - * |
|
155 | - * @param IUser $user |
|
156 | - * @param IEmailTemplate $emailTemplate |
|
157 | - * @throws \Exception If mail could not be sent |
|
158 | - */ |
|
159 | - public function sendMail(IUser $user, |
|
160 | - IEMailTemplate $emailTemplate) { |
|
161 | - $message = $this->mailer->createMessage(); |
|
162 | - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
163 | - $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
164 | - $message->useTemplate($emailTemplate); |
|
165 | - $this->mailer->send($message); |
|
166 | - } |
|
152 | + /** |
|
153 | + * Sends a welcome mail to $user |
|
154 | + * |
|
155 | + * @param IUser $user |
|
156 | + * @param IEmailTemplate $emailTemplate |
|
157 | + * @throws \Exception If mail could not be sent |
|
158 | + */ |
|
159 | + public function sendMail(IUser $user, |
|
160 | + IEMailTemplate $emailTemplate) { |
|
161 | + $message = $this->mailer->createMessage(); |
|
162 | + $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); |
|
163 | + $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); |
|
164 | + $message->useTemplate($emailTemplate); |
|
165 | + $this->mailer->send($message); |
|
166 | + } |
|
167 | 167 | } |
@@ -39,138 +39,138 @@ |
||
39 | 39 | */ |
40 | 40 | class MailSettingsController extends Controller { |
41 | 41 | |
42 | - /** @var IL10N */ |
|
43 | - private $l10n; |
|
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
46 | - /** @var IUserSession */ |
|
47 | - private $userSession; |
|
48 | - /** @var IMailer */ |
|
49 | - private $mailer; |
|
50 | - /** @var string */ |
|
51 | - private $defaultMailAddress; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $appName |
|
55 | - * @param IRequest $request |
|
56 | - * @param IL10N $l10n |
|
57 | - * @param IConfig $config |
|
58 | - * @param IUserSession $userSession |
|
59 | - * @param IMailer $mailer |
|
60 | - * @param string $fromMailAddress |
|
61 | - */ |
|
62 | - public function __construct($appName, |
|
63 | - IRequest $request, |
|
64 | - IL10N $l10n, |
|
65 | - IConfig $config, |
|
66 | - IUserSession $userSession, |
|
67 | - IMailer $mailer, |
|
68 | - $fromMailAddress) { |
|
69 | - parent::__construct($appName, $request); |
|
70 | - $this->l10n = $l10n; |
|
71 | - $this->config = $config; |
|
72 | - $this->userSession = $userSession; |
|
73 | - $this->mailer = $mailer; |
|
74 | - $this->defaultMailAddress = $fromMailAddress; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Sets the email settings |
|
79 | - * |
|
80 | - * @PasswordConfirmationRequired |
|
81 | - * |
|
82 | - * @param string $mail_domain |
|
83 | - * @param string $mail_from_address |
|
84 | - * @param string $mail_smtpmode |
|
85 | - * @param string $mail_smtpsecure |
|
86 | - * @param string $mail_smtphost |
|
87 | - * @param string $mail_smtpauthtype |
|
88 | - * @param int $mail_smtpauth |
|
89 | - * @param string $mail_smtpport |
|
90 | - * @return DataResponse |
|
91 | - */ |
|
92 | - public function setMailSettings($mail_domain, |
|
93 | - $mail_from_address, |
|
94 | - $mail_smtpmode, |
|
95 | - $mail_smtpsecure, |
|
96 | - $mail_smtphost, |
|
97 | - $mail_smtpauthtype, |
|
98 | - $mail_smtpauth, |
|
99 | - $mail_smtpport) { |
|
100 | - |
|
101 | - $params = get_defined_vars(); |
|
102 | - $configs = []; |
|
103 | - foreach($params as $key => $value) { |
|
104 | - $configs[$key] = (empty($value)) ? null : $value; |
|
105 | - } |
|
106 | - |
|
107 | - // Delete passwords from config in case no auth is specified |
|
108 | - if ($params['mail_smtpauth'] !== 1) { |
|
109 | - $configs['mail_smtpname'] = null; |
|
110 | - $configs['mail_smtppassword'] = null; |
|
111 | - } |
|
112 | - |
|
113 | - $this->config->setSystemValues($configs); |
|
114 | - |
|
115 | - return new DataResponse(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Store the credentials used for SMTP in the config |
|
120 | - * |
|
121 | - * @PasswordConfirmationRequired |
|
122 | - * |
|
123 | - * @param string $mail_smtpname |
|
124 | - * @param string $mail_smtppassword |
|
125 | - * @return DataResponse |
|
126 | - */ |
|
127 | - public function storeCredentials($mail_smtpname, $mail_smtppassword) { |
|
128 | - if ($mail_smtppassword === '********') { |
|
129 | - return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST); |
|
130 | - } |
|
131 | - |
|
132 | - $this->config->setSystemValues([ |
|
133 | - 'mail_smtpname' => $mail_smtpname, |
|
134 | - 'mail_smtppassword' => $mail_smtppassword, |
|
135 | - ]); |
|
136 | - |
|
137 | - return new DataResponse(); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Send a mail to test the settings |
|
142 | - * @return DataResponse |
|
143 | - */ |
|
144 | - public function sendTestMail() { |
|
145 | - $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', ''); |
|
146 | - if (!empty($email)) { |
|
147 | - try { |
|
148 | - $displayName = $this->userSession->getUser()->getDisplayName(); |
|
149 | - |
|
150 | - $template = $this->mailer->createEMailTemplate('settings.TestEmail', [ |
|
151 | - 'displayname' => $displayName, |
|
152 | - ]); |
|
153 | - |
|
154 | - $template->setSubject($this->l10n->t('Email setting test')); |
|
155 | - $template->addHeader(); |
|
156 | - $template->addHeading($this->l10n->t('Well done, %s!', [$displayName])); |
|
157 | - $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.')); |
|
158 | - $template->addFooter(); |
|
159 | - |
|
160 | - $message = $this->mailer->createMessage(); |
|
161 | - $message->setTo([$email => $displayName]); |
|
162 | - $message->useTemplate($template); |
|
163 | - $errors = $this->mailer->send($message); |
|
164 | - if (!empty($errors)) { |
|
165 | - throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log')); |
|
166 | - } |
|
167 | - return new DataResponse(); |
|
168 | - } catch (\Exception $e) { |
|
169 | - return new DataResponse($this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]), Http::STATUS_BAD_REQUEST); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST); |
|
174 | - } |
|
42 | + /** @var IL10N */ |
|
43 | + private $l10n; |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | + /** @var IUserSession */ |
|
47 | + private $userSession; |
|
48 | + /** @var IMailer */ |
|
49 | + private $mailer; |
|
50 | + /** @var string */ |
|
51 | + private $defaultMailAddress; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $appName |
|
55 | + * @param IRequest $request |
|
56 | + * @param IL10N $l10n |
|
57 | + * @param IConfig $config |
|
58 | + * @param IUserSession $userSession |
|
59 | + * @param IMailer $mailer |
|
60 | + * @param string $fromMailAddress |
|
61 | + */ |
|
62 | + public function __construct($appName, |
|
63 | + IRequest $request, |
|
64 | + IL10N $l10n, |
|
65 | + IConfig $config, |
|
66 | + IUserSession $userSession, |
|
67 | + IMailer $mailer, |
|
68 | + $fromMailAddress) { |
|
69 | + parent::__construct($appName, $request); |
|
70 | + $this->l10n = $l10n; |
|
71 | + $this->config = $config; |
|
72 | + $this->userSession = $userSession; |
|
73 | + $this->mailer = $mailer; |
|
74 | + $this->defaultMailAddress = $fromMailAddress; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Sets the email settings |
|
79 | + * |
|
80 | + * @PasswordConfirmationRequired |
|
81 | + * |
|
82 | + * @param string $mail_domain |
|
83 | + * @param string $mail_from_address |
|
84 | + * @param string $mail_smtpmode |
|
85 | + * @param string $mail_smtpsecure |
|
86 | + * @param string $mail_smtphost |
|
87 | + * @param string $mail_smtpauthtype |
|
88 | + * @param int $mail_smtpauth |
|
89 | + * @param string $mail_smtpport |
|
90 | + * @return DataResponse |
|
91 | + */ |
|
92 | + public function setMailSettings($mail_domain, |
|
93 | + $mail_from_address, |
|
94 | + $mail_smtpmode, |
|
95 | + $mail_smtpsecure, |
|
96 | + $mail_smtphost, |
|
97 | + $mail_smtpauthtype, |
|
98 | + $mail_smtpauth, |
|
99 | + $mail_smtpport) { |
|
100 | + |
|
101 | + $params = get_defined_vars(); |
|
102 | + $configs = []; |
|
103 | + foreach($params as $key => $value) { |
|
104 | + $configs[$key] = (empty($value)) ? null : $value; |
|
105 | + } |
|
106 | + |
|
107 | + // Delete passwords from config in case no auth is specified |
|
108 | + if ($params['mail_smtpauth'] !== 1) { |
|
109 | + $configs['mail_smtpname'] = null; |
|
110 | + $configs['mail_smtppassword'] = null; |
|
111 | + } |
|
112 | + |
|
113 | + $this->config->setSystemValues($configs); |
|
114 | + |
|
115 | + return new DataResponse(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Store the credentials used for SMTP in the config |
|
120 | + * |
|
121 | + * @PasswordConfirmationRequired |
|
122 | + * |
|
123 | + * @param string $mail_smtpname |
|
124 | + * @param string $mail_smtppassword |
|
125 | + * @return DataResponse |
|
126 | + */ |
|
127 | + public function storeCredentials($mail_smtpname, $mail_smtppassword) { |
|
128 | + if ($mail_smtppassword === '********') { |
|
129 | + return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST); |
|
130 | + } |
|
131 | + |
|
132 | + $this->config->setSystemValues([ |
|
133 | + 'mail_smtpname' => $mail_smtpname, |
|
134 | + 'mail_smtppassword' => $mail_smtppassword, |
|
135 | + ]); |
|
136 | + |
|
137 | + return new DataResponse(); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Send a mail to test the settings |
|
142 | + * @return DataResponse |
|
143 | + */ |
|
144 | + public function sendTestMail() { |
|
145 | + $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', ''); |
|
146 | + if (!empty($email)) { |
|
147 | + try { |
|
148 | + $displayName = $this->userSession->getUser()->getDisplayName(); |
|
149 | + |
|
150 | + $template = $this->mailer->createEMailTemplate('settings.TestEmail', [ |
|
151 | + 'displayname' => $displayName, |
|
152 | + ]); |
|
153 | + |
|
154 | + $template->setSubject($this->l10n->t('Email setting test')); |
|
155 | + $template->addHeader(); |
|
156 | + $template->addHeading($this->l10n->t('Well done, %s!', [$displayName])); |
|
157 | + $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.')); |
|
158 | + $template->addFooter(); |
|
159 | + |
|
160 | + $message = $this->mailer->createMessage(); |
|
161 | + $message->setTo([$email => $displayName]); |
|
162 | + $message->useTemplate($template); |
|
163 | + $errors = $this->mailer->send($message); |
|
164 | + if (!empty($errors)) { |
|
165 | + throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log')); |
|
166 | + } |
|
167 | + return new DataResponse(); |
|
168 | + } catch (\Exception $e) { |
|
169 | + return new DataResponse($this->l10n->t('A problem occurred while sending the email. Please revise your settings. (Error: %s)', [$e->getMessage()]), Http::STATUS_BAD_REQUEST); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | } |
@@ -28,57 +28,57 @@ |
||
28 | 28 | * @since 13.0.0 |
29 | 29 | */ |
30 | 30 | interface IMessage { |
31 | - /** |
|
32 | - * Set the from address of this message. |
|
33 | - * |
|
34 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
35 | - * |
|
36 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
37 | - * @return $this |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function setFrom(array $addresses); |
|
31 | + /** |
|
32 | + * Set the from address of this message. |
|
33 | + * |
|
34 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
35 | + * |
|
36 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
37 | + * @return $this |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function setFrom(array $addresses); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Set the Reply-To address of this message |
|
44 | - * |
|
45 | - * @param array $addresses |
|
46 | - * @return $this |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function setReplyTo(array $addresses); |
|
42 | + /** |
|
43 | + * Set the Reply-To address of this message |
|
44 | + * |
|
45 | + * @param array $addresses |
|
46 | + * @return $this |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function setReplyTo(array $addresses); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Set the to addresses of this message. |
|
53 | - * |
|
54 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
55 | - * @return $this |
|
56 | - * @since 13.0.0 |
|
57 | - */ |
|
58 | - public function setTo(array $recipients); |
|
51 | + /** |
|
52 | + * Set the to addresses of this message. |
|
53 | + * |
|
54 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
55 | + * @return $this |
|
56 | + * @since 13.0.0 |
|
57 | + */ |
|
58 | + public function setTo(array $recipients); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Set the CC recipients of this message. |
|
62 | - * |
|
63 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
64 | - * @return $this |
|
65 | - * @since 13.0.0 |
|
66 | - */ |
|
67 | - public function setCc(array $recipients); |
|
60 | + /** |
|
61 | + * Set the CC recipients of this message. |
|
62 | + * |
|
63 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
64 | + * @return $this |
|
65 | + * @since 13.0.0 |
|
66 | + */ |
|
67 | + public function setCc(array $recipients); |
|
68 | 68 | |
69 | - /** |
|
70 | - * Set the BCC recipients of this message. |
|
71 | - * |
|
72 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
73 | - * @return $this |
|
74 | - * @since 13.0.0 |
|
75 | - */ |
|
76 | - public function setBcc(array $recipients); |
|
69 | + /** |
|
70 | + * Set the BCC recipients of this message. |
|
71 | + * |
|
72 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
73 | + * @return $this |
|
74 | + * @since 13.0.0 |
|
75 | + */ |
|
76 | + public function setBcc(array $recipients); |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param IEMailTemplate $emailTemplate |
|
80 | - * @return $this |
|
81 | - * @since 13.0.0 |
|
82 | - */ |
|
83 | - public function useTemplate(IEMailTemplate $emailTemplate); |
|
78 | + /** |
|
79 | + * @param IEMailTemplate $emailTemplate |
|
80 | + * @return $this |
|
81 | + * @since 13.0.0 |
|
82 | + */ |
|
83 | + public function useTemplate(IEMailTemplate $emailTemplate); |
|
84 | 84 | } |