@@ -39,134 +39,134 @@ |
||
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 | - |
|
51 | - /** |
|
52 | - * @param string $appName |
|
53 | - * @param IRequest $request |
|
54 | - * @param IL10N $l10n |
|
55 | - * @param IConfig $config |
|
56 | - * @param IUserSession $userSession |
|
57 | - * @param IMailer $mailer |
|
58 | - */ |
|
59 | - public function __construct($appName, |
|
60 | - IRequest $request, |
|
61 | - IL10N $l10n, |
|
62 | - IConfig $config, |
|
63 | - IUserSession $userSession, |
|
64 | - IMailer $mailer) { |
|
65 | - parent::__construct($appName, $request); |
|
66 | - $this->l10n = $l10n; |
|
67 | - $this->config = $config; |
|
68 | - $this->userSession = $userSession; |
|
69 | - $this->mailer = $mailer; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Sets the email settings |
|
74 | - * |
|
75 | - * @PasswordConfirmationRequired |
|
76 | - * |
|
77 | - * @param string $mail_domain |
|
78 | - * @param string $mail_from_address |
|
79 | - * @param string $mail_smtpmode |
|
80 | - * @param string $mail_smtpsecure |
|
81 | - * @param string $mail_smtphost |
|
82 | - * @param string $mail_smtpauthtype |
|
83 | - * @param int $mail_smtpauth |
|
84 | - * @param string $mail_smtpport |
|
85 | - * @return DataResponse |
|
86 | - */ |
|
87 | - public function setMailSettings($mail_domain, |
|
88 | - $mail_from_address, |
|
89 | - $mail_smtpmode, |
|
90 | - $mail_smtpsecure, |
|
91 | - $mail_smtphost, |
|
92 | - $mail_smtpauthtype, |
|
93 | - $mail_smtpauth, |
|
94 | - $mail_smtpport, |
|
95 | - $mail_sendmailmode) { |
|
96 | - |
|
97 | - $params = get_defined_vars(); |
|
98 | - $configs = []; |
|
99 | - foreach($params as $key => $value) { |
|
100 | - $configs[$key] = empty($value) ? null : $value; |
|
101 | - } |
|
102 | - |
|
103 | - // Delete passwords from config in case no auth is specified |
|
104 | - if ($params['mail_smtpauth'] !== 1) { |
|
105 | - $configs['mail_smtpname'] = null; |
|
106 | - $configs['mail_smtppassword'] = null; |
|
107 | - } |
|
108 | - |
|
109 | - $this->config->setSystemValues($configs); |
|
110 | - |
|
111 | - return new DataResponse(); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Store the credentials used for SMTP in the config |
|
116 | - * |
|
117 | - * @PasswordConfirmationRequired |
|
118 | - * |
|
119 | - * @param string $mail_smtpname |
|
120 | - * @param string $mail_smtppassword |
|
121 | - * @return DataResponse |
|
122 | - */ |
|
123 | - public function storeCredentials($mail_smtpname, $mail_smtppassword) { |
|
124 | - if ($mail_smtppassword === '********') { |
|
125 | - return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST); |
|
126 | - } |
|
127 | - |
|
128 | - $this->config->setSystemValues([ |
|
129 | - 'mail_smtpname' => $mail_smtpname, |
|
130 | - 'mail_smtppassword' => $mail_smtppassword, |
|
131 | - ]); |
|
132 | - |
|
133 | - return new DataResponse(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Send a mail to test the settings |
|
138 | - * @return DataResponse |
|
139 | - */ |
|
140 | - public function sendTestMail() { |
|
141 | - $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', ''); |
|
142 | - if (!empty($email)) { |
|
143 | - try { |
|
144 | - $displayName = $this->userSession->getUser()->getDisplayName(); |
|
145 | - |
|
146 | - $template = $this->mailer->createEMailTemplate('settings.TestEmail', [ |
|
147 | - 'displayname' => $displayName, |
|
148 | - ]); |
|
149 | - |
|
150 | - $template->setSubject($this->l10n->t('Email setting test')); |
|
151 | - $template->addHeader(); |
|
152 | - $template->addHeading($this->l10n->t('Well done, %s!', [$displayName])); |
|
153 | - $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.')); |
|
154 | - $template->addFooter(); |
|
155 | - |
|
156 | - $message = $this->mailer->createMessage(); |
|
157 | - $message->setTo([$email => $displayName]); |
|
158 | - $message->useTemplate($template); |
|
159 | - $errors = $this->mailer->send($message); |
|
160 | - if (!empty($errors)) { |
|
161 | - throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log')); |
|
162 | - } |
|
163 | - return new DataResponse(); |
|
164 | - } catch (\Exception $e) { |
|
165 | - 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); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST); |
|
170 | - } |
|
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 | + |
|
51 | + /** |
|
52 | + * @param string $appName |
|
53 | + * @param IRequest $request |
|
54 | + * @param IL10N $l10n |
|
55 | + * @param IConfig $config |
|
56 | + * @param IUserSession $userSession |
|
57 | + * @param IMailer $mailer |
|
58 | + */ |
|
59 | + public function __construct($appName, |
|
60 | + IRequest $request, |
|
61 | + IL10N $l10n, |
|
62 | + IConfig $config, |
|
63 | + IUserSession $userSession, |
|
64 | + IMailer $mailer) { |
|
65 | + parent::__construct($appName, $request); |
|
66 | + $this->l10n = $l10n; |
|
67 | + $this->config = $config; |
|
68 | + $this->userSession = $userSession; |
|
69 | + $this->mailer = $mailer; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Sets the email settings |
|
74 | + * |
|
75 | + * @PasswordConfirmationRequired |
|
76 | + * |
|
77 | + * @param string $mail_domain |
|
78 | + * @param string $mail_from_address |
|
79 | + * @param string $mail_smtpmode |
|
80 | + * @param string $mail_smtpsecure |
|
81 | + * @param string $mail_smtphost |
|
82 | + * @param string $mail_smtpauthtype |
|
83 | + * @param int $mail_smtpauth |
|
84 | + * @param string $mail_smtpport |
|
85 | + * @return DataResponse |
|
86 | + */ |
|
87 | + public function setMailSettings($mail_domain, |
|
88 | + $mail_from_address, |
|
89 | + $mail_smtpmode, |
|
90 | + $mail_smtpsecure, |
|
91 | + $mail_smtphost, |
|
92 | + $mail_smtpauthtype, |
|
93 | + $mail_smtpauth, |
|
94 | + $mail_smtpport, |
|
95 | + $mail_sendmailmode) { |
|
96 | + |
|
97 | + $params = get_defined_vars(); |
|
98 | + $configs = []; |
|
99 | + foreach($params as $key => $value) { |
|
100 | + $configs[$key] = empty($value) ? null : $value; |
|
101 | + } |
|
102 | + |
|
103 | + // Delete passwords from config in case no auth is specified |
|
104 | + if ($params['mail_smtpauth'] !== 1) { |
|
105 | + $configs['mail_smtpname'] = null; |
|
106 | + $configs['mail_smtppassword'] = null; |
|
107 | + } |
|
108 | + |
|
109 | + $this->config->setSystemValues($configs); |
|
110 | + |
|
111 | + return new DataResponse(); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Store the credentials used for SMTP in the config |
|
116 | + * |
|
117 | + * @PasswordConfirmationRequired |
|
118 | + * |
|
119 | + * @param string $mail_smtpname |
|
120 | + * @param string $mail_smtppassword |
|
121 | + * @return DataResponse |
|
122 | + */ |
|
123 | + public function storeCredentials($mail_smtpname, $mail_smtppassword) { |
|
124 | + if ($mail_smtppassword === '********') { |
|
125 | + return new DataResponse($this->l10n->t('Invalid SMTP password.'), Http::STATUS_BAD_REQUEST); |
|
126 | + } |
|
127 | + |
|
128 | + $this->config->setSystemValues([ |
|
129 | + 'mail_smtpname' => $mail_smtpname, |
|
130 | + 'mail_smtppassword' => $mail_smtppassword, |
|
131 | + ]); |
|
132 | + |
|
133 | + return new DataResponse(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Send a mail to test the settings |
|
138 | + * @return DataResponse |
|
139 | + */ |
|
140 | + public function sendTestMail() { |
|
141 | + $email = $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'email', ''); |
|
142 | + if (!empty($email)) { |
|
143 | + try { |
|
144 | + $displayName = $this->userSession->getUser()->getDisplayName(); |
|
145 | + |
|
146 | + $template = $this->mailer->createEMailTemplate('settings.TestEmail', [ |
|
147 | + 'displayname' => $displayName, |
|
148 | + ]); |
|
149 | + |
|
150 | + $template->setSubject($this->l10n->t('Email setting test')); |
|
151 | + $template->addHeader(); |
|
152 | + $template->addHeading($this->l10n->t('Well done, %s!', [$displayName])); |
|
153 | + $template->addBodyText($this->l10n->t('If you received this email, the email configuration seems to be correct.')); |
|
154 | + $template->addFooter(); |
|
155 | + |
|
156 | + $message = $this->mailer->createMessage(); |
|
157 | + $message->setTo([$email => $displayName]); |
|
158 | + $message->useTemplate($template); |
|
159 | + $errors = $this->mailer->send($message); |
|
160 | + if (!empty($errors)) { |
|
161 | + throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log')); |
|
162 | + } |
|
163 | + return new DataResponse(); |
|
164 | + } catch (\Exception $e) { |
|
165 | + 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); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + return new DataResponse($this->l10n->t('You need to set your user email before being able to send test emails.'), Http::STATUS_BAD_REQUEST); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | } |
@@ -25,31 +25,31 @@ discard block |
||
25 | 25 | /** @var array $_ */ |
26 | 26 | |
27 | 27 | $mail_smtpauthtype = [ |
28 | - '' => $l->t('None'), |
|
29 | - 'LOGIN' => $l->t('Login'), |
|
30 | - 'PLAIN' => $l->t('Plain'), |
|
31 | - 'NTLM' => $l->t('NT LAN Manager'), |
|
28 | + '' => $l->t('None'), |
|
29 | + 'LOGIN' => $l->t('Login'), |
|
30 | + 'PLAIN' => $l->t('Plain'), |
|
31 | + 'NTLM' => $l->t('NT LAN Manager'), |
|
32 | 32 | ]; |
33 | 33 | |
34 | 34 | $mail_smtpsecure = [ |
35 | - '' => $l->t('None'), |
|
36 | - 'ssl' => $l->t('SSL/TLS'), |
|
37 | - 'tls' => $l->t('STARTTLS'), |
|
35 | + '' => $l->t('None'), |
|
36 | + 'ssl' => $l->t('SSL/TLS'), |
|
37 | + 'tls' => $l->t('STARTTLS'), |
|
38 | 38 | ]; |
39 | 39 | |
40 | 40 | $mail_smtpmode = [ |
41 | - ['smtp', 'SMTP'], |
|
41 | + ['smtp', 'SMTP'], |
|
42 | 42 | ]; |
43 | 43 | if ($_['sendmail_is_available']) { |
44 | - $mail_smtpmode[] = ['sendmail', 'Sendmail']; |
|
44 | + $mail_smtpmode[] = ['sendmail', 'Sendmail']; |
|
45 | 45 | } |
46 | 46 | if ($_['mail_smtpmode'] === 'qmail') { |
47 | - $mail_smtpmode[] = ['qmail', 'qmail']; |
|
47 | + $mail_smtpmode[] = ['qmail', 'qmail']; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $mail_sendmailmode = [ |
51 | - 'smtp' => 'smtp (-bs)', |
|
52 | - 'pipe' => 'pipe (-t)' |
|
51 | + 'smtp' => 'smtp (-bs)', |
|
52 | + 'pipe' => 'pipe (-t)' |
|
53 | 53 | ]; |
54 | 54 | |
55 | 55 | ?> |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | <label for="mail_smtpmode"><?php p($l->t('Send mode')); ?></label> |
68 | 68 | <select name="mail_smtpmode" id="mail_smtpmode"> |
69 | 69 | <?php foreach ($mail_smtpmode as $smtpmode): |
70 | - $selected = ''; |
|
71 | - if ($smtpmode[0] == $_['mail_smtpmode']): |
|
72 | - $selected = 'selected="selected"'; |
|
73 | - endif; ?> |
|
70 | + $selected = ''; |
|
71 | + if ($smtpmode[0] == $_['mail_smtpmode']): |
|
72 | + $selected = 'selected="selected"'; |
|
73 | + endif; ?> |
|
74 | 74 | <option value="<?php p($smtpmode[0])?>" <?php p($selected) ?>><?php p($smtpmode[1]) ?></option> |
75 | 75 | <?php endforeach;?> |
76 | 76 | </select> |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | <select name="mail_smtpsecure" id="mail_smtpsecure" |
83 | 83 | <?php if ($_['mail_smtpmode'] !== 'smtp') print_unescaped(' class="hidden"'); ?>> |
84 | 84 | <?php foreach ($mail_smtpsecure as $secure => $name): |
85 | - $selected = ''; |
|
86 | - if ($secure == $_['mail_smtpsecure']): |
|
87 | - $selected = 'selected="selected"'; |
|
88 | - endif; ?> |
|
85 | + $selected = ''; |
|
86 | + if ($secure == $_['mail_smtpsecure']): |
|
87 | + $selected = 'selected="selected"'; |
|
88 | + endif; ?> |
|
89 | 89 | <option value="<?php p($secure)?>" <?php p($selected) ?>><?php p($name) ?></option> |
90 | 90 | <?php endforeach;?> |
91 | 91 | </select> |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | <label for="mail_smtpauthtype"><?php p($l->t('Authentication method')); ?></label> |
113 | 113 | <select name="mail_smtpauthtype" id="mail_smtpauthtype"> |
114 | 114 | <?php foreach ($mail_smtpauthtype as $authtype => $name): |
115 | - $selected = ''; |
|
116 | - if ($authtype == $_['mail_smtpauthtype']): |
|
117 | - $selected = 'selected="selected"'; |
|
118 | - endif; ?> |
|
115 | + $selected = ''; |
|
116 | + if ($authtype == $_['mail_smtpauthtype']): |
|
117 | + $selected = 'selected="selected"'; |
|
118 | + endif; ?> |
|
119 | 119 | <option value="<?php p($authtype)?>" <?php p($selected) ?>><?php p($name) ?></option> |
120 | 120 | <?php endforeach;?> |
121 | 121 | </select> |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | |
57 | 57 | <div class="section" id="mail_general_settings"> |
58 | 58 | <form id="mail_general_settings_form" class="mail_settings"> |
59 | - <h2><?php p($l->t('Email server'));?></h2> |
|
59 | + <h2><?php p($l->t('Email server')); ?></h2> |
|
60 | 60 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
61 | - title="<?php p($l->t('Open documentation'));?>" |
|
61 | + title="<?php p($l->t('Open documentation')); ?>" |
|
62 | 62 | href="<?php p(link_to_docs('admin-email')); ?>"></a> |
63 | 63 | <p class="settings-hint"><?php p($l->t('It is important to set up this server to be able to send emails, like for password reset and notifications.')); ?></p> |
64 | 64 | <p><span id="mail_settings_msg" class="msg"></span></p> |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $selected = 'selected="selected"'; |
73 | 73 | endif; ?> |
74 | 74 | <option value="<?php p($smtpmode[0])?>" <?php p($selected) ?>><?php p($smtpmode[1]) ?></option> |
75 | - <?php endforeach;?> |
|
75 | + <?php endforeach; ?> |
|
76 | 76 | </select> |
77 | 77 | |
78 | 78 | <label id="mail_smtpsecure_label" for="mail_smtpsecure" |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $selected = 'selected="selected"'; |
88 | 88 | endif; ?> |
89 | 89 | <option value="<?php p($secure)?>" <?php p($selected) ?>><?php p($name) ?></option> |
90 | - <?php endforeach;?> |
|
90 | + <?php endforeach; ?> |
|
91 | 91 | </select> |
92 | 92 | |
93 | 93 | <label id="mail_sendmailmode_label" for="mail_sendmailmode" class="<?= $_['mail_smtpmode'] !== 'sendmail' ? 'hidden' : '' ?>"> |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | <select name="mail_sendmailmode" id="mail_sendmailmode" class="<?= $_['mail_smtpmode'] !== 'sendmail' ? 'hidden' : '' ?>"> |
97 | 97 | <?php foreach ($mail_sendmailmode as $sendmailmodeValue => $sendmailmodeLabel): ?> |
98 | 98 | <option value="<?php p($sendmailmodeValue)?>" <?= $sendmailmodeValue === $_['mail_sendmailmode'] ? 'selected="selected"' : '' ?>><?php p($sendmailmodeLabel) ?></option> |
99 | - <?php endforeach;?> |
|
99 | + <?php endforeach; ?> |
|
100 | 100 | </select> |
101 | 101 | </p> |
102 | 102 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $selected = 'selected="selected"'; |
118 | 118 | endif; ?> |
119 | 119 | <option value="<?php p($authtype)?>" <?php p($selected) ?>><?php p($name) ?></option> |
120 | - <?php endforeach;?> |
|
120 | + <?php endforeach; ?> |
|
121 | 121 | </select> |
122 | 122 | |
123 | 123 | <input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" class="checkbox" value="1" |
@@ -30,62 +30,62 @@ |
||
30 | 30 | use OCP\Settings\ISettings; |
31 | 31 | |
32 | 32 | class Mail implements ISettings { |
33 | - /** @var IConfig */ |
|
34 | - private $config; |
|
33 | + /** @var IConfig */ |
|
34 | + private $config; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param IConfig $config |
|
38 | - */ |
|
39 | - public function __construct(IConfig $config) { |
|
40 | - $this->config = $config; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param IConfig $config |
|
38 | + */ |
|
39 | + public function __construct(IConfig $config) { |
|
40 | + $this->config = $config; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return TemplateResponse |
|
45 | - */ |
|
46 | - public function getForm() { |
|
47 | - $parameters = [ |
|
48 | ||
49 | - 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), |
|
50 | - 'mail_domain' => $this->config->getSystemValue('mail_domain', ''), |
|
51 | - 'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''), |
|
52 | - 'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''), |
|
53 | - 'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''), |
|
54 | - 'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''), |
|
55 | - 'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''), |
|
56 | - 'mail_smtpauthtype' => $this->config->getSystemValue('mail_smtpauthtype', ''), |
|
57 | - 'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false), |
|
58 | - 'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''), |
|
59 | - 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''), |
|
60 | - 'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'), |
|
61 | - ]; |
|
43 | + /** |
|
44 | + * @return TemplateResponse |
|
45 | + */ |
|
46 | + public function getForm() { |
|
47 | + $parameters = [ |
|
48 | ||
49 | + 'sendmail_is_available' => (bool) \OC_Helper::findBinaryPath('sendmail'), |
|
50 | + 'mail_domain' => $this->config->getSystemValue('mail_domain', ''), |
|
51 | + 'mail_from_address' => $this->config->getSystemValue('mail_from_address', ''), |
|
52 | + 'mail_smtpmode' => $this->config->getSystemValue('mail_smtpmode', ''), |
|
53 | + 'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''), |
|
54 | + 'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''), |
|
55 | + 'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''), |
|
56 | + 'mail_smtpauthtype' => $this->config->getSystemValue('mail_smtpauthtype', ''), |
|
57 | + 'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false), |
|
58 | + 'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''), |
|
59 | + 'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''), |
|
60 | + 'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'), |
|
61 | + ]; |
|
62 | 62 | |
63 | - if ($parameters['mail_smtppassword'] !== '') { |
|
64 | - $parameters['mail_smtppassword'] = '********'; |
|
65 | - } |
|
63 | + if ($parameters['mail_smtppassword'] !== '') { |
|
64 | + $parameters['mail_smtppassword'] = '********'; |
|
65 | + } |
|
66 | 66 | |
67 | - if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') { |
|
68 | - $parameters['mail_smtpmode'] = 'smtp'; |
|
69 | - } |
|
67 | + if ($parameters['mail_smtpmode'] === '' || $parameters['mail_smtpmode'] === 'php') { |
|
68 | + $parameters['mail_smtpmode'] = 'smtp'; |
|
69 | + } |
|
70 | 70 | |
71 | - return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, ''); |
|
72 | - } |
|
71 | + return new TemplateResponse('settings', 'settings/admin/additional-mail', $parameters, ''); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string the section ID, e.g. 'sharing' |
|
76 | - */ |
|
77 | - public function getSection() { |
|
78 | - return 'server'; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return string the section ID, e.g. 'sharing' |
|
76 | + */ |
|
77 | + public function getSection() { |
|
78 | + return 'server'; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return int whether the form should be rather on the top or bottom of |
|
83 | - * the admin section. The forms are arranged in ascending order of the |
|
84 | - * priority values. It is required to return a value between 0 and 100. |
|
85 | - * |
|
86 | - * E.g.: 70 |
|
87 | - */ |
|
88 | - public function getPriority() { |
|
89 | - return 10; |
|
90 | - } |
|
81 | + /** |
|
82 | + * @return int whether the form should be rather on the top or bottom of |
|
83 | + * the admin section. The forms are arranged in ascending order of the |
|
84 | + * priority values. It is required to return a value between 0 and 100. |
|
85 | + * |
|
86 | + * E.g.: 70 |
|
87 | + */ |
|
88 | + public function getPriority() { |
|
89 | + return 10; |
|
90 | + } |
|
91 | 91 | } |
@@ -57,240 +57,240 @@ |
||
57 | 57 | * @package OC\Mail |
58 | 58 | */ |
59 | 59 | class Mailer implements IMailer { |
60 | - /** @var \Swift_Mailer Cached mailer */ |
|
61 | - private $instance = null; |
|
62 | - /** @var IConfig */ |
|
63 | - private $config; |
|
64 | - /** @var ILogger */ |
|
65 | - private $logger; |
|
66 | - /** @var Defaults */ |
|
67 | - private $defaults; |
|
68 | - /** @var IURLGenerator */ |
|
69 | - private $urlGenerator; |
|
70 | - /** @var IL10N */ |
|
71 | - private $l10n; |
|
60 | + /** @var \Swift_Mailer Cached mailer */ |
|
61 | + private $instance = null; |
|
62 | + /** @var IConfig */ |
|
63 | + private $config; |
|
64 | + /** @var ILogger */ |
|
65 | + private $logger; |
|
66 | + /** @var Defaults */ |
|
67 | + private $defaults; |
|
68 | + /** @var IURLGenerator */ |
|
69 | + private $urlGenerator; |
|
70 | + /** @var IL10N */ |
|
71 | + private $l10n; |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param IConfig $config |
|
75 | - * @param ILogger $logger |
|
76 | - * @param Defaults $defaults |
|
77 | - * @param IURLGenerator $urlGenerator |
|
78 | - * @param IL10N $l10n |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - ILogger $logger, |
|
82 | - Defaults $defaults, |
|
83 | - IURLGenerator $urlGenerator, |
|
84 | - IL10N $l10n) { |
|
85 | - $this->config = $config; |
|
86 | - $this->logger = $logger; |
|
87 | - $this->defaults = $defaults; |
|
88 | - $this->urlGenerator = $urlGenerator; |
|
89 | - $this->l10n = $l10n; |
|
90 | - } |
|
73 | + /** |
|
74 | + * @param IConfig $config |
|
75 | + * @param ILogger $logger |
|
76 | + * @param Defaults $defaults |
|
77 | + * @param IURLGenerator $urlGenerator |
|
78 | + * @param IL10N $l10n |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + ILogger $logger, |
|
82 | + Defaults $defaults, |
|
83 | + IURLGenerator $urlGenerator, |
|
84 | + IL10N $l10n) { |
|
85 | + $this->config = $config; |
|
86 | + $this->logger = $logger; |
|
87 | + $this->defaults = $defaults; |
|
88 | + $this->urlGenerator = $urlGenerator; |
|
89 | + $this->l10n = $l10n; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Creates a new message object that can be passed to send() |
|
94 | - * |
|
95 | - * @return IMessage |
|
96 | - */ |
|
97 | - public function createMessage(): IMessage { |
|
98 | - $plainTextOnly = $this->config->getSystemValue('mail_send_plaintext_only', false); |
|
99 | - return new Message(new \Swift_Message(), $plainTextOnly); |
|
100 | - } |
|
92 | + /** |
|
93 | + * Creates a new message object that can be passed to send() |
|
94 | + * |
|
95 | + * @return IMessage |
|
96 | + */ |
|
97 | + public function createMessage(): IMessage { |
|
98 | + $plainTextOnly = $this->config->getSystemValue('mail_send_plaintext_only', false); |
|
99 | + return new Message(new \Swift_Message(), $plainTextOnly); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param string|null $data |
|
104 | - * @param string|null $filename |
|
105 | - * @param string|null $contentType |
|
106 | - * @return IAttachment |
|
107 | - * @since 13.0.0 |
|
108 | - */ |
|
109 | - public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
110 | - return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); |
|
111 | - } |
|
102 | + /** |
|
103 | + * @param string|null $data |
|
104 | + * @param string|null $filename |
|
105 | + * @param string|null $contentType |
|
106 | + * @return IAttachment |
|
107 | + * @since 13.0.0 |
|
108 | + */ |
|
109 | + public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
110 | + return new Attachment(new \Swift_Attachment($data, $filename, $contentType)); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $path |
|
115 | - * @param string|null $contentType |
|
116 | - * @return IAttachment |
|
117 | - * @since 13.0.0 |
|
118 | - */ |
|
119 | - public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
120 | - return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
121 | - } |
|
113 | + /** |
|
114 | + * @param string $path |
|
115 | + * @param string|null $contentType |
|
116 | + * @return IAttachment |
|
117 | + * @since 13.0.0 |
|
118 | + */ |
|
119 | + public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
120 | + return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Creates a new email template object |
|
125 | - * |
|
126 | - * @param string $emailId |
|
127 | - * @param array $data |
|
128 | - * @return IEMailTemplate |
|
129 | - * @since 12.0.0 |
|
130 | - */ |
|
131 | - public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
132 | - $class = $this->config->getSystemValue('mail_template_class', ''); |
|
123 | + /** |
|
124 | + * Creates a new email template object |
|
125 | + * |
|
126 | + * @param string $emailId |
|
127 | + * @param array $data |
|
128 | + * @return IEMailTemplate |
|
129 | + * @since 12.0.0 |
|
130 | + */ |
|
131 | + public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
132 | + $class = $this->config->getSystemValue('mail_template_class', ''); |
|
133 | 133 | |
134 | - if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
135 | - return new $class( |
|
136 | - $this->defaults, |
|
137 | - $this->urlGenerator, |
|
138 | - $this->l10n, |
|
139 | - $emailId, |
|
140 | - $data |
|
141 | - ); |
|
142 | - } |
|
134 | + if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
135 | + return new $class( |
|
136 | + $this->defaults, |
|
137 | + $this->urlGenerator, |
|
138 | + $this->l10n, |
|
139 | + $emailId, |
|
140 | + $data |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | - return new EMailTemplate( |
|
145 | - $this->defaults, |
|
146 | - $this->urlGenerator, |
|
147 | - $this->l10n, |
|
148 | - $emailId, |
|
149 | - $data |
|
150 | - ); |
|
151 | - } |
|
144 | + return new EMailTemplate( |
|
145 | + $this->defaults, |
|
146 | + $this->urlGenerator, |
|
147 | + $this->l10n, |
|
148 | + $emailId, |
|
149 | + $data |
|
150 | + ); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
155 | - * if no-one has been passed. |
|
156 | - * |
|
157 | - * @param IMessage|Message $message Message to send |
|
158 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
159 | - * therefore should be considered |
|
160 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
161 | - * has been supplied.) |
|
162 | - */ |
|
163 | - public function send(IMessage $message): array { |
|
164 | - $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
153 | + /** |
|
154 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
155 | + * if no-one has been passed. |
|
156 | + * |
|
157 | + * @param IMessage|Message $message Message to send |
|
158 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
159 | + * therefore should be considered |
|
160 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
161 | + * has been supplied.) |
|
162 | + */ |
|
163 | + public function send(IMessage $message): array { |
|
164 | + $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
165 | 165 | |
166 | - if (empty($message->getFrom())) { |
|
167 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
168 | - } |
|
166 | + if (empty($message->getFrom())) { |
|
167 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
168 | + } |
|
169 | 169 | |
170 | - $failedRecipients = []; |
|
170 | + $failedRecipients = []; |
|
171 | 171 | |
172 | - $mailer = $this->getInstance(); |
|
172 | + $mailer = $this->getInstance(); |
|
173 | 173 | |
174 | - // Enable logger if debug mode is enabled |
|
175 | - if($debugMode) { |
|
176 | - $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
177 | - $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
178 | - } |
|
174 | + // Enable logger if debug mode is enabled |
|
175 | + if($debugMode) { |
|
176 | + $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
177 | + $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
178 | + } |
|
179 | 179 | |
180 | - $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
180 | + $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
181 | 181 | |
182 | - // Debugging logging |
|
183 | - $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
184 | - $this->logger->debug($logMessage, ['app' => 'core']); |
|
185 | - if($debugMode && isset($mailLogger)) { |
|
186 | - $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
187 | - } |
|
182 | + // Debugging logging |
|
183 | + $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
184 | + $this->logger->debug($logMessage, ['app' => 'core']); |
|
185 | + if($debugMode && isset($mailLogger)) { |
|
186 | + $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
187 | + } |
|
188 | 188 | |
189 | - return $failedRecipients; |
|
190 | - } |
|
189 | + return $failedRecipients; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Checks if an e-mail address is valid |
|
194 | - * |
|
195 | - * @param string $email Email address to be validated |
|
196 | - * @return bool True if the mail address is valid, false otherwise |
|
197 | - */ |
|
198 | - public function validateMailAddress(string $email): bool { |
|
199 | - $validator = new EmailValidator(); |
|
200 | - $validation = new RFCValidation(); |
|
192 | + /** |
|
193 | + * Checks if an e-mail address is valid |
|
194 | + * |
|
195 | + * @param string $email Email address to be validated |
|
196 | + * @return bool True if the mail address is valid, false otherwise |
|
197 | + */ |
|
198 | + public function validateMailAddress(string $email): bool { |
|
199 | + $validator = new EmailValidator(); |
|
200 | + $validation = new RFCValidation(); |
|
201 | 201 | |
202 | - return $validator->isValid($this->convertEmail($email), $validation); |
|
203 | - } |
|
202 | + return $validator->isValid($this->convertEmail($email), $validation); |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
207 | - * |
|
208 | - * FIXME: Remove this once SwiftMailer supports IDN |
|
209 | - * |
|
210 | - * @param string $email |
|
211 | - * @return string Converted mail address if `idn_to_ascii` exists |
|
212 | - */ |
|
213 | - protected function convertEmail(string $email): string { |
|
214 | - if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46') || strpos($email, '@') === false) { |
|
215 | - return $email; |
|
216 | - } |
|
205 | + /** |
|
206 | + * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
207 | + * |
|
208 | + * FIXME: Remove this once SwiftMailer supports IDN |
|
209 | + * |
|
210 | + * @param string $email |
|
211 | + * @return string Converted mail address if `idn_to_ascii` exists |
|
212 | + */ |
|
213 | + protected function convertEmail(string $email): string { |
|
214 | + if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46') || strpos($email, '@') === false) { |
|
215 | + return $email; |
|
216 | + } |
|
217 | 217 | |
218 | - list($name, $domain) = explode('@', $email, 2); |
|
219 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
220 | - return $name.'@'.$domain; |
|
221 | - } |
|
218 | + list($name, $domain) = explode('@', $email, 2); |
|
219 | + $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
220 | + return $name.'@'.$domain; |
|
221 | + } |
|
222 | 222 | |
223 | - protected function getInstance(): \Swift_Mailer { |
|
224 | - if (!is_null($this->instance)) { |
|
225 | - return $this->instance; |
|
226 | - } |
|
223 | + protected function getInstance(): \Swift_Mailer { |
|
224 | + if (!is_null($this->instance)) { |
|
225 | + return $this->instance; |
|
226 | + } |
|
227 | 227 | |
228 | - $transport = null; |
|
228 | + $transport = null; |
|
229 | 229 | |
230 | - switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
231 | - case 'sendmail': |
|
232 | - $transport = $this->getSendMailInstance(); |
|
233 | - break; |
|
234 | - case 'smtp': |
|
235 | - default: |
|
236 | - $transport = $this->getSmtpInstance(); |
|
237 | - break; |
|
238 | - } |
|
230 | + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
231 | + case 'sendmail': |
|
232 | + $transport = $this->getSendMailInstance(); |
|
233 | + break; |
|
234 | + case 'smtp': |
|
235 | + default: |
|
236 | + $transport = $this->getSmtpInstance(); |
|
237 | + break; |
|
238 | + } |
|
239 | 239 | |
240 | - return new \Swift_Mailer($transport); |
|
241 | - } |
|
240 | + return new \Swift_Mailer($transport); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Returns the SMTP transport |
|
245 | - * |
|
246 | - * @return \Swift_SmtpTransport |
|
247 | - */ |
|
248 | - protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
249 | - $transport = new \Swift_SmtpTransport(); |
|
250 | - $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
251 | - $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
252 | - $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
253 | - if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
254 | - $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
255 | - $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
256 | - $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
257 | - } |
|
258 | - $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
259 | - if (!empty($smtpSecurity)) { |
|
260 | - $transport->setEncryption($smtpSecurity); |
|
261 | - } |
|
243 | + /** |
|
244 | + * Returns the SMTP transport |
|
245 | + * |
|
246 | + * @return \Swift_SmtpTransport |
|
247 | + */ |
|
248 | + protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
249 | + $transport = new \Swift_SmtpTransport(); |
|
250 | + $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
251 | + $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
252 | + $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
253 | + if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
254 | + $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
255 | + $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
256 | + $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
257 | + } |
|
258 | + $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
259 | + if (!empty($smtpSecurity)) { |
|
260 | + $transport->setEncryption($smtpSecurity); |
|
261 | + } |
|
262 | 262 | |
263 | - return $transport; |
|
264 | - } |
|
263 | + return $transport; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Returns the sendmail transport |
|
268 | - * |
|
269 | - * @return \Swift_SendmailTransport |
|
270 | - */ |
|
271 | - protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
272 | - switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
273 | - case 'qmail': |
|
274 | - $binaryPath = '/var/qmail/bin/sendmail'; |
|
275 | - break; |
|
276 | - default: |
|
277 | - $sendmail = \OC_Helper::findBinaryPath('sendmail'); |
|
278 | - if ($sendmail === null) { |
|
279 | - $sendmail = '/usr/sbin/sendmail'; |
|
280 | - } |
|
281 | - $binaryPath = $sendmail; |
|
282 | - break; |
|
283 | - } |
|
266 | + /** |
|
267 | + * Returns the sendmail transport |
|
268 | + * |
|
269 | + * @return \Swift_SendmailTransport |
|
270 | + */ |
|
271 | + protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
272 | + switch ($this->config->getSystemValue('mail_smtpmode', 'smtp')) { |
|
273 | + case 'qmail': |
|
274 | + $binaryPath = '/var/qmail/bin/sendmail'; |
|
275 | + break; |
|
276 | + default: |
|
277 | + $sendmail = \OC_Helper::findBinaryPath('sendmail'); |
|
278 | + if ($sendmail === null) { |
|
279 | + $sendmail = '/usr/sbin/sendmail'; |
|
280 | + } |
|
281 | + $binaryPath = $sendmail; |
|
282 | + break; |
|
283 | + } |
|
284 | 284 | |
285 | - switch ($this->config->getSystemValue('mail_sendmailmode', 'smtp')) { |
|
286 | - case 'pipe': |
|
287 | - $binaryParam = ' -t'; |
|
288 | - break; |
|
289 | - default: |
|
290 | - $binaryParam = ' -bs'; |
|
291 | - break; |
|
292 | - } |
|
285 | + switch ($this->config->getSystemValue('mail_sendmailmode', 'smtp')) { |
|
286 | + case 'pipe': |
|
287 | + $binaryParam = ' -t'; |
|
288 | + break; |
|
289 | + default: |
|
290 | + $binaryParam = ' -bs'; |
|
291 | + break; |
|
292 | + } |
|
293 | 293 | |
294 | - return new \Swift_SendmailTransport($binaryPath . $binaryParam); |
|
295 | - } |
|
294 | + return new \Swift_SendmailTransport($binaryPath . $binaryParam); |
|
295 | + } |
|
296 | 296 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $mailer = $this->getInstance(); |
173 | 173 | |
174 | 174 | // Enable logger if debug mode is enabled |
175 | - if($debugMode) { |
|
175 | + if ($debugMode) { |
|
176 | 176 | $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
177 | 177 | $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
178 | 178 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | // Debugging logging |
183 | 183 | $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
184 | 184 | $this->logger->debug($logMessage, ['app' => 'core']); |
185 | - if($debugMode && isset($mailLogger)) { |
|
185 | + if ($debugMode && isset($mailLogger)) { |
|
186 | 186 | $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
187 | 187 | } |
188 | 188 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | list($name, $domain) = explode('@', $email, 2); |
219 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
219 | + $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
220 | 220 | return $name.'@'.$domain; |
221 | 221 | } |
222 | 222 | |
@@ -291,6 +291,6 @@ discard block |
||
291 | 291 | break; |
292 | 292 | } |
293 | 293 | |
294 | - return new \Swift_SendmailTransport($binaryPath . $binaryParam); |
|
294 | + return new \Swift_SendmailTransport($binaryPath.$binaryParam); |
|
295 | 295 | } |
296 | 296 | } |