security update for smtp module

This commit is contained in:
Bachir Soussi Chiadmi
2017-07-25 19:17:08 +02:00
parent 8feebe3d1e
commit ed483507e5
12 changed files with 872 additions and 288 deletions

View File

@@ -15,6 +15,22 @@
* This module uses array('default-system' => 'SmtpMailSystem').
*/
/**
* SMTP logging -- logging is disabled
*/
define('SMTP_LOGGING_NONE', 0);
/**
* SMTP logging -- all messages are logged
*/
define('SMTP_LOGGING_ALL', 1);
/**
* SMTP logging -- only errors are logged
*/
define('SMTP_LOGGING_ERRORS', 2);
/**
* Implements hook_help().
*/
@@ -68,8 +84,14 @@ function smtp_mail($key, &$message, $params) {
function smtp_cron_queue_info() {
$queues['smtp_send_queue'] = array(
'worker callback' => 'smtp_send_queue_runner',
'time' => 60, // This is the max run time per cron run in seconds.
'time' => 60,
);
$queues['smtp_failure_queue'] = array(
'worker callback' => 'smtp_failure_queue_runner',
'time' => 30,
);
return $queues;
}
@@ -81,24 +103,55 @@ function smtp_send_queue($mailerObj) {
$queue->createItem($mailerObj);
}
function smtp_send_queue_runner($variables) {
_smtp_mailer_send($variables);
}
function smtp_send_queue_runner($message) {
$logging = variable_get('smtp_debugging', SMTP_LOGGING_ERRORS);
function _smtp_mailer_send($variables) {
$mailer = $variables['mailer'];
$to = $variables['to'];
$from = $variables['from'];
// Let the people know what is going on.
watchdog('smtp', 'Sending mail to: @to', array('@to' => $to));
// Try to send e-mail. If it fails, set watchdog entry.
if (!$mailer->Send()) {
watchdog('smtp', 'Error sending e-mail from @from to @to : !error_message', array('@from' => $from, '@to' => $to, '!error_message' => $mailer->ErrorInfo), WATCHDOG_ERROR);
return FALSE;
// Legacy for mails queued before 7.x-v1.3
// What was passed to the runner used to be a PHPMailer object, not a message array.
if (!empty($message['mailer']) && is_object($message['mailer'])) {
if (!$message['mailer']->Send()) {
if ($logging == SMTP_LOGGING_ALL || $logging == SMTP_LOGGING_ERRORS) {
watchdog('smtp', 'Error sending e-mail from @from to @to, will retry on cron run : !error_message.',
array(
'@from' => $message['from'],
'@to' => $message['to'],
'!error_message' => $message['mailer']->ErrorInfo,
), WATCHDOG_ERROR);
}
}
return;
}
$mailer->SmtpClose();
return TRUE;
}
// Let the people know what is going on.
if ($logging == SMTP_LOGGING_ALL) {
watchdog('smtp', 'Sending mail to: @to', array('@to' => $message['to']));
}
// Send the message.
$mail_system = new SmtpMailSystem();
$mail_system->mailWithoutQueue($message);
}
/**
* Store failed messages for later.
*
* @param array $new_message
*
* @return array
* All messages that have been saved.
*/
function smtp_failed_messages($message) {
$queue = DrupalQueue::get('smtp_failure_queue');
$queue->createItem($message);
}
/**
* Queue runner for smtp_failure_queue.
*
* @param $message
* A drupal_mail-formatted message.
*/
function smtp_failure_queue_runner($message) {
$queue = DrupalQueue::get('smtp_send_queue');
$queue->createItem($message);
}