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