Skip to content
Snippets Groups Projects
Commit b9aee532 authored by bcweaver's avatar bcweaver
Browse files

Update 'smtp' module: 8.x-1.0-beta3 --> 8.x-1.0-beta4

parent 3711a990
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "660f35d22fb7bba03ecb6151fb4ee806",
"content-hash": "5eb47f8a36f62539ff7f81a51b48209d",
"packages": [
{
"name": "alchemy/zippy",
......@@ -5224,17 +5224,17 @@
},
{
"name": "drupal/smtp",
"version": "1.0.0-beta3",
"version": "1.0.0-beta4",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/smtp",
"reference": "8.x-1.0-beta3"
"reference": "8.x-1.0-beta4"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.0-beta3.zip",
"reference": "8.x-1.0-beta3",
"shasum": "a351dac3765b9570933fd07f1e029aa22e5c69b0"
"url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.0-beta4.zip",
"reference": "8.x-1.0-beta4",
"shasum": "80a4df4b2fd2d1b2dc653552d232ce98cb54bb9d"
},
"require": {
"drupal/core": "~8.0"
......@@ -5245,7 +5245,7 @@
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.0-beta3",
"version": "8.x-1.0-beta4",
"datestamp": "1527598380",
"security-coverage": {
"status": "not-covered",
......
......@@ -5386,18 +5386,18 @@
},
{
"name": "drupal/smtp",
"version": "1.0.0-beta3",
"version_normalized": "1.0.0.0-beta3",
"version": "1.0.0-beta4",
"version_normalized": "1.0.0.0-beta4",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/smtp",
"reference": "8.x-1.0-beta3"
"reference": "8.x-1.0-beta4"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.0-beta3.zip",
"reference": "8.x-1.0-beta3",
"shasum": "a351dac3765b9570933fd07f1e029aa22e5c69b0"
"url": "https://ftp.drupal.org/files/projects/smtp-8.x-1.0-beta4.zip",
"reference": "8.x-1.0-beta4",
"shasum": "80a4df4b2fd2d1b2dc653552d232ce98cb54bb9d"
},
"require": {
"drupal/core": "~8.0"
......@@ -5408,7 +5408,7 @@
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.0-beta3",
"version": "8.x-1.0-beta4",
"datestamp": "1527598380",
"security-coverage": {
"status": "not-covered",
......
......@@ -6,22 +6,22 @@ smtp.settings:
type: boolean
label: 'Turn this module on or off'
smtp_host:
type: text
type: string
label: 'SMTP server'
smtp_hostbackup:
type: text
type: string
label: 'SMTP backup server'
smtp_port:
type: text
type: string
label: 'SMTP port'
smtp_protocol:
type: text
type: string
label: 'Use encrypted protocol'
smtp_username:
type: text
type: string
label: 'Username'
smtp_password:
type: text
type: string
label: 'Password'
smtp_from:
type: email
......@@ -30,13 +30,13 @@ smtp.settings:
type: text
label: 'E-mail from name'
smtp_client_hostname:
type: text
type: string
label: 'Hostname'
smtp_client_helo:
type: text
type: string
label: 'HELO'
smtp_allowhtml:
type: text
type: string
label: 'Allow to send e-mails formated as HTML'
smtp_test_address:
type: email
......@@ -45,5 +45,5 @@ smtp.settings:
type: boolean
label: 'Enable debugging'
prev_mail_system:
type: text
type: string
label: 'Previous mail system'
......@@ -5,8 +5,8 @@ type: module
# core: 8.x
configure: smtp.config
# Information added by Drupal.org packaging script on 2017-06-27
version: '8.x-1.0-beta3'
# Information added by Drupal.org packaging script on 2018-05-29
version: '8.x-1.0-beta4'
core: '8.x'
project: 'smtp'
datestamp: 1498598947
datestamp: 1527598397
......@@ -31,11 +31,11 @@ function smtp_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_menu().
*/
function smtp_menu() {
$items['admin/config/system/smtp'] = array(
$items['admin/config/system/smtp'] = [
'title' => 'SMTP Authentication Support',
'description' => 'Allow for site emails to be sent through an SMTP server of your choice.',
'route_name' => 'smtp.config',
);
];
return $items;
}
......@@ -53,12 +53,12 @@ function smtp_mail($key, &$message, $params) {
* Implementation of hook_queue_info().
*/
function smtp_queue_info() {
$queues['smtp_send_queue'] = array(
$queues['smtp_send_queue'] = [
'worker callback' => 'smtp_send_queue_runner',
'cron' => array(
'cron' => [
'time' => 60, // This is the max run time per cron run in seconds.
),
);
],
];
return $queues;
}
......@@ -82,11 +82,11 @@ function _smtp_mailer_send($variables) {
$logger = \Drupal::logger('smtp');
// Let the people know what is going on.
$logger->info('Sending mail to: @to', array('@to' => $to));
$logger->info('Sending mail to: @to', ['@to' => $to]);
// Try to send e-mail. If it fails, set watchdog entry.
if (!$mailer->Send()) {
$logger->error('Error sending e-mail from @from to @to: @error_message', array('@from' => $from, '@to' => $to, '@error_message' => $mailer->ErrorInfo));
$logger->error('Error sending e-mail from @from to @to: @error_message', ['@from' => $from, '@to' => $to, '@error_message' => $mailer->ErrorInfo]);
return FALSE;
}
......
......@@ -2,9 +2,12 @@
namespace Drupal\smtp\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\smtp\Plugin\Mail\SMTPMailSystem;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Implements the SMTP admin settings form.
......@@ -12,179 +15,215 @@
class SMTPConfigForm extends ConfigFormBase {
/**
* {@inheritdoc}.
* The D8 messenger.
*
* @var \Drupal\Core\Messenger\Messenger
*/
protected $messenger;
/**
* Constructs $messenger and $config_factory objects.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Messenger\Messenger $messenger
* The D8 messenger object.
*/
public function __construct(ConfigFactoryInterface $config_factory, Messenger $messenger) {
$this->messenger = $messenger;
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('messenger')
);
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'smtp_admin_settings';
}
/**
* {@inheritdoc}.
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory->get('smtp.settings');
if ($config->get('smtp_on')) {
drupal_set_message(t('SMTP module is active.'));
$this->messenger->addMessage($this->t('SMTP module is active.'));
}
else {
drupal_set_message(t('SMTP module is INACTIVE.'));
$this->messenger->addMessage($this->t('SMTP module is INACTIVE.'));
}
drupal_set_message(t('Disabled fields are overridden in site-specific configuration file.'), 'warning');
$form['onoff'] = array(
$this->messenger->addMessage($this->t('Disabled fields are overridden in site-specific configuration file.'), 'warning');
$form['onoff'] = [
'#type' => 'details',
'#title' => t('Install options'),
'#title' => $this->t('Install options'),
'#open' => TRUE,
);
$form['onoff']['smtp_on'] = array(
];
$form['onoff']['smtp_on'] = [
'#type' => 'radios',
'#title' => t('Turn this module on or off'),
'#title' => $this->t('Turn this module on or off'),
'#default_value' => $config->get('smtp_on') ? 'on' : 'off',
'#options' => array('on' => t('On'), 'off' => t('Off')),
'#description' => t('To uninstall this module you must turn it off here first.'),
'#options' => ['on' => $this->t('On'), 'off' => $this->t('Off')],
'#description' => $this->t('To uninstall this module you must turn it off here first.'),
'#disabled' => $this->isOverridden('smtp_on'),
);
$form['server'] = array(
];
$form['server'] = [
'#type' => 'details',
'#title' => t('SMTP server settings'),
'#title' => $this->t('SMTP server settings'),
'#open' => TRUE,
);
$form['server']['smtp_host'] = array(
];
$form['server']['smtp_host'] = [
'#type' => 'textfield',
'#title' => t('SMTP server'),
'#title' => $this->t('SMTP server'),
'#default_value' => $config->get('smtp_host'),
'#description' => t('The address of your outgoing SMTP server.'),
'#description' => $this->t('The address of your outgoing SMTP server.'),
'#disabled' => $this->isOverridden('smtp_host'),
);
$form['server']['smtp_hostbackup'] = array(
];
$form['server']['smtp_hostbackup'] = [
'#type' => 'textfield',
'#title' => t('SMTP backup server'),
'#title' => $this->t('SMTP backup server'),
'#default_value' => $config->get('smtp_hostbackup'),
'#description' => t('The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional.'),
'#description' => $this->t("The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional."),
'#disabled' => $this->isOverridden('smtp_hostbackup'),
);
$form['server']['smtp_port'] = array(
];
$form['server']['smtp_port'] = [
'#type' => 'number',
'#title' => t('SMTP port'),
'#title' => $this->t('SMTP port'),
'#size' => 6,
'#maxlength' => 6,
'#default_value' => $config->get('smtp_port'),
'#description' => t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465. See :url for more information on configuring for use with Gmail.', array(':url' => 'http://gmail.google.com/support/bin/answer.py?answer=13287')),
'#description' => $this->t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465. See :url for more information on configuring for use with Gmail.',
[':url' => 'http://gmail.google.com/support/bin/answer.py?answer=13287']),
'#disabled' => $this->isOverridden('smtp_port'),
);
];
// Only display the option if openssl is installed.
if (function_exists('openssl_open')) {
$encryption_options = array(
'standard' => t('No'),
'ssl' => t('Use SSL'),
'tls' => t('Use TLS'),
);
$encryption_description = t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.');
$encryption_options = [
'standard' => $this->t('No'),
'ssl' => $this->t('Use SSL'),
'tls' => $this->t('Use TLS'),
];
$encryption_description = $this->t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.');
}
// If openssl is not installed, use normal protocol.
else {
$config->set('smtp_protocol', 'standard');
$encryption_options = array('standard' => t('No'));
$encryption_description = t('Your PHP installation does not have SSL enabled. See the :url page on php.net for more information. Gmail requires SSL.', array(':url' => 'http://php.net/openssl'));
$encryption_options = ['standard' => $this->t('No')];
$encryption_description = $this->t('Your PHP installation does not have SSL enabled. See the :url page on php.net for more information. Gmail requires SSL.',
[':url' => 'http://php.net/openssl']);
}
$form['server']['smtp_protocol'] = array(
$form['server']['smtp_protocol'] = [
'#type' => 'select',
'#title' => t('Use encrypted protocol'),
'#title' => $this->t('Use encrypted protocol'),
'#default_value' => $config->get('smtp_protocol'),
'#options' => $encryption_options,
'#description' => $encryption_description,
'#disabled' => $this->isOverridden('smtp_protocol'),
);
];
$form['auth'] = array(
$form['auth'] = [
'#type' => 'details',
'#title' => t('SMTP Authentication'),
'#description' => t('Leave blank if your SMTP server does not require authentication.'),
'#title' => $this->t('SMTP Authentication'),
'#description' => $this->t('Leave blank if your SMTP server does not require authentication.'),
'#open' => TRUE,
);
$form['auth']['smtp_username'] = array(
];
$form['auth']['smtp_username'] = [
'#type' => 'textfield',
'#title' => t('Username'),
'#title' => $this->t('Username'),
'#default_value' => $config->get('smtp_username'),
'#description' => t('SMTP Username.'),
'#description' => $this->t('SMTP Username.'),
'#disabled' => $this->isOverridden('smtp_username'),
);
$form['auth']['smtp_password'] = array(
];
$form['auth']['smtp_password'] = [
'#type' => 'password',
'#title' => t('Password'),
'#title' => $this->t('Password'),
'#default_value' => $config->get('smtp_password'),
'#description' => t('SMTP password. If you have already entered your password before, you should leave this field blank, unless you want to change the stored password. Please note that this password will be stored as plain-text inside Drupal\'s core configuration variables.'),
'#description' => $this->t("SMTP password. If you have already entered your password before, you should leave this field blank, unless you want to change the stored password. Please note that this password will be stored as plain-text inside Drupal\'s core configuration variables."),
'#disabled' => $this->isOverridden('smtp_password'),
);
];
$form['email_options'] = array(
$form['email_options'] = [
'#type' => 'details',
'#title' => t('E-mail options'),
'#title' =>$this->t('E-mail options'),
'#open' => TRUE,
);
$form['email_options']['smtp_from'] = array(
];
$form['email_options']['smtp_from'] = [
'#type' => 'textfield',
'#title' => t('E-mail from address'),
'#title' => $this->t('E-mail from address'),
'#default_value' => $config->get('smtp_from'),
'#description' => t('The e-mail address that all e-mails will be from.'),
'#description' => $this->t('The e-mail address that all e-mails will be from.'),
'#disabled' => $this->isOverridden('smtp_from'),
);
$form['email_options']['smtp_fromname'] = array(
];
$form['email_options']['smtp_fromname'] = [
'#type' => 'textfield',
'#title' => t('E-mail from name'),
'#title' => $this->t('E-mail from name'),
'#default_value' => $config->get('smtp_fromname'),
'#description' => t('The name that all e-mails will be from. If left blank will use a default of: @name',
'#description' => $this->t('The name that all e-mails will be from. If left blank will use a default of: @name',
['@name' => $this->configFactory->get('system.site')->get('name')]),
'#disabled' => $this->isOverridden('smtp_fromname'),
);
$form['email_options']['smtp_allowhtml'] = array(
];
$form['email_options']['smtp_allowhtml'] = [
'#type' => 'checkbox',
'#title' => t('Allow to send e-mails formatted as HTML'),
'#title' => $this->t('Allow to send e-mails formatted as HTML'),
'#default_value' => $config->get('smtp_allowhtml'),
'#description' => t('Checking this box will allow HTML formatted e-mails to be sent with the SMTP protocol.'),
'#description' => $this->t('Checking this box will allow HTML formatted e-mails to be sent with the SMTP protocol.'),
'#disabled' => $this->isOverridden('smtp_allowhtml'),
);
];
$form['client'] = array(
$form['client'] = [
'#type' => 'details',
'#title' => t('SMTP client settings'),
'#title' => $this->t('SMTP client settings'),
'#open' => TRUE,
);
$form['client']['smtp_client_hostname'] = array(
];
$form['client']['smtp_client_hostname'] = [
'#type' => 'textfield',
'#title' => t('Hostname'),
'#title' => $this->t('Hostname'),
'#default_value' => $config->get('smtp_client_hostname'),
'#description' => t('The hostname to use in the Message-Id and Received headers, and as the default HELO string. Leave blank for using %server_name.', array('%server_name' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain')),
'#description' => $this->t('The hostname to use in the Message-Id and Received headers, and as the default HELO string. Leave blank for using %server_name.',
['%server_name' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain']),
'#disabled' => $this->isOverridden('smtp_client_hostname'),
);
$form['client']['smtp_client_helo'] = array(
];
$form['client']['smtp_client_helo'] = [
'#type' => 'textfield',
'#title' => t('HELO'),
'#title' => $this->t('HELO'),
'#default_value' => $config->get('smtp_client_helo'),
'#description' => t('The SMTP HELO/EHLO of the message. Defaults to hostname (see above).'),
'#description' => $this->t('The SMTP HELO/EHLO of the message. Defaults to hostname (see above).'),
'#disabled' => $this->isOverridden('smtp_client_helo'),
);
];
$form['email_test'] = array(
$form['email_test'] = [
'#type' => 'details',
'#title' => t('Send test e-mail'),
'#title' => $this->t('Send test e-mail'),
'#open' => TRUE,
);
$form['email_test']['smtp_test_address'] = array(
];
$form['email_test']['smtp_test_address'] = [
'#type' => 'textfield',
'#title' => t('E-mail address to send a test e-mail to'),
'#title' => $this->t('E-mail address to send a test e-mail to'),
'#default_value' => '',
'#description' => t('Type in an address to have a test e-mail sent there.'),
);
'#description' => $this->t('Type in an address to have a test e-mail sent there.'),
];
$form['smtp_debugging'] = array(
$form['smtp_debugging'] = [
'#type' => 'checkbox',
'#title' => t('Enable debugging'),
'#title' => $this->t('Enable debugging'),
'#default_value' => $config->get('smtp_debugging'),
'#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
'#description' => $this->t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
'#disabled' => $this->isOverridden('smtp_debugging'),
);
];
return parent::buildForm($form, $form_state);
}
......@@ -193,9 +232,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* Check if config variable is overridden by the settings.php.
*
* @param string $name
* STMP settings key.
* STMP settings key.
*
* @return bool
* Boolean.
*/
protected function isOverridden($name) {
$original = $this->configFactory->getEditable('smtp.settings')->get($name);
......@@ -225,12 +265,15 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
}
// If username is set empty, we must set both username/password empty as well.
// If username is set empty, we must set both
// username/password empty as well.
if (empty($values['smtp_username'])) {
$values['smtp_password'] = '';
}
// A little hack. When form is presented, the password is not shown (Drupal way of doing).
// So, if user submits the form without changing the password, we must prevent it from being reset.
// A little hack. When form is presented,
// the password is not shown (Drupal way of doing).
// So, if user submits the form without changing the password,
// we must prevent it from being reset.
elseif (empty($values['smtp_password'])) {
$form_state->unsetValue('smtp_password');
}
......@@ -289,10 +332,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// If an address was given, send a test e-mail message.
if ($test_address = $values['smtp_test_address']) {
$params['subject'] = t('Drupal SMTP test e-mail');
$params['body'] = array(t('If you receive this message it means your site is capable of using SMTP to send e-mail.'));
$params['subject'] = $this->t('Drupal SMTP test e-mail');
$params['body'] = [$this->t('If you receive this message it means your site is capable of using SMTP to send e-mail.')];
$account = \Drupal::currentUser();
// If module is off, send the test message with SMTP by temporarily overriding.
// If module is off, send the test message
// with SMTP by temporarily overriding.
if (!$config->get('smtp_on')) {
$original = $mail_config->get('interface');
$mail_system = 'SMTPMailSystem';
......@@ -302,7 +346,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if (!$config->get('smtp_on')) {
$mail_config->set('interface', $original)->save();
}
drupal_set_message(t('A test e-mail has been sent to @email via SMTP. You may want to check the log for any error messages.', ['@email' => $test_address]));
$this->messenger->addMessage($this->t('A test e-mail has been sent to @email via SMTP. You may want to check the log for any error messages.', ['@email' => $test_address]));
}
parent::submitForm($form, $form_state);
......
......@@ -1054,7 +1054,8 @@ public function CreateHeader() {
$result = '';
// Set the boundaries
$uniq_id = md5(uniqid(REQUEST_TIME));
$request_time = \Drupal::time()->getRequestTime();
$uniq_id = md5(uniqid($request_time));
$this->boundary[1] = 'b1_' . $uniq_id;
$this->boundary[2] = 'b2_' . $uniq_id;
......@@ -2288,7 +2289,7 @@ public function DKIM_Add($headers_line, $subject, $body) {
$DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
$DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
$DKIMquery = 'dns/txt'; // Query method
$DKIMtime = REQUEST_TIME; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$DKIMtime = \Drupal::time()->getRequestTime(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$subject_header = "Subject: $subject";
$headers = explode("\r\n", $headers_line);
foreach ($headers as $header) {
......
......@@ -127,7 +127,7 @@ public function mail(array $message) {
// Defines the From value to what we expect.
$mailer->From = $from;
$mailer->FromName = $from_name;
$mailer->FromName = Unicode::mimeHeaderEncode($from_name);
$mailer->Sender = $from;
$hostname = $this->smtpConfig->get('smtp_client_hostname');
......@@ -215,8 +215,8 @@ public function mail(array $message) {
break;
default:
// Everything else is unsuppored by PHPMailer.
drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value")), 'error');
$this->logger->error(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value")));
drupal_set_message(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', ['%header' => "Content-Type: $value"]), 'error');
$this->logger->error(t('The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', ['%header' => "Content-Type: $value"]));
// Force the Content-Type to be text/plain.
$mailer->IsHTML(FALSE);
......@@ -228,7 +228,7 @@ public function mail(array $message) {
// Only add a "reply-to" if it's not the same as "return-path".
if ($value != $headers['Return-Path']) {
$reply_to_comp = $this->_get_components($value);
$mailer->AddReplyTo($reply_to_comp['email'], $reply_to_comp['name']);
$mailer->AddReplyTo($reply_to_comp['email'], Unicode::mimeHeaderEncode($reply_to_comp['name']));
}
break;
......@@ -253,7 +253,7 @@ public function mail(array $message) {
$ccrecipients = explode(',', $value);
foreach ($ccrecipients as $ccrecipient) {
$cc_comp = $this->_get_components($ccrecipient);
$mailer->AddCC($cc_comp['email'], $cc_comp['name']);
$mailer->AddCC($cc_comp['email'], Unicode::mimeHeaderEncode($cc_comp['name']));
}
break;
......@@ -261,7 +261,7 @@ public function mail(array $message) {
$bccrecipients = explode(',', $value);
foreach ($bccrecipients as $bccrecipient) {
$bcc_comp = $this->_get_components($bccrecipient);
$mailer->AddBCC($bcc_comp['email'], $bcc_comp['name']);
$mailer->AddBCC($bcc_comp['email'], Unicode::mimeHeaderEncode($bcc_comp['name']));
}
break;
......@@ -287,7 +287,7 @@ public function mail(array $message) {
* }
*/
// Add the message's subject.
$mailer->Subject = $subject;
$mailer->Subject = Unicode::mimeHeaderEncode($subject);
// Processes the message's body.
switch ($content_type) {
......@@ -489,13 +489,13 @@ public function mail(array $message) {
$mailer->Port = $this->smtpConfig->get('smtp_port');
$mailer->Mailer = 'smtp';
$mailerArr = array(
$mailerArr = [
'mailer' => $mailer,
'to' => $to,
'from' => $from,
);
];
if ($this->smtpConfig->get('smtp_queue')) {
$this->logger->info(t('Queue sending mail to: @to', array('@to' => $to)));
$this->logger->info(t('Queue sending mail to: @to', ['@to' => $to]));
smtp_send_queue($mailerArr);
}
else {
......@@ -519,7 +519,7 @@ public function mail(array $message) {
* An array containing the resulting mime parts
*/
protected function _boundary_split($input, $boundary) {
$parts = array();
$parts = [];
$bs_possible = substr($boundary, 2, -2);
$bs_check = '\"' . $bs_possible . '\"';
......@@ -549,35 +549,35 @@ protected function _boundary_split($input, $boundary) {
protected function _remove_headers($input) {
$part_array = explode("\n", $input);
// will strip these headers according to RFC2045
$headers_to_strip = array( 'Content-Type', 'Content-Transfer-Encoding', 'Content-ID', 'Content-Disposition');
// Will strip these headers according to RFC2045.
$headers_to_strip = ['Content-Type', 'Content-Transfer-Encoding', 'Content-ID', 'Content-Disposition'];
$pattern = '/^(' . implode('|', $headers_to_strip) . '):/';
while (count($part_array) > 0) {
// ignore trailing spaces/newlines
// Ignore trailing spaces/newlines.
$line = rtrim($part_array[0]);
// if the line starts with a known header string
// If the line starts with a known header string.
if (preg_match($pattern, $line)) {
$line = rtrim(array_shift($part_array));
// remove line containing matched header.
// Remove line containing matched header.
// if line ends in a ';' and the next line starts with four spaces, it's a continuation
// If line ends in a ';' and the next line starts with four spaces, it's a continuation
// of the header split onto the next line. Continue removing lines while we have this condition.
while (substr($line, -1) == ';' && count($part_array) > 0 && substr($part_array[0], 0, 4) == ' ') {
$line = rtrim(array_shift($part_array));
}
}
else {
// no match header, must be past headers; stop searching.
// No match header, must be past headers; stop searching.
break;
}
}
$output = implode("\n", $part_array);
return $output;
} // End of _smtp_remove_headers().
}
/**
* Returns a string that is contained within another string.
......@@ -609,7 +609,7 @@ protected function _get_substring($source, $target, $beginning_character, $endin
}
return $substring;
} // End of _smtp_get_substring().
}
/**
* Returns an array of name and email address from a string.
......@@ -621,11 +621,11 @@ protected function _get_substring($source, $target, $beginning_character, $endin
* An array containing a name and an email address.
*/
protected function _get_components($input) {
$components = array(
$components = [
'input' => $input,
'name' => '',
'email' => '',
);
];
// If the input is a valid email address in its entirety, then there is
// nothing to do, just return that.
......
......@@ -16,7 +16,7 @@ class SmtpTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('smtp');
public static $modules = ['smtp'];
/**
* Perform any initial set up tasks that run before every test method
......
<?php
namespace Drupal\Tests\smtp\Unit;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\smtp\Form\SMTPConfigForm;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Validate requirements for ProceedingsRealmNegotiator.
*
* @group SMTP
*/
class SMTPConfigFormTest extends UnitTestCase {
/**
* Test setup.
*/
public function setup() {
$this->mockConfigFactory = $this->prophesize(ConfigFactoryInterface::class);
$this->mockConfig = $this->prophesize(Config::class);
$this->mockConfigFactory->get('smtp.settings')->willReturn($this->mockConfig->reveal());
$this->mockConfigFactory->getEditable('smtp.settings')->willReturn($this->mockConfig->reveal());
$this->mockConfigSystemSite = $this->prophesize(Config::class);
$this->mockConfigSystemSite->get('name')->willReturn('Site name');
$this->mockConfigFactory->get('system.site')->willReturn($this->mockConfigSystemSite->reveal());
$this->mockMessenger = $this->prophesize(Messenger::class);
$mockContainer = $this->mockContainer = $this->prophesize(ContainerInterface::class);
$mockContainer->get('config.factory')->willReturn($this->mockConfigFactory->reveal());
$mockContainer->get('messenger')->willReturn($this->mockMessenger->reveal());
$mockStringTranslation = $this->prophesize(TranslationInterface::class);
$mockStringTranslation->translate(Argument::any())->willReturnArgument(0);
$mockStringTranslation->translate(Argument::any(), Argument::any())->willReturnArgument(0);
$mockStringTranslation->translateString(Argument::any())->willReturn('.');
$mockContainer->get('string_translation')->willReturn($mockStringTranslation->reveal());
\Drupal::setContainer($this->mockContainer->reveal());
}
/**
* Sets the default smtp config.
*/
public function setDefaultConfig() {
$this->mockConfig->get('smtp_on')->willReturn(TRUE);
$this->mockConfig->get('smtp_host')->willReturn('');
$this->mockConfig->get('smtp_hostbackup')->willReturn('');
$this->mockConfig->get('smtp_port')->willReturn('');
$this->mockConfig->get('smtp_protocol')->willReturn('');
$this->mockConfig->get('smtp_username')->willReturn('');
$this->mockConfig->get('smtp_password')->willReturn('');
$this->mockConfig->get('smtp_from')->willReturn('');
$this->mockConfig->get('smtp_fromname')->willReturn('');
$this->mockConfig->get('smtp_allowhtml')->willReturn('');
$this->mockConfig->get('smtp_client_hostname')->willReturn('');
$this->mockConfig->get('smtp_client_helo')->willReturn('');
$this->mockConfig->get('smtp_debugging')->willReturn('');
}
/**
* Test if enabled message is properly shown.
*/
public function testBuildFormEnabledMessage() {
$this->setDefaultConfig();
$this->mockConfig->get('smtp_on')->willReturn(TRUE);
$formBuilder = SMTPConfigForm::create($this->mockContainer->reveal());
$form = [];
$formBuilder->buildForm($form, new FormState());
$this->mockMessenger->addMessage(Argument::which('getUntranslatedString', 'SMTP module is active.'))->shouldHaveBeenCalled();
}
/**
* Test if enabled message is properly shown.
*/
public function testBuildFormDisabledMessage() {
$this->setDefaultConfig();
$this->mockConfig->get('smtp_on')->willReturn(FALSE);
$formBuilder = SMTPConfigForm::create($this->mockContainer->reveal());
$form = [];
$formBuilder->buildForm($form, new FormState());
$this->mockMessenger->addMessage(Argument::which('getUntranslatedString', 'SMTP module is INACTIVE.'))->shouldHaveBeenCalled();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment