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