| 1 |
<?php |
<?php |
| 2 |
// $Id: phpmailer.module,v 1.1.2.1.2.8 2009/11/04 19:11:32 smk Exp $ |
// $Id: phpmailer.module,v 1.1.2.1.2.9 2009/11/04 19:19:17 smk Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 101 |
/** |
/** |
| 102 |
* Extract address and optional display name of an e-mail address. |
* Extract address and optional display name of an e-mail address. |
| 103 |
* |
* |
| 104 |
* @param $address |
* @param $string |
| 105 |
* A string containing one or more valid e-mail address(es) separated with |
* A string containing one or more valid e-mail address(es) separated with |
| 106 |
* commas. |
* commas. |
| 107 |
* |
* |
| 110 |
* |
* |
| 111 |
* @see http://tools.ietf.org/html/rfc5322#section-3.4 |
* @see http://tools.ietf.org/html/rfc5322#section-3.4 |
| 112 |
*/ |
*/ |
| 113 |
function phpmailer_parse_address($address) { |
function phpmailer_parse_address($string) { |
| 114 |
$parsed = array(); |
$parsed = array(); |
|
$regexp = "/^(.*) <([a-z0-9]+(?:[_\\.-][a-z0-9]+)*@(?:[a-z0-9]+(?:[\.-][a-z0-9]+)*)+\\.[a-z]{2,})>$/i"; |
|
| 115 |
|
|
| 116 |
// Split multiple addresses and process each. |
// The display name may contain commas (3.4). Extract all quoted strings |
| 117 |
foreach (explode(',', $address) as $email) { |
// (3.2.4) to a stack and replace them with a placeholder to prevent |
| 118 |
$email = trim($email); |
// splitting at wrong places. |
| 119 |
if (preg_match($regexp, $email, $matches)) { |
$string = preg_replace('/(".*?(?<!\\\\)")/e', '_phpmailer_stack("$1")', $string); |
| 120 |
$parsed[] = array('mail' => $matches[2], 'name' => trim($matches[1], '"')); |
|
| 121 |
|
// Build a regex that matches a name-addr (3.4). |
| 122 |
|
// @see valid_email_address() |
| 123 |
|
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+'; |
| 124 |
|
$domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+'; |
| 125 |
|
$ipv4 = '[0-9]{1,3}(?:\.[0-9]{1,3}){3}'; |
| 126 |
|
$ipv6 = '[0-9a-fA-F]{1,4}(?:\:[0-9a-fA-F]{1,4}){7}'; |
| 127 |
|
$address = "$user@(?:$domain|(?:\[(?:$ipv4|$ipv6)\]))"; |
| 128 |
|
$adr_rx = "/^(?<name>.*)\s<(?<address>$address)>$/"; |
| 129 |
|
|
| 130 |
|
// Split string into multiple parts and process each. |
| 131 |
|
foreach (explode(',', $string) as $email) { |
| 132 |
|
// Re-inject stripped placeholders. |
| 133 |
|
$email = preg_replace('/\x01/e', '_phpmailer_stack()', trim($email)); |
| 134 |
|
// Check if it's a name-addr or a plain address (3.4). |
| 135 |
|
if (preg_match($adr_rx, $email, $matches)) { |
| 136 |
|
$parsed[] = array('mail' => $matches['address'], 'name' => $matches['name']); |
| 137 |
} |
} |
| 138 |
else { |
else { |
| 139 |
$parsed[] = array('mail' => $email, 'name' => ''); |
$parsed[] = array('mail' => trim($email, '<>'), 'name' => ''); |
| 140 |
} |
} |
| 141 |
} |
} |
| 142 |
return $parsed; |
return $parsed; |
| 143 |
} |
} |
| 144 |
|
|
| 145 |
/** |
/** |
| 146 |
|
* Implements a FIFO stack to store extracted quoted strings. |
| 147 |
|
*/ |
| 148 |
|
function _phpmailer_stack($string = NULL) { |
| 149 |
|
static $stack = array(); |
| 150 |
|
|
| 151 |
|
if (!isset($string)) { |
| 152 |
|
// Unescape quoted characters (3.2.4) to prevent double escaping. |
| 153 |
|
return str_replace(array('\"', '\\\\'), array('"', '\\'), array_shift($stack)); |
| 154 |
|
} |
| 155 |
|
// Remove surrounding quotes and push on stack. |
| 156 |
|
array_push($stack, substr($string, 1, -1)); |
| 157 |
|
// Return placeholder substitution. 0x01 may never appear outside a quoted |
| 158 |
|
// string (3.2.3). |
| 159 |
|
return "\x01"; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
/** |
| 163 |
* Menu callback to render the settings page. |
* Menu callback to render the settings page. |
| 164 |
*/ |
*/ |
| 165 |
function phpmailer_settings() { |
function phpmailer_settings() { |