Skip to content

Commit

Permalink
Updating SMTP Authentication Support to 7.x-1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mwanberg committed Dec 4, 2018
1 parent 2dc4452 commit 9ee4cbc
Show file tree
Hide file tree
Showing 12 changed files with 703 additions and 276 deletions.
3 changes: 3 additions & 0 deletions sites/all/modules/contrib/smtp/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ extension is working. If the SMTP module detects openssl is available it
will display the options in the modules settings page.

Sending mail to Gmail requires SSL or TLS.

If the Maillog module (https://www.drupal.org/project/maillog) is installed, it
can be used to keep copies of all messages sent through the site.
164 changes: 99 additions & 65 deletions sites/all/modules/contrib/smtp/smtp.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,17 @@
/**
* @file
* Administrative page code for the smtp module.
*
*/


/**
* Administrative settings.
*
* @return
* An array containing form items to place on the module settings page.
*/
function smtp_admin_settings() {
// Override the smtp_library variable.
if (module_exists('mimemail') &&
strpos(variable_get('smtp_library', ''), 'mimemail')) {
// don't touch smtp_library
if (variable_get('smtp_on', 0)) {
drupal_set_message(t('SMTP.module is active.'));
}
else {
if (variable_get('smtp_on', 0)) {
$smtp_path = drupal_get_filename('module', 'smtp');
if ($smtp_path) {
variable_set('smtp_library', $smtp_path);
drupal_set_message(t('SMTP.module is active.'));
}
// If drupal can't find the path to the module, display an error.
else {
drupal_set_message(t("SMTP.module error: Can't find file."), 'error');
}
}
// If this module is turned off, delete the variable.
else {
variable_del('smtp_library');
drupal_set_message(t('SMTP.module is INACTIVE.'));
}
drupal_set_message(t('SMTP.module is INACTIVE.'));
}

$logging = variable_get('smtp_debugging', SMTP_LOGGING_ERRORS);
Expand All @@ -47,10 +25,17 @@ function smtp_admin_settings() {
$form['onoff']['smtp_on'] = array(
'#type' => 'radios',
'#title' => t('Turn this module on or off'),
'#default_value' => variable_get('smtp_on', 0),
'#default_value' => variable_get('smtp_on', FALSE),
'#options' => array(1 => t('On'), 0 => t('Off')),
'#description' => t('To uninstall this module you must turn it off here first.'),
);
$form['onoff']['smtp_deliver'] = array(
'#type' => 'radios',
'#title' => t('Turn on delivery of emails'),
'#default_value' => variable_get('smtp_deliver', TRUE),
'#options' => array(1 => t('On'), 0 => t('Off')),
'#description' => t('With this option turned off, email messages will be queued up and processed as normal, but not actually delivered. This option should only be used for testing purposes.'),
);
$form['onoff']['smtp_queue'] = array(
'#type' => 'checkbox',
'#title' => t('Send mail by queue'),
Expand Down Expand Up @@ -96,7 +81,7 @@ function smtp_admin_settings() {
'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_description = t('This allows connection to a SMTP server that requires SSL encryption such as Gmail.');
}
// If openssl is not installed, use normal protocol.
else {
Expand Down Expand Up @@ -128,6 +113,9 @@ function smtp_admin_settings() {
'#title' => t('Password'),
'#default_value' => variable_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.'),
'#attributes' => array(
'autocomplete' => 'off',
),
);

$form['email_options'] = array(
Expand All @@ -153,23 +141,22 @@ function smtp_admin_settings() {
'#description' => t('Checking this box will allow Html formatted e-mails to be sent with the SMTP protocol.'),
);

// If an address was given, send a test e-mail message.
$test_address = variable_get('smtp_test_address', '');
if ($test_address != '') {
// Clear the variable so only one message is sent.
variable_del('smtp_test_address');
global $language;
$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.'));
drupal_mail('smtp', 'smtp-test', $test_address, $language, $params);

if ($logging === SMTP_LOGGING_NONE) {
drupal_set_message(t('A test e-mail has been sent to @email.', array('@email' => $test_address)));
}
else {
drupal_set_message(t('A test e-mail has been sent to @email. You may want to !check for any error messages.', array('@email' => $test_address, '!check' => l(t('check the logs'), 'admin/reports/dblog'))));
}
}
$form['client'] = array(
'#type' => 'fieldset',
'#title' => t('SMTP client settings'),
);
$form['client']['smtp_client_hostname'] = array(
'#type' => 'textfield',
'#title' => t('Hostname'),
'#default_value' => variable_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')),
);
$form['client']['smtp_client_helo'] = array(
'#type' => 'textfield',
'#title' => t('HELO'),
'#default_value' => variable_get('smtp_client_helo', ''),
'#description' => t('The SMTP HELO/EHLO of the message. Defaults to hostname (see above).'),
);

$form['email_test'] = array(
'#type' => 'fieldset',
Expand Down Expand Up @@ -199,45 +186,59 @@ function smtp_admin_settings() {
'#default_value' => $logging,
'#description' => t('Choose the appropriate log level. "Log everything" will log errors and informational messages when an email is sent. "Errors only" will only create a log entry when sending failed. "No logging" will disable all logging for this module.'),
);
$form['email_test']['smtp_reroute_address'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address to reroute all emails to'),
'#default_value' => variable_get('smtp_reroute_address', ''),
'#description' => t('All emails sent by the site will be rerouted to this email address; use with caution.'),
);

$form['#submit'][] = 'smtp_admin_settings_form_submit';
$form['debugging']['maillog'] = array(
'#type' => 'fieldset',
'#title' => t('Maillog integration'),
);

return system_settings_form($form);
} // End of smtp_admin_settings().
if (!module_exists('maillog')) {
$form['debugging']['maillog']['#description'] = t('Installing the <a href="@url">Maillog module</a> also allows keeping copies of all emails sent through the site.', array('@url' => 'https://www.drupal.org/project/maillog'));
}
else {
$form['debugging']['maillog']['#description'] = t('The <a href="@url">Maillog module</a> is installed, it can also be used to keep copies of all emails sent through the site.', array('@url' => url('admin/config/development/maillog')));

$form['debugging']['maillog']['maillog_log'] = array(
'#type' => 'checkbox',
'#title' => t("Create table entries in maillog table for each e-mail."),
'#default_value' => variable_get('maillog_log', TRUE),
);

$form['debugging']['maillog']['maillog_devel'] = array(
'#type' => 'checkbox',
'#title' => t("Display the e-mails on page using devel module (if enabled)."),
'#default_value' => variable_get('maillog_devel', TRUE),
'#disabled' => !module_exists('devel'),
);
}

$form['#submit'][] = 'smtp_admin_settings_form_submit';
$form = system_settings_form($form);
$form['#submit'][] = 'smtp_admin_settings_submit_post_system_settings';
return $form;
}

/**
* Validation for the administrative settings form.
*
* @param form
* An associative array containing the structure of the form.
* @param form_state
* A keyed array containing the current state of the form.
*/
function smtp_admin_settings_validate($form, &$form_state) {
if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_host'] == '') {
form_set_error('smtp_host', t('You must enter an SMTP server address.'));
form_set_error('smtp_host', t('You must enter a SMTP server address.'));
}

if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_port'] == '') {
form_set_error('smtp_port', t('You must enter an SMTP port number.'));
form_set_error('smtp_port', t('You must enter a SMTP port number.'));
}

if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) {
form_set_error('smtp_from', t('The provided from e-mail address is not valid.'));
}

// If username is set empty, we must set both username/password empty as well.
if (empty($form_state['values']['smtp_username'])) {
$form_state['values']['smtp_password'] = '';
}

// A little hack. When form is presentend, 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($form_state['values']['smtp_password'])) {
unset($form_state['values']['smtp_password']);
}
} // End of smtp_admin_settings_validate().

/**
Expand All @@ -263,4 +264,37 @@ function smtp_admin_settings_form_submit($form, &$form_state) {

variable_set('mail_system', $mail_modes);
}

// If username is set empty, we must set both username/password empty as well.
if (empty($form_state['values']['smtp_username'])) {
$form_state['values']['smtp_password'] = '';
}

// A little hack. When form is presentend, 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($form_state['values']['smtp_password'])) {
unset($form_state['values']['smtp_password']);
}

// Save the test address to send an email after all the settings have been
// updated.
$form_state['storage']['smtp']['smtp_test_address'] = $form_state['values']['smtp_test_address'];
unset($form_state['values']['smtp_test_address']);
}

/**
* Submit handler for the administrative settings form containing all
* functionality to be run after system_settings_form_submit.
*/
function smtp_admin_settings_submit_post_system_settings($form, &$form_state) {
// If an address was given, send a test e-mail message.
$test_address = $form_state['storage']['smtp']['smtp_test_address'];
if ($test_address != '') {
$language = language_default();
$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.'));
drupal_mail('smtp', 'smtp-test', $test_address, $language, $params);
drupal_set_message(t('A test e-mail has been sent to @email. You may want to !check for any error messages.', array('@email' => $test_address, '!check' => l(t('check the logs'), 'admin/reports/dblog'))));
}
}
12 changes: 9 additions & 3 deletions sites/all/modules/contrib/smtp/smtp.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ files[] = smtp.mail.inc
files[] = smtp.phpmailer.inc
files[] = smtp.transport.inc

; Information added by Drupal.org packaging script on 2015-12-08
version = "7.x-1.3"
; Test suite.
files[] = tests/smtp.unit.test

; For the tests the Maillog module is also required.
test_dependencies[] = maillog

; Information added by Drupal.org packaging script on 2017-06-27
version = "7.x-1.7"
core = "7.x"
project = "smtp"
datestamp = "1449607140"
datestamp = "1498593247"

65 changes: 54 additions & 11 deletions sites/all/modules/contrib/smtp/smtp.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@
* The installation instructions for the SMTP Authentication Support.
*/

/**
* Implements hook_requirements().
*/
function smtp_requirements($phase) {
$requirements = array();

if ($phase == 'runtime') {
if (variable_get('smtp_queue', FALSE) || variable_get('smtp_queue_fail', FALSE)) {
$count = db_query("SELECT count('name') FROM {queue} WHERE name='smtp_send_queue'")->fetchField();
$requirements['smtp_queue'] = array(
'title' => t('SMTP Queue'),
'value' => '',
'severity' => REQUIREMENT_INFO,
);
if ($count > 0) {
$requirements['smtp_queue']['value'] = format_plural($count, 'There is 1 message queued for delivery.', 'There are @count messages queued for delivery.', array('@count' => $count))
. ' '
. t('Delivery of the message(s) will be attempted the next time cron runs.');
}
else {
$requirements['smtp_queue']['value'] = t('There are no messages queued for delivery.');
}
}
}

return $requirements;
}

/**
* Implements hook_install().
*/
Expand All @@ -27,13 +55,12 @@ function smtp_uninstall() {
variable_del('smtp_protocol');
variable_del('smtp_queue');
variable_del('smtp_queue_fail');
variable_del('smtp_test_address');
variable_del('smtp_username');
variable_del('smtp_debugging');

if (variable_get('smtp_library', '') == drupal_get_path('module', 'smtp') . '/smtp.module') {
variable_del('smtp_library');
}
variable_del('smtp_client_hostname');
variable_del('smtp_client_helo');
variable_del('smtp_deliver');
variable_del('smtp_reroute_address');
}

/**
Expand All @@ -46,19 +73,21 @@ function smtp_disable() {
}

/**
* Implements hook_update_N().
*
* Implementations of hook_update_N().
*/

/**
* Upgrade to Drupal 7.x
*/
function smtp_update_7000() {
if (variable_get('smtp_on', 0) != 0) {
variable_set('mail_system', array('default-system' => 'SmtpMailSystem'));
}
// Not used any more in D7.
variable_del('smtp_library');
}

/**
* Implements hook_update_N().
*
* Back to default mail system if the status flag is off.
*/
function smtp_update_7100() {
Expand All @@ -70,8 +99,6 @@ function smtp_update_7100() {
}

/**
* Implements hook_update_N().
*
* Updating variable value now that new SMTP logging behavior has been
* implemented.
*/
Expand All @@ -86,3 +113,19 @@ function smtp_update_7101() {

variable_set('smtp_debugging', $logging);
}

/**
* Remove the unused 'smtp_library' variable.
*/
function smtp_update_7102() {
variable_del('smtp_library');
}

/**
* Delete the variable "smtp_test_address". It is unlikely that this would
* actually be set in the normal course of events, and it's no longer needed as
* it was replaced with a form submit handler.
*/
function smtp_update_7103() {
variable_del('smtp_test_address');
}
Loading

0 comments on commit 9ee4cbc

Please sign in to comment.