You are here

protected function SmtpMailSystem::_get_components in SMTP Authentication Support 7

Same name and namespace in other branches
  1. 7.2 smtp.mail.inc \SmtpMailSystem::_get_components()

Returns an array of name and email address from a string.

Parameters

$input: A string that contains different possible combinations of names and email address.

Return value

An array containing a name and an email address.

2 calls to SmtpMailSystem::_get_components()
SmtpMailSystem::mailWithoutQueue in ./smtp.mail.inc
SmtpMailSystemWrapper::getComponents in tests/smtp_tests.mail.inc
Expose public method to directly test _get_components().

File

./smtp.mail.inc, line 801
The code processing mail in the smtp module.

Class

SmtpMailSystem
Modify the drupal mail system to use smtp when sending emails. Include the option to choose between plain text or HTML

Code

protected function _get_components($input) {
  $input = trim($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'] = $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;
}