Merge pull request #12749 from nextcloud/backport/12424/stable14
[stable14] Add pipe mode for sendmail
This commit is contained in:
commit
26a5b6d5c6
|
@ -421,6 +421,19 @@ $CONFIG = array(
|
||||||
*/
|
*/
|
||||||
'mail_send_plaintext_only' => false,
|
'mail_send_plaintext_only' => false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which mode is used for sendmail/qmail: ``smtp`` or ``pipe``.
|
||||||
|
*
|
||||||
|
* For ``smtp`` the sendmail binary is started with the parameter ``-bs``:
|
||||||
|
* - Use the SMTP protocol on standard input and output.
|
||||||
|
*
|
||||||
|
* For ``pipe`` the binary is started with the parameters ``-t``:
|
||||||
|
* - Read message from STDIN and extract recipients.
|
||||||
|
*
|
||||||
|
* Defaults to ``smtp``
|
||||||
|
*/
|
||||||
|
'mail_sendmailmode' => 'smtp',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy Configurations
|
* Proxy Configurations
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -278,6 +278,15 @@ class Mailer implements IMailer {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new \Swift_SendmailTransport($binaryPath . ' -bs');
|
switch ($this->config->getSystemValue('mail_sendmailmode', 'smtp')) {
|
||||||
|
case 'pipe':
|
||||||
|
$binaryParam = ' -t';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$binaryParam = ' -bs';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new \Swift_SendmailTransport($binaryPath . $binaryParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Mail implements ISettings {
|
||||||
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
|
'mail_smtpauth' => $this->config->getSystemValue('mail_smtpauth', false),
|
||||||
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
|
'mail_smtpname' => $this->config->getSystemValue('mail_smtpname', ''),
|
||||||
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
|
'mail_smtppassword' => $this->config->getSystemValue('mail_smtppassword', ''),
|
||||||
|
'mail_sendmailmode' => $this->config->getSystemValue('mail_sendmailmode', 'smtp'),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($parameters['mail_smtppassword'] !== '') {
|
if ($parameters['mail_smtppassword'] !== '') {
|
||||||
|
|
|
@ -91,7 +91,8 @@ class MailSettingsController extends Controller {
|
||||||
$mail_smtphost,
|
$mail_smtphost,
|
||||||
$mail_smtpauthtype,
|
$mail_smtpauthtype,
|
||||||
$mail_smtpauth,
|
$mail_smtpauth,
|
||||||
$mail_smtpport) {
|
$mail_smtpport,
|
||||||
|
$mail_sendmailmode) {
|
||||||
|
|
||||||
$params = get_defined_vars();
|
$params = get_defined_vars();
|
||||||
$configs = [];
|
$configs = [];
|
||||||
|
|
|
@ -161,6 +161,7 @@ $(document).ready(function(){
|
||||||
$('#mail_smtpsecure_label').addClass('hidden');
|
$('#mail_smtpsecure_label').addClass('hidden');
|
||||||
$('#mail_smtpsecure').addClass('hidden');
|
$('#mail_smtpsecure').addClass('hidden');
|
||||||
$('#mail_credentials').addClass('hidden');
|
$('#mail_credentials').addClass('hidden');
|
||||||
|
$('#mail_sendmailmode_label, #mail_sendmailmode').removeClass('hidden');
|
||||||
} else {
|
} else {
|
||||||
$('#setting_smtpauth').removeClass('hidden');
|
$('#setting_smtpauth').removeClass('hidden');
|
||||||
$('#setting_smtphost').removeClass('hidden');
|
$('#setting_smtphost').removeClass('hidden');
|
||||||
|
@ -169,6 +170,7 @@ $(document).ready(function(){
|
||||||
if ($('#mail_smtpauth').is(':checked')) {
|
if ($('#mail_smtpauth').is(':checked')) {
|
||||||
$('#mail_credentials').removeClass('hidden');
|
$('#mail_credentials').removeClass('hidden');
|
||||||
}
|
}
|
||||||
|
$('#mail_sendmailmode_label, #mail_sendmailmode').addClass('hidden');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,11 @@ if ($_['mail_smtpmode'] === 'qmail') {
|
||||||
$mail_smtpmode[] = ['qmail', 'qmail'];
|
$mail_smtpmode[] = ['qmail', 'qmail'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$mail_sendmailmode = [
|
||||||
|
'smtp' => 'smtp (-bs)',
|
||||||
|
'pipe' => 'pipe (-t)'
|
||||||
|
];
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="section" id="mail_general_settings">
|
<div class="section" id="mail_general_settings">
|
||||||
|
@ -84,6 +89,15 @@ if ($_['mail_smtpmode'] === 'qmail') {
|
||||||
<option value="<?php p($secure)?>" <?php p($selected) ?>><?php p($name) ?></option>
|
<option value="<?php p($secure)?>" <?php p($selected) ?>><?php p($name) ?></option>
|
||||||
<?php endforeach;?>
|
<?php endforeach;?>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<label id="mail_sendmailmode_label" for="mail_sendmailmode" class="<?= $_['mail_smtpmode'] !== 'sendmail' ? 'hidden' : '' ?>">
|
||||||
|
<?php p($l->t('Sendmail mode')); ?>
|
||||||
|
</label>
|
||||||
|
<select name="mail_sendmailmode" id="mail_sendmailmode" class="<?= $_['mail_smtpmode'] !== 'sendmail' ? 'hidden' : '' ?>">
|
||||||
|
<?php foreach ($mail_sendmailmode as $sendmailmodeValue => $sendmailmodeLabel): ?>
|
||||||
|
<option value="<?php p($sendmailmodeValue)?>" <?= $sendmailmodeValue === $_['mail_sendmailmode'] ? 'selected="selected"' : '' ?>><?php p($sendmailmodeLabel) ?></option>
|
||||||
|
<?php endforeach;?>
|
||||||
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -74,6 +74,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mail_smtpauthtype' => 'NTLM',
|
'mail_smtpauthtype' => 'NTLM',
|
||||||
'mail_smtpauth' => 1,
|
'mail_smtpauth' => 1,
|
||||||
'mail_smtpport' => '25',
|
'mail_smtpport' => '25',
|
||||||
|
'mail_sendmailmode' => null,
|
||||||
]],
|
]],
|
||||||
[[
|
[[
|
||||||
'mail_domain' => 'nextcloud.com',
|
'mail_domain' => 'nextcloud.com',
|
||||||
|
@ -86,6 +87,7 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mail_smtpport' => '25',
|
'mail_smtpport' => '25',
|
||||||
'mail_smtpname' => null,
|
'mail_smtpname' => null,
|
||||||
'mail_smtppassword' => null,
|
'mail_smtppassword' => null,
|
||||||
|
'mail_sendmailmode' => null,
|
||||||
]]
|
]]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -98,7 +100,8 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mx.nextcloud.org',
|
'mx.nextcloud.org',
|
||||||
'NTLM',
|
'NTLM',
|
||||||
1,
|
1,
|
||||||
'25'
|
'25',
|
||||||
|
null
|
||||||
);
|
);
|
||||||
$this->assertSame(Http::STATUS_OK, $response->getStatus());
|
$this->assertSame(Http::STATUS_OK, $response->getStatus());
|
||||||
|
|
||||||
|
@ -111,7 +114,8 @@ class MailSettingsControllerTest extends \Test\TestCase {
|
||||||
'mx.nextcloud.org',
|
'mx.nextcloud.org',
|
||||||
'NTLM',
|
'NTLM',
|
||||||
0,
|
0,
|
||||||
'25'
|
'25',
|
||||||
|
null
|
||||||
);
|
);
|
||||||
$this->assertSame(Http::STATUS_OK, $response->getStatus());
|
$this->assertSame(Http::STATUS_OK, $response->getStatus());
|
||||||
|
|
||||||
|
|
|
@ -48,24 +48,48 @@ class MailerTest extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSendMailInstanceSendMail() {
|
/**
|
||||||
$this->config
|
* @return array
|
||||||
->expects($this->once())
|
*/
|
||||||
->method('getSystemValue')
|
public function sendmailModeProvider(): array {
|
||||||
->with('mail_smtpmode', 'smtp')
|
return [
|
||||||
->will($this->returnValue('sendmail'));
|
'smtp' => ['smtp', ' -bs'],
|
||||||
|
'pipe' => ['pipe', ' -t'],
|
||||||
$this->assertEquals(new \Swift_SendmailTransport('/usr/sbin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance'));
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSendMailInstanceSendMailQmail() {
|
/**
|
||||||
|
* @dataProvider sendmailModeProvider
|
||||||
|
* @param $sendmailMode
|
||||||
|
* @param $binaryParam
|
||||||
|
*/
|
||||||
|
public function testGetSendmailInstanceSendMail($sendmailMode, $binaryParam) {
|
||||||
$this->config
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->exactly(2))
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('mail_smtpmode', 'smtp')
|
->will($this->returnValueMap([
|
||||||
->will($this->returnValue('qmail'));
|
['mail_smtpmode', 'smtp', 'sendmail'],
|
||||||
|
['mail_sendmailmode', 'smtp', $sendmailMode],
|
||||||
|
]));
|
||||||
|
|
||||||
$this->assertEquals(new \Swift_SendmailTransport('/var/qmail/bin/sendmail -bs'), self::invokePrivate($this->mailer, 'getSendMailInstance'));
|
$this->assertEquals(new \Swift_SendmailTransport('/usr/sbin/sendmail' . $binaryParam), self::invokePrivate($this->mailer, 'getSendMailInstance'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider sendmailModeProvider
|
||||||
|
* @param $sendmailMode
|
||||||
|
* @param $binaryParam
|
||||||
|
*/
|
||||||
|
public function testGetSendmailInstanceSendMailQmail($sendmailMode, $binaryParam) {
|
||||||
|
$this->config
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->will($this->returnValueMap([
|
||||||
|
['mail_smtpmode', 'smtp', 'qmail'],
|
||||||
|
['mail_sendmailmode', 'smtp', $sendmailMode],
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals(new \Swift_SendmailTransport('/var/qmail/bin/sendmail' . $binaryParam), self::invokePrivate($this->mailer, 'getSendMailInstance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInstanceDefault() {
|
public function testGetInstanceDefault() {
|
||||||
|
@ -77,8 +101,10 @@ class MailerTest extends TestCase {
|
||||||
public function testGetInstanceSendmail() {
|
public function testGetInstanceSendmail() {
|
||||||
$this->config
|
$this->config
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('mail_smtpmode', 'smtp')
|
->will($this->returnValueMap([
|
||||||
->willReturn('sendmail');
|
['mail_smtpmode', 'smtp', 'sendmail'],
|
||||||
|
['mail_sendmailmode', 'smtp', 'smtp'],
|
||||||
|
]));
|
||||||
|
|
||||||
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
$mailer = self::invokePrivate($this->mailer, 'getInstance');
|
||||||
$this->assertInstanceOf(\Swift_Mailer::class, $mailer);
|
$this->assertInstanceOf(\Swift_Mailer::class, $mailer);
|
||||||
|
|
|
@ -95,6 +95,11 @@ class MailTest extends TestCase {
|
||||||
->method('getSystemValue')
|
->method('getSystemValue')
|
||||||
->with('mail_smtppassword', '')
|
->with('mail_smtppassword', '')
|
||||||
->willReturn('mypassword');
|
->willReturn('mypassword');
|
||||||
|
$this->config
|
||||||
|
->expects($this->at(10))
|
||||||
|
->method('getSystemValue')
|
||||||
|
->with('mail_sendmailmode', 'smtp')
|
||||||
|
->willReturn('smtp');
|
||||||
|
|
||||||
$expected = new TemplateResponse(
|
$expected = new TemplateResponse(
|
||||||
'settings',
|
'settings',
|
||||||
|
@ -111,6 +116,7 @@ class MailTest extends TestCase {
|
||||||
'mail_smtpauth' => true,
|
'mail_smtpauth' => true,
|
||||||
'mail_smtpname' => 'smtp.sender.com',
|
'mail_smtpname' => 'smtp.sender.com',
|
||||||
'mail_smtppassword' => '********',
|
'mail_smtppassword' => '********',
|
||||||
|
'mail_sendmailmode' => 'smtp',
|
||||||
],
|
],
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue