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