|
@@ -46,35 +46,84 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
* TRUE if the mail was successfully accepted, otherwise FALSE.
|
|
* TRUE if the mail was successfully accepted, otherwise FALSE.
|
|
*/
|
|
*/
|
|
public function mail(array $message) {
|
|
public function mail(array $message) {
|
|
- $id = $message['id'];
|
|
|
|
|
|
+ if (variable_get('smtp_queue', FALSE)
|
|
|
|
+ && (!isset($message['params']['skip_queue']) || !$message['params']['skip_queue'])) {
|
|
|
|
+ smtp_send_queue($message);
|
|
|
|
+ if (variable_get('smtp_debugging', SMTP_LOGGING_ERRORS) == SMTP_LOGGING_ALL) {
|
|
|
|
+ watchdog('smtp', 'Queue sending mail to: @to', array('@to' => $message['to']));
|
|
|
|
+ }
|
|
|
|
+ return TRUE;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return $this->mailWithoutQueue($message);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function mailWithoutQueue(array $message) {
|
|
$to = $message['to'];
|
|
$to = $message['to'];
|
|
$from = $message['from'];
|
|
$from = $message['from'];
|
|
$body = $message['body'];
|
|
$body = $message['body'];
|
|
$headers = $message['headers'];
|
|
$headers = $message['headers'];
|
|
$subject = $message['subject'];
|
|
$subject = $message['subject'];
|
|
|
|
|
|
|
|
+ // Optionally reroute all emails to a single address.
|
|
|
|
+ $reroute_address = variable_get('smtp_reroute_address', '');
|
|
|
|
+ if (!empty($reroute_address)) {
|
|
|
|
+ $to = $reroute_address;
|
|
|
|
+ // Remove any CC and BCC headers that might have been set.
|
|
|
|
+ unset($headers['cc']);
|
|
|
|
+ unset($headers['bcc']);
|
|
|
|
+ }
|
|
|
|
+
|
|
// Create a new PHPMailer object - autoloaded from registry.
|
|
// Create a new PHPMailer object - autoloaded from registry.
|
|
$mailer = new PHPMailer();
|
|
$mailer = new PHPMailer();
|
|
|
|
|
|
|
|
+ $logging = variable_get('smtp_debugging', SMTP_LOGGING_ERRORS);
|
|
|
|
+
|
|
// Turn on debugging, if requested.
|
|
// Turn on debugging, if requested.
|
|
- if (variable_get('smtp_debugging', 0) == 1) {
|
|
|
|
|
|
+ if ($logging == SMTP_LOGGING_ALL && user_access('administer smtp module')) {
|
|
$mailer->SMTPDebug = TRUE;
|
|
$mailer->SMTPDebug = TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
- // Set the from name.
|
|
|
|
- if (variable_get('smtp_fromname', '') != '') {
|
|
|
|
- $from_name = variable_get('smtp_fromname', '');
|
|
|
|
|
|
+ // Set the from name. First we try to get the name from i18n, in the case
|
|
|
|
+ // that it has been translated. The name is set according to the language
|
|
|
|
+ // of the email being sent.
|
|
|
|
+ $from_name = FALSE;
|
|
|
|
+ if (function_exists('i18n_variable_get')) {
|
|
|
|
+ // The 'language' value may be stored as an object.
|
|
|
|
+ $langcode = $message['language'];
|
|
|
|
+ if (is_object($langcode)) {
|
|
|
|
+ $langcode = $langcode->language;
|
|
|
|
+ }
|
|
|
|
+ if (i18n_variable_get('smtp_fromname', $langcode, '') != '') {
|
|
|
|
+ $from_name = i18n_variable_get('smtp_fromname', $langcode, '');
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // If value is not defined in settings, use site_name.
|
|
|
|
+ $from_name = i18n_variable_get('site_name', $langcode, '');
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else {
|
|
|
|
- // If value is not defined in settings, use site_name.
|
|
|
|
- $from_name = variable_get('site_name', '');
|
|
|
|
|
|
+
|
|
|
|
+ if (variable_get('smtp_client_hostname', '') != '') {
|
|
|
|
+ $mailer->Hostname = variable_get('smtp_client_hostname', '');
|
|
}
|
|
}
|
|
|
|
|
|
- //Hack to fix reply-to issue.
|
|
|
|
- $properfrom = variable_get('site_mail', '');
|
|
|
|
- if (!empty($properfrom)) {
|
|
|
|
- $headers['From'] = $properfrom;
|
|
|
|
|
|
+ if (variable_get('smtp_client_helo', '') != '') {
|
|
|
|
+ $mailer->Helo = variable_get('smtp_client_helo', '');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // If i18n is not enabled, we get the From Name through normal variables
|
|
|
|
+ if (!$from_name) {
|
|
|
|
+ if (variable_get('smtp_fromname', '') != '') {
|
|
|
|
+ $from_name = variable_get('smtp_fromname', '');
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // If value is not defined in settings, use site_name.
|
|
|
|
+ $from_name = variable_get('site_name', '');
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //Hack to fix reply-to issue.
|
|
if (!isset($headers['Reply-To']) || empty($headers['Reply-To'])) {
|
|
if (!isset($headers['Reply-To']) || empty($headers['Reply-To'])) {
|
|
if (strpos($from, '<')) {
|
|
if (strpos($from, '<')) {
|
|
$reply = preg_replace('/>.*/', '', preg_replace('/.*</', '', $from));
|
|
$reply = preg_replace('/>.*/', '', preg_replace('/.*</', '', $from));
|
|
@@ -84,6 +133,11 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
}
|
|
}
|
|
$headers['Reply-To'] = $reply;
|
|
$headers['Reply-To'] = $reply;
|
|
}
|
|
}
|
|
|
|
+ $properfrom = variable_get('smtp_from', '');
|
|
|
|
+ if (!empty($properfrom)) {
|
|
|
|
+ $headers['From'] = $properfrom;
|
|
|
|
+ $from = $properfrom;
|
|
|
|
+ }
|
|
|
|
|
|
// Blank value will let the e-mail address appear.
|
|
// Blank value will let the e-mail address appear.
|
|
|
|
|
|
@@ -93,42 +147,34 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
// If smtp_from config option is blank, use site_email.
|
|
// If smtp_from config option is blank, use site_email.
|
|
if (($from = variable_get('site_mail', '')) == '') {
|
|
if (($from = variable_get('site_mail', '')) == '') {
|
|
drupal_set_message(t('There is no submitted from address.'), 'error');
|
|
drupal_set_message(t('There is no submitted from address.'), 'error');
|
|
- watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR);
|
|
|
|
|
|
+ if ($logging) {
|
|
|
|
+ watchdog('smtp', 'There is no submitted from address.', array(), WATCHDOG_ERROR);
|
|
|
|
+ }
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (preg_match('/^"?.*"?\s*<.*>$/', $from)) {
|
|
|
|
- // . == Matches any single character except line break characters \r and \n.
|
|
|
|
- // * == Repeats the previous item zero or more times.
|
|
|
|
- $from_name = preg_replace('/"?([^("\t\n)]*)"?.*$/', '$1', $from); // It gives: Name
|
|
|
|
- $from = preg_replace("/(.*)\<(.*)\>/i", '$2', $from); // It gives: name@domain.tld
|
|
|
|
- }
|
|
|
|
- elseif (!valid_email_address($from)) {
|
|
|
|
- drupal_set_message(t('The submitted from address (@from) is not valid.', array('@from' => $from)), 'error');
|
|
|
|
- watchdog('smtp', 'The submitted from address (@from) is not valid.', array('@from' => $from), WATCHDOG_ERROR);
|
|
|
|
|
|
+ $from_comp = $this->_get_components($from);
|
|
|
|
+
|
|
|
|
+ if (!valid_email_address($from_comp['email'])) {
|
|
|
|
+ drupal_set_message(t('The submitted from address (@from) is not valid.', array('@from' => $from_comp['email'])), 'error');
|
|
|
|
+ if ($logging) {
|
|
|
|
+ watchdog('smtp', 'The submitted from address (@from) is not valid.', array('@from' => $from_comp['email']), WATCHDOG_ERROR);
|
|
|
|
+ }
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
// Defines the From value to what we expect.
|
|
// Defines the From value to what we expect.
|
|
- $mailer->From = $from;
|
|
|
|
- $mailer->FromName = $from_name;
|
|
|
|
- $mailer->Sender = $from;
|
|
|
|
|
|
+ $mailer->From = $from_comp['email'];
|
|
|
|
+ $mailer->FromName = empty($from_comp['name']) ? $from_name : $from_comp['name'];
|
|
|
|
+ $mailer->Sender = $from_comp['email'];
|
|
|
|
|
|
|
|
|
|
// Create the list of 'To:' recipients.
|
|
// Create the list of 'To:' recipients.
|
|
$torecipients = explode(',', $to);
|
|
$torecipients = explode(',', $to);
|
|
foreach ($torecipients as $torecipient) {
|
|
foreach ($torecipients as $torecipient) {
|
|
- if (strpos($torecipient, '<') !== FALSE) {
|
|
|
|
- $toparts = explode(' <', $torecipient);
|
|
|
|
- $toname = $toparts[0];
|
|
|
|
- $toaddr = rtrim($toparts[1], '>');
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $toname = '';
|
|
|
|
- $toaddr = $torecipient;
|
|
|
|
- }
|
|
|
|
- $mailer->AddAddress($toaddr, $toname);
|
|
|
|
|
|
+ $to_comp = $this->_get_components($torecipient);
|
|
|
|
+ $mailer->AddAddress($to_comp['email'], $to_comp['name']);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -201,8 +247,9 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
default:
|
|
default:
|
|
// Everything else is unsuppored by PHPMailer.
|
|
// 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');
|
|
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');
|
|
- watchdog('smtp', 'The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value"), WATCHDOG_ERROR);
|
|
|
|
-
|
|
|
|
|
|
+ if ($logging) {
|
|
|
|
+ watchdog('smtp', 'The %header of your message is not supported by PHPMailer and will be sent as text/plain instead.', array('%header' => "Content-Type: $value"), WATCHDOG_ERROR);
|
|
|
|
+ }
|
|
// Force the Content-Type to be text/plain.
|
|
// Force the Content-Type to be text/plain.
|
|
$mailer->IsHTML(FALSE);
|
|
$mailer->IsHTML(FALSE);
|
|
$content_type = 'text/plain';
|
|
$content_type = 'text/plain';
|
|
@@ -212,16 +259,8 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
case 'reply-to':
|
|
case 'reply-to':
|
|
// Only add a "reply-to" if it's not the same as "return-path".
|
|
// Only add a "reply-to" if it's not the same as "return-path".
|
|
if ($value != $headers['Return-Path']) {
|
|
if ($value != $headers['Return-Path']) {
|
|
- if (strpos($value, '<') !== FALSE) {
|
|
|
|
- $replyToParts = explode('<', $value);
|
|
|
|
- $replyToName = trim($replyToParts[0]);
|
|
|
|
- $replyToName = trim($replyToName, '"');
|
|
|
|
- $replyToAddr = rtrim($replyToParts[1], '>');
|
|
|
|
- $mailer->AddReplyTo($replyToAddr, $replyToName);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $mailer->AddReplyTo($value);
|
|
|
|
- }
|
|
|
|
|
|
+ $replyto_comp = $this->_get_components($value);
|
|
|
|
+ $mailer->AddReplyTo($replyto_comp['email'], $replyto_comp['name']);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -230,14 +269,8 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
break;
|
|
break;
|
|
|
|
|
|
case 'return-path':
|
|
case 'return-path':
|
|
- if (strpos($value, '<') !== FALSE) {
|
|
|
|
- $returnPathParts = explode('<', $value);
|
|
|
|
- $returnPathAddr = rtrim($returnPathParts[1], '>');
|
|
|
|
- $mailer->Sender = $returnPathAddr;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $mailer->Sender = $value;
|
|
|
|
- }
|
|
|
|
|
|
+ $returnpath_comp = $this->_get_components($value);
|
|
|
|
+ $mailer->Sender = $returnpath_comp['email'];
|
|
break;
|
|
break;
|
|
|
|
|
|
case 'mime-version':
|
|
case 'mime-version':
|
|
@@ -252,32 +285,16 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
case 'cc':
|
|
case 'cc':
|
|
$ccrecipients = explode(',', $value);
|
|
$ccrecipients = explode(',', $value);
|
|
foreach ($ccrecipients as $ccrecipient) {
|
|
foreach ($ccrecipients as $ccrecipient) {
|
|
- if (strpos($ccrecipient, '<') !== FALSE) {
|
|
|
|
- $ccparts = explode(' <', $ccrecipient);
|
|
|
|
- $ccname = $ccparts[0];
|
|
|
|
- $ccaddr = rtrim($ccparts[1], '>');
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $ccname = '';
|
|
|
|
- $ccaddr = $ccrecipient;
|
|
|
|
- }
|
|
|
|
- $mailer->AddCC($ccaddr, $ccname);
|
|
|
|
|
|
+ $cc_comp = $this->_get_components($ccrecipient);
|
|
|
|
+ $mailer->AddCC($cc_comp['email'], $cc_comp['name']);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
case 'bcc':
|
|
case 'bcc':
|
|
$bccrecipients = explode(',', $value);
|
|
$bccrecipients = explode(',', $value);
|
|
foreach ($bccrecipients as $bccrecipient) {
|
|
foreach ($bccrecipients as $bccrecipient) {
|
|
- if (strpos($bccrecipient, '<') !== FALSE) {
|
|
|
|
- $bccparts = explode(' <', $bccrecipient);
|
|
|
|
- $bccname = $bccparts[0];
|
|
|
|
- $bccaddr = rtrim($bccparts[1], '>');
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $bccname = '';
|
|
|
|
- $bccaddr = $bccrecipient;
|
|
|
|
- }
|
|
|
|
- $mailer->AddBCC($bccaddr, $bccname);
|
|
|
|
|
|
+ $bcc_comp = $this->_get_components($bccrecipient);
|
|
|
|
+ $mailer->AddBCC($bcc_comp['email'], $bcc_comp['name']);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -377,7 +394,7 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
// If plain/html within the body part, add it to $mailer->Body.
|
|
// If plain/html within the body part, add it to $mailer->Body.
|
|
elseif (strpos($body_part2, 'text/html')) {
|
|
elseif (strpos($body_part2, 'text/html')) {
|
|
// Get the encoding.
|
|
// Get the encoding.
|
|
- $body_part2_encoding = $this->_get_substring($body_part2, 'Content-Transfer-Encoding', ':', "\n");
|
|
|
|
|
|
+ $body_part2_encoding = trim($this->_get_substring($body_part2, 'Content-Transfer-Encoding', ':', "\n"));
|
|
// Clean up the text.
|
|
// Clean up the text.
|
|
$body_part2 = trim($this->_remove_headers(trim($body_part2)));
|
|
$body_part2 = trim($this->_remove_headers(trim($body_part2)));
|
|
// Check whether the encoding is base64, and if so, decode it.
|
|
// Check whether the encoding is base64, and if so, decode it.
|
|
@@ -509,20 +526,124 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
$mailer->Port = variable_get('smtp_port', '25');
|
|
$mailer->Port = variable_get('smtp_port', '25');
|
|
$mailer->Mailer = 'smtp';
|
|
$mailer->Mailer = 'smtp';
|
|
|
|
|
|
- $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);
|
|
|
|
|
|
+ // Integration with the Maillog module.
|
|
|
|
+ if (module_exists('maillog')) {
|
|
|
|
+ if (variable_get('maillog_log', TRUE)) {
|
|
|
|
+ $record = new stdClass;
|
|
|
|
+
|
|
|
|
+ // In case the subject/from/to is already encoded, decode with
|
|
|
|
+ // mime_header_decode.
|
|
|
|
+ $record->header_message_id = isset($mailer->MessageID) ? $mailer->MessageID : NULL;
|
|
|
|
+ $record->subject = drupal_substr(mime_header_decode($mailer->Subject), 0, 255);
|
|
|
|
+ $record->header_from = $from;
|
|
|
|
+ $record->header_to = $to;
|
|
|
|
+ $record->header_reply_to = isset($headers['Reply-To']) ? $headers['Reply-To'] : '';
|
|
|
|
+ $record->header_all = serialize($headers);
|
|
|
|
+ $record->sent_date = REQUEST_TIME;
|
|
|
|
+
|
|
|
|
+ // Used to separate different portions of the body string.
|
|
|
|
+ $divider = str_repeat('-', 60) . "\n";
|
|
|
|
+
|
|
|
|
+ // Load the attachments.
|
|
|
|
+ $attachments = $mailer->GetAttachments();
|
|
|
|
+
|
|
|
|
+ $record->body = '';
|
|
|
|
+
|
|
|
|
+ // If there's more than one item to display, add a divider.
|
|
|
|
+ if (!empty($mailer->AltBody) || !empty($attachments)) {
|
|
|
|
+ $record->body .= t('Body') . ":\n";
|
|
|
|
+ $record->body .= $divider;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Add the body field.
|
|
|
|
+ if (isset($mailer->Body)) {
|
|
|
|
+ $record->body .= $mailer->Body;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $record->body .= t('*No message body*') . ":\n";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // The AltBody value is optional.
|
|
|
|
+ if (!empty($mailer->AltBody)) {
|
|
|
|
+ $record->body .= "\n";
|
|
|
|
+ $record->body .= $divider;
|
|
|
|
+ $record->body .= t('Alternative body') . ":\n";
|
|
|
|
+ $record->body .= $divider;
|
|
|
|
+ $record->body .= $mailer->AltBody;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // List the attachments.
|
|
|
|
+ if (!empty($attachments)) {
|
|
|
|
+ $record->body .= "\n";
|
|
|
|
+ $record->body .= $divider;
|
|
|
|
+ $record->body .= t('Attachments') . ":\n";
|
|
|
|
+ $record->body .= $divider;
|
|
|
|
+ foreach ($attachments as $file) {
|
|
|
|
+ $record->body .= t('Filename') . ':' . $file[1] . "\n";
|
|
|
|
+ $record->body .= t('Name') . ':' . $file[2] . "\n";
|
|
|
|
+ $record->body .= t('Encoding') . ':' . $file[3] . "\n";
|
|
|
|
+ $record->body .= t('Type') . ':' . $file[4] . "\n";
|
|
|
|
+ $record->body .= "\n";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ drupal_write_record('maillog', $record);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Display the e-mail using Devel module.
|
|
|
|
+ if (variable_get('maillog_devel', TRUE) && function_exists('dpm')) {
|
|
|
|
+ $devel_msg = array();
|
|
|
|
+ $devel_msg[t('Subject')] = $mailer->Subject;
|
|
|
|
+ $devel_msg[t('From')] = $from;
|
|
|
|
+ $devel_msg[t('To')] = $to;
|
|
|
|
+ $devel_msg[t('Reply-To')] = isset($headers['Reply-To']) ? $headers['Reply-To'] : NULL;
|
|
|
|
+ $devel_msg[t('Headers')] = $headers;
|
|
|
|
+ $devel_msg[t('Body')] = $mailer->Body;
|
|
|
|
+ $devel_msg[t('Alternative body')] = $mailer->AltBody;
|
|
|
|
+ $devel_msg[t('Attachments')] = $mailer->GetAttachments();
|
|
|
|
+
|
|
|
|
+ dpm($devel_msg, 'maillog');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $error = FALSE;
|
|
|
|
+
|
|
|
|
+ // Email delivery was disabled.
|
|
|
|
+ if (!variable_get('smtp_deliver', TRUE)) {
|
|
|
|
+ if ($logging) {
|
|
|
|
+ $params = array(
|
|
|
|
+ '@from' => $from,
|
|
|
|
+ '@to' => $to,
|
|
|
|
+ );
|
|
|
|
+ watchdog('smtp', 'Email delivery is disabled, did not send email from @from to @to.', $params);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- return _smtp_mailer_send($mailerArr);
|
|
|
|
|
|
+ if (!$mailer->send()) {
|
|
|
|
+ $params = array(
|
|
|
|
+ '@from' => $from,
|
|
|
|
+ '@to' => $to,
|
|
|
|
+ '!error_message' => $mailer->ErrorInfo
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (variable_get('smtp_queue_fail', FALSE)) {
|
|
|
|
+ if ($logging) {
|
|
|
|
+ watchdog('smtp', 'Error sending e-mail from @from to @to, will retry on cron run : !error_message.', $params, WATCHDOG_ERROR);
|
|
|
|
+ }
|
|
|
|
+ smtp_failed_messages($message);
|
|
|
|
+ }
|
|
|
|
+ elseif ($logging) {
|
|
|
|
+ $error = TRUE;
|
|
|
|
+ watchdog('smtp', 'Error sending e-mail from @from to @to : !error_message', $params, WATCHDOG_ERROR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ elseif (variable_get('smtp_debugging', SMTP_LOGGING_ERRORS) == SMTP_LOGGING_ALL) {
|
|
|
|
+ watchdog('smtp', 'Sent mail to: @to', array('@to' => $to));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- return TRUE;
|
|
|
|
|
|
+ $mailer->SmtpClose();
|
|
|
|
+ return !$error;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -628,6 +749,41 @@ class SmtpMailSystem implements MailSystemInterface {
|
|
$substring = drupal_substr($substring, 0, $string_length);
|
|
$substring = drupal_substr($substring, 0, $string_length);
|
|
}
|
|
}
|
|
|
|
|
|
- return $substring;
|
|
|
|
|
|
+ return trim($substring);
|
|
} // End of _smtp_get_substring().
|
|
} // End of _smtp_get_substring().
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns an array of name and email address from a string.
|
|
|
|
+ *
|
|
|
|
+ * @param $input
|
|
|
|
+ * A string that contains different possible combinations of names and
|
|
|
|
+ * email address.
|
|
|
|
+ * @return
|
|
|
|
+ * An array containing a name and an email address.
|
|
|
|
+ */
|
|
|
|
+ protected function _get_components($input) {
|
|
|
|
+ $components = array(
|
|
|
|
+ 'input' => $input,
|
|
|
|
+ 'name' => '',
|
|
|
|
+ 'email' => '',
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // If the input is a valid email address in its entirety, then there is
|
|
|
|
+ // nothing to do, just return that.
|
|
|
|
+ if (valid_email_address($input)) {
|
|
|
|
+ $components['email'] = trim($input);
|
|
|
|
+ return $components;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Check if $input has one of the following formats, extract what we can:
|
|
|
|
+ // some name <address@example.com>
|
|
|
|
+ // "another name" <address@example.com>
|
|
|
|
+ // <address@example.com>
|
|
|
|
+ if (preg_match('/^"?([^"\t\n]*)"?\s*<([^>\t\n]*)>$/', $input, $matches)) {
|
|
|
|
+ $components['name'] = trim($matches[1]);
|
|
|
|
+ $components['email'] = trim($matches[2]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $components;
|
|
|
|
+ }
|
|
}
|
|
}
|