Skip to content

Commit dde5c46

Browse files
come-ncblizzz
authored andcommitted
Migrate to Symfony Mailer
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent fc4e87a commit dde5c46

14 files changed

Lines changed: 480 additions & 486 deletions

File tree

3rdparty

Submodule 3rdparty updated 121 files

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ public function schedule(Message $iTipMessage) {
172172
return;
173173
}
174174

175-
$senderName = $iTipMessage->senderName ?: null;
176175
$recipientName = $iTipMessage->recipientName ?: null;
177176

177+
/** @var Parameter|string|null $senderName */
178+
$senderName = $iTipMessage->senderName ?: null;
179+
if($senderName instanceof Parameter) {
180+
$senderName = $senderName->getValue() ?? null;
181+
}
182+
178183
if ($senderName === null || empty(trim($senderName))) {
179184
$senderName = $this->userManager->getDisplayName($this->userId);
180185
}

apps/settings/lib/Controller/MailSettingsController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function __construct($appName,
8585
* @param string $mail_smtpmode
8686
* @param string $mail_smtpsecure
8787
* @param string $mail_smtphost
88-
* @param string $mail_smtpauthtype
8988
* @param int $mail_smtpauth
9089
* @param string $mail_smtpport
9190
* @return DataResponse
@@ -95,7 +94,6 @@ public function setMailSettings($mail_domain,
9594
$mail_smtpmode,
9695
$mail_smtpsecure,
9796
$mail_smtphost,
98-
$mail_smtpauthtype,
9997
$mail_smtpauth,
10098
$mail_smtpport,
10199
$mail_sendmailmode) {

apps/settings/lib/Settings/Admin/Mail.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function getForm() {
6161
'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''),
6262
'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''),
6363
'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''),
64-
'mail_smtpauthtype' => $this->config->getSystemValue('mail_smtpauthtype', ''),
6564
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
6665
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
6766
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),

apps/settings/templates/settings/admin/additional-mail.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,9 @@
2424
/** @var \OCP\IL10N $l */
2525
/** @var array $_ */
2626

27-
$mail_smtpauthtype = [
28-
'' => $l->t('None'),
29-
'LOGIN' => $l->t('Login'),
30-
'PLAIN' => $l->t('Plain'),
31-
'NTLM' => $l->t('NT LAN Manager'),
32-
];
33-
3427
$mail_smtpsecure = [
3528
'' => $l->t('None'),
36-
'ssl' => $l->t('SSL/TLS'),
37-
'tls' => $l->t('STARTTLS'),
29+
'ssl' => $l->t('SSL/TLS')
3830
];
3931

4032
$mail_smtpmode = [
@@ -112,26 +104,7 @@
112104
value="<?php p($_['mail_domain']) ?>" />
113105
</p>
114106

115-
<p id="setting_smtpauth" <?php if ($_['mail_smtpmode'] !== 'smtp') {
116-
print_unescaped(' class="hidden"');
117-
} ?>>
118-
<label for="mail_smtpauthtype"><?php p($l->t('Authentication method')); ?></label>
119-
<select name="mail_smtpauthtype" id="mail_smtpauthtype">
120-
<?php foreach ($mail_smtpauthtype as $authtype => $name):
121-
$selected = '';
122-
if ($authtype == $_['mail_smtpauthtype']):
123-
$selected = 'selected="selected"';
124-
endif; ?>
125-
<option value="<?php p($authtype)?>" <?php p($selected) ?>><?php p($name) ?></option>
126-
<?php endforeach;?>
127-
</select>
128-
129-
<input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" class="checkbox" value="1"
130-
<?php if ($_['mail_smtpauth']) {
131-
print_unescaped('checked="checked"');
132-
} ?> />
133-
<label for="mail_smtpauth"><?php p($l->t('Authentication required')); ?></label>
134-
</p>
107+
<!--lo-->
135108

136109
<p id="setting_smtphost" <?php if ($_['mail_smtpmode'] !== 'smtp') {
137110
print_unescaped(' class="hidden"');
@@ -145,7 +118,7 @@
145118
</p>
146119
</form>
147120
<form class="mail_settings" id="mail_credentials_settings">
148-
<p id="mail_credentials" <?php if (!$_['mail_smtpauth'] || $_['mail_smtpmode'] !== 'smtp') {
121+
<p id="mail_credentials" <?php if ($_['mail_smtpmode'] !== 'smtp') {
149122
print_unescaped(' class="hidden"');
150123
} ?>>
151124
<label for="mail_smtpname"><?php p($l->t('Credentials')); ?></label>

apps/settings/tests/Controller/MailSettingsControllerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public function testSetMailSettings() {
9191
'mail_smtpmode' => 'smtp',
9292
'mail_smtpsecure' => 'ssl',
9393
'mail_smtphost' => 'mx.nextcloud.org',
94-
'mail_smtpauthtype' => 'NTLM',
9594
'mail_smtpauth' => 1,
9695
'mail_smtpport' => '25',
9796
'mail_sendmailmode' => null,
@@ -102,7 +101,6 @@ public function testSetMailSettings() {
102101
'mail_smtpmode' => 'smtp',
103102
'mail_smtpsecure' => 'ssl',
104103
'mail_smtphost' => 'mx.nextcloud.org',
105-
'mail_smtpauthtype' => 'NTLM',
106104
'mail_smtpauth' => null,
107105
'mail_smtpport' => '25',
108106
'mail_smtpname' => null,
@@ -118,7 +116,6 @@ public function testSetMailSettings() {
118116
'smtp',
119117
'ssl',
120118
'mx.nextcloud.org',
121-
'NTLM',
122119
1,
123120
'25',
124121
null
@@ -132,7 +129,6 @@ public function testSetMailSettings() {
132129
'smtp',
133130
'ssl',
134131
'mx.nextcloud.org',
135-
'NTLM',
136132
0,
137133
'25',
138134
null

apps/settings/tests/Settings/Admin/MailTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function testGetForm() {
6464
['mail_smtpsecure', '', true],
6565
['mail_smtphost', '', 'smtp.nextcloud.com'],
6666
['mail_smtpport', '', 25],
67-
['mail_smtpauthtype', '', 'login'],
6867
['mail_smtpauth', false, true],
6968
['mail_smtpname', '', 'smtp.sender.com'],
7069
['mail_smtppassword', '', 'mypassword'],
@@ -82,7 +81,6 @@ public function testGetForm() {
8281
'mail_smtpsecure' => true,
8382
'mail_smtphost' => 'smtp.nextcloud.com',
8483
'mail_smtpport' => 25,
85-
'mail_smtpauthtype' => 'login',
8684
'mail_smtpauth' => true,
8785
'mail_smtpname' => 'smtp.sender.com',
8886
'mail_smtppassword' => '********',

config/config.sample.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -463,29 +463,24 @@
463463
'mail_smtptimeout' => 10,
464464

465465
/**
466-
* This depends on ``mail_smtpmode``. Specify when you are using ``ssl`` for SSL/TLS or
467-
* ``tls`` for STARTTLS, or leave empty for no encryption.
466+
* This depends on ``mail_smtpmode``. Specify ``ssl`` when you are using SSL/TLS. Any other value will be ignored.
467+
*
468+
* If the server advertises STARTTLS capabilities, they might be used, but they cannot be enforced by
469+
* this config option.
468470
*
469471
* Defaults to ``''`` (empty string)
470472
*/
471473
'mail_smtpsecure' => '',
472474

473475
/**
476+
*
474477
* This depends on ``mail_smtpmode``. Change this to ``true`` if your mail
475478
* server requires authentication.
476479
*
477480
* Defaults to ``false``
478481
*/
479482
'mail_smtpauth' => false,
480483

481-
/**
482-
* This depends on ``mail_smtpmode``. If SMTP authentication is required, choose
483-
* the authentication type as ``LOGIN`` or ``PLAIN``.
484-
*
485-
* Defaults to ``LOGIN``
486-
*/
487-
'mail_smtpauthtype' => 'LOGIN',
488-
489484
/**
490485
* This depends on ``mail_smtpauth``. Specify the username for authenticating to
491486
* the SMTP server.
@@ -1190,14 +1185,14 @@
11901185
'preview_office_cl_parameters' =>
11911186
' --headless --nologo --nofirststartwizard --invisible --norestore '.
11921187
'--convert-to png --outdir ',
1193-
1188+
11941189
/**
11951190
* custom path for ffmpeg binary
1196-
*
1191+
*
11971192
* Defaults to ``null`` and falls back to searching ``avconv`` and ``ffmpeg`` in the configured ``PATH`` environment
11981193
*/
1199-
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',
1200-
1194+
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',
1195+
12011196
/**
12021197
* Set the URL of the Imaginary service to send image previews to.
12031198
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled.

lib/private/Mail/Attachment.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace OC\Mail;
2828

2929
use OCP\Mail\IAttachment;
30+
use Symfony\Component\Mime\Email;
3031

3132
/**
3233
* Class Attachment
@@ -35,11 +36,21 @@
3536
* @since 13.0.0
3637
*/
3738
class Attachment implements IAttachment {
38-
/** @var \Swift_Mime_Attachment */
39-
protected $swiftAttachment;
39+
private ?string $body;
40+
private ?string $name;
41+
private ?string $contentType;
42+
private ?string $path;
4043

41-
public function __construct(\Swift_Mime_Attachment $attachment) {
42-
$this->swiftAttachment = $attachment;
44+
public function __construct(
45+
?string $body,
46+
?string $name,
47+
?string $contentType,
48+
?string $path = null
49+
) {
50+
$this->body = $body;
51+
$this->name = $name;
52+
$this->contentType = $contentType;
53+
$this->path = $path;
4354
}
4455

4556
/**
@@ -48,7 +59,7 @@ public function __construct(\Swift_Mime_Attachment $attachment) {
4859
* @since 13.0.0
4960
*/
5061
public function setFilename(string $filename): IAttachment {
51-
$this->swiftAttachment->setFilename($filename);
62+
$this->name = $filename;
5263
return $this;
5364
}
5465

@@ -58,7 +69,7 @@ public function setFilename(string $filename): IAttachment {
5869
* @since 13.0.0
5970
*/
6071
public function setContentType(string $contentType): IAttachment {
61-
$this->swiftAttachment->setContentType($contentType);
72+
$this->contentType = $contentType;
6273
return $this;
6374
}
6475

@@ -68,14 +79,15 @@ public function setContentType(string $contentType): IAttachment {
6879
* @since 13.0.0
6980
*/
7081
public function setBody(string $body): IAttachment {
71-
$this->swiftAttachment->setBody($body);
82+
$this->body = $body;
7283
return $this;
7384
}
7485

75-
/**
76-
* @return \Swift_Mime_Attachment
77-
*/
78-
public function getSwiftAttachment(): \Swift_Mime_Attachment {
79-
return $this->swiftAttachment;
86+
public function attach(Email $symfonyEmail): void {
87+
if ($this->path !== null) {
88+
$symfonyEmail->attachFromPath($this->path, $this->name, $this->contentType);
89+
} else {
90+
$symfonyEmail->attach($this->body, $this->name, $this->contentType);
91+
}
8092
}
8193
}

0 commit comments

Comments
 (0)