Skip to content

Commit

Permalink
Merge pull request #30349 from nextcloud/enhancement/migrate_to_symfo…
Browse files Browse the repository at this point in the history
…ny_mailer

Migrate to Symfony Mailer
  • Loading branch information
blizzz authored Feb 2, 2023
2 parents fc4e87a + e123d27 commit bbd3e2b
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 487 deletions.
2 changes: 1 addition & 1 deletion 3rdparty
Submodule 3rdparty updated 121 files
7 changes: 6 additions & 1 deletion apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ public function schedule(Message $iTipMessage) {
return;
}

$senderName = $iTipMessage->senderName ?: null;
$recipientName = $iTipMessage->recipientName ?: null;

/** @var Parameter|string|null $senderName */
$senderName = $iTipMessage->senderName ?: null;
if($senderName instanceof Parameter) {
$senderName = $senderName->getValue() ?? null;
}

if ($senderName === null || empty(trim($senderName))) {
$senderName = $this->userManager->getDisplayName($this->userId);
}
Expand Down
2 changes: 0 additions & 2 deletions apps/settings/lib/Controller/MailSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function __construct($appName,
* @param string $mail_smtpmode
* @param string $mail_smtpsecure
* @param string $mail_smtphost
* @param string $mail_smtpauthtype
* @param int $mail_smtpauth
* @param string $mail_smtpport
* @return DataResponse
Expand All @@ -95,7 +94,6 @@ public function setMailSettings($mail_domain,
$mail_smtpmode,
$mail_smtpsecure,
$mail_smtphost,
$mail_smtpauthtype,
$mail_smtpauth,
$mail_smtpport,
$mail_sendmailmode) {
Expand Down
1 change: 0 additions & 1 deletion apps/settings/lib/Settings/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function getForm() {
'mail_smtpsecure' => $this->config->getSystemValue('mail_smtpsecure', ''),
'mail_smtphost' => $this->config->getSystemValue('mail_smtphost', ''),
'mail_smtpport' => $this->config->getSystemValue('mail_smtpport', ''),
'mail_smtpauthtype' => $this->config->getSystemValue('mail_smtpauthtype', ''),
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
Expand Down
33 changes: 3 additions & 30 deletions apps/settings/templates/settings/admin/additional-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@
/** @var \OCP\IL10N $l */
/** @var array $_ */

$mail_smtpauthtype = [
'' => $l->t('None'),
'LOGIN' => $l->t('Login'),
'PLAIN' => $l->t('Plain'),
'NTLM' => $l->t('NT LAN Manager'),
];

$mail_smtpsecure = [
'' => $l->t('None'),
'ssl' => $l->t('SSL/TLS'),
'tls' => $l->t('STARTTLS'),
'ssl' => $l->t('SSL/TLS')
];

$mail_smtpmode = [
Expand Down Expand Up @@ -112,26 +104,7 @@
value="<?php p($_['mail_domain']) ?>" />
</p>

<p id="setting_smtpauth" <?php if ($_['mail_smtpmode'] !== 'smtp') {
print_unescaped(' class="hidden"');
} ?>>
<label for="mail_smtpauthtype"><?php p($l->t('Authentication method')); ?></label>
<select name="mail_smtpauthtype" id="mail_smtpauthtype">
<?php foreach ($mail_smtpauthtype as $authtype => $name):
$selected = '';
if ($authtype == $_['mail_smtpauthtype']):
$selected = 'selected="selected"';
endif; ?>
<option value="<?php p($authtype)?>" <?php p($selected) ?>><?php p($name) ?></option>
<?php endforeach;?>
</select>

<input type="checkbox" name="mail_smtpauth" id="mail_smtpauth" class="checkbox" value="1"
<?php if ($_['mail_smtpauth']) {
print_unescaped('checked="checked"');
} ?> />
<label for="mail_smtpauth"><?php p($l->t('Authentication required')); ?></label>
</p>
<!--lo-->

<p id="setting_smtphost" <?php if ($_['mail_smtpmode'] !== 'smtp') {
print_unescaped(' class="hidden"');
Expand All @@ -145,7 +118,7 @@
</p>
</form>
<form class="mail_settings" id="mail_credentials_settings">
<p id="mail_credentials" <?php if (!$_['mail_smtpauth'] || $_['mail_smtpmode'] !== 'smtp') {
<p id="mail_credentials" <?php if ($_['mail_smtpmode'] !== 'smtp') {
print_unescaped(' class="hidden"');
} ?>>
<label for="mail_smtpname"><?php p($l->t('Credentials')); ?></label>
Expand Down
4 changes: 0 additions & 4 deletions apps/settings/tests/Controller/MailSettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function testSetMailSettings() {
'mail_smtpmode' => 'smtp',
'mail_smtpsecure' => 'ssl',
'mail_smtphost' => 'mx.nextcloud.org',
'mail_smtpauthtype' => 'NTLM',
'mail_smtpauth' => 1,
'mail_smtpport' => '25',
'mail_sendmailmode' => null,
Expand All @@ -102,7 +101,6 @@ public function testSetMailSettings() {
'mail_smtpmode' => 'smtp',
'mail_smtpsecure' => 'ssl',
'mail_smtphost' => 'mx.nextcloud.org',
'mail_smtpauthtype' => 'NTLM',
'mail_smtpauth' => null,
'mail_smtpport' => '25',
'mail_smtpname' => null,
Expand All @@ -118,7 +116,6 @@ public function testSetMailSettings() {
'smtp',
'ssl',
'mx.nextcloud.org',
'NTLM',
1,
'25',
null
Expand All @@ -132,7 +129,6 @@ public function testSetMailSettings() {
'smtp',
'ssl',
'mx.nextcloud.org',
'NTLM',
0,
'25',
null
Expand Down
2 changes: 0 additions & 2 deletions apps/settings/tests/Settings/Admin/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function testGetForm() {
['mail_smtpsecure', '', true],
['mail_smtphost', '', 'smtp.nextcloud.com'],
['mail_smtpport', '', 25],
['mail_smtpauthtype', '', 'login'],
['mail_smtpauth', false, true],
['mail_smtpname', '', 'smtp.sender.com'],
['mail_smtppassword', '', 'mypassword'],
Expand All @@ -82,7 +81,6 @@ public function testGetForm() {
'mail_smtpsecure' => true,
'mail_smtphost' => 'smtp.nextcloud.com',
'mail_smtpport' => 25,
'mail_smtpauthtype' => 'login',
'mail_smtpauth' => true,
'mail_smtpname' => 'smtp.sender.com',
'mail_smtppassword' => '********',
Expand Down
23 changes: 9 additions & 14 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,29 +463,24 @@
'mail_smtptimeout' => 10,

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

/**
*
* This depends on ``mail_smtpmode``. Change this to ``true`` if your mail
* server requires authentication.
*
* Defaults to ``false``
*/
'mail_smtpauth' => false,

/**
* This depends on ``mail_smtpmode``. If SMTP authentication is required, choose
* the authentication type as ``LOGIN`` or ``PLAIN``.
*
* Defaults to ``LOGIN``
*/
'mail_smtpauthtype' => 'LOGIN',

/**
* This depends on ``mail_smtpauth``. Specify the username for authenticating to
* the SMTP server.
Expand Down Expand Up @@ -1190,14 +1185,14 @@
'preview_office_cl_parameters' =>
' --headless --nologo --nofirststartwizard --invisible --norestore '.
'--convert-to png --outdir ',

/**
* custom path for ffmpeg binary
*
*
* Defaults to ``null`` and falls back to searching ``avconv`` and ``ffmpeg`` in the configured ``PATH`` environment
*/
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',
'preview_ffmpeg_path' => '/usr/bin/ffmpeg',

/**
* Set the URL of the Imaginary service to send image previews to.
* Also requires the ``OC\Preview\Imaginary`` provider to be enabled.
Expand Down
36 changes: 24 additions & 12 deletions lib/private/Mail/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\Mail;

use OCP\Mail\IAttachment;
use Symfony\Component\Mime\Email;

/**
* Class Attachment
Expand All @@ -35,11 +36,21 @@
* @since 13.0.0
*/
class Attachment implements IAttachment {
/** @var \Swift_Mime_Attachment */
protected $swiftAttachment;
private ?string $body;
private ?string $name;
private ?string $contentType;
private ?string $path;

public function __construct(\Swift_Mime_Attachment $attachment) {
$this->swiftAttachment = $attachment;
public function __construct(
?string $body,
?string $name,
?string $contentType,
?string $path = null
) {
$this->body = $body;
$this->name = $name;
$this->contentType = $contentType;
$this->path = $path;
}

/**
Expand All @@ -48,7 +59,7 @@ public function __construct(\Swift_Mime_Attachment $attachment) {
* @since 13.0.0
*/
public function setFilename(string $filename): IAttachment {
$this->swiftAttachment->setFilename($filename);
$this->name = $filename;
return $this;
}

Expand All @@ -58,7 +69,7 @@ public function setFilename(string $filename): IAttachment {
* @since 13.0.0
*/
public function setContentType(string $contentType): IAttachment {
$this->swiftAttachment->setContentType($contentType);
$this->contentType = $contentType;
return $this;
}

Expand All @@ -68,14 +79,15 @@ public function setContentType(string $contentType): IAttachment {
* @since 13.0.0
*/
public function setBody(string $body): IAttachment {
$this->swiftAttachment->setBody($body);
$this->body = $body;
return $this;
}

/**
* @return \Swift_Mime_Attachment
*/
public function getSwiftAttachment(): \Swift_Mime_Attachment {
return $this->swiftAttachment;
public function attach(Email $symfonyEmail): void {
if ($this->path !== null) {
$symfonyEmail->attachFromPath($this->path, $this->name, $this->contentType);
} else {
$symfonyEmail->attach($this->body, $this->name, $this->contentType);
}
}
}
Loading

0 comments on commit bbd3e2b

Please sign in to comment.