| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
http://php.net/function.mail |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 11 |
|
|---|
| 12 |
@copyright |
|---|
| 13 |
@author will@flourishlib.com |
|---|
| 14 |
@author bill@imarc.net |
|---|
| 15 |
@license http://flourishlib.com/license |
|---|
| 16 |
|
|---|
| 17 |
@package |
|---|
| 18 |
@link http://flourishlib.com/fEmail |
|---|
| 19 |
|
|---|
| 20 |
@version |
|---|
| 21 |
@changes |
|---|
| 22 |
@changes |
|---|
| 23 |
@changes |
|---|
| 24 |
@changes |
|---|
| 25 |
@changes |
|---|
| 26 |
@changes |
|---|
| 27 |
@changes |
|---|
| 28 |
@changes |
|---|
| 29 |
@changes |
|---|
| 30 |
@changes |
|---|
| 31 |
@changes |
|---|
| 32 |
@changes |
|---|
| 33 |
@changes |
|---|
| 34 |
@changes |
|---|
| 35 |
@changes |
|---|
| 36 |
@changes |
|---|
| 37 |
@changes |
|---|
| 38 |
@changes |
|---|
| 39 |
@changes |
|---|
| 40 |
@changes |
|---|
| 41 |
@changes |
|---|
| 42 |
|
|---|
| 43 |
class fEmail |
|---|
| 44 |
{ |
|---|
| 45 |
|
|---|
| 46 |
const fixQmail = 'fEmail::fixQmail'; |
|---|
| 47 |
const reset = 'fEmail::reset'; |
|---|
| 48 |
const unindentExpand = 'fEmail::unindentExpand'; |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
@var |
|---|
| 61 |
|
|---|
| 62 |
const EMAIL_REGEX = '~^[ \t]*( # Allow leading whitespace |
|---|
| 63 |
(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+") # An "atom" or a quoted string |
|---|
| 64 |
(?:\.[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+"[ \t]*))* # A . plus another "atom" or a quoted string, any number of times |
|---|
| 65 |
)@( # The @ symbol |
|---|
| 66 |
(?:[a-z0-9\\-]+\.)+[a-z]{2,}| # Domain name |
|---|
| 67 |
\[(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5])\] # (or) IP addresses |
|---|
| 68 |
)[ \t]*$~ixD'; |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
@var |
|---|
| 82 |
|
|---|
| 83 |
const NAME_EMAIL_REGEX = '~^[ \t]*( # Allow leading whitespace |
|---|
| 84 |
(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+[ \t]*|"[^"\\\\\n\r]+"[ \t]*) # An "atom" or a quoted string |
|---|
| 85 |
(?:\.?[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+[ \t]*|"[^"\\\\\n\r]+"[ \t]*))*) # Another "atom" or a quoted string or a . followed by one of those, any number of times |
|---|
| 86 |
[ \t]*<[ \t]*(( # The < encapsulating the email address |
|---|
| 87 |
(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+") # An "atom" or a quoted string |
|---|
| 88 |
(?:\.[ \t]*(?:[^\x00-\x20\(\)<>@,;:\\\\"\.\[\]]+|"[^"\\\\\n\r]+"[ \t]*))* # A . plus another "atom" or a quoted string, any number of times |
|---|
| 89 |
)@( # The @ symbol |
|---|
| 90 |
(?:[a-z0-9\\-]+\.)+[a-z]{2,}| # Domain nam |
|---|
| 91 |
\[(?:(?:[01]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d?\d|2[0-4]\d|25[0-5])\] # (or) IP addresses |
|---|
| 92 |
))[ \t]*>[ \t]*$~ixD'; |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
http://php.net/popen |
|---|
| 97 |
|
|---|
| 98 |
@var |
|---|
| 99 |
|
|---|
| 100 |
static private $popen_sendmail = FALSE; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
@var |
|---|
| 106 |
|
|---|
| 107 |
static private $convert_crlf = FALSE; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
static private $local_hostname; |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
@param |
|---|
| 119 |
@param |
|---|
| 120 |
@param |
|---|
| 121 |
@return |
|---|
| 122 |
|
|---|
| 123 |
static protected function compose($message) |
|---|
| 124 |
{ |
|---|
| 125 |
$args = array_slice(func_get_args(), 1); |
|---|
| 126 |
|
|---|
| 127 |
if (class_exists('fText', FALSE)) { |
|---|
| 128 |
return call_user_func_array( |
|---|
| 129 |
array('fText', 'compose'), |
|---|
| 130 |
array($message, $args) |
|---|
| 131 |
); |
|---|
| 132 |
} else { |
|---|
| 133 |
return vsprintf($message, $args); |
|---|
| 134 |
} |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
@return |
|---|
| 145 |
|
|---|
| 146 |
static public function fixQmail() |
|---|
| 147 |
{ |
|---|
| 148 |
if (fCore::checkOS('windows')) { |
|---|
| 149 |
return; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
$sendmail_command = ini_get('sendmail_path'); |
|---|
| 153 |
|
|---|
| 154 |
if (!$sendmail_command) { |
|---|
| 155 |
self::$convert_crlf = TRUE; |
|---|
| 156 |
trigger_error( |
|---|
| 157 |
self::compose('The proper fix for sending through qmail is not possible since the sendmail path is not set'), |
|---|
| 158 |
E_USER_WARNING |
|---|
| 159 |
); |
|---|
| 160 |
trigger_error( |
|---|
| 161 |
self::compose('Trying to fix qmail by converting all \r\n to \n. This will cause invalid (but possibly functioning) email headers to be generated.'), |
|---|
| 162 |
E_USER_WARNING |
|---|
| 163 |
); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
$sendmail_command_parts = explode(' ', $sendmail_command, 2); |
|---|
| 167 |
|
|---|
| 168 |
$sendmail_path = $sendmail_command_parts[0]; |
|---|
| 169 |
$sendmail_dir = pathinfo($sendmail_path, PATHINFO_DIRNAME); |
|---|
| 170 |
$sendmail_params = (isset($sendmail_command_parts[1])) ? $sendmail_command_parts[1] : ''; |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
$executable = FALSE; |
|---|
| 174 |
$safe_mode = FALSE; |
|---|
| 175 |
|
|---|
| 176 |
if (!in_array(strtolower(ini_get('safe_mode')), array('0', '', 'off'))) { |
|---|
| 177 |
$safe_mode = TRUE; |
|---|
| 178 |
$exec_dirs = explode(';', ini_get('safe_mode_exec_dir')); |
|---|
| 179 |
foreach ($exec_dirs as $exec_dir) { |
|---|
| 180 |
if (stripos($sendmail_dir, $exec_dir) !== 0) { |
|---|
| 181 |
continue; |
|---|
| 182 |
} |
|---|
| 183 |
if (file_exists($sendmail_path) && is_executable($sendmail_path)) { |
|---|
| 184 |
$executable = TRUE; |
|---|
| 185 |
} |
|---|
| 186 |
} |
|---|
| 187 |
|
|---|
| 188 |
} else { |
|---|
| 189 |
if (file_exists($sendmail_path) && is_executable($sendmail_path)) { |
|---|
| 190 |
$executable = TRUE; |
|---|
| 191 |
} |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
if ($executable) { |
|---|
| 195 |
self::$popen_sendmail = TRUE; |
|---|
| 196 |
} else { |
|---|
| 197 |
self::$convert_crlf = TRUE; |
|---|
| 198 |
if ($safe_mode) { |
|---|
| 199 |
trigger_error( |
|---|
| 200 |
self::compose('The proper fix for sending through qmail is not possible since safe mode is turned on and the sendmail binary is not in one of the paths defined by the safe_mode_exec_dir ini setting'), |
|---|
| 201 |
E_USER_WARNING |
|---|
| 202 |
); |
|---|
| 203 |
trigger_error( |
|---|
| 204 |
self::compose('Trying to fix qmail by converting all \r\n to \n. This will cause invalid (but possibly functioning) email headers to be generated.'), |
|---|
| 205 |
E_USER_WARNING |
|---|
| 206 |
); |
|---|
| 207 |
} else { |
|---|
| 208 |
trigger_error( |
|---|
| 209 |
self::compose('The proper fix for sending through qmail is not possible since the sendmail binary could not be found or is not executable'), |
|---|
| 210 |
E_USER_WARNING |
|---|
| 211 |
); |
|---|
| 212 |
trigger_error( |
|---|
| 213 |
self::compose('Trying to fix qmail by converting all \r\n to \n. This will cause invalid (but possibly functioning) email headers to be generated.'), |
|---|
| 214 |
E_USER_WARNING |
|---|
| 215 |
); |
|---|
| 216 |
} |
|---|
| 217 |
} |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
@internal |
|---|
| 225 |
|
|---|
| 226 |
@return |
|---|
| 227 |
|
|---|
| 228 |
static public function reset() |
|---|
| 229 |
{ |
|---|
| 230 |
self::$popen_sendmail = FALSE; |
|---|
| 231 |
self::$convert_crlf = FALSE; |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
@param |
|---|
| 239 |
@return |
|---|
| 240 |
|
|---|
| 241 |
static protected function stringlike($value) |
|---|
| 242 |
{ |
|---|
| 243 |
if ((!is_string($value) && !is_object($value) && !is_numeric($value)) || !strlen(trim($value))) { |
|---|
| 244 |
return FALSE; |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
return TRUE; |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
@param |
|---|
| 255 |
@return |
|---|
| 256 |
|
|---|
| 257 |
static public function unindentExpand($text) |
|---|
| 258 |
{ |
|---|
| 259 |
$text = preg_replace('#^[ \t]*\n|\n[ \t]*$#D', '', $text); |
|---|
| 260 |
|
|---|
| 261 |
if (preg_match('#^[ \t]+(?=\S)#m', $text, $match)) { |
|---|
| 262 |
$text = preg_replace('#^' . preg_quote($match[0]) . '#m', '', $text); |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
preg_match_all('#\{([a-z][a-z0-9_]*)\}#i', $text, $constants, PREG_SET_ORDER); |
|---|
| 266 |
foreach ($constants as $constant) { |
|---|
| 267 |
if (!defined($constant[1])) { continue; } |
|---|
| 268 |
$text = preg_replace('#' . preg_quote($constant[0], '#') . '#', constant($constant[1]), $text, 1); |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
return $text; |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
@var |
|---|
| 279 |
|
|---|
| 280 |
private $attachments = array(); |
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
@var |
|---|
| 286 |
|
|---|
| 287 |
private $bcc_emails = array(); |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
@var |
|---|
| 293 |
|
|---|
| 294 |
private $bounce_to_email = NULL; |
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
@var |
|---|
| 300 |
|
|---|
| 301 |
private $cc_emails = array(); |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
@var |
|---|
| 307 |
|
|---|
| 308 |
private $from_email = NULL; |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
@var |
|---|
| 314 |
|
|---|
| 315 |
private $html_body = NULL; |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
@var |
|---|
| 321 |
|
|---|
| 322 |
private $plaintext_body = NULL; |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
@var |
|---|
| 328 |
|
|---|
| 329 |
private $recipients_smime_cert_file = NULL; |
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
@var |
|---|
| 335 |
|
|---|
| 336 |
private $reply_to_email = NULL; |
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
@var |
|---|
| 342 |
|
|---|
| 343 |
private $sender_email = NULL; |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
@var |
|---|
| 349 |
|
|---|
| 350 |
private $senders_smime_cert_file = NULL; |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
@var |
|---|
| 356 |
|
|---|
| 357 |
private $senders_smime_pk_file = NULL; |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
@var |
|---|
| 363 |
|
|---|
| 364 |
private $senders_smime_pk_password = NULL; |
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
@var |
|---|
| 370 |
|
|---|
| 371 |
private $smime_encrypt = FALSE; |
|---|
| 372 |
|
|---|
| 373 |
|
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
@var |
|---|
| 377 |
|
|---|
| 378 |
private $smime_sign = FALSE; |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
@var |
|---|
| 384 |
|
|---|
| 385 |
private $subject = NULL; |
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
@var |
|---|
| 391 |
|
|---|
| 392 |
private $to_emails = array(); |
|---|
| 393 |
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
@return |
|---|
| 399 |
|
|---|
| 400 |
public function __construct() |
|---|
| 401 |
{ |
|---|
| 402 |
if (self::$local_hostname !== NULL) { |
|---|
| 403 |
return; |
|---|
| 404 |
} |
|---|
| 405 |
|
|---|
| 406 |
if (isset($_ENV['HOST'])) { |
|---|
| 407 |
self::$local_hostname = $_ENV['HOST']; |
|---|
| 408 |
} |
|---|
| 409 |
if (strpos(self::$local_hostname, '.') === FALSE && isset($_ENV['HOSTNAME'])) { |
|---|
| 410 |
self::$local_hostname = $_ENV['HOSTNAME']; |
|---|
| 411 |
} |
|---|
| 412 |
if (strpos(self::$local_hostname, '.') === FALSE) { |
|---|
| 413 |
self::$local_hostname = php_uname('n'); |
|---|
| 414 |
} |
|---|
| 415 |
if (strpos(self::$local_hostname, '.') === FALSE && !in_array('exec', array_map('trim', explode(',', ini_get('disable_functions')))) && !ini_get('safe_mode') && !ini_get('open_basedir')) { |
|---|
| 416 |
if (fCore::checkOS('linux')) { |
|---|
| 417 |
self::$local_hostname = trim(shell_exec('hostname --fqdn')); |
|---|
| 418 |
} elseif (fCore::checkOS('windows') && is_executable($_SERVER['WINDIR'] . '\system32\ipconfig.exe')) { |
|---|
| 419 |
$output = shell_exec('ipconfig /all'); |
|---|
| 420 |
if (preg_match('#DNS Suffix Search List[ .:]+([a-z0-9_.-]+)#i', $output, $match)) { |
|---|
| 421 |
self::$local_hostname .= '.' . $match[1]; |
|---|
| 422 |
} |
|---|
| 423 |
} elseif (fCore::checkOS('bsd', 'osx') && file_exists('/etc/resolv.conf')) { |
|---|
| 424 |
$output = file_get_contents('/etc/resolv.conf'); |
|---|
| 425 |
if (preg_match('#^domain ([a-z0-9_.-]+)#im', $output, $match)) { |
|---|
| 426 |
self::$local_hostname .= '.' . $match[1]; |
|---|
| 427 |
} |
|---|
| 428 |
} |
|---|
| 429 |
} |
|---|
| 430 |
} |
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
@internal |
|---|
| 437 |
|
|---|
| 438 |
@param |
|---|
| 439 |
@return |
|---|
| 440 |
|
|---|
| 441 |
public function __get($method) |
|---|
| 442 |
{ |
|---|
| 443 |
return array($this, $method); |
|---|
| 444 |
} |
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
@param |
|---|
| 453 |
@param |
|---|
| 454 |
@param |
|---|
| 455 |
@return |
|---|
| 456 |
|
|---|
| 457 |
public function addAttachment($filename, $mime_type, $contents) |
|---|
| 458 |
{ |
|---|
| 459 |
if (!self::stringlike($filename)) { |
|---|
| 460 |
throw new fProgrammerException( |
|---|
| 461 |
'The filename specified, %s, does not appear to be a valid filename', |
|---|
| 462 |
$filename |
|---|
| 463 |
); |
|---|
| 464 |
} |
|---|
| 465 |
|
|---|
| 466 |
$filename = (string) $filename; |
|---|
| 467 |
|
|---|
| 468 |
$i = 1; |
|---|
| 469 |
while (isset($this->attachments[$filename])) { |
|---|
| 470 |
$filename_info = fFilesystem::getPathInfo($filename); |
|---|
| 471 |
$extension = ($filename_info['extension']) ? '.' . $filename_info['extension'] : ''; |
|---|
| 472 |
$filename = preg_replace('#_copy\d+$#D', '', $filename_info['filename']) . '_copy' . $i . $extension; |
|---|
| 473 |
$i++; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
$this->attachments[$filename] = array( |
|---|
| 477 |
'mime-type' => $mime_type, |
|---|
| 478 |
'contents' => $contents |
|---|
| 479 |
); |
|---|
| 480 |
} |
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
@param |
|---|
| 487 |
@param |
|---|
| 488 |
@return |
|---|
| 489 |
|
|---|
| 490 |
public function addBCCRecipient($email, $name=NULL) |
|---|
| 491 |
{ |
|---|
| 492 |
if (!$email) { |
|---|
| 493 |
return; |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
$this->bcc_emails[] = $this->combineNameEmail($name, $email); |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
@param |
|---|
| 504 |
@param |
|---|
| 505 |
@return |
|---|
| 506 |
|
|---|
| 507 |
public function addCCRecipient($email, $name=NULL) |
|---|
| 508 |
{ |
|---|
| 509 |
if (!$email) { |
|---|
| 510 |
return; |
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
$this->cc_emails[] = $this->combineNameEmail($name, $email); |
|---|
| 514 |
} |
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
@param |
|---|
| 521 |
@param |
|---|
| 522 |
@return |
|---|
| 523 |
|
|---|
| 524 |
public function addRecipient($email, $name=NULL) |
|---|
| 525 |
{ |
|---|
| 526 |
if (!$email) { |
|---|
| 527 |
return; |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
$this->to_emails[] = $this->combineNameEmail($name, $email); |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
@param |
|---|
| 538 |
@param |
|---|
| 539 |
@return |
|---|
| 540 |
|
|---|
| 541 |
private function buildMultiAddressHeader($header, $emails) |
|---|
| 542 |
{ |
|---|
| 543 |
if ($header) { |
|---|
| 544 |
$header .= ': '; |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
$first = TRUE; |
|---|
| 548 |
$line = 1; |
|---|
| 549 |
foreach ($emails as $email) { |
|---|
| 550 |
if ($first) { $first = FALSE; } else { $header .= ', '; } |
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
if (strlen($header . $email) / 950 > $line) { |
|---|
| 554 |
$header .= "\r\n "; |
|---|
| 555 |
$line++; |
|---|
| 556 |
} |
|---|
| 557 |
|
|---|
| 558 |
$header .= trim($email); |
|---|
| 559 |
} |
|---|
| 560 |
|
|---|
| 561 |
return $header . "\r\n"; |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
@return |
|---|
| 569 |
|
|---|
| 570 |
public function clearRecipients() |
|---|
| 571 |
{ |
|---|
| 572 |
$this->to_emails = array(); |
|---|
| 573 |
$this->cc_emails = array(); |
|---|
| 574 |
$this->bcc_emails = array(); |
|---|
| 575 |
} |
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
@return |
|---|
| 582 |
|
|---|
| 583 |
private function createBoundary() |
|---|
| 584 |
{ |
|---|
| 585 |
$chars = 'ancdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:-_'; |
|---|
| 586 |
$last_index = strlen($chars) - 1; |
|---|
| 587 |
$output = ''; |
|---|
| 588 |
|
|---|
| 589 |
for ($i = 0; $i < 28; $i++) { |
|---|
| 590 |
$output .= $chars[rand(0, $last_index)]; |
|---|
| 591 |
} |
|---|
| 592 |
return $output; |
|---|
| 593 |
} |
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
@param |
|---|
| 604 |
@param |
|---|
| 605 |
@return |
|---|
| 606 |
|
|---|
| 607 |
private function combineNameEmail($name, $email) |
|---|
| 608 |
{ |
|---|
| 609 |
|
|---|
| 610 |
$email = preg_replace('#[\x0-\x19]+#', '', $email); |
|---|
| 611 |
$name = preg_replace('#[\x0-\x19]+#', '', $name); |
|---|
| 612 |
|
|---|
| 613 |
if (!$name) { |
|---|
| 614 |
return $email; |
|---|
| 615 |
} |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
if (preg_replace('#[\x80-\xff\x5C\x22]#', '', $name) != $name) { |
|---|
| 620 |
$name = $this->makeEncodedWord($name); |
|---|
| 621 |
} else { |
|---|
| 622 |
$name = '"' . $name . '"'; |
|---|
| 623 |
} |
|---|
| 624 |
|
|---|
| 625 |
return $name . ' <' . $email . '>'; |
|---|
| 626 |
} |
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 |
@param |
|---|
| 633 |
@return |
|---|
| 634 |
|
|---|
| 635 |
private function createBody($boundary) |
|---|
| 636 |
{ |
|---|
| 637 |
$mime_notice = self::compose( |
|---|
| 638 |
"This message has been formatted using MIME. It does not appear that your\r\nemail client supports MIME." |
|---|
| 639 |
); |
|---|
| 640 |
|
|---|
| 641 |
$body = ''; |
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
if ($this->html_body) { |
|---|
| 645 |
|
|---|
| 646 |
$alternative_boundary = $boundary; |
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
if ($this->attachments) { |
|---|
| 650 |
$alternative_boundary = $this->createBoundary(); |
|---|
| 651 |
$body .= 'Content-Type: multipart/alternative; boundary="' . $alternative_boundary . "\"\r\n\r\n"; |
|---|
| 652 |
} else { |
|---|
| 653 |
$body .= $mime_notice . "\r\n\r\n"; |
|---|
| 654 |
} |
|---|
| 655 |
|
|---|
| 656 |
$body .= '--' . $alternative_boundary . "\r\n"; |
|---|
| 657 |
$body .= "Content-Type: text/plain; charset=utf-8\r\n"; |
|---|
| 658 |
$body .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n"; |
|---|
| 659 |
$body .= $this->makeQuotedPrintable($this->plaintext_body) . "\r\n"; |
|---|
| 660 |
$body .= '--' . $alternative_boundary . "\r\n"; |
|---|
| 661 |
$body .= "Content-Type: text/html; charset=utf-8\r\n"; |
|---|
| 662 |
$body .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n"; |
|---|
| 663 |
$body .= $this->makeQuotedPrintable($this->html_body) . "\r\n"; |
|---|
| 664 |
$body .= '--' . $alternative_boundary . "--\r\n"; |
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
} else { |
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
if ($this->attachments) { |
|---|
| 671 |
$body .= "Content-Type: text/plain; charset=utf-8\r\n"; |
|---|
| 672 |
$body .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n"; |
|---|
| 673 |
} |
|---|
| 674 |
|
|---|
| 675 |
$body .= $this->makeQuotedPrintable($this->plaintext_body) . "\r\n"; |
|---|
| 676 |
} |
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
if ($this->attachments) { |
|---|
| 680 |
|
|---|
| 681 |
$multipart_body = $mime_notice . "\r\n\r\n"; |
|---|
| 682 |
$multipart_body .= '--' . $boundary . "\r\n"; |
|---|
| 683 |
$multipart_body .= $body; |
|---|
| 684 |
|
|---|
| 685 |
foreach ($this->attachments as $filename => $file_info) { |
|---|
| 686 |
$multipart_body .= '--' . $boundary . "\r\n"; |
|---|
| 687 |
$multipart_body .= 'Content-Type: ' . $file_info['mime-type'] . "\r\n"; |
|---|
| 688 |
$multipart_body .= "Content-Transfer-Encoding: base64\r\n"; |
|---|
| 689 |
$multipart_body .= 'Content-Disposition: attachment; filename="' . $filename . "\";\r\n\r\n"; |
|---|
| 690 |
$multipart_body .= $this->makeBase64($file_info['contents']) . "\r\n"; |
|---|
| 691 |
} |
|---|
| 692 |
|
|---|
| 693 |
$multipart_body .= '--' . $boundary . "--\r\n"; |
|---|
| 694 |
|
|---|
| 695 |
$body = $multipart_body; |
|---|
| 696 |
} |
|---|
| 697 |
|
|---|
| 698 |
return $body; |
|---|
| 699 |
} |
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
@param |
|---|
| 706 |
@param |
|---|
| 707 |
@return http://php.net/function.mail |
|---|
| 708 |
|
|---|
| 709 |
private function createHeaders($boundary, $message_id) |
|---|
| 710 |
{ |
|---|
| 711 |
$headers = ''; |
|---|
| 712 |
|
|---|
| 713 |
if ($this->cc_emails) { |
|---|
| 714 |
$headers .= $this->buildMultiAddressHeader("Cc", $this->cc_emails); |
|---|
| 715 |
} |
|---|
| 716 |
|
|---|
| 717 |
if ($this->bcc_emails) { |
|---|
| 718 |
$headers .= $this->buildMultiAddressHeader("Bcc", $this->bcc_emails); |
|---|
| 719 |
} |
|---|
| 720 |
|
|---|
| 721 |
$headers .= "From: " . trim($this->from_email) . "\r\n"; |
|---|
| 722 |
|
|---|
| 723 |
if ($this->reply_to_email) { |
|---|
| 724 |
$headers .= "Reply-To: " . trim($this->reply_to_email) . "\r\n"; |
|---|
| 725 |
} |
|---|
| 726 |
|
|---|
| 727 |
if ($this->sender_email) { |
|---|
| 728 |
$headers .= "Sender: " . trim($this->sender_email) . "\r\n"; |
|---|
| 729 |
} |
|---|
| 730 |
|
|---|
| 731 |
$headers .= "Message-ID: " . $message_id . "\r\n"; |
|---|
| 732 |
$headers .= "MIME-Version: 1.0\r\n"; |
|---|
| 733 |
|
|---|
| 734 |
if ($this->html_body && !$this->attachments) { |
|---|
| 735 |
$headers .= 'Content-Type: multipart/alternative; boundary="' . $boundary . "\"\r\n"; |
|---|
| 736 |
} |
|---|
| 737 |
|
|---|
| 738 |
if (!$this->html_body && !$this->attachments) { |
|---|
| 739 |
$headers .= "Content-Type: text/plain; charset=utf-8\r\n"; |
|---|
| 740 |
$headers .= "Content-Transfer-Encoding: quoted-printable\r\n"; |
|---|
| 741 |
} |
|---|
| 742 |
|
|---|
| 743 |
if ($this->attachments) { |
|---|
| 744 |
$headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . "\"\r\n"; |
|---|
| 745 |
} |
|---|
| 746 |
|
|---|
| 747 |
return $headers . "\r\n"; |
|---|
| 748 |
} |
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
@param |
|---|
| 755 |
@param |
|---|
| 756 |
@param |
|---|
| 757 |
@param |
|---|
| 758 |
@return |
|---|
| 759 |
|
|---|
| 760 |
private function createSMIMEBody($to, $subject, $headers, $body) |
|---|
| 761 |
{ |
|---|
| 762 |
if (!$this->smime_encrypt && !$this->smime_sign) { |
|---|
| 763 |
return array($headers, $body); |
|---|
| 764 |
} |
|---|
| 765 |
|
|---|
| 766 |
$plaintext_file = tempnam('', '__fEmail_'); |
|---|
| 767 |
$ciphertext_file = tempnam('', '__fEmail_'); |
|---|
| 768 |
|
|---|
| 769 |
$headers_array = array( |
|---|
| 770 |
'To' => $to, |
|---|
| 771 |
'Subject' => $subject |
|---|
| 772 |
); |
|---|
| 773 |
|
|---|
| 774 |
preg_match_all('#^([\w\-]+):\s+([^\n]+\n( [^\n]+\n)*)#im', $headers, $header_matches, PREG_SET_ORDER); |
|---|
| 775 |
foreach ($header_matches as $header_match) { |
|---|
| 776 |
$headers_array[$header_match[1]] = trim($header_match[2]); |
|---|
| 777 |
} |
|---|
| 778 |
|
|---|
| 779 |
$body_headers = ""; |
|---|
| 780 |
if (isset($headers_array['Content-Type'])) { |
|---|
| 781 |
$body_headers .= 'Content-Type: ' . $headers_array['Content-Type'] . "\r\n"; |
|---|
| 782 |
} |
|---|
| 783 |
if (isset($headers_array['Content-Transfer-Encoding'])) { |
|---|
| 784 |
$body_headers .= 'Content-Transfer-Encoding: ' . $headers_array['Content-Transfer-Encoding'] . "\r\n"; |
|---|
| 785 |
} |
|---|
| 786 |
|
|---|
| 787 |
if ($body_headers) { |
|---|
| 788 |
$body = $body_headers . "\r\n" . $body; |
|---|
| 789 |
} |
|---|
| 790 |
|
|---|
| 791 |
file_put_contents($plaintext_file, $body); |
|---|
| 792 |
file_put_contents($ciphertext_file, ''); |
|---|
| 793 |
|
|---|
| 794 |
|
|---|
| 795 |
if ($this->smime_sign) { |
|---|
| 796 |
$senders_smime_cert = file_get_contents($this->senders_smime_cert_file); |
|---|
| 797 |
$senders_private_key = openssl_pkey_get_private( |
|---|
| 798 |
file_get_contents($this->senders_smime_pk_file), |
|---|
| 799 |
$this->senders_smime_pk_password |
|---|
| 800 |
); |
|---|
| 801 |
|
|---|
| 802 |
if ($senders_private_key === FALSE) { |
|---|
| 803 |
throw new fValidationException( |
|---|
| 804 |
"The sender's S/MIME private key password specified does not appear to be valid for the private key" |
|---|
| 805 |
); |
|---|
| 806 |
} |
|---|
| 807 |
} |
|---|
| 808 |
|
|---|
| 809 |
if ($this->smime_encrypt) { |
|---|
| 810 |
$recipients_smime_cert = file_get_contents($this->recipients_smime_cert_file); |
|---|
| 811 |
} |
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 |
if ($this->smime_encrypt && $this->smime_sign) { |
|---|
| 816 |
openssl_pkcs7_sign($plaintext_file, $ciphertext_file, $senders_smime_cert, $senders_private_key, array()); |
|---|
| 817 |
openssl_pkcs7_encrypt($ciphertext_file, $plaintext_file, $recipients_smime_cert, array(), NULL, OPENSSL_CIPHER_RC2_128); |
|---|
| 818 |
openssl_pkcs7_sign($plaintext_file, $ciphertext_file, $senders_smime_cert, $senders_private_key, $headers_array); |
|---|
| 819 |
|
|---|
| 820 |
} elseif ($this->smime_sign) { |
|---|
| 821 |
openssl_pkcs7_sign($plaintext_file, $ciphertext_file, $senders_smime_cert, $senders_private_key, $headers_array); |
|---|
| 822 |
|
|---|
| 823 |
} elseif ($this->smime_encrypt) { |
|---|
| 824 |
openssl_pkcs7_encrypt($plaintext_file, $ciphertext_file, $recipients_smime_cert, $headers_array, NULL, OPENSSL_CIPHER_RC2_128); |
|---|
| 825 |
} |
|---|
| 826 |
|
|---|
| 827 |
|
|---|
| 828 |
$message = file_get_contents($ciphertext_file); |
|---|
| 829 |
$message = str_replace("\r\n", "\n", $message); |
|---|
| 830 |
$message = str_replace("\r", "\n", $message); |
|---|
| 831 |
$message = str_replace("\n", "\r\n", $message); |
|---|
| 832 |
|
|---|
| 833 |
list($new_headers, $new_body) = explode("\r\n\r\n", $message, 2); |
|---|
| 834 |
|
|---|
| 835 |
$new_headers = preg_replace('#^To:[^\n]+\n( [^\n]+\n)*#mi', '', $new_headers); |
|---|
| 836 |
$new_headers = preg_replace('#^Subject:[^\n]+\n( [^\n]+\n)*#mi', '', $new_headers); |
|---|
| 837 |
$new_headers = preg_replace("#^MIME-Version: 1.0\r?\n#mi", '', $new_headers, 1); |
|---|
| 838 |
$new_headers = preg_replace('#^Content-Type:\s+' . preg_quote($headers_array['Content-Type'], '#') . "\r?\n#mi", '', $new_headers); |
|---|
| 839 |
$new_headers = preg_replace('#^Content-Transfer-Encoding:\s+' . preg_quote($headers_array['Content-Transfer-Encoding'], '#') . "\r?\n#mi", '', $new_headers); |
|---|
| 840 |
|
|---|
| 841 |
unlink($plaintext_file); |
|---|
| 842 |
unlink($ciphertext_file); |
|---|
| 843 |
|
|---|
| 844 |
if ($this->smime_sign) { |
|---|
| 845 |
openssl_pkey_free($senders_private_key); |
|---|
| 846 |
} |
|---|
| 847 |
|
|---|
| 848 |
return array($new_headers, $new_body); |
|---|
| 849 |
} |
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
@param |
|---|
| 856 |
@return |
|---|
| 857 |
|
|---|
| 858 |
public function encrypt($recipients_smime_cert_file) |
|---|
| 859 |
{ |
|---|
| 860 |
if (!extension_loaded('openssl')) { |
|---|
| 861 |
throw new fEnvironmentException( |
|---|
| 862 |
'S/MIME encryption was requested for an email, but the %s extension is not installed', |
|---|
| 863 |
'openssl' |
|---|
| 864 |
); |
|---|
| 865 |
} |
|---|
| 866 |
|
|---|
| 867 |
if (!self::stringlike($recipients_smime_cert_file)) { |
|---|
| 868 |
throw new fProgrammerException( |
|---|
| 869 |
"The recipient's S/MIME certificate filename specified, %s, does not appear to be a valid filename", |
|---|
| 870 |
$recipients_smime_cert_file |
|---|
| 871 |
); |
|---|
| 872 |
} |
|---|
| 873 |
|
|---|
| 874 |
$this->smime_encrypt = TRUE; |
|---|
| 875 |
$this->recipients_smime_cert_file = $recipients_smime_cert_file; |
|---|
| 876 |
} |
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 |
email@address.comemail@address.com |
|---|
| 882 |
|
|---|
| 883 |
@param |
|---|
| 884 |
@return |
|---|
| 885 |
|
|---|
| 886 |
private function extractEmails($list) |
|---|
| 887 |
{ |
|---|
| 888 |
$output = array(); |
|---|
| 889 |
foreach ($list as $email) { |
|---|
| 890 |
if (preg_match(self::NAME_EMAIL_REGEX, $email, $match)) { |
|---|
| 891 |
$output[] = $match[2]; |
|---|
| 892 |
} else { |
|---|
| 893 |
preg_match(self::EMAIL_REGEX, $email, $match); |
|---|
| 894 |
$output[] = $match[0]; |
|---|
| 895 |
} |
|---|
| 896 |
} |
|---|
| 897 |
return $output; |
|---|
| 898 |
} |
|---|
| 899 |
|
|---|
| 900 |
|
|---|
| 901 |
|
|---|
| 902 |
|
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 906 |
|
|---|
| 907 |
@throws |
|---|
| 908 |
|
|---|
| 909 |
@param |
|---|
| 910 |
@param |
|---|
| 911 |
@return |
|---|
| 912 |
|
|---|
| 913 |
public function loadBody($file, $replacements=array()) |
|---|
| 914 |
{ |
|---|
| 915 |
if (!$file instanceof fFile) { |
|---|
| 916 |
$file = new fFile($file); |
|---|
| 917 |
} |
|---|
| 918 |
|
|---|
| 919 |
$plaintext = $file->read(); |
|---|
| 920 |
if ($replacements) { |
|---|
| 921 |
$plaintext = strtr($plaintext, $replacements); |
|---|
| 922 |
} |
|---|
| 923 |
|
|---|
| 924 |
$this->plaintext_body = $plaintext; |
|---|
| 925 |
} |
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 933 |
|
|---|
| 934 |
@throws |
|---|
| 935 |
|
|---|
| 936 |
@param |
|---|
| 937 |
@param |
|---|
| 938 |
@return |
|---|
| 939 |
|
|---|
| 940 |
public function loadHTMLBody($file, $replacements=array()) |
|---|
| 941 |
{ |
|---|
| 942 |
if (!$file instanceof fFile) { |
|---|
| 943 |
$file = new fFile($file); |
|---|
| 944 |
} |
|---|
| 945 |
|
|---|
| 946 |
$html = $file->read(); |
|---|
| 947 |
if ($replacements) { |
|---|
| 948 |
$html = strtr($html, $replacements); |
|---|
| 949 |
} |
|---|
| 950 |
|
|---|
| 951 |
$this->html_body = $html; |
|---|
| 952 |
} |
|---|
| 953 |
|
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 |
|
|---|
| 957 |
|
|---|
| 958 |
@param |
|---|
| 959 |
@return |
|---|
| 960 |
|
|---|
| 961 |
private function makeBase64($content) |
|---|
| 962 |
{ |
|---|
| 963 |
return chunk_split(base64_encode($content)); |
|---|
| 964 |
} |
|---|
| 965 |
|
|---|
| 966 |
|
|---|
| 967 |
|
|---|
| 968 |
|
|---|
| 969 |
|
|---|
| 970 |
@param |
|---|
| 971 |
@return |
|---|
| 972 |
|
|---|
| 973 |
private function makeEncodedWord($content) |
|---|
| 974 |
{ |
|---|
| 975 |
|
|---|
| 976 |
$content = str_replace("\r\n", "\n", $content); |
|---|
| 977 |
$content = str_replace("\r", "\n", $content); |
|---|
| 978 |
$content = str_replace("\n", "\r\n", $content); |
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
$content = rawurlencode($content); |
|---|
| 982 |
$content = str_replace('=', '%3D', $content); |
|---|
| 983 |
$content = str_replace('%', '=', $content); |
|---|
| 984 |
|
|---|
| 985 |
|
|---|
| 986 |
$decodings = array( |
|---|
| 987 |
'=20' => '_', '=21' => '!', '=22' => '"', '=23' => '#', |
|---|
| 988 |
'=24' => '$', '=25' => '%', '=26' => '&', '=27' => "'", |
|---|
| 989 |
'=28' => '(', '=29' => ')', '=2A' => '*', '=2B' => '+', |
|---|
| 990 |
'=2C' => ',', '=2D' => '-', '=2E' => '.', '=2F' => '/', |
|---|
| 991 |
'=3A' => ':', '=3B' => ';', '=3C' => '<', '=3E' => '>', |
|---|
| 992 |
'=40' => '@', '=5B' => '[', '=5C' => '\\', '=5D' => ']', |
|---|
| 993 |
'=5E' => '^', '=60' => '`', '=7B' => '{', '=7C' => '|', |
|---|
| 994 |
'=7D' => '}', '=7E' => '~', ' ' => '_' |
|---|
| 995 |
); |
|---|
| 996 |
|
|---|
| 997 |
$content = strtr($content, $decodings); |
|---|
| 998 |
|
|---|
| 999 |
$length = strlen($content); |
|---|
| 1000 |
|
|---|
| 1001 |
$prefix = '=?utf-8?Q?'; |
|---|
| 1002 |
$suffix = '?='; |
|---|
| 1003 |
|
|---|
| 1004 |
$prefix_length = 10; |
|---|
| 1005 |
$suffix_length = 2; |
|---|
| 1006 |
|
|---|
| 1007 |
|
|---|
| 1008 |
|
|---|
| 1009 |
$output = $prefix; |
|---|
| 1010 |
$line_length = $prefix_length; |
|---|
| 1011 |
|
|---|
| 1012 |
for ($i=0; $i<$length; $i++) { |
|---|
| 1013 |
|
|---|
| 1014 |
|
|---|
| 1015 |
$char_length = ($content[$i] == '=') ? 3 : 1; |
|---|
| 1016 |
$char = $content[$i]; |
|---|
| 1017 |
if ($char_length == 3) { |
|---|
| 1018 |
$char .= $content[$i+1] . $content[$i+2]; |
|---|
| 1019 |
} |
|---|
| 1020 |
|
|---|
| 1021 |
|
|---|
| 1022 |
if ($line_length + $suffix_length + $char_length > 75) { |
|---|
| 1023 |
$output .= $suffix . "\r\n " . $prefix; |
|---|
| 1024 |
$line_length = $prefix_length + 2; |
|---|
| 1025 |
} |
|---|
| 1026 |
|
|---|
| 1027 |
|
|---|
| 1028 |
$output .= $char; |
|---|
| 1029 |
|
|---|
| 1030 |
|
|---|
| 1031 |
$line_length += $char_length; |
|---|
| 1032 |
|
|---|
| 1033 |
|
|---|
| 1034 |
$i += $char_length-1; |
|---|
| 1035 |
} |
|---|
| 1036 |
|
|---|
| 1037 |
if (substr($output, -2) != $suffix) { |
|---|
| 1038 |
$output .= $suffix; |
|---|
| 1039 |
} |
|---|
| 1040 |
|
|---|
| 1041 |
return $output; |
|---|
| 1042 |
} |
|---|
| 1043 |
|
|---|
| 1044 |
|
|---|
| 1045 |
|
|---|
| 1046 |
|
|---|
| 1047 |
|
|---|
| 1048 |
@param |
|---|
| 1049 |
@return |
|---|
| 1050 |
|
|---|
| 1051 |
private function makeQuotedPrintable($content) |
|---|
| 1052 |
{ |
|---|
| 1053 |
|
|---|
| 1054 |
$content = str_replace("\r\n", "\n", $content); |
|---|
| 1055 |
$content = str_replace("\r", "\n", $content); |
|---|
| 1056 |
$content = str_replace("\n", "\r\n", $content); |
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
$content = rawurlencode($content); |
|---|
| 1060 |
$content = str_replace('=', '%3D', $content); |
|---|
| 1061 |
$content = str_replace('%', '=', $content); |
|---|
| 1062 |
|
|---|
| 1063 |
|
|---|
| 1064 |
$decodings = array( |
|---|
| 1065 |
'=20' => ' ', '=21' => '!', '=22' => '"', '=23' => '#', |
|---|
| 1066 |
'=24' => '$', '=25' => '%', '=26' => '&', '=27' => "'", |
|---|
| 1067 |
'=28' => '(', '=29' => ')', '=2A' => '*', '=2B' => '+', |
|---|
| 1068 |
'=2C' => ',', '=2D' => '-', '=2E' => '.', '=2F' => '/', |
|---|
| 1069 |
'=3A' => ':', '=3B' => ';', '=3C' => '<', '=3E' => '>', |
|---|
| 1070 |
'=3F' => '?', '=40' => '@', '=5B' => '[', '=5C' => '\\', |
|---|
| 1071 |
'=5D' => ']', '=5E' => '^', '=5F' => '_', '=60' => '`', |
|---|
| 1072 |
'=7B' => '{', '=7C' => '|', '=7D' => '}', '=7E' => '~' |
|---|
| 1073 |
); |
|---|
| 1074 |
|
|---|
| 1075 |
$content = strtr($content, $decodings); |
|---|
| 1076 |
|
|---|
| 1077 |
$output = ''; |
|---|
| 1078 |
|
|---|
| 1079 |
$length = strlen($content); |
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
$line_length = 0; |
|---|
| 1083 |
for ($i=0; $i<$length; $i++) { |
|---|
| 1084 |
|
|---|
| 1085 |
|
|---|
| 1086 |
$char_length = ($content[$i] == '=') ? 3 : 1; |
|---|
| 1087 |
$char = $content[$i]; |
|---|
| 1088 |
if ($char_length == 3) { |
|---|
| 1089 |
$char .= $content[$i+1] . $content[$i+2]; |
|---|
| 1090 |
} |
|---|
| 1091 |
|
|---|
| 1092 |
|
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|
| 1095 |
$i += $char_length-1; |
|---|
| 1096 |
|
|---|
| 1097 |
|
|---|
| 1098 |
$begining_or_end = $line_length > 69 || $line_length == 0; |
|---|
| 1099 |
$tab_or_space = $char == ' ' || $char == "\t"; |
|---|
| 1100 |
if ($begining_or_end && $tab_or_space) { |
|---|
| 1101 |
$char_length = 3; |
|---|
| 1102 |
$char = ($char == ' ') ? '=20' : '=09'; |
|---|
| 1103 |
} |
|---|
| 1104 |
|
|---|
| 1105 |
|
|---|
| 1106 |
if ($char != "\r" && $char != "\n" && $line_length + $char_length > 75) { |
|---|
| 1107 |
$output .= "=\r\n"; |
|---|
| 1108 |
$line_length = 0; |
|---|
| 1109 |
} |
|---|
| 1110 |
|
|---|
| 1111 |
|
|---|
| 1112 |
$output .= $char; |
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 |
if ($char == "\r" || $char == "\n") { |
|---|
| 1116 |
$line_length = 0; |
|---|
| 1117 |
} else { |
|---|
| 1118 |
$line_length += $char_length; |
|---|
| 1119 |
} |
|---|
| 1120 |
} |
|---|
| 1121 |
|
|---|
| 1122 |
return $output; |
|---|
| 1123 |
} |
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
|
|---|
| 1128 |
|
|---|
| 1129 |
|
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 |
|
|---|
| 1133 |
|
|---|
| 1134 |
@throws |
|---|
| 1135 |
|
|---|
| 1136 |
@param |
|---|
| 1137 |
@return |
|---|
| 1138 |
|
|---|
| 1139 |
public function send($connection=NULL) |
|---|
| 1140 |
{ |
|---|
| 1141 |
$this->validate(); |
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
if ($connection === NULL && fCore::checkOS('windows')) { |
|---|
| 1146 |
$vars = array('bcc_emails', 'bounce_to_email', 'cc_emails', 'from_email', 'reply_to_email', 'sender_email', 'to_emails'); |
|---|
| 1147 |
foreach ($vars as $var) { |
|---|
| 1148 |
if (!is_array($this->$var)) { |
|---|
| 1149 |
if (preg_match(self::NAME_EMAIL_REGEX, $this->$var, $match)) { |
|---|
| 1150 |
$this->$var = $match[2]; |
|---|
| 1151 |
} |
|---|
| 1152 |
} else { |
|---|
| 1153 |
$new_emails = array(); |
|---|
| 1154 |
foreach ($this->$var as $email) { |
|---|
| 1155 |
if (preg_match(self::NAME_EMAIL_REGEX, $email, $match)) { |
|---|
| 1156 |
$email = $match[2]; |
|---|
| 1157 |
} |
|---|
| 1158 |
$new_emails[] = $email; |
|---|
| 1159 |
} |
|---|
| 1160 |
$this->$var = $new_emails; |
|---|
| 1161 |
} |
|---|
| 1162 |
} |
|---|
| 1163 |
} |
|---|
| 1164 |
|
|---|
| 1165 |
$to = trim($this->buildMultiAddressHeader("", $this->to_emails)); |
|---|
| 1166 |
|
|---|
| 1167 |
$message_id = '<' . fCryptography::randomString(32, 'hexadecimal') . '@' . self::$local_hostname . '>'; |
|---|
| 1168 |
$top_level_boundary = $this->createBoundary(); |
|---|
| 1169 |
$headers = $this->createHeaders($top_level_boundary, $message_id); |
|---|
| 1170 |
|
|---|
| 1171 |
$subject = str_replace(array("\r", "\n"), '', $this->subject); |
|---|
| 1172 |
$subject = $this->makeEncodedWord($subject); |
|---|
| 1173 |
|
|---|
| 1174 |
$body = $this->createBody($top_level_boundary); |
|---|
| 1175 |
|
|---|
| 1176 |
if ($this->smime_encrypt || $this->smime_sign) { |
|---|
| 1177 |
list($headers, $body) = $this->createSMIMEBody($to, $subject, $headers, $body); |
|---|
| 1178 |
} |
|---|
| 1179 |
|
|---|
| 1180 |
|
|---|
| 1181 |
$headers = trim($headers); |
|---|
| 1182 |
$body = trim($body); |
|---|
| 1183 |
|
|---|
| 1184 |
if ($connection) { |
|---|
| 1185 |
$to_emails = $this->extractEmails($this->to_emails); |
|---|
| 1186 |
$to_emails = array_merge($to_emails, $this->extractEmails($this->cc_emails)); |
|---|
| 1187 |
$to_emails = array_merge($to_emails, $this->extractEmails($this->bcc_emails)); |
|---|
| 1188 |
$from = $this->bounce_to_email ? $this->bounce_to_email : current($this->extractEmails(array($this->from_email))); |
|---|
| 1189 |
$connection->send($from, $to_emails, "To: " . $to . "\r\nSubject: " . $subject . "\r\n" . $headers, $body); |
|---|
| 1190 |
return $message_id; |
|---|
| 1191 |
} |
|---|
| 1192 |
|
|---|
| 1193 |
|
|---|
| 1194 |
$parameters = NULL; |
|---|
| 1195 |
if (!fCore::checkOS('windows') && $this->bounce_to_email) { |
|---|
| 1196 |
preg_match(self::EMAIL_REGEX, $this->bounce_to_email, $matches); |
|---|
| 1197 |
$parameters = '-f ' . $matches[0]; |
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
} elseif (fCore::checkOS('windows') && $this->bounce_to_email) { |
|---|
| 1201 |
$old_sendmail_from = ini_get('sendmail_from'); |
|---|
| 1202 |
preg_match(self::EMAIL_REGEX, $this->bounce_to_email, $matches); |
|---|
| 1203 |
ini_set('sendmail_from', $matches[0]); |
|---|
| 1204 |
} |
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
if (self::$popen_sendmail || self::$convert_crlf) { |
|---|
| 1208 |
$to = str_replace("\r\n", "\n", $to); |
|---|
| 1209 |
$subject = str_replace("\r\n", "\n", $subject); |
|---|
| 1210 |
$body = str_replace("\r\n", "\n", $body); |
|---|
| 1211 |
$headers = str_replace("\r\n", "\n", $headers); |
|---|
| 1212 |
} |
|---|
| 1213 |
|
|---|
| 1214 |
|
|---|
| 1215 |
if (self::$popen_sendmail) { |
|---|
| 1216 |
$sendmail_command = ini_get('sendmail_path'); |
|---|
| 1217 |
if ($parameters) { |
|---|
| 1218 |
$sendmail_command .= ' ' . $parameters; |
|---|
| 1219 |
} |
|---|
| 1220 |
|
|---|
| 1221 |
$sendmail_process = popen($sendmail_command, 'w'); |
|---|
| 1222 |
fprintf($sendmail_process, "To: %s\n", $to); |
|---|
| 1223 |
fprintf($sendmail_process, "Subject: %s\n", $subject); |
|---|
| 1224 |
if ($headers) { |
|---|
| 1225 |
fprintf($sendmail_process, "%s\n", $headers); |
|---|
| 1226 |
} |
|---|
| 1227 |
fprintf($sendmail_process, "\n%s\n", $body); |
|---|
| 1228 |
$error = pclose($sendmail_process); |
|---|
| 1229 |
|
|---|
| 1230 |
|
|---|
| 1231 |
} else { |
|---|
| 1232 |
if ($parameters) { |
|---|
| 1233 |
$error = !mail($to, $subject, $body, $headers, $parameters); |
|---|
| 1234 |
} else { |
|---|
| 1235 |
$error = !mail($to, $subject, $body, $headers); |
|---|
| 1236 |
} |
|---|
| 1237 |
} |
|---|
| 1238 |
|
|---|
| 1239 |
if (fCore::checkOS('windows') && $this->bounce_to_email) { |
|---|
| 1240 |
ini_set('sendmail_from', $old_sendmail_from); |
|---|
| 1241 |
} |
|---|
| 1242 |
|
|---|
| 1243 |
if ($error) { |
|---|
| 1244 |
throw new fConnectivityException( |
|---|
| 1245 |
'An error occured while trying to send the email entitled %s', |
|---|
| 1246 |
$this->subject |
|---|
| 1247 |
); |
|---|
| 1248 |
} |
|---|
| 1249 |
|
|---|
| 1250 |
return $message_id; |
|---|
| 1251 |
} |
|---|
| 1252 |
|
|---|
| 1253 |
|
|---|
| 1254 |
|
|---|
| 1255 |
|
|---|
| 1256 |
|
|---|
| 1257 |
|
|---|
| 1258 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 1259 |
|
|---|
| 1260 |
@param |
|---|
| 1261 |
@param |
|---|
| 1262 |
@return |
|---|
| 1263 |
|
|---|
| 1264 |
public function setBody($plaintext, $unindent_expand_constants=FALSE) |
|---|
| 1265 |
{ |
|---|
| 1266 |
if ($unindent_expand_constants) { |
|---|
| 1267 |
$plaintext = self::unindentExpand($plaintext); |
|---|
| 1268 |
} |
|---|
| 1269 |
|
|---|
| 1270 |
$this->plaintext_body = $plaintext; |
|---|
| 1271 |
} |
|---|
| 1272 |
|
|---|
| 1273 |
|
|---|
| 1274 |
|
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
|
|---|
| 1278 |
|
|---|
| 1279 |
@param |
|---|
| 1280 |
@return |
|---|
| 1281 |
|
|---|
| 1282 |
public function setBounceToEmail($email) |
|---|
| 1283 |
{ |
|---|
| 1284 |
if (ini_get('safe_mode') && !fCore::checkOS('windows')) { |
|---|
| 1285 |
throw new fProgrammerException('It is not possible to set a Bounce-To Email address when safe mode is enabled on a non-Windows server'); |
|---|
| 1286 |
} |
|---|
| 1287 |
if (!$email) { |
|---|
| 1288 |
return; |
|---|
| 1289 |
} |
|---|
| 1290 |
|
|---|
| 1291 |
$this->bounce_to_email = $this->combineNameEmail('', $email); |
|---|
| 1292 |
} |
|---|
| 1293 |
|
|---|
| 1294 |
|
|---|
| 1295 |
|
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 |
@param |
|---|
| 1299 |
@param |
|---|
| 1300 |
@return |
|---|
| 1301 |
|
|---|
| 1302 |
public function setFromEmail($email, $name=NULL) |
|---|
| 1303 |
{ |
|---|
| 1304 |
if (!$email) { |
|---|
| 1305 |
return; |
|---|
| 1306 |
} |
|---|
| 1307 |
|
|---|
| 1308 |
$this->from_email = $this->combineNameEmail($name, $email); |
|---|
| 1309 |
} |
|---|
| 1310 |
|
|---|
| 1311 |
|
|---|
| 1312 |
|
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 1317 |
|
|---|
| 1318 |
@param |
|---|
| 1319 |
@return |
|---|
| 1320 |
|
|---|
| 1321 |
public function setHTMLBody($html) |
|---|
| 1322 |
{ |
|---|
| 1323 |
$this->html_body = $html; |
|---|
| 1324 |
} |
|---|
| 1325 |
|
|---|
| 1326 |
|
|---|
| 1327 |
|
|---|
| 1328 |
|
|---|
| 1329 |
|
|---|
| 1330 |
@param |
|---|
| 1331 |
@param |
|---|
| 1332 |
@return |
|---|
| 1333 |
|
|---|
| 1334 |
public function setReplyToEmail($email, $name=NULL) |
|---|
| 1335 |
{ |
|---|
| 1336 |
if (!$email) { |
|---|
| 1337 |
return; |
|---|
| 1338 |
} |
|---|
| 1339 |
|
|---|
| 1340 |
$this->reply_to_email = $this->combineNameEmail($name, $email); |
|---|
| 1341 |
} |
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 |
|
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
|
|---|
| 1348 |
|
|---|
| 1349 |
|
|---|
| 1350 |
@param |
|---|
| 1351 |
@param |
|---|
| 1352 |
@return |
|---|
| 1353 |
|
|---|
| 1354 |
public function setSenderEmail($email, $name=NULL) |
|---|
| 1355 |
{ |
|---|
| 1356 |
if (!$email) { |
|---|
| 1357 |
return; |
|---|
| 1358 |
} |
|---|
| 1359 |
|
|---|
| 1360 |
$this->sender_email = $this->combineNameEmail($name, $email); |
|---|
| 1361 |
} |
|---|
| 1362 |
|
|---|
| 1363 |
|
|---|
| 1364 |
|
|---|
| 1365 |
|
|---|
| 1366 |
|
|---|
| 1367 |
|
|---|
| 1368 |
http://flourishlib.com/docs/UTF-8 |
|---|
| 1369 |
|
|---|
| 1370 |
@param |
|---|
| 1371 |
@return |
|---|
| 1372 |
|
|---|
| 1373 |
public function setSubject($subject) |
|---|
| 1374 |
{ |
|---|
| 1375 |
$this->subject = $subject; |
|---|
| 1376 |
} |
|---|
| 1377 |
|
|---|
| 1378 |
|
|---|
| 1379 |
|
|---|
| 1380 |
|
|---|
| 1381 |
|
|---|
| 1382 |
@param |
|---|
| 1383 |
@param |
|---|
| 1384 |
@param |
|---|
| 1385 |
@return |
|---|
| 1386 |
|
|---|
| 1387 |
public function sign($senders_smime_cert_file, $senders_smime_pk_file, $senders_smime_pk_password) |
|---|
| 1388 |
{ |
|---|
| 1389 |
if (!extension_loaded('openssl')) { |
|---|
| 1390 |
throw new fEnvironmentException( |
|---|
| 1391 |
'An S/MIME signature was requested for an email, but the %s extension is not installed', |
|---|
| 1392 |
'openssl' |
|---|
| 1393 |
); |
|---|
| 1394 |
} |
|---|
| 1395 |
|
|---|
| 1396 |
if (!self::stringlike($senders_smime_cert_file)) { |
|---|
| 1397 |
throw new fProgrammerException( |
|---|
| 1398 |
"The sender's S/MIME certificate file specified, %s, does not appear to be a valid filename", |
|---|
| 1399 |
$senders_smime_cert_file |
|---|
| 1400 |
); |
|---|
| 1401 |
} |
|---|
| 1402 |
if (!file_exists($senders_smime_cert_file) || !is_readable($senders_smime_cert_file)) { |
|---|
| 1403 |
throw new fEnvironmentException( |
|---|
| 1404 |
"The sender's S/MIME certificate file specified, %s, does not exist or could not be read", |
|---|
| 1405 |
$senders_smime_cert_file |
|---|
| 1406 |
); |
|---|
| 1407 |
} |
|---|
| 1408 |
|
|---|
| 1409 |
if (!self::stringlike($senders_smime_pk_file)) { |
|---|
| 1410 |
throw new fProgrammerException( |
|---|
| 1411 |
"The sender's S/MIME primary key file specified, %s, does not appear to be a valid filename", |
|---|
| 1412 |
$senders_smime_pk_file |
|---|
| 1413 |
); |
|---|
| 1414 |
} |
|---|
| 1415 |
if (!file_exists($senders_smime_pk_file) || !is_readable($senders_smime_pk_file)) { |
|---|
| 1416 |
throw new fEnvironmentException( |
|---|
| 1417 |
"The sender's S/MIME primary key file specified, %s, does not exist or could not be read", |
|---|
| 1418 |
$senders_smime_pk_file |
|---|
| 1419 |
); |
|---|
| 1420 |
} |
|---|
| 1421 |
|
|---|
| 1422 |
$this->smime_sign = TRUE; |
|---|
| 1423 |
$this->senders_smime_cert_file = $senders_smime_cert_file; |
|---|
| 1424 |
$this->senders_smime_pk_file = $senders_smime_pk_file; |
|---|
| 1425 |
$this->senders_smime_pk_password = $senders_smime_pk_password; |
|---|
| 1426 |
} |
|---|
| 1427 |
|
|---|
| 1428 |
|
|---|
| 1429 |
|
|---|
| 1430 |
|
|---|
| 1431 |
|
|---|
| 1432 |
@throws |
|---|
| 1433 |
|
|---|
| 1434 |
@return |
|---|
| 1435 |
|
|---|
| 1436 |
private function validate() |
|---|
| 1437 |
{ |
|---|
| 1438 |
$validation_messages = array(); |
|---|
| 1439 |
|
|---|
| 1440 |
|
|---|
| 1441 |
$multi_address_field_list = array( |
|---|
| 1442 |
'to_emails' => self::compose('recipient'), |
|---|
| 1443 |
'cc_emails' => self::compose('CC recipient'), |
|---|
| 1444 |
'bcc_emails' => self::compose('BCC recipient') |
|---|
| 1445 |
); |
|---|
| 1446 |
|
|---|
| 1447 |
foreach ($multi_address_field_list as $field => $name) { |
|---|
| 1448 |
foreach ($this->$field as $email) { |
|---|
| 1449 |
if ($email && !preg_match(self::NAME_EMAIL_REGEX, $email) && !preg_match(self::EMAIL_REGEX, $email)) { |
|---|
| 1450 |
$validation_messages[] = htmlspecialchars(self::compose( |
|---|
| 1451 |
'The %1$s %2$s is not a valid email address. Should be like "John Smith" <name@example.com> or name@example.com.', |
|---|
| 1452 |
$name, |
|---|
| 1453 |
$email |
|---|
| 1454 |
), ENT_QUOTES, 'UTF-8'); |
|---|
| 1455 |
} |
|---|
| 1456 |
} |
|---|
| 1457 |
} |
|---|
| 1458 |
|
|---|
| 1459 |
|
|---|
| 1460 |
$single_address_field_list = array( |
|---|
| 1461 |
'from_email' => self::compose('From email address'), |
|---|
| 1462 |
'reply_to_email' => self::compose('Reply-To email address'), |
|---|
| 1463 |
'sender_email' => self::compose('Sender email address'), |
|---|
| 1464 |
'bounce_to_email' => self::compose('Bounce-To email address') |
|---|
| 1465 |
); |
|---|
| 1466 |
|
|---|
| 1467 |
foreach ($single_address_field_list as $field => $name) { |
|---|
| 1468 |
if ($this->$field && !preg_match(self::NAME_EMAIL_REGEX, $this->$field) && !preg_match(self::EMAIL_REGEX, $this->$field)) { |
|---|
| 1469 |
$validation_messages[] = htmlspecialchars(self::compose( |
|---|
| 1470 |
'The %1$s %2$s is not a valid email address. Should be like "John Smith" <name@example.com> or name@example.com.', |
|---|
| 1471 |
$name, |
|---|
| 1472 |
$this->$field |
|---|
| 1473 |
), ENT_QUOTES, 'UTF-8'); |
|---|
| 1474 |
} |
|---|
| 1475 |
} |
|---|
| 1476 |
|
|---|
| 1477 |
|
|---|
| 1478 |
if (!$this->to_emails) { |
|---|
| 1479 |
$validation_messages[] = self::compose( |
|---|
| 1480 |
"Please provide at least one recipient" |
|---|
| 1481 |
); |
|---|
| 1482 |
} |
|---|
| 1483 |
|
|---|
| 1484 |
if (!$this->from_email) { |
|---|
| 1485 |
$validation_messages[] = self::compose( |
|---|
| 1486 |
"Please provide the from email address" |
|---|
| 1487 |
); |
|---|
| 1488 |
} |
|---|
| 1489 |
|
|---|
| 1490 |
if (!self::stringlike($this->subject)) { |
|---|
| 1491 |
$validation_messages[] = self::compose( |
|---|
| 1492 |
"Please provide an email subject" |
|---|
| 1493 |
); |
|---|
| 1494 |
} |
|---|
| 1495 |
|
|---|
| 1496 |
if (strpos($this->subject, "\n") !== FALSE) { |
|---|
| 1497 |
$validation_messages[] = self::compose( |
|---|
| 1498 |
"The subject contains one or more newline characters" |
|---|
| 1499 |
); |
|---|
| 1500 |
} |
|---|
| 1501 |
|
|---|
| 1502 |
if (!self::stringlike($this->plaintext_body)) { |
|---|
| 1503 |
$validation_messages[] = self::compose( |
|---|
| 1504 |
"Please provide a plaintext email body" |
|---|
| 1505 |
); |
|---|
| 1506 |
} |
|---|
| 1507 |
|
|---|
| 1508 |
|
|---|
| 1509 |
foreach ($this->attachments as $filename => $file_info) { |
|---|
| 1510 |
if (!self::stringlike($file_info['mime-type'])) { |
|---|
| 1511 |
$validation_messages[] = self::compose( |
|---|
| 1512 |
"No mime-type was specified for the attachment %s", |
|---|
| 1513 |
$filename |
|---|
| 1514 |
); |
|---|
| 1515 |
} |
|---|
| 1516 |
if (!self::stringlike($file_info['contents'])) { |
|---|
| 1517 |
$validation_messages[] = self::compose( |
|---|
| 1518 |
"The attachment %s appears to be a blank file", |
|---|
| 1519 |
$filename |
|---|
| 1520 |
); |
|---|
| 1521 |
} |
|---|
| 1522 |
} |
|---|
| 1523 |
|
|---|
| 1524 |
if ($validation_messages) { |
|---|
| 1525 |
throw new fValidationException( |
|---|
| 1526 |
'The email could not be sent because:', |
|---|
| 1527 |
$validation_messages |
|---|
| 1528 |
); |
|---|
| 1529 |
} |
|---|
| 1530 |
} |
|---|
| 1531 |
} |
|---|
| 1532 |
|
|---|
| 1533 |
|
|---|
| 1534 |
|
|---|
| 1535 |
|
|---|
| 1536 |
will@flourishlib.com |
|---|
| 1537 |
|
|---|
| 1538 |
|
|---|
| 1539 |
|
|---|
| 1540 |
|
|---|
| 1541 |
|
|---|
| 1542 |
|
|---|
| 1543 |
|
|---|
| 1544 |
|
|---|
| 1545 |
|
|---|
| 1546 |
|
|---|
| 1547 |
|
|---|
| 1548 |
|
|---|
| 1549 |
|
|---|
| 1550 |
|
|---|
| 1551 |
|
|---|
| 1552 |
|
|---|
| 1553 |
|
|---|
| 1554 |
|
|---|
| 1555 |
|
|---|