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