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