You are here

function swiftmailer_filter_message in Swift Mailer 7

Filters out unwanted elements from a message.

Parameters

Swift_Message $message: The message which unwanted elements is to be filtered out from.

1 call to swiftmailer_filter_message()
SWIFTMailSystem::mail in includes/classes/SWIFTMailSystem.inc
Sends a message composed by drupal_mail().

File

includes/helpers/conversion.inc, line 399
This file contains conversion functions.

Code

function swiftmailer_filter_message(Swift_Message $message) {
  $headers = $message
    ->getHeaders();
  $senders = $headers
    ->get('From')
    ->getAddresses();
  if (!empty($senders)) {
    for ($i = 0; $i < count($senders); $i++) {
      if (!valid_email_address($senders[$i])) {
        $headers
          ->remove('From', $i);
        watchdog('swiftmailer', 'The invalid "From" e-mail address "!mail" was skipped.', array(
          '!mail' => $senders[$i],
        ), WATCHDOG_WARNING);
      }
    }
  }
  $recipients = $headers
    ->get('To')
    ->getAddresses();
  if (!empty($recipients)) {
    for ($i = 0; $i < count($recipients); $i++) {
      if (!valid_email_address($recipients[$i])) {
        $headers
          ->remove('To', $i);
        watchdog('swiftmailer', 'The invalid "To" e-mail address "!mail" was skipped.', array(
          '!mail' => $recipients[$i],
        ), WATCHDOG_WARNING);
      }
    }
  }
}