Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * CodeIgniter Email Class |
| 20 | * |
| 21 | * Permits email to be sent using Mail, Sendmail, or SMTP. |
| 22 | * |
| 23 | * @package CodeIgniter |
| 24 | * @subpackage Libraries |
| 25 | * @category Libraries |
| 26 | * @author ExpressionEngine Dev Team |
| 27 | * @link http://codeigniter.com/user_guide/libraries/email.html |
| 28 | */ |
| 29 | class CI_Email { |
| 30 | |
| 31 | var $useragent = "CodeIgniter"; |
| 32 | var $mailpath = "/usr/sbin/sendmail"; // Sendmail path |
| 33 | var $protocol = "mail"; // mail/sendmail/smtp |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 34 | var $smtp_host = ""; // SMTP Server. Example: mail.earthlink.net |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | var $smtp_user = ""; // SMTP Username |
| 36 | var $smtp_pass = ""; // SMTP Password |
| 37 | var $smtp_port = "25"; // SMTP Port |
| 38 | var $smtp_timeout = 5; // SMTP Timeout in seconds |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 39 | var $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 40 | var $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 41 | var $wrapchars = "76"; // Number of characters to wrap at. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 42 | var $mailtype = "text"; // text/html Defines email formatting |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | var $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii |
| 44 | var $multipart = "mixed"; // "mixed" (in the body) or "related" (separate) |
| 45 | var $alt_message = ''; // Alternative message for HTML emails |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 46 | var $validate = FALSE; // TRUE/FALSE. Enables email validation |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | var $priority = "3"; // Default priority (1 - 5) |
| 48 | var $newline = "\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822) |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 49 | var $crlf = "\n"; // The RFC 2045 compliant CRLF for quoted-printable is "\r\n". Apparently some servers, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | // even on the receiving end think they need to muck with CRLFs, so using "\n", while |
| 51 | // distasteful, is the only thing that seems to work for all environments. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 52 | var $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo. |
| 53 | var $bcc_batch_mode = FALSE; // TRUE/FALSE Turns on/off Bcc batch feature |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 54 | var $bcc_batch_size = 200; // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch |
| 55 | var $_safe_mode = FALSE; |
| 56 | var $_subject = ""; |
| 57 | var $_body = ""; |
| 58 | var $_finalbody = ""; |
| 59 | var $_alt_boundary = ""; |
| 60 | var $_atc_boundary = ""; |
| 61 | var $_header_str = ""; |
| 62 | var $_smtp_connect = ""; |
| 63 | var $_encoding = "8bit"; |
| 64 | var $_IP = FALSE; |
| 65 | var $_smtp_auth = FALSE; |
| 66 | var $_replyto_flag = FALSE; |
| 67 | var $_debug_msg = array(); |
| 68 | var $_recipients = array(); |
| 69 | var $_cc_array = array(); |
| 70 | var $_bcc_array = array(); |
| 71 | var $_headers = array(); |
| 72 | var $_attach_name = array(); |
| 73 | var $_attach_type = array(); |
| 74 | var $_attach_disp = array(); |
| 75 | var $_protocols = array('mail', 'sendmail', 'smtp'); |
| 76 | var $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) |
| 77 | var $_bit_depths = array('7bit', '8bit'); |
| 78 | var $_priorities = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)'); |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * Constructor - Sets Email Preferences |
| 83 | * |
| 84 | * The constructor can be passed an array of config values |
| 85 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 86 | public function __construct($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | { |
| 88 | if (count($config) > 0) |
| 89 | { |
| 90 | $this->initialize($config); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; |
| 95 | $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; |
| 96 | } |
| 97 | |
| 98 | log_message('debug', "Email Class Initialized"); |
| 99 | } |
| 100 | |
| 101 | // -------------------------------------------------------------------- |
| 102 | |
| 103 | /** |
| 104 | * Initialize preferences |
| 105 | * |
| 106 | * @access public |
| 107 | * @param array |
| 108 | * @return void |
| 109 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 110 | public function initialize($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | foreach ($config as $key => $val) |
| 113 | { |
| 114 | if (isset($this->$key)) |
| 115 | { |
| 116 | $method = 'set_'.$key; |
| 117 | |
| 118 | if (method_exists($this, $method)) |
| 119 | { |
| 120 | $this->$method($val); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | $this->$key = $val; |
| 125 | } |
| 126 | } |
| 127 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 128 | $this->clear(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | |
| 130 | $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; |
| 131 | $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 132 | |
| 133 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 135 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | // -------------------------------------------------------------------- |
| 137 | |
| 138 | /** |
| 139 | * Initialize the Email Data |
| 140 | * |
| 141 | * @access public |
Bo-Yi Wu | 83320eb | 2011-09-15 13:28:02 +0800 | [diff] [blame] | 142 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | * @return void |
| 144 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 145 | public function clear($clear_attachments = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | { |
| 147 | $this->_subject = ""; |
| 148 | $this->_body = ""; |
| 149 | $this->_finalbody = ""; |
| 150 | $this->_header_str = ""; |
| 151 | $this->_replyto_flag = FALSE; |
| 152 | $this->_recipients = array(); |
Derek Jones | d160635 | 2010-09-01 11:16:07 -0500 | [diff] [blame] | 153 | $this->_cc_array = array(); |
| 154 | $this->_bcc_array = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | $this->_headers = array(); |
| 156 | $this->_debug_msg = array(); |
| 157 | |
| 158 | $this->_set_header('User-Agent', $this->useragent); |
| 159 | $this->_set_header('Date', $this->_set_date()); |
| 160 | |
| 161 | if ($clear_attachments !== FALSE) |
| 162 | { |
| 163 | $this->_attach_name = array(); |
| 164 | $this->_attach_type = array(); |
| 165 | $this->_attach_disp = array(); |
| 166 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 167 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 168 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 170 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | // -------------------------------------------------------------------- |
| 172 | |
| 173 | /** |
| 174 | * Set FROM |
| 175 | * |
| 176 | * @access public |
| 177 | * @param string |
| 178 | * @param string |
| 179 | * @return void |
| 180 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 181 | public function from($from, $name = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | { |
| 183 | if (preg_match( '/\<(.*)\>/', $from, $match)) |
| 184 | { |
| 185 | $from = $match['1']; |
| 186 | } |
| 187 | |
| 188 | if ($this->validate) |
| 189 | { |
| 190 | $this->validate_email($this->_str_to_array($from)); |
| 191 | } |
| 192 | |
| 193 | // prepare the display name |
| 194 | if ($name != '') |
| 195 | { |
| 196 | // only use Q encoding if there are characters that would require it |
| 197 | if ( ! preg_match('/[\200-\377]/', $name)) |
| 198 | { |
| 199 | // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 200 | $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 201 | } |
| 202 | else |
| 203 | { |
| 204 | $name = $this->_prep_q_encoding($name, TRUE); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | $this->_set_header('From', $name.' <'.$from.'>'); |
| 209 | $this->_set_header('Return-Path', '<'.$from.'>'); |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 210 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 211 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | // -------------------------------------------------------------------- |
| 215 | |
| 216 | /** |
| 217 | * Set Reply-to |
| 218 | * |
| 219 | * @access public |
| 220 | * @param string |
| 221 | * @param string |
| 222 | * @return void |
| 223 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 224 | public function reply_to($replyto, $name = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | { |
| 226 | if (preg_match( '/\<(.*)\>/', $replyto, $match)) |
| 227 | { |
| 228 | $replyto = $match['1']; |
| 229 | } |
| 230 | |
| 231 | if ($this->validate) |
| 232 | { |
| 233 | $this->validate_email($this->_str_to_array($replyto)); |
| 234 | } |
| 235 | |
| 236 | if ($name == '') |
| 237 | { |
| 238 | $name = $replyto; |
| 239 | } |
| 240 | |
| 241 | if (strncmp($name, '"', 1) != 0) |
| 242 | { |
| 243 | $name = '"'.$name.'"'; |
| 244 | } |
| 245 | |
| 246 | $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); |
| 247 | $this->_replyto_flag = TRUE; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 248 | |
| 249 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | // -------------------------------------------------------------------- |
| 253 | |
| 254 | /** |
| 255 | * Set Recipients |
| 256 | * |
| 257 | * @access public |
| 258 | * @param string |
| 259 | * @return void |
| 260 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 261 | public function to($to) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | { |
| 263 | $to = $this->_str_to_array($to); |
| 264 | $to = $this->clean_email($to); |
| 265 | |
| 266 | if ($this->validate) |
| 267 | { |
| 268 | $this->validate_email($to); |
| 269 | } |
| 270 | |
| 271 | if ($this->_get_protocol() != 'mail') |
| 272 | { |
| 273 | $this->_set_header('To', implode(", ", $to)); |
| 274 | } |
| 275 | |
| 276 | switch ($this->_get_protocol()) |
| 277 | { |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 278 | case 'smtp' : |
| 279 | $this->_recipients = $to; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | break; |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 281 | case 'sendmail' : |
| 282 | case 'mail' : |
| 283 | $this->_recipients = implode(", ", $to); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | break; |
| 285 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 286 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 287 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 289 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | // -------------------------------------------------------------------- |
| 291 | |
| 292 | /** |
| 293 | * Set CC |
| 294 | * |
| 295 | * @access public |
| 296 | * @param string |
| 297 | * @return void |
| 298 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 299 | public function cc($cc) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
| 301 | $cc = $this->_str_to_array($cc); |
| 302 | $cc = $this->clean_email($cc); |
| 303 | |
| 304 | if ($this->validate) |
| 305 | { |
| 306 | $this->validate_email($cc); |
| 307 | } |
| 308 | |
| 309 | $this->_set_header('Cc', implode(", ", $cc)); |
| 310 | |
| 311 | if ($this->_get_protocol() == "smtp") |
| 312 | { |
| 313 | $this->_cc_array = $cc; |
| 314 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 315 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 316 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | // -------------------------------------------------------------------- |
| 320 | |
| 321 | /** |
| 322 | * Set BCC |
| 323 | * |
| 324 | * @access public |
| 325 | * @param string |
| 326 | * @param string |
| 327 | * @return void |
| 328 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 329 | public function bcc($bcc, $limit = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | { |
| 331 | if ($limit != '' && is_numeric($limit)) |
| 332 | { |
| 333 | $this->bcc_batch_mode = TRUE; |
| 334 | $this->bcc_batch_size = $limit; |
| 335 | } |
| 336 | |
| 337 | $bcc = $this->_str_to_array($bcc); |
| 338 | $bcc = $this->clean_email($bcc); |
| 339 | |
| 340 | if ($this->validate) |
| 341 | { |
| 342 | $this->validate_email($bcc); |
| 343 | } |
| 344 | |
| 345 | if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) |
| 346 | { |
| 347 | $this->_bcc_array = $bcc; |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | $this->_set_header('Bcc', implode(", ", $bcc)); |
| 352 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 353 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 354 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | // -------------------------------------------------------------------- |
| 358 | |
| 359 | /** |
| 360 | * Set Email Subject |
| 361 | * |
| 362 | * @access public |
| 363 | * @param string |
| 364 | * @return void |
| 365 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 366 | public function subject($subject) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | { |
| 368 | $subject = $this->_prep_q_encoding($subject); |
| 369 | $this->_set_header('Subject', $subject); |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 370 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 372 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 373 | // -------------------------------------------------------------------- |
| 374 | |
| 375 | /** |
| 376 | * Set Body |
| 377 | * |
| 378 | * @access public |
| 379 | * @param string |
| 380 | * @return void |
| 381 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 382 | public function message($body) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | { |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 384 | $this->_body = rtrim(str_replace("\r", "", $body)); |
| 385 | |
| 386 | //strip slashes only if magic quotes is ON |
| 387 | //if we do it with magic quotes OFF, it strips real, user-inputted chars. |
diegorivera | 9fca615 | 2011-10-19 11:18:45 -0200 | [diff] [blame^] | 388 | if (get_magic_quotes_gpc()) |
| 389 | { |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 390 | $this->_body = stripslashes($this->_body); |
diegorivera | 9fca615 | 2011-10-19 11:18:45 -0200 | [diff] [blame^] | 391 | } |
diegorivera | 33c3280 | 2011-10-19 02:56:15 -0200 | [diff] [blame] | 392 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 393 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 394 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 395 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | // -------------------------------------------------------------------- |
| 397 | |
| 398 | /** |
| 399 | * Assign file attachments |
| 400 | * |
| 401 | * @access public |
| 402 | * @param string |
| 403 | * @return void |
| 404 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 405 | public function attach($filename, $disposition = 'attachment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | { |
| 407 | $this->_attach_name[] = $filename; |
Phil Sturgeon | 0aaf42b | 2011-08-10 08:06:37 -0600 | [diff] [blame] | 408 | $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 409 | $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 410 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | // -------------------------------------------------------------------- |
| 414 | |
| 415 | /** |
| 416 | * Add a Header Item |
| 417 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 418 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | * @param string |
| 420 | * @param string |
| 421 | * @return void |
| 422 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 423 | protected function _set_header($header, $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | { |
| 425 | $this->_headers[$header] = $value; |
| 426 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 427 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | // -------------------------------------------------------------------- |
| 429 | |
| 430 | /** |
| 431 | * Convert a String to an Array |
| 432 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 433 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | * @param string |
| 435 | * @return array |
| 436 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 437 | protected function _str_to_array($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | { |
| 439 | if ( ! is_array($email)) |
| 440 | { |
| 441 | if (strpos($email, ',') !== FALSE) |
| 442 | { |
| 443 | $email = preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY); |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | $email = trim($email); |
| 448 | settype($email, "array"); |
| 449 | } |
| 450 | } |
| 451 | return $email; |
| 452 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 453 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 454 | // -------------------------------------------------------------------- |
| 455 | |
| 456 | /** |
| 457 | * Set Multipart Value |
| 458 | * |
| 459 | * @access public |
| 460 | * @param string |
| 461 | * @return void |
| 462 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 463 | public function set_alt_message($str = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | { |
Dan Horrigan | d0ddeaf | 2011-08-21 09:07:27 -0400 | [diff] [blame] | 465 | $this->alt_message = (string) $str; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 466 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 467 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 468 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | // -------------------------------------------------------------------- |
| 470 | |
| 471 | /** |
| 472 | * Set Mailtype |
| 473 | * |
| 474 | * @access public |
| 475 | * @param string |
| 476 | * @return void |
| 477 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 478 | public function set_mailtype($type = 'text') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | { |
| 480 | $this->mailtype = ($type == 'html') ? 'html' : 'text'; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 481 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 482 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 483 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | // -------------------------------------------------------------------- |
| 485 | |
| 486 | /** |
| 487 | * Set Wordwrap |
| 488 | * |
| 489 | * @access public |
Dan Horrigan | 628e660 | 2011-08-21 09:08:31 -0400 | [diff] [blame] | 490 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 491 | * @return void |
| 492 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 493 | public function set_wordwrap($wordwrap = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | { |
Dan Horrigan | 628e660 | 2011-08-21 09:08:31 -0400 | [diff] [blame] | 495 | $this->wordwrap = (bool) $wordwrap; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 496 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 498 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | // -------------------------------------------------------------------- |
| 500 | |
| 501 | /** |
| 502 | * Set Protocol |
| 503 | * |
| 504 | * @access public |
| 505 | * @param string |
| 506 | * @return void |
| 507 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 508 | public function set_protocol($protocol = 'mail') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | { |
| 510 | $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 511 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 513 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | // -------------------------------------------------------------------- |
| 515 | |
| 516 | /** |
| 517 | * Set Priority |
| 518 | * |
| 519 | * @access public |
| 520 | * @param integer |
| 521 | * @return void |
| 522 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 523 | public function set_priority($n = 3) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 524 | { |
| 525 | if ( ! is_numeric($n)) |
| 526 | { |
| 527 | $this->priority = 3; |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | if ($n < 1 OR $n > 5) |
| 532 | { |
| 533 | $this->priority = 3; |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | $this->priority = $n; |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 538 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 540 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 541 | // -------------------------------------------------------------------- |
| 542 | |
| 543 | /** |
| 544 | * Set Newline Character |
| 545 | * |
| 546 | * @access public |
| 547 | * @param string |
| 548 | * @return void |
| 549 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 550 | public function set_newline($newline = "\n") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | { |
| 552 | if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") |
| 553 | { |
| 554 | $this->newline = "\n"; |
| 555 | return; |
| 556 | } |
| 557 | |
| 558 | $this->newline = $newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 559 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 560 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 562 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | // -------------------------------------------------------------------- |
| 564 | |
| 565 | /** |
| 566 | * Set CRLF |
| 567 | * |
| 568 | * @access public |
| 569 | * @param string |
| 570 | * @return void |
| 571 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 572 | public function set_crlf($crlf = "\n") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 573 | { |
| 574 | if ($crlf != "\n" AND $crlf != "\r\n" AND $crlf != "\r") |
| 575 | { |
| 576 | $this->crlf = "\n"; |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | $this->crlf = $crlf; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 581 | |
Greg Aker | a769deb | 2010-11-10 15:47:29 -0600 | [diff] [blame] | 582 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 583 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 584 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | // -------------------------------------------------------------------- |
| 586 | |
| 587 | /** |
| 588 | * Set Message Boundary |
| 589 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 590 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | * @return void |
| 592 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 593 | protected function _set_boundaries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 594 | { |
| 595 | $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative |
| 596 | $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary |
| 597 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 598 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 599 | // -------------------------------------------------------------------- |
| 600 | |
| 601 | /** |
| 602 | * Get the Message ID |
| 603 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 604 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 605 | * @return string |
| 606 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 607 | protected function _get_message_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 608 | { |
| 609 | $from = $this->_headers['Return-Path']; |
| 610 | $from = str_replace(">", "", $from); |
| 611 | $from = str_replace("<", "", $from); |
| 612 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 613 | return "<".uniqid('').strstr($from, '@').">"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 615 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 616 | // -------------------------------------------------------------------- |
| 617 | |
| 618 | /** |
| 619 | * Get Mail Protocol |
| 620 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 621 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | * @param bool |
| 623 | * @return string |
| 624 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 625 | protected function _get_protocol($return = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | { |
| 627 | $this->protocol = strtolower($this->protocol); |
| 628 | $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; |
| 629 | |
| 630 | if ($return == TRUE) |
| 631 | { |
| 632 | return $this->protocol; |
| 633 | } |
| 634 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 635 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | // -------------------------------------------------------------------- |
| 637 | |
| 638 | /** |
| 639 | * Get Mail Encoding |
| 640 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 641 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 642 | * @param bool |
| 643 | * @return string |
| 644 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 645 | protected function _get_encoding($return = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 646 | { |
| 647 | $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '8bit' : $this->_encoding; |
| 648 | |
| 649 | foreach ($this->_base_charsets as $charset) |
| 650 | { |
| 651 | if (strncmp($charset, $this->charset, strlen($charset)) == 0) |
| 652 | { |
| 653 | $this->_encoding = '7bit'; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | if ($return == TRUE) |
| 658 | { |
| 659 | return $this->_encoding; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | // -------------------------------------------------------------------- |
| 664 | |
| 665 | /** |
| 666 | * Get content type (text/html/attachment) |
| 667 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 668 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 669 | * @return string |
| 670 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 671 | protected function _get_content_type() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 672 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 673 | if ($this->mailtype == 'html' && count($this->_attach_name) == 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 674 | { |
| 675 | return 'html'; |
| 676 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 677 | elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 678 | { |
| 679 | return 'html-attach'; |
| 680 | } |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 681 | elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 682 | { |
| 683 | return 'plain-attach'; |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | return 'plain'; |
| 688 | } |
| 689 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 690 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 691 | // -------------------------------------------------------------------- |
| 692 | |
| 693 | /** |
| 694 | * Set RFC 822 Date |
| 695 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 696 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 697 | * @return string |
| 698 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 699 | protected function _set_date() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 700 | { |
| 701 | $timezone = date("Z"); |
| 702 | $operator = (strncmp($timezone, '-', 1) == 0) ? '-' : '+'; |
| 703 | $timezone = abs($timezone); |
| 704 | $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; |
| 705 | |
| 706 | return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); |
| 707 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 708 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 709 | // -------------------------------------------------------------------- |
| 710 | |
| 711 | /** |
| 712 | * Mime message |
| 713 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 714 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 715 | * @return string |
| 716 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 717 | protected function _get_mime_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 718 | { |
| 719 | return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; |
| 720 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 721 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 722 | // -------------------------------------------------------------------- |
| 723 | |
| 724 | /** |
| 725 | * Validate Email Address |
| 726 | * |
| 727 | * @access public |
| 728 | * @param string |
| 729 | * @return bool |
| 730 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 731 | public function validate_email($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 732 | { |
| 733 | if ( ! is_array($email)) |
| 734 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 735 | $this->_set_error_message('lang:email_must_be_array'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 736 | return FALSE; |
| 737 | } |
| 738 | |
| 739 | foreach ($email as $val) |
| 740 | { |
| 741 | if ( ! $this->valid_email($val)) |
| 742 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 743 | $this->_set_error_message('lang:email_invalid_address', $val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 744 | return FALSE; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | return TRUE; |
| 749 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 750 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 751 | // -------------------------------------------------------------------- |
| 752 | |
| 753 | /** |
| 754 | * Email Validation |
| 755 | * |
| 756 | * @access public |
| 757 | * @param string |
| 758 | * @return bool |
| 759 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 760 | public function valid_email($address) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 761 | { |
| 762 | return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE; |
| 763 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 764 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 765 | // -------------------------------------------------------------------- |
| 766 | |
| 767 | /** |
| 768 | * Clean Extended Email Address: Joe Smith <joe@smith.com> |
| 769 | * |
| 770 | * @access public |
| 771 | * @param string |
| 772 | * @return string |
| 773 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 774 | public function clean_email($email) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 775 | { |
| 776 | if ( ! is_array($email)) |
| 777 | { |
| 778 | if (preg_match('/\<(.*)\>/', $email, $match)) |
| 779 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 780 | return $match['1']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 781 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 782 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 783 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 784 | return $email; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
| 788 | $clean_email = array(); |
| 789 | |
| 790 | foreach ($email as $addy) |
| 791 | { |
| 792 | if (preg_match( '/\<(.*)\>/', $addy, $match)) |
| 793 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 794 | $clean_email[] = $match['1']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 795 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 796 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 797 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 798 | $clean_email[] = $addy; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
| 802 | return $clean_email; |
| 803 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 804 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 805 | // -------------------------------------------------------------------- |
| 806 | |
| 807 | /** |
| 808 | * Build alternative plain text message |
| 809 | * |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 810 | * This public function provides the raw message for use |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 811 | * in plain-text headers of HTML-formatted emails. |
| 812 | * If the user hasn't specified his own alternative message |
| 813 | * it creates one by stripping the HTML |
| 814 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 815 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 816 | * @return string |
| 817 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 818 | protected function _get_alt_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 819 | { |
| 820 | if ($this->alt_message != "") |
| 821 | { |
| 822 | return $this->word_wrap($this->alt_message, '76'); |
| 823 | } |
| 824 | |
| 825 | if (preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->_body, $match)) |
| 826 | { |
| 827 | $body = $match['1']; |
| 828 | } |
| 829 | else |
| 830 | { |
| 831 | $body = $this->_body; |
| 832 | } |
| 833 | |
| 834 | $body = trim(strip_tags($body)); |
| 835 | $body = preg_replace( '#<!--(.*)--\>#', "", $body); |
| 836 | $body = str_replace("\t", "", $body); |
| 837 | |
| 838 | for ($i = 20; $i >= 3; $i--) |
| 839 | { |
| 840 | $n = ""; |
| 841 | |
| 842 | for ($x = 1; $x <= $i; $x ++) |
| 843 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 844 | $n .= "\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | $body = str_replace($n, "\n\n", $body); |
| 848 | } |
| 849 | |
| 850 | return $this->word_wrap($body, '76'); |
| 851 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 852 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 853 | // -------------------------------------------------------------------- |
| 854 | |
| 855 | /** |
| 856 | * Word Wrap |
| 857 | * |
| 858 | * @access public |
| 859 | * @param string |
| 860 | * @param integer |
| 861 | * @return string |
| 862 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 863 | public function word_wrap($str, $charlim = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 864 | { |
| 865 | // Se the character limit |
| 866 | if ($charlim == '') |
| 867 | { |
| 868 | $charlim = ($this->wrapchars == "") ? "76" : $this->wrapchars; |
| 869 | } |
| 870 | |
| 871 | // Reduce multiple spaces |
| 872 | $str = preg_replace("| +|", " ", $str); |
| 873 | |
| 874 | // Standardize newlines |
| 875 | if (strpos($str, "\r") !== FALSE) |
| 876 | { |
| 877 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
| 878 | } |
| 879 | |
| 880 | // If the current word is surrounded by {unwrap} tags we'll |
| 881 | // strip the entire chunk and replace it with a marker. |
| 882 | $unwrap = array(); |
| 883 | if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches)) |
| 884 | { |
| 885 | for ($i = 0; $i < count($matches['0']); $i++) |
| 886 | { |
| 887 | $unwrap[] = $matches['1'][$i]; |
| 888 | $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str); |
| 889 | } |
| 890 | } |
| 891 | |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 892 | // Use PHP's native public function to do the initial wordwrap. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 893 | // We set the cut flag to FALSE so that any individual words that are |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 894 | // too long get left alone. In the next step we'll deal with them. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 895 | $str = wordwrap($str, $charlim, "\n", FALSE); |
| 896 | |
| 897 | // Split the string into individual lines of text and cycle through them |
| 898 | $output = ""; |
| 899 | foreach (explode("\n", $str) as $line) |
| 900 | { |
| 901 | // Is the line within the allowed character count? |
| 902 | // If so we'll join it to the output and continue |
| 903 | if (strlen($line) <= $charlim) |
| 904 | { |
| 905 | $output .= $line.$this->newline; |
| 906 | continue; |
| 907 | } |
| 908 | |
| 909 | $temp = ''; |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 910 | while ((strlen($line)) > $charlim) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 911 | { |
| 912 | // If the over-length word is a URL we won't wrap it |
| 913 | if (preg_match("!\[url.+\]|://|wwww.!", $line)) |
| 914 | { |
| 915 | break; |
| 916 | } |
| 917 | |
| 918 | // Trim the word down |
| 919 | $temp .= substr($line, 0, $charlim-1); |
| 920 | $line = substr($line, $charlim-1); |
| 921 | } |
| 922 | |
| 923 | // If $temp contains data it means we had to split up an over-length |
| 924 | // word into smaller chunks so we'll add it back to our current line |
| 925 | if ($temp != '') |
| 926 | { |
| 927 | $output .= $temp.$this->newline.$line; |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | $output .= $line; |
| 932 | } |
| 933 | |
| 934 | $output .= $this->newline; |
| 935 | } |
| 936 | |
| 937 | // Put our markers back |
| 938 | if (count($unwrap) > 0) |
| 939 | { |
| 940 | foreach ($unwrap as $key => $val) |
| 941 | { |
| 942 | $output = str_replace("{{unwrapped".$key."}}", $val, $output); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return $output; |
| 947 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 948 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 949 | // -------------------------------------------------------------------- |
| 950 | |
| 951 | /** |
| 952 | * Build final headers |
| 953 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 954 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 955 | * @param string |
| 956 | * @return string |
| 957 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 958 | protected function _build_headers() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 959 | { |
| 960 | $this->_set_header('X-Sender', $this->clean_email($this->_headers['From'])); |
| 961 | $this->_set_header('X-Mailer', $this->useragent); |
| 962 | $this->_set_header('X-Priority', $this->_priorities[$this->priority - 1]); |
| 963 | $this->_set_header('Message-ID', $this->_get_message_id()); |
| 964 | $this->_set_header('Mime-Version', '1.0'); |
| 965 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 966 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 967 | // -------------------------------------------------------------------- |
| 968 | |
| 969 | /** |
| 970 | * Write Headers as a string |
| 971 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 972 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 973 | * @return void |
| 974 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 975 | protected function _write_headers() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 976 | { |
| 977 | if ($this->protocol == 'mail') |
| 978 | { |
| 979 | $this->_subject = $this->_headers['Subject']; |
| 980 | unset($this->_headers['Subject']); |
| 981 | } |
| 982 | |
| 983 | reset($this->_headers); |
| 984 | $this->_header_str = ""; |
| 985 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 986 | foreach ($this->_headers as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 987 | { |
| 988 | $val = trim($val); |
| 989 | |
| 990 | if ($val != "") |
| 991 | { |
| 992 | $this->_header_str .= $key.": ".$val.$this->newline; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | if ($this->_get_protocol() == 'mail') |
| 997 | { |
Derek Jones | 1d89088 | 2009-02-10 20:32:14 +0000 | [diff] [blame] | 998 | $this->_header_str = rtrim($this->_header_str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1001 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1002 | // -------------------------------------------------------------------- |
| 1003 | |
| 1004 | /** |
| 1005 | * Build Final Body and attachments |
| 1006 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1007 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1008 | * @return void |
| 1009 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1010 | protected function _build_message() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1011 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1012 | if ($this->wordwrap === TRUE AND $this->mailtype != 'html') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1013 | { |
| 1014 | $this->_body = $this->word_wrap($this->_body); |
| 1015 | } |
| 1016 | |
| 1017 | $this->_set_boundaries(); |
| 1018 | $this->_write_headers(); |
| 1019 | |
| 1020 | $hdr = ($this->_get_protocol() == 'mail') ? $this->newline : ''; |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1021 | $body = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1022 | |
| 1023 | switch ($this->_get_content_type()) |
| 1024 | { |
| 1025 | case 'plain' : |
| 1026 | |
| 1027 | $hdr .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1028 | $hdr .= "Content-Transfer-Encoding: " . $this->_get_encoding(); |
| 1029 | |
| 1030 | if ($this->_get_protocol() == 'mail') |
| 1031 | { |
| 1032 | $this->_header_str .= $hdr; |
| 1033 | $this->_finalbody = $this->_body; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1034 | } |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1035 | else |
| 1036 | { |
| 1037 | $this->_finalbody = $hdr . $this->newline . $this->newline . $this->_body; |
| 1038 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1039 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1040 | return; |
| 1041 | |
| 1042 | break; |
| 1043 | case 'html' : |
| 1044 | |
| 1045 | if ($this->send_multipart === FALSE) |
| 1046 | { |
| 1047 | $hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1048 | $hdr .= "Content-Transfer-Encoding: quoted-printable"; |
| 1049 | } |
| 1050 | else |
| 1051 | { |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1052 | $hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1053 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1054 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1055 | $body .= "--" . $this->_alt_boundary . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1056 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1057 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1058 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
| 1059 | $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; |
| 1060 | |
| 1061 | $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1062 | $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1063 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1064 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1065 | $this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1066 | |
| 1067 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1068 | if ($this->_get_protocol() == 'mail') |
| 1069 | { |
| 1070 | $this->_header_str .= $hdr; |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1071 | } |
| 1072 | else |
| 1073 | { |
| 1074 | $this->_finalbody = $hdr . $this->_finalbody; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1077 | |
| 1078 | if ($this->send_multipart !== FALSE) |
| 1079 | { |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1080 | $this->_finalbody .= "--" . $this->_alt_boundary . "--"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1083 | return; |
| 1084 | |
| 1085 | break; |
| 1086 | case 'plain-attach' : |
| 1087 | |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1088 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1089 | |
| 1090 | if ($this->_get_protocol() == 'mail') |
| 1091 | { |
| 1092 | $this->_header_str .= $hdr; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1095 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1096 | $body .= "--" . $this->_atc_boundary . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1097 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1098 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1099 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1100 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1101 | $body .= $this->_body . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1102 | |
| 1103 | break; |
| 1104 | case 'html-attach' : |
| 1105 | |
Derek Jones | a45e761 | 2009-02-10 18:33:01 +0000 | [diff] [blame] | 1106 | $hdr .= "Content-Type: multipart/".$this->multipart."; boundary=\"" . $this->_atc_boundary."\"" . $this->newline . $this->newline; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1107 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1108 | if ($this->_get_protocol() == 'mail') |
| 1109 | { |
| 1110 | $this->_header_str .= $hdr; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1113 | $body .= $this->_get_mime_message() . $this->newline . $this->newline; |
| 1114 | $body .= "--" . $this->_atc_boundary . $this->newline; |
| 1115 | |
| 1116 | $body .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline .$this->newline; |
| 1117 | $body .= "--" . $this->_alt_boundary . $this->newline; |
| 1118 | |
| 1119 | $body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline; |
| 1120 | $body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline; |
| 1121 | $body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline; |
| 1122 | |
| 1123 | $body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline; |
| 1124 | $body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline; |
| 1125 | |
| 1126 | $body .= $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline; |
| 1127 | $body .= "--" . $this->_alt_boundary . "--" . $this->newline . $this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1128 | |
| 1129 | break; |
| 1130 | } |
| 1131 | |
| 1132 | $attachment = array(); |
| 1133 | |
| 1134 | $z = 0; |
| 1135 | |
| 1136 | for ($i=0; $i < count($this->_attach_name); $i++) |
| 1137 | { |
| 1138 | $filename = $this->_attach_name[$i]; |
| 1139 | $basename = basename($filename); |
| 1140 | $ctype = $this->_attach_type[$i]; |
| 1141 | |
| 1142 | if ( ! file_exists($filename)) |
| 1143 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1144 | $this->_set_error_message('lang:email_attachment_missing', $filename); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1145 | return FALSE; |
| 1146 | } |
| 1147 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1148 | $h = "--".$this->_atc_boundary.$this->newline; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1149 | $h .= "Content-type: ".$ctype."; "; |
| 1150 | $h .= "name=\"".$basename."\"".$this->newline; |
| 1151 | $h .= "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline; |
| 1152 | $h .= "Content-Transfer-Encoding: base64".$this->newline; |
| 1153 | |
| 1154 | $attachment[$z++] = $h; |
| 1155 | $file = filesize($filename) +1; |
| 1156 | |
| 1157 | if ( ! $fp = fopen($filename, FOPEN_READ)) |
| 1158 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1159 | $this->_set_error_message('lang:email_attachment_unreadable', $filename); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1160 | return FALSE; |
| 1161 | } |
| 1162 | |
| 1163 | $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file))); |
| 1164 | fclose($fp); |
| 1165 | } |
| 1166 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1167 | $body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--"; |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1168 | |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1169 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1170 | if ($this->_get_protocol() == 'mail') |
| 1171 | { |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1172 | $this->_finalbody = $body; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1173 | } |
Brandon Jones | 485d741 | 2010-11-09 16:38:17 -0500 | [diff] [blame] | 1174 | else |
| 1175 | { |
| 1176 | $this->_finalbody = $hdr . $body; |
| 1177 | } |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1178 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1179 | return; |
| 1180 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1181 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1182 | // -------------------------------------------------------------------- |
| 1183 | |
| 1184 | /** |
| 1185 | * Prep Quoted Printable |
| 1186 | * |
| 1187 | * Prepares string for Quoted-Printable Content-Transfer-Encoding |
| 1188 | * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt |
| 1189 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1190 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1191 | * @param string |
| 1192 | * @param integer |
| 1193 | * @return string |
| 1194 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1195 | protected function _prep_quoted_printable($str, $charlim = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1196 | { |
| 1197 | // Set the character limit |
| 1198 | // Don't allow over 76, as that will make servers and MUAs barf |
| 1199 | // all over quoted-printable data |
| 1200 | if ($charlim == '' OR $charlim > '76') |
| 1201 | { |
| 1202 | $charlim = '76'; |
| 1203 | } |
| 1204 | |
| 1205 | // Reduce multiple spaces |
| 1206 | $str = preg_replace("| +|", " ", $str); |
| 1207 | |
| 1208 | // kill nulls |
| 1209 | $str = preg_replace('/\x00+/', '', $str); |
| 1210 | |
| 1211 | // Standardize newlines |
| 1212 | if (strpos($str, "\r") !== FALSE) |
| 1213 | { |
| 1214 | $str = str_replace(array("\r\n", "\r"), "\n", $str); |
| 1215 | } |
| 1216 | |
| 1217 | // We are intentionally wrapping so mail servers will encode characters |
| 1218 | // properly and MUAs will behave, so {unwrap} must go! |
| 1219 | $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); |
| 1220 | |
| 1221 | // Break into an array of lines |
| 1222 | $lines = explode("\n", $str); |
| 1223 | |
| 1224 | $escape = '='; |
| 1225 | $output = ''; |
| 1226 | |
| 1227 | foreach ($lines as $line) |
| 1228 | { |
| 1229 | $length = strlen($line); |
| 1230 | $temp = ''; |
| 1231 | |
| 1232 | // Loop through each character in the line to add soft-wrap |
| 1233 | // characters at the end of a line " =\r\n" and add the newly |
| 1234 | // processed line(s) to the output (see comment on $crlf class property) |
| 1235 | for ($i = 0; $i < $length; $i++) |
| 1236 | { |
| 1237 | // Grab the next character |
| 1238 | $char = substr($line, $i, 1); |
| 1239 | $ascii = ord($char); |
| 1240 | |
| 1241 | // Convert spaces and tabs but only if it's the end of the line |
| 1242 | if ($i == ($length - 1)) |
| 1243 | { |
| 1244 | $char = ($ascii == '32' OR $ascii == '9') ? $escape.sprintf('%02s', dechex($ascii)) : $char; |
| 1245 | } |
| 1246 | |
| 1247 | // encode = signs |
| 1248 | if ($ascii == '61') |
| 1249 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1250 | $char = $escape.strtoupper(sprintf('%02s', dechex($ascii))); // =3D |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | // If we're at the character limit, add the line to the output, |
| 1254 | // reset our temp variable, and keep on chuggin' |
| 1255 | if ((strlen($temp) + strlen($char)) >= $charlim) |
| 1256 | { |
| 1257 | $output .= $temp.$escape.$this->crlf; |
| 1258 | $temp = ''; |
| 1259 | } |
| 1260 | |
| 1261 | // Add the character to our temporary line |
| 1262 | $temp .= $char; |
| 1263 | } |
| 1264 | |
| 1265 | // Add our completed line to the output |
| 1266 | $output .= $temp.$this->crlf; |
| 1267 | } |
| 1268 | |
| 1269 | // get rid of extra CRLF tacked onto the end |
| 1270 | $output = substr($output, 0, strlen($this->crlf) * -1); |
| 1271 | |
| 1272 | return $output; |
| 1273 | } |
| 1274 | |
| 1275 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1276 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1277 | /** |
| 1278 | * Prep Q Encoding |
| 1279 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1280 | * Performs "Q Encoding" on a string for use in email headers. It's related |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1281 | * but not identical to quoted-printable, so it has its own method |
| 1282 | * |
| 1283 | * @access public |
| 1284 | * @param str |
| 1285 | * @param bool // set to TRUE for processing From: headers |
| 1286 | * @return str |
| 1287 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1288 | protected function _prep_q_encoding($str, $from = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1289 | { |
| 1290 | $str = str_replace(array("\r", "\n"), array('', ''), $str); |
| 1291 | |
| 1292 | // Line length must not exceed 76 characters, so we adjust for |
| 1293 | // a space, 7 extra characters =??Q??=, and the charset that we will add to each line |
| 1294 | $limit = 75 - 7 - strlen($this->charset); |
| 1295 | |
| 1296 | // these special characters must be converted too |
| 1297 | $convert = array('_', '=', '?'); |
| 1298 | |
| 1299 | if ($from === TRUE) |
| 1300 | { |
| 1301 | $convert[] = ','; |
| 1302 | $convert[] = ';'; |
| 1303 | } |
| 1304 | |
| 1305 | $output = ''; |
| 1306 | $temp = ''; |
| 1307 | |
| 1308 | for ($i = 0, $length = strlen($str); $i < $length; $i++) |
| 1309 | { |
| 1310 | // Grab the next character |
| 1311 | $char = substr($str, $i, 1); |
| 1312 | $ascii = ord($char); |
| 1313 | |
| 1314 | // convert ALL non-printable ASCII characters and our specials |
| 1315 | if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert)) |
| 1316 | { |
| 1317 | $char = '='.dechex($ascii); |
| 1318 | } |
| 1319 | |
| 1320 | // handle regular spaces a bit more compactly than =20 |
| 1321 | if ($ascii == 32) |
| 1322 | { |
| 1323 | $char = '_'; |
| 1324 | } |
| 1325 | |
| 1326 | // If we're at the character limit, add the line to the output, |
| 1327 | // reset our temp variable, and keep on chuggin' |
| 1328 | if ((strlen($temp) + strlen($char)) >= $limit) |
| 1329 | { |
| 1330 | $output .= $temp.$this->crlf; |
| 1331 | $temp = ''; |
| 1332 | } |
| 1333 | |
| 1334 | // Add the character to our temporary line |
| 1335 | $temp .= $char; |
| 1336 | } |
| 1337 | |
| 1338 | $str = $output.$temp; |
| 1339 | |
| 1340 | // wrap each line with the shebang, charset, and transfer encoding |
| 1341 | // the preceding space on successive lines is required for header "folding" |
| 1342 | $str = trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $str)); |
| 1343 | |
| 1344 | return $str; |
| 1345 | } |
| 1346 | |
| 1347 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1348 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1349 | /** |
| 1350 | * Send Email |
| 1351 | * |
| 1352 | * @access public |
| 1353 | * @return bool |
| 1354 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1355 | public function send() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1356 | { |
| 1357 | if ($this->_replyto_flag == FALSE) |
| 1358 | { |
| 1359 | $this->reply_to($this->_headers['From']); |
| 1360 | } |
| 1361 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1362 | if (( ! isset($this->_recipients) AND ! isset($this->_headers['To'])) AND |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1363 | ( ! isset($this->_bcc_array) AND ! isset($this->_headers['Bcc'])) AND |
| 1364 | ( ! isset($this->_headers['Cc']))) |
| 1365 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1366 | $this->_set_error_message('lang:email_no_recipients'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1367 | return FALSE; |
| 1368 | } |
| 1369 | |
| 1370 | $this->_build_headers(); |
| 1371 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1372 | if ($this->bcc_batch_mode AND count($this->_bcc_array) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1373 | { |
| 1374 | if (count($this->_bcc_array) > $this->bcc_batch_size) |
| 1375 | return $this->batch_bcc_send(); |
| 1376 | } |
| 1377 | |
| 1378 | $this->_build_message(); |
| 1379 | |
| 1380 | if ( ! $this->_spool_email()) |
| 1381 | { |
| 1382 | return FALSE; |
| 1383 | } |
| 1384 | else |
| 1385 | { |
| 1386 | return TRUE; |
| 1387 | } |
| 1388 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1389 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1390 | // -------------------------------------------------------------------- |
| 1391 | |
| 1392 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1393 | * Batch Bcc Send. Sends groups of BCCs in batches |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1394 | * |
| 1395 | * @access public |
| 1396 | * @return bool |
| 1397 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1398 | public function batch_bcc_send() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1399 | { |
| 1400 | $float = $this->bcc_batch_size -1; |
| 1401 | |
| 1402 | $set = ""; |
| 1403 | |
| 1404 | $chunk = array(); |
| 1405 | |
| 1406 | for ($i = 0; $i < count($this->_bcc_array); $i++) |
| 1407 | { |
| 1408 | if (isset($this->_bcc_array[$i])) |
| 1409 | { |
| 1410 | $set .= ", ".$this->_bcc_array[$i]; |
| 1411 | } |
| 1412 | |
| 1413 | if ($i == $float) |
| 1414 | { |
| 1415 | $chunk[] = substr($set, 1); |
| 1416 | $float = $float + $this->bcc_batch_size; |
| 1417 | $set = ""; |
| 1418 | } |
| 1419 | |
| 1420 | if ($i == count($this->_bcc_array)-1) |
| 1421 | { |
| 1422 | $chunk[] = substr($set, 1); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | for ($i = 0; $i < count($chunk); $i++) |
| 1427 | { |
| 1428 | unset($this->_headers['Bcc']); |
| 1429 | unset($bcc); |
| 1430 | |
| 1431 | $bcc = $this->_str_to_array($chunk[$i]); |
| 1432 | $bcc = $this->clean_email($bcc); |
| 1433 | |
| 1434 | if ($this->protocol != 'smtp') |
| 1435 | { |
| 1436 | $this->_set_header('Bcc', implode(", ", $bcc)); |
| 1437 | } |
| 1438 | else |
| 1439 | { |
| 1440 | $this->_bcc_array = $bcc; |
| 1441 | } |
| 1442 | |
| 1443 | $this->_build_message(); |
| 1444 | $this->_spool_email(); |
| 1445 | } |
| 1446 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1447 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1448 | // -------------------------------------------------------------------- |
| 1449 | |
| 1450 | /** |
| 1451 | * Unwrap special elements |
| 1452 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1453 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1454 | * @return void |
| 1455 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1456 | protected function _unwrap_specials() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1457 | { |
| 1458 | $this->_finalbody = preg_replace_callback("/\{unwrap\}(.*?)\{\/unwrap\}/si", array($this, '_remove_nl_callback'), $this->_finalbody); |
| 1459 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1460 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1461 | // -------------------------------------------------------------------- |
| 1462 | |
| 1463 | /** |
| 1464 | * Strip line-breaks via callback |
| 1465 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1466 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1467 | * @return string |
| 1468 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1469 | protected function _remove_nl_callback($matches) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1470 | { |
| 1471 | if (strpos($matches[1], "\r") !== FALSE OR strpos($matches[1], "\n") !== FALSE) |
| 1472 | { |
| 1473 | $matches[1] = str_replace(array("\r\n", "\r", "\n"), '', $matches[1]); |
| 1474 | } |
| 1475 | |
| 1476 | return $matches[1]; |
| 1477 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1478 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1479 | // -------------------------------------------------------------------- |
| 1480 | |
| 1481 | /** |
| 1482 | * Spool mail to the mail server |
| 1483 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1484 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1485 | * @return bool |
| 1486 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1487 | protected function _spool_email() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1488 | { |
| 1489 | $this->_unwrap_specials(); |
| 1490 | |
| 1491 | switch ($this->_get_protocol()) |
| 1492 | { |
| 1493 | case 'mail' : |
| 1494 | |
| 1495 | if ( ! $this->_send_with_mail()) |
| 1496 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1497 | $this->_set_error_message('lang:email_send_failure_phpmail'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1498 | return FALSE; |
| 1499 | } |
| 1500 | break; |
| 1501 | case 'sendmail' : |
| 1502 | |
| 1503 | if ( ! $this->_send_with_sendmail()) |
| 1504 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1505 | $this->_set_error_message('lang:email_send_failure_sendmail'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1506 | return FALSE; |
| 1507 | } |
| 1508 | break; |
| 1509 | case 'smtp' : |
| 1510 | |
| 1511 | if ( ! $this->_send_with_smtp()) |
| 1512 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1513 | $this->_set_error_message('lang:email_send_failure_smtp'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1514 | return FALSE; |
| 1515 | } |
| 1516 | break; |
| 1517 | |
| 1518 | } |
| 1519 | |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1520 | $this->_set_error_message('lang:email_sent', $this->_get_protocol()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1521 | return TRUE; |
| 1522 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1523 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1524 | // -------------------------------------------------------------------- |
| 1525 | |
| 1526 | /** |
| 1527 | * Send using mail() |
| 1528 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1529 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1530 | * @return bool |
| 1531 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1532 | protected function _send_with_mail() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1533 | { |
| 1534 | if ($this->_safe_mode == TRUE) |
| 1535 | { |
| 1536 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)) |
| 1537 | { |
| 1538 | return FALSE; |
| 1539 | } |
| 1540 | else |
| 1541 | { |
| 1542 | return TRUE; |
| 1543 | } |
| 1544 | } |
| 1545 | else |
| 1546 | { |
| 1547 | // most documentation of sendmail using the "-f" flag lacks a space after it, however |
| 1548 | // we've encountered servers that seem to require it to be in place. |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1549 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1550 | if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']))) |
| 1551 | { |
| 1552 | return FALSE; |
| 1553 | } |
| 1554 | else |
| 1555 | { |
| 1556 | return TRUE; |
| 1557 | } |
| 1558 | } |
| 1559 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1560 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1561 | // -------------------------------------------------------------------- |
| 1562 | |
| 1563 | /** |
| 1564 | * Send using Sendmail |
| 1565 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1566 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1567 | * @return bool |
| 1568 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1569 | protected function _send_with_sendmail() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1570 | { |
| 1571 | $fp = @popen($this->mailpath . " -oi -f ".$this->clean_email($this->_headers['From'])." -t", 'w'); |
| 1572 | |
Derek Jones | 4cefaa4 | 2009-04-29 19:13:56 +0000 | [diff] [blame] | 1573 | if ($fp === FALSE OR $fp === NULL) |
| 1574 | { |
| 1575 | // server probably has popen disabled, so nothing we can do to get a verbose error. |
| 1576 | return FALSE; |
| 1577 | } |
Derek Jones | 71141ce | 2010-03-02 16:41:20 -0600 | [diff] [blame] | 1578 | |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 1579 | fputs($fp, $this->_header_str); |
| 1580 | fputs($fp, $this->_finalbody); |
| 1581 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1582 | $status = pclose($fp); |
Eric Barnes | 6113f54 | 2010-12-29 13:36:12 -0500 | [diff] [blame] | 1583 | |
Derek Jones | c630bcf | 2008-11-17 21:09:45 +0000 | [diff] [blame] | 1584 | if (version_compare(PHP_VERSION, '4.2.3') == -1) |
| 1585 | { |
| 1586 | $status = $status >> 8 & 0xFF; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1587 | } |
Derek Jones | 71141ce | 2010-03-02 16:41:20 -0600 | [diff] [blame] | 1588 | |
Derek Jones | 604873f | 2008-11-18 15:57:24 +0000 | [diff] [blame] | 1589 | if ($status != 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1590 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1591 | $this->_set_error_message('lang:email_exit_status', $status); |
| 1592 | $this->_set_error_message('lang:email_no_socket'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1593 | return FALSE; |
| 1594 | } |
| 1595 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1596 | return TRUE; |
| 1597 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1598 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1599 | // -------------------------------------------------------------------- |
| 1600 | |
| 1601 | /** |
| 1602 | * Send using SMTP |
| 1603 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1604 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1605 | * @return bool |
| 1606 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1607 | protected function _send_with_smtp() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1608 | { |
| 1609 | if ($this->smtp_host == '') |
| 1610 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1611 | $this->_set_error_message('lang:email_no_hostname'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1612 | return FALSE; |
| 1613 | } |
| 1614 | |
| 1615 | $this->_smtp_connect(); |
| 1616 | $this->_smtp_authenticate(); |
| 1617 | |
| 1618 | $this->_send_command('from', $this->clean_email($this->_headers['From'])); |
| 1619 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1620 | foreach ($this->_recipients as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1621 | { |
| 1622 | $this->_send_command('to', $val); |
| 1623 | } |
| 1624 | |
| 1625 | if (count($this->_cc_array) > 0) |
| 1626 | { |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1627 | foreach ($this->_cc_array as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1628 | { |
| 1629 | if ($val != "") |
| 1630 | { |
| 1631 | $this->_send_command('to', $val); |
| 1632 | } |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | if (count($this->_bcc_array) > 0) |
| 1637 | { |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1638 | foreach ($this->_bcc_array as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1639 | { |
| 1640 | if ($val != "") |
| 1641 | { |
| 1642 | $this->_send_command('to', $val); |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | $this->_send_command('data'); |
| 1648 | |
| 1649 | // perform dot transformation on any lines that begin with a dot |
| 1650 | $this->_send_data($this->_header_str . preg_replace('/^\./m', '..$1', $this->_finalbody)); |
| 1651 | |
| 1652 | $this->_send_data('.'); |
| 1653 | |
| 1654 | $reply = $this->_get_smtp_data(); |
| 1655 | |
| 1656 | $this->_set_error_message($reply); |
| 1657 | |
| 1658 | if (strncmp($reply, '250', 3) != 0) |
| 1659 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1660 | $this->_set_error_message('lang:email_smtp_error', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1661 | return FALSE; |
| 1662 | } |
| 1663 | |
| 1664 | $this->_send_command('quit'); |
| 1665 | return TRUE; |
| 1666 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1667 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1668 | // -------------------------------------------------------------------- |
| 1669 | |
| 1670 | /** |
| 1671 | * SMTP Connect |
| 1672 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1673 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1674 | * @param string |
| 1675 | * @return string |
| 1676 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1677 | protected function _smtp_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1678 | { |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1679 | $ssl = NULL; |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1680 | |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1681 | if ($this->smtp_crypto == 'ssl') |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1682 | { |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1683 | $ssl = 'ssl://'; |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1684 | } |
| 1685 | |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1686 | $this->_smtp_connect = fsockopen($ssl.$this->smtp_host, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1687 | $this->smtp_port, |
| 1688 | $errno, |
| 1689 | $errstr, |
| 1690 | $this->smtp_timeout); |
| 1691 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1692 | if ( ! is_resource($this->_smtp_connect)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1693 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1694 | $this->_set_error_message('lang:email_smtp_error', $errno." ".$errstr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1695 | return FALSE; |
| 1696 | } |
| 1697 | |
| 1698 | $this->_set_error_message($this->_get_smtp_data()); |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1699 | |
| 1700 | if ($this->smtp_crypto == 'tls') |
| 1701 | { |
| 1702 | $this->_send_command('hello'); |
| 1703 | $this->_send_command('starttls'); |
Radu Potop | 4c589ae | 2011-09-29 10:19:55 +0300 | [diff] [blame] | 1704 | $crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); |
| 1705 | } |
| 1706 | |
| 1707 | if ($crypto !== TRUE) |
| 1708 | { |
| 1709 | $this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data()); |
| 1710 | return FALSE; |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1711 | } |
| 1712 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1713 | return $this->_send_command('hello'); |
| 1714 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1715 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1716 | // -------------------------------------------------------------------- |
| 1717 | |
| 1718 | /** |
| 1719 | * Send SMTP command |
| 1720 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1721 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1722 | * @param string |
| 1723 | * @param string |
| 1724 | * @return string |
| 1725 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1726 | protected function _send_command($cmd, $data = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1727 | { |
| 1728 | switch ($cmd) |
| 1729 | { |
| 1730 | case 'hello' : |
| 1731 | |
| 1732 | if ($this->_smtp_auth OR $this->_get_encoding() == '8bit') |
| 1733 | $this->_send_data('EHLO '.$this->_get_hostname()); |
| 1734 | else |
| 1735 | $this->_send_data('HELO '.$this->_get_hostname()); |
| 1736 | |
| 1737 | $resp = 250; |
| 1738 | break; |
Radu Potop | bbf04b0 | 2011-09-28 13:57:51 +0300 | [diff] [blame] | 1739 | case 'starttls' : |
| 1740 | |
| 1741 | $this->_send_data('STARTTLS'); |
| 1742 | |
| 1743 | $resp = 220; |
| 1744 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1745 | case 'from' : |
| 1746 | |
| 1747 | $this->_send_data('MAIL FROM:<'.$data.'>'); |
| 1748 | |
| 1749 | $resp = 250; |
| 1750 | break; |
| 1751 | case 'to' : |
| 1752 | |
| 1753 | $this->_send_data('RCPT TO:<'.$data.'>'); |
| 1754 | |
| 1755 | $resp = 250; |
| 1756 | break; |
| 1757 | case 'data' : |
| 1758 | |
| 1759 | $this->_send_data('DATA'); |
| 1760 | |
| 1761 | $resp = 354; |
| 1762 | break; |
| 1763 | case 'quit' : |
| 1764 | |
| 1765 | $this->_send_data('QUIT'); |
| 1766 | |
| 1767 | $resp = 221; |
| 1768 | break; |
| 1769 | } |
| 1770 | |
| 1771 | $reply = $this->_get_smtp_data(); |
| 1772 | |
| 1773 | $this->_debug_msg[] = "<pre>".$cmd.": ".$reply."</pre>"; |
| 1774 | |
| 1775 | if (substr($reply, 0, 3) != $resp) |
| 1776 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1777 | $this->_set_error_message('lang:email_smtp_error', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1778 | return FALSE; |
| 1779 | } |
| 1780 | |
| 1781 | if ($cmd == 'quit') |
| 1782 | { |
| 1783 | fclose($this->_smtp_connect); |
| 1784 | } |
| 1785 | |
| 1786 | return TRUE; |
| 1787 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1788 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1789 | // -------------------------------------------------------------------- |
| 1790 | |
| 1791 | /** |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1792 | * SMTP Authenticate |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1793 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1794 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1795 | * @return bool |
| 1796 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1797 | protected function _smtp_authenticate() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1798 | { |
| 1799 | if ( ! $this->_smtp_auth) |
| 1800 | { |
| 1801 | return TRUE; |
| 1802 | } |
| 1803 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1804 | if ($this->smtp_user == "" AND $this->smtp_pass == "") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1805 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1806 | $this->_set_error_message('lang:email_no_smtp_unpw'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1807 | return FALSE; |
| 1808 | } |
| 1809 | |
| 1810 | $this->_send_data('AUTH LOGIN'); |
| 1811 | |
| 1812 | $reply = $this->_get_smtp_data(); |
| 1813 | |
| 1814 | if (strncmp($reply, '334', 3) != 0) |
| 1815 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1816 | $this->_set_error_message('lang:email_failed_smtp_login', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1817 | return FALSE; |
| 1818 | } |
| 1819 | |
| 1820 | $this->_send_data(base64_encode($this->smtp_user)); |
| 1821 | |
| 1822 | $reply = $this->_get_smtp_data(); |
| 1823 | |
| 1824 | if (strncmp($reply, '334', 3) != 0) |
| 1825 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1826 | $this->_set_error_message('lang:email_smtp_auth_un', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1827 | return FALSE; |
| 1828 | } |
| 1829 | |
| 1830 | $this->_send_data(base64_encode($this->smtp_pass)); |
| 1831 | |
| 1832 | $reply = $this->_get_smtp_data(); |
| 1833 | |
| 1834 | if (strncmp($reply, '235', 3) != 0) |
| 1835 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1836 | $this->_set_error_message('lang:email_smtp_auth_pw', $reply); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1837 | return FALSE; |
| 1838 | } |
| 1839 | |
| 1840 | return TRUE; |
| 1841 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1842 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1843 | // -------------------------------------------------------------------- |
| 1844 | |
| 1845 | /** |
| 1846 | * Send SMTP data |
| 1847 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1848 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1849 | * @return bool |
| 1850 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1851 | protected function _send_data($data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1852 | { |
| 1853 | if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) |
| 1854 | { |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1855 | $this->_set_error_message('lang:email_smtp_data_failure', $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1856 | return FALSE; |
| 1857 | } |
| 1858 | else |
| 1859 | { |
| 1860 | return TRUE; |
| 1861 | } |
| 1862 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1863 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1864 | // -------------------------------------------------------------------- |
| 1865 | |
| 1866 | /** |
| 1867 | * Get SMTP data |
| 1868 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1869 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1870 | * @return string |
| 1871 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1872 | protected function _get_smtp_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1873 | { |
| 1874 | $data = ""; |
| 1875 | |
| 1876 | while ($str = fgets($this->_smtp_connect, 512)) |
| 1877 | { |
| 1878 | $data .= $str; |
| 1879 | |
| 1880 | if (substr($str, 3, 1) == " ") |
| 1881 | { |
| 1882 | break; |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | return $data; |
| 1887 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1888 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1889 | // -------------------------------------------------------------------- |
| 1890 | |
| 1891 | /** |
| 1892 | * Get Hostname |
| 1893 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1894 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1895 | * @return string |
| 1896 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1897 | protected function _get_hostname() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1898 | { |
| 1899 | return (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain'; |
| 1900 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1901 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1902 | // -------------------------------------------------------------------- |
| 1903 | |
| 1904 | /** |
| 1905 | * Get IP |
| 1906 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1907 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1908 | * @return string |
| 1909 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1910 | protected function _get_ip() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1911 | { |
| 1912 | if ($this->_IP !== FALSE) |
| 1913 | { |
| 1914 | return $this->_IP; |
| 1915 | } |
| 1916 | |
| 1917 | $cip = (isset($_SERVER['HTTP_CLIENT_IP']) AND $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; |
| 1918 | $rip = (isset($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE; |
| 1919 | $fip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; |
| 1920 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1921 | if ($cip && $rip) $this->_IP = $cip; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1922 | elseif ($rip) $this->_IP = $rip; |
| 1923 | elseif ($cip) $this->_IP = $cip; |
| 1924 | elseif ($fip) $this->_IP = $fip; |
| 1925 | |
Robin Sowell | 76b369e | 2010-03-19 11:15:28 -0400 | [diff] [blame] | 1926 | if (strpos($this->_IP, ',') !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1927 | { |
| 1928 | $x = explode(',', $this->_IP); |
| 1929 | $this->_IP = end($x); |
| 1930 | } |
| 1931 | |
| 1932 | if ( ! preg_match( "/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $this->_IP)) |
| 1933 | { |
| 1934 | $this->_IP = '0.0.0.0'; |
| 1935 | } |
| 1936 | |
| 1937 | unset($cip); |
| 1938 | unset($rip); |
| 1939 | unset($fip); |
| 1940 | |
| 1941 | return $this->_IP; |
| 1942 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1943 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1944 | // -------------------------------------------------------------------- |
| 1945 | |
| 1946 | /** |
| 1947 | * Get Debug Message |
| 1948 | * |
| 1949 | * @access public |
| 1950 | * @return string |
| 1951 | */ |
Phil Sturgeon | a0f980e | 2011-01-13 10:59:12 +0000 | [diff] [blame] | 1952 | public function print_debugger() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1953 | { |
| 1954 | $msg = ''; |
| 1955 | |
| 1956 | if (count($this->_debug_msg) > 0) |
| 1957 | { |
| 1958 | foreach ($this->_debug_msg as $val) |
| 1959 | { |
| 1960 | $msg .= $val; |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | $msg .= "<pre>".$this->_header_str."\n".htmlspecialchars($this->_subject)."\n".htmlspecialchars($this->_finalbody).'</pre>'; |
| 1965 | return $msg; |
| 1966 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1967 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1968 | // -------------------------------------------------------------------- |
| 1969 | |
| 1970 | /** |
| 1971 | * Set Message |
| 1972 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1973 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1974 | * @param string |
| 1975 | * @return string |
| 1976 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1977 | protected function _set_error_message($msg, $val = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1978 | { |
| 1979 | $CI =& get_instance(); |
| 1980 | $CI->lang->load('email'); |
| 1981 | |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 1982 | if (substr($msg, 0, 5) != 'lang:' || FALSE === ($line = $CI->lang->line(substr($msg, 5)))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1983 | { |
| 1984 | $this->_debug_msg[] = str_replace('%s', $val, $msg)."<br />"; |
| 1985 | } |
| 1986 | else |
| 1987 | { |
| 1988 | $this->_debug_msg[] = str_replace('%s', $val, $line)."<br />"; |
| 1989 | } |
| 1990 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1991 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1992 | // -------------------------------------------------------------------- |
| 1993 | |
| 1994 | /** |
| 1995 | * Mime Types |
| 1996 | * |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 1997 | * @access protected |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1998 | * @param string |
| 1999 | * @return string |
| 2000 | */ |
Phil Sturgeon | 6d2f13a | 2011-07-20 10:04:52 -0600 | [diff] [blame] | 2001 | protected function _mime_types($ext = "") |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2002 | { |
| 2003 | $mimes = array( 'hqx' => 'application/mac-binhex40', |
| 2004 | 'cpt' => 'application/mac-compactpro', |
| 2005 | 'doc' => 'application/msword', |
| 2006 | 'bin' => 'application/macbinary', |
| 2007 | 'dms' => 'application/octet-stream', |
| 2008 | 'lha' => 'application/octet-stream', |
| 2009 | 'lzh' => 'application/octet-stream', |
| 2010 | 'exe' => 'application/octet-stream', |
| 2011 | 'class' => 'application/octet-stream', |
| 2012 | 'psd' => 'application/octet-stream', |
| 2013 | 'so' => 'application/octet-stream', |
| 2014 | 'sea' => 'application/octet-stream', |
| 2015 | 'dll' => 'application/octet-stream', |
| 2016 | 'oda' => 'application/oda', |
| 2017 | 'pdf' => 'application/pdf', |
| 2018 | 'ai' => 'application/postscript', |
| 2019 | 'eps' => 'application/postscript', |
| 2020 | 'ps' => 'application/postscript', |
| 2021 | 'smi' => 'application/smil', |
| 2022 | 'smil' => 'application/smil', |
| 2023 | 'mif' => 'application/vnd.mif', |
| 2024 | 'xls' => 'application/vnd.ms-excel', |
| 2025 | 'ppt' => 'application/vnd.ms-powerpoint', |
| 2026 | 'wbxml' => 'application/vnd.wap.wbxml', |
| 2027 | 'wmlc' => 'application/vnd.wap.wmlc', |
| 2028 | 'dcr' => 'application/x-director', |
| 2029 | 'dir' => 'application/x-director', |
| 2030 | 'dxr' => 'application/x-director', |
| 2031 | 'dvi' => 'application/x-dvi', |
| 2032 | 'gtar' => 'application/x-gtar', |
| 2033 | 'php' => 'application/x-httpd-php', |
| 2034 | 'php4' => 'application/x-httpd-php', |
| 2035 | 'php3' => 'application/x-httpd-php', |
| 2036 | 'phtml' => 'application/x-httpd-php', |
| 2037 | 'phps' => 'application/x-httpd-php-source', |
| 2038 | 'js' => 'application/x-javascript', |
| 2039 | 'swf' => 'application/x-shockwave-flash', |
| 2040 | 'sit' => 'application/x-stuffit', |
| 2041 | 'tar' => 'application/x-tar', |
| 2042 | 'tgz' => 'application/x-tar', |
| 2043 | 'xhtml' => 'application/xhtml+xml', |
| 2044 | 'xht' => 'application/xhtml+xml', |
| 2045 | 'zip' => 'application/zip', |
| 2046 | 'mid' => 'audio/midi', |
| 2047 | 'midi' => 'audio/midi', |
| 2048 | 'mpga' => 'audio/mpeg', |
| 2049 | 'mp2' => 'audio/mpeg', |
| 2050 | 'mp3' => 'audio/mpeg', |
| 2051 | 'aif' => 'audio/x-aiff', |
| 2052 | 'aiff' => 'audio/x-aiff', |
| 2053 | 'aifc' => 'audio/x-aiff', |
| 2054 | 'ram' => 'audio/x-pn-realaudio', |
| 2055 | 'rm' => 'audio/x-pn-realaudio', |
| 2056 | 'rpm' => 'audio/x-pn-realaudio-plugin', |
| 2057 | 'ra' => 'audio/x-realaudio', |
| 2058 | 'rv' => 'video/vnd.rn-realvideo', |
| 2059 | 'wav' => 'audio/x-wav', |
| 2060 | 'bmp' => 'image/bmp', |
| 2061 | 'gif' => 'image/gif', |
| 2062 | 'jpeg' => 'image/jpeg', |
| 2063 | 'jpg' => 'image/jpeg', |
| 2064 | 'jpe' => 'image/jpeg', |
| 2065 | 'png' => 'image/png', |
| 2066 | 'tiff' => 'image/tiff', |
| 2067 | 'tif' => 'image/tiff', |
| 2068 | 'css' => 'text/css', |
| 2069 | 'html' => 'text/html', |
| 2070 | 'htm' => 'text/html', |
| 2071 | 'shtml' => 'text/html', |
| 2072 | 'txt' => 'text/plain', |
| 2073 | 'text' => 'text/plain', |
| 2074 | 'log' => 'text/plain', |
| 2075 | 'rtx' => 'text/richtext', |
| 2076 | 'rtf' => 'text/rtf', |
| 2077 | 'xml' => 'text/xml', |
| 2078 | 'xsl' => 'text/xml', |
| 2079 | 'mpeg' => 'video/mpeg', |
| 2080 | 'mpg' => 'video/mpeg', |
| 2081 | 'mpe' => 'video/mpeg', |
| 2082 | 'qt' => 'video/quicktime', |
| 2083 | 'mov' => 'video/quicktime', |
| 2084 | 'avi' => 'video/x-msvideo', |
| 2085 | 'movie' => 'video/x-sgi-movie', |
| 2086 | 'doc' => 'application/msword', |
| 2087 | 'word' => 'application/msword', |
| 2088 | 'xl' => 'application/excel', |
| 2089 | 'eml' => 'message/rfc822' |
| 2090 | ); |
| 2091 | |
| 2092 | return ( ! isset($mimes[strtolower($ext)])) ? "application/x-unknown-content-type" : $mimes[strtolower($ext)]; |
| 2093 | } |
| 2094 | |
| 2095 | } |
| 2096 | // END CI_Email class |
| 2097 | |
| 2098 | /* End of file Email.php */ |
patwork | b070798 | 2011-04-08 15:10:05 +0200 | [diff] [blame] | 2099 | /* Location: ./system/libraries/Email.php */ |