You are here

function _invite_get_emails in Invite 6.2

Same name and namespace in other branches
  1. 5.2 invite.module \_invite_get_emails()
  2. 5 invite.module \_invite_get_emails()
  3. 7.2 invite.module \_invite_get_emails()

Extract valid e-mail addresses from a string.

E-mails must be separated by newlines or commas. E-mails are allowed to include a display name (eg. Some Name <foo@example.com>). Invalid addresses are filtered out and stored in a session variable for re-display.

Parameters

$string: The string to process. Recognized delimiters are comma, NL and CR.

Return value

Array of valid e-mail addresses.

1 call to _invite_get_emails()
invite_form_validate in ./invite.module
Forms API callback; validate submitted form data.

File

./invite.module, line 1013
Allows your users to send and track invitations to join your site.

Code

function _invite_get_emails($string) {
  $valid_emails = $failed_emails = array();
  $user = '[a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~\']+';
  $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+';
  $ipv4 = '[0-9]{1,3}(\\.[0-9]{1,3}){3}';
  $ipv6 = '[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7}';
  $rx = "/({$user}@({$domain}|(\\[({$ipv4}|{$ipv6})\\])))>?\$/";
  $emails = array_unique(split("[,\n\r]", drupal_strtolower($string)));
  foreach ($emails as $email) {
    $email = preg_replace('/^.*<(.*)>$/', '${1}', trim($email));
    if ($email) {
      if (preg_match($rx, $email, $match)) {
        $valid_emails[] = $match[1];
      }
      else {
        $failed_emails[] = $email;
      }
    }
  }
  if (count($failed_emails)) {
    $_SESSION['invite_failed_emails'] = serialize($failed_emails);
  }
  return $valid_emails;
}