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