more module updates
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
diff --git a/smtp.mail.inc b/smtp.mail.inc
|
||||
index 2cf0841..b228e45 100644
|
||||
--- a/smtp.mail.inc
|
||||
+++ b/smtp.mail.inc
|
||||
@@ -367,10 +367,21 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
}
|
||||
// If plain/html within the body part, add it to $mailer->Body.
|
||||
elseif (strpos($body_part2, 'text/html')) {
|
||||
+ // Get the encoding.
|
||||
+ $body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ' ', "\n");
|
||||
// Clean up the text.
|
||||
$body_part2 = trim($this->_remove_headers(trim($body_part2)));
|
||||
- // Include it as part of the mail object.
|
||||
- $mailer->Body = $body_part2;
|
||||
+ // Check whether the encoding is base64, and if so, decode it.
|
||||
+ if (drupal_strtolower($body_part2_encoding) == 'base64') {
|
||||
+ // Include it as part of the mail object.
|
||||
+ $mailer->Body = base64_decode($body_part2);
|
||||
+ // Ensure the whole message is recoded in the base64 format.
|
||||
+ $mailer->Encoding = 'base64';
|
||||
+ }
|
||||
+ else {
|
||||
+ // Include it as part of the mail object.
|
||||
+ $mailer->Body = $body_part2;
|
||||
+ }
|
||||
$mailer->ContentType = 'multipart/mixed';
|
||||
}
|
||||
}
|
@@ -49,6 +49,12 @@ function smtp_admin_settings() {
|
||||
'#options' => array(1 => t('On'), 0 => t('Off')),
|
||||
'#description' => t('To uninstall this module you must turn it off here first.'),
|
||||
);
|
||||
$form['onoff']['smtp_queue'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Send mail by queue'),
|
||||
'#default_value' => variable_get('smtp_queue', FALSE),
|
||||
'#description' => t('Mails will be sent by drupal queue api.'),
|
||||
);
|
||||
|
||||
$form['server'] = array(
|
||||
'#type' => 'fieldset',
|
||||
@@ -167,6 +173,8 @@ function smtp_admin_settings() {
|
||||
'#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
|
||||
);
|
||||
|
||||
$form['#submit'][] = 'smtp_admin_settings_form_submit';
|
||||
|
||||
return system_settings_form($form);
|
||||
} // End of smtp_admin_settings().
|
||||
|
||||
@@ -205,3 +213,27 @@ function smtp_admin_settings_validate($form, &$form_state) {
|
||||
}
|
||||
} // End of smtp_admin_settings_validate().
|
||||
|
||||
/**
|
||||
* Submit handler().
|
||||
*/
|
||||
function smtp_admin_settings_form_submit($form, &$form_state) {
|
||||
// Check if SMTP status has been changed.
|
||||
if (
|
||||
(!variable_get('smtp_on', FALSE) && $form_state['values']['smtp_on']) ||
|
||||
(variable_get('smtp_on', FALSE) && !$form_state['values']['smtp_on'])
|
||||
) {
|
||||
$mail_modes = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||
|
||||
// Turning on.
|
||||
if ($form_state['values']['smtp_on']) {
|
||||
variable_set('smtp_previous_mail_system', $mail_modes['default-system']);
|
||||
$mail_modes['default-system'] = 'SmtpMailSystem';
|
||||
}
|
||||
// Turning off.
|
||||
else {
|
||||
$mail_modes['default-system'] = variable_get('smtp_previous_mail_system', 'DefaultMailSystem');
|
||||
}
|
||||
|
||||
variable_set('mail_system', $mail_modes);
|
||||
}
|
||||
}
|
||||
|
@@ -7,9 +7,9 @@ files[] = smtp.mail.inc
|
||||
files[] = smtp.phpmailer.inc
|
||||
files[] = smtp.transport.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-17
|
||||
version = "7.x-1.0"
|
||||
; Information added by Drupal.org packaging script on 2015-01-07
|
||||
version = "7.x-1.2"
|
||||
core = "7.x"
|
||||
project = "smtp"
|
||||
datestamp = "1361062292"
|
||||
datestamp = "1420662781"
|
||||
|
||||
|
@@ -32,15 +32,6 @@ function smtp_uninstall() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function smtp_enable() {
|
||||
$mail_modes = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||
$mail_modes['default-system'] = 'SmtpMailSystem';
|
||||
variable_set('mail_system', $mail_modes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
@@ -59,3 +50,16 @@ function smtp_update_7000() {
|
||||
variable_set('mail_system', array('default-system' => 'SmtpMailSystem'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_N().
|
||||
*
|
||||
* Back to default mail system if the status flag is off.
|
||||
*/
|
||||
function smtp_update_7100() {
|
||||
$mail_modes = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||
if ($mail_modes['default-system'] == 'SmtpMailSystem' && !variable_get('smtp_on', FALSE)) {
|
||||
$mail_modes['default-system'] = 'DefaultMailSystem';
|
||||
variable_set('mail_system', $mail_modes);
|
||||
}
|
||||
}
|
||||
|
@@ -230,6 +230,16 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
break;
|
||||
|
||||
case 'return-path':
|
||||
if (strpos($value, '<') !== FALSE) {
|
||||
$returnPathParts = explode('<', $value);
|
||||
$returnPathAddr = rtrim($returnPathParts[1], '>');
|
||||
$mailer->Sender = $returnPathAddr;
|
||||
}
|
||||
else {
|
||||
$mailer->Sender = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mime-version':
|
||||
case 'x-mailer':
|
||||
// Let PHPMailer specify these.
|
||||
@@ -271,27 +281,31 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'message-id':
|
||||
$mailer->MessageID = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
// The header key is not special - add it as is.
|
||||
$mailer->AddCustomHeader($key . ': ' . $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Need to figure out the following.
|
||||
*
|
||||
* Add one last header item, but not if it has already been added.
|
||||
* $errors_to = FALSE;
|
||||
* foreach ($mailer->CustomHeader as $custom_header) {
|
||||
* if ($custom_header[0] = '') {
|
||||
* $errors_to = TRUE;
|
||||
* }
|
||||
* }
|
||||
* if ($errors_to) {
|
||||
* $mailer->AddCustomHeader('Errors-To: '. $from);
|
||||
* }
|
||||
*/
|
||||
/**
|
||||
* TODO
|
||||
* Need to figure out the following.
|
||||
*
|
||||
* Add one last header item, but not if it has already been added.
|
||||
* $errors_to = FALSE;
|
||||
* foreach ($mailer->CustomHeader as $custom_header) {
|
||||
* if ($custom_header[0] = '') {
|
||||
* $errors_to = TRUE;
|
||||
* }
|
||||
* }
|
||||
* if ($errors_to) {
|
||||
* $mailer->AddCustomHeader('Errors-To: '. $from);
|
||||
* }
|
||||
*/
|
||||
// Add the message's subject.
|
||||
$mailer->Subject = $subject;
|
||||
|
||||
@@ -299,12 +313,7 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
switch ($content_type) {
|
||||
case 'multipart/related':
|
||||
$mailer->Body = $body;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Firgure out if there is anything more to handling this type.
|
||||
*/
|
||||
|
||||
// TODO: Figure out if there is anything more to handling this type.
|
||||
break;
|
||||
|
||||
case 'multipart/alternative':
|
||||
@@ -368,7 +377,7 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
// If plain/html within the body part, add it to $mailer->Body.
|
||||
elseif (strpos($body_part2, 'text/html')) {
|
||||
// Get the encoding.
|
||||
$body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ' ', "\n");
|
||||
$body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ':', "\n");
|
||||
// Clean up the text.
|
||||
$body_part2 = trim($this->_remove_headers(trim($body_part2)));
|
||||
// Check whether the encoding is base64, and if so, decode it.
|
||||
@@ -412,7 +421,7 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
$mailer->ContentType = 'multipart/mixed';
|
||||
}
|
||||
// Add the attachment.
|
||||
elseif (strpos($body_part, 'Content-Disposition: attachment;')) {
|
||||
elseif (strpos($body_part, 'Content-Disposition: attachment;') && !isset($message['params']['attachments'])) {
|
||||
$file_path = $this->_get_substring($body_part, 'filename=', '"', '"');
|
||||
$file_name = $this->_get_substring($body_part, ' name=', '"', '"');
|
||||
$file_encoding = $this->_get_substring($body_part, 'Content-Transfer-Encoding', ' ', "\n");
|
||||
@@ -454,14 +463,16 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
break;
|
||||
}
|
||||
|
||||
// Process mimemail attachments
|
||||
// Process mimemail attachments, which are prepared in mimemail_mail().
|
||||
if (isset($message['params']['attachments'])) {
|
||||
foreach ($message['params']['attachments'] as $attachment) {
|
||||
if (isset($attachment['filecontent'])) {
|
||||
$mailer->AddStringAttachment($attachment['filecontent'], $attachment['filename'], 'base64', $attachment['filemime']);
|
||||
}
|
||||
if (isset($attachment['filepath'])) {
|
||||
$mailer->AddAttachment($attachment['filepath'], $attachment['filename'], 'base64', $attachment['filemime']);
|
||||
$filename = isset($attachment['filename']) ? $attachment['filename'] : basename($attachment['filepath']);
|
||||
$filemime = isset($attachment['filemime']) ? $attachment['filemime'] : file_get_mimetype($attachment['filepath']);
|
||||
$mailer->AddAttachment($attachment['filepath'], $filename, 'base64', $filemime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,16 +509,19 @@ class SmtpMailSystem implements MailSystemInterface {
|
||||
$mailer->Port = variable_get('smtp_port', '25');
|
||||
$mailer->Mailer = 'smtp';
|
||||
|
||||
// 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;
|
||||
$mailerArr = array(
|
||||
'mailer' => $mailer,
|
||||
'to' => $to,
|
||||
'from' => $from,
|
||||
);
|
||||
if (variable_get('smtp_queue', FALSE)) {
|
||||
watchdog('smtp', 'Queue sending mail to: @to', array('@to' => $to));
|
||||
smtp_send_queue($mailerArr);
|
||||
}
|
||||
else {
|
||||
return _smtp_mailer_send($mailerArr);
|
||||
}
|
||||
|
||||
$mailer->SmtpClose();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -61,3 +61,44 @@ function smtp_mail($key, &$message, $params) {
|
||||
$message['body'] = $params['body'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_cron_queue_info().
|
||||
*/
|
||||
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.
|
||||
);
|
||||
return $queues;
|
||||
}
|
||||
|
||||
/**
|
||||
* smtp_send_queue queuer.
|
||||
*/
|
||||
function smtp_send_queue($mailerObj) {
|
||||
$queue = DrupalQueue::get('smtp_send_queue');
|
||||
$queue->createItem($mailerObj);
|
||||
}
|
||||
|
||||
function smtp_send_queue_runner($variables) {
|
||||
_smtp_mailer_send($variables);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$mailer->SmtpClose();
|
||||
return TRUE;
|
||||
}
|
@@ -1741,27 +1741,41 @@ class PHPMailer {
|
||||
*/
|
||||
public function EncodeQ($str, $position = 'text') {
|
||||
// There should not be any EOL in the string
|
||||
$encoded = preg_replace('/[\r\n]*/', '', $str);
|
||||
|
||||
$pattern = '';
|
||||
$encoded = str_replace(array("\r", "\n"), '', $str);
|
||||
switch (strtolower($position)) {
|
||||
case 'phrase':
|
||||
$encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
|
||||
// RFC 2047 section 5.3
|
||||
$pattern = '^A-Za-z0-9!*+\/ -';
|
||||
break;
|
||||
/** @noinspection PhpMissingBreakStatementInspection */
|
||||
case 'comment':
|
||||
$encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
|
||||
// RFC 2047 section 5.2
|
||||
$pattern = '\(\)"';
|
||||
// intentional fall-through
|
||||
// for this reason we build the $pattern without including delimiters and []
|
||||
case 'text':
|
||||
default:
|
||||
// Replace every high ascii, control =, ? and _ characters
|
||||
//TODO using /e (equivalent to eval()) is probably not a good idea
|
||||
$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
|
||||
"'='.sprintf('%02X', ord('\\1'))", $encoded);
|
||||
// RFC 2047 section 5.1
|
||||
// Replace every high ascii, control, =, ? and _ characters
|
||||
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
|
||||
break;
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
|
||||
// If the string contains an '=', make sure it's the first thing we replace
|
||||
// so as to avoid double-encoding
|
||||
$s = array_search('=', $matches[0]);
|
||||
if ($s !== false) {
|
||||
unset($matches[0][$s]);
|
||||
array_unshift($matches[0], '=');
|
||||
}
|
||||
foreach (array_unique($matches[0]) as $char) {
|
||||
$encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
|
||||
}
|
||||
}
|
||||
// Replace every spaces to _ (more readable than =20)
|
||||
$encoded = str_replace(' ', '_', $encoded);
|
||||
|
||||
return $encoded;
|
||||
return str_replace(' ', '_', $encoded);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user