author | ymh <ymh.work@gmail.com> |
Tue, 22 Oct 2019 16:11:46 +0200 | |
changeset 15 | 3d4e9c994f10 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
5 | 3 |
* PHPMailer - PHP email creation and transport class. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* PHP Version 5 |
0 | 5 |
* @package PHPMailer |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk> |
5 | 8 |
* @author Jim Jagielski (jimjag) <jimjag@gmail.com> |
9 |
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net> |
|
10 |
* @author Brent R. Matzelle (original founder) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* @copyright 2012 - 2014 Marcus Bointon |
0 | 12 |
* @copyright 2010 - 2012 Jim Jagielski |
13 |
* @copyright 2004 - 2009 Andy Prevost |
|
14 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
|
5 | 15 |
* @note This program is distributed in the hope that it will be useful - WITHOUT |
16 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
17 |
* FITNESS FOR A PARTICULAR PURPOSE. |
|
0 | 18 |
*/ |
19 |
||
20 |
/** |
|
5 | 21 |
* PHPMailer - PHP email creation and transport class. |
22 |
* @package PHPMailer |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk> |
5 | 24 |
* @author Jim Jagielski (jimjag) <jimjag@gmail.com> |
25 |
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net> |
|
26 |
* @author Brent R. Matzelle (original founder) |
|
0 | 27 |
*/ |
5 | 28 |
class PHPMailer |
29 |
{ |
|
30 |
/** |
|
31 |
* The PHPMailer Version number. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* @var string |
5 | 33 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
public $Version = '5.2.22'; |
5 | 35 |
|
36 |
/** |
|
37 |
* Email priority. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* Options: null (default), 1 = High, 3 = Normal, 5 = low. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* When null, the header is not set at all. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
* @var integer |
5 | 41 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
public $Priority = null; |
5 | 43 |
|
44 |
/** |
|
45 |
* The character set of the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* @var string |
5 | 47 |
*/ |
48 |
public $CharSet = 'iso-8859-1'; |
|
49 |
||
50 |
/** |
|
51 |
* The MIME Content-type of the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
* @var string |
5 | 53 |
*/ |
54 |
public $ContentType = 'text/plain'; |
|
55 |
||
56 |
/** |
|
57 |
* The message encoding. |
|
58 |
* Options: "8bit", "7bit", "binary", "base64", and "quoted-printable". |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @var string |
5 | 60 |
*/ |
61 |
public $Encoding = '8bit'; |
|
62 |
||
63 |
/** |
|
64 |
* Holds the most recent mailer error message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* @var string |
5 | 66 |
*/ |
67 |
public $ErrorInfo = ''; |
|
68 |
||
69 |
/** |
|
70 |
* The From email address for the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
* @var string |
5 | 72 |
*/ |
73 |
public $From = 'root@localhost'; |
|
74 |
||
75 |
/** |
|
76 |
* The From name of the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
* @var string |
5 | 78 |
*/ |
79 |
public $FromName = 'Root User'; |
|
80 |
||
81 |
/** |
|
82 |
* The Sender email (Return-Path) of the message. |
|
83 |
* If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @var string |
5 | 85 |
*/ |
86 |
public $Sender = ''; |
|
87 |
||
88 |
/** |
|
89 |
* The Return-Path of the message. |
|
90 |
* If empty, it will be set to either From or Sender. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* @deprecated Email senders should never set a return-path header; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* it's the receiver's job (RFC5321 section 4.4), so this no longer does anything. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference |
5 | 95 |
*/ |
96 |
public $ReturnPath = ''; |
|
97 |
||
98 |
/** |
|
99 |
* The Subject of the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* @var string |
5 | 101 |
*/ |
102 |
public $Subject = ''; |
|
0 | 103 |
|
5 | 104 |
/** |
105 |
* An HTML or plain text message body. |
|
106 |
* If HTML then call isHTML(true). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
* @var string |
5 | 108 |
*/ |
109 |
public $Body = ''; |
|
110 |
||
111 |
/** |
|
112 |
* The plain-text message body. |
|
113 |
* This body can be read by mail clients that do not have HTML email |
|
114 |
* capability such as mutt & Eudora. |
|
115 |
* Clients that can read HTML will view the normal Body. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* @var string |
5 | 117 |
*/ |
118 |
public $AltBody = ''; |
|
119 |
||
120 |
/** |
|
121 |
* An iCal message part body. |
|
122 |
* Only supported in simple alt or alt_inline message types |
|
123 |
* To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator |
|
124 |
* @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/ |
|
125 |
* @link http://kigkonsult.se/iCalcreator/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* @var string |
5 | 127 |
*/ |
128 |
public $Ical = ''; |
|
129 |
||
130 |
/** |
|
131 |
* The complete compiled MIME message body. |
|
132 |
* @access protected |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* @var string |
5 | 134 |
*/ |
135 |
protected $MIMEBody = ''; |
|
136 |
||
137 |
/** |
|
138 |
* The complete compiled MIME message headers. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* @var string |
5 | 140 |
* @access protected |
141 |
*/ |
|
142 |
protected $MIMEHeader = ''; |
|
0 | 143 |
|
5 | 144 |
/** |
145 |
* Extra headers that createHeader() doesn't fold in. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @var string |
5 | 147 |
* @access protected |
148 |
*/ |
|
149 |
protected $mailHeader = ''; |
|
150 |
||
151 |
/** |
|
152 |
* Word-wrap the message body to this number of chars. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
* Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
* @var integer |
5 | 155 |
*/ |
156 |
public $WordWrap = 0; |
|
157 |
||
158 |
/** |
|
159 |
* Which method to use to send mail. |
|
160 |
* Options: "mail", "sendmail", or "smtp". |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @var string |
5 | 162 |
*/ |
163 |
public $Mailer = 'mail'; |
|
164 |
||
165 |
/** |
|
166 |
* The path to the sendmail program. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* @var string |
5 | 168 |
*/ |
169 |
public $Sendmail = '/usr/sbin/sendmail'; |
|
170 |
||
171 |
/** |
|
172 |
* Whether mail() uses a fully sendmail-compatible MTA. |
|
173 |
* One which supports sendmail's "-oi -f" options. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @var boolean |
5 | 175 |
*/ |
176 |
public $UseSendmailOptions = true; |
|
177 |
||
178 |
/** |
|
179 |
* Path to PHPMailer plugins. |
|
180 |
* Useful if the SMTP class is not in the PHP include path. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
* @var string |
5 | 182 |
* @deprecated Should not be needed now there is an autoloader. |
183 |
*/ |
|
184 |
public $PluginDir = ''; |
|
185 |
||
186 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
* The email address that a reading confirmation should be sent to, also known as read receipt. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* @var string |
5 | 189 |
*/ |
190 |
public $ConfirmReadingTo = ''; |
|
0 | 191 |
|
5 | 192 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* The hostname to use in the Message-ID header and as default HELO string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* If empty, PHPMailer attempts to find one with, in order, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* 'localhost.localdomain'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* @var string |
5 | 198 |
*/ |
199 |
public $Hostname = ''; |
|
200 |
||
201 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* An ID to be used in the Message-ID header. |
5 | 203 |
* If empty, a unique id will be generated. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
* You can set your own, but it must be in the format "<id@domain>", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* as defined in RFC5322 section 3.6.4 or it will be ignored. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* @see https://tools.ietf.org/html/rfc5322#section-3.6.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
* @var string |
5 | 208 |
*/ |
209 |
public $MessageID = ''; |
|
210 |
||
211 |
/** |
|
212 |
* The message Date to be used in the Date header. |
|
213 |
* If empty, the current date will be added. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* @var string |
5 | 215 |
*/ |
216 |
public $MessageDate = ''; |
|
217 |
||
218 |
/** |
|
219 |
* SMTP hosts. |
|
220 |
* Either a single hostname or multiple semicolon-delimited hostnames. |
|
221 |
* You can also specify a different port |
|
222 |
* for each host by using this format: [hostname:port] |
|
223 |
* (e.g. "smtp1.example.com:25;smtp2.example.com"). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* You can also specify encryption type, for example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). |
5 | 226 |
* Hosts will be tried in order. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* @var string |
5 | 228 |
*/ |
229 |
public $Host = 'localhost'; |
|
230 |
||
231 |
/** |
|
232 |
* The default SMTP server port. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
* @var integer |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
* @TODO Why is this needed when the SMTP class takes care of it? |
5 | 235 |
*/ |
236 |
public $Port = 25; |
|
0 | 237 |
|
5 | 238 |
/** |
239 |
* The SMTP HELO of the message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* one with the same method described above for $Hostname. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* @var string |
5 | 243 |
* @see PHPMailer::$Hostname |
244 |
*/ |
|
245 |
public $Helo = ''; |
|
246 |
||
247 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* What kind of encryption to use on the SMTP connection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* Options: '', 'ssl' or 'tls' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @var string |
5 | 251 |
*/ |
252 |
public $SMTPSecure = ''; |
|
253 |
||
254 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* Whether to enable TLS encryption automatically if a server supports it, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* even if `SMTPSecure` is not set to 'tls'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* Be aware that in PHP >= 5.6 this requires that the server's certificates are valid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* @var boolean |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
public $SMTPAutoTLS = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
/** |
5 | 263 |
* Whether to use SMTP authentication. |
264 |
* Uses the Username and Password properties. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
* @var boolean |
5 | 266 |
* @see PHPMailer::$Username |
267 |
* @see PHPMailer::$Password |
|
268 |
*/ |
|
269 |
public $SMTPAuth = false; |
|
0 | 270 |
|
5 | 271 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* Options array passed to stream_context_create when connecting via SMTP. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
public $SMTPOptions = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
/** |
5 | 278 |
* SMTP username. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
* @var string |
5 | 280 |
*/ |
281 |
public $Username = ''; |
|
282 |
||
283 |
/** |
|
284 |
* SMTP password. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
* @var string |
5 | 286 |
*/ |
287 |
public $Password = ''; |
|
288 |
||
289 |
/** |
|
290 |
* SMTP auth type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
* Options are CRAM-MD5, LOGIN, PLAIN, attempted in that order if not specified |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
* @var string |
5 | 293 |
*/ |
294 |
public $AuthType = ''; |
|
295 |
||
296 |
/** |
|
297 |
* SMTP realm. |
|
298 |
* Used for NTLM auth |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @var string |
5 | 300 |
*/ |
301 |
public $Realm = ''; |
|
0 | 302 |
|
5 | 303 |
/** |
304 |
* SMTP workstation. |
|
305 |
* Used for NTLM auth |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
* @var string |
5 | 307 |
*/ |
308 |
public $Workstation = ''; |
|
309 |
||
310 |
/** |
|
311 |
* The SMTP server timeout in seconds. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* @var integer |
5 | 314 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
public $Timeout = 300; |
5 | 316 |
|
317 |
/** |
|
318 |
* SMTP class debug output mode. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* Debug output level. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* Options: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* * `0` No output |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* * `1` Commands |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
* * `2` Data and commands |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* * `3` As 2 plus connection status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* * `4` Low-level data output |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @var integer |
5 | 327 |
* @see SMTP::$do_debug |
328 |
*/ |
|
329 |
public $SMTPDebug = 0; |
|
0 | 330 |
|
5 | 331 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
* How to handle debug output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* Options: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
* * `echo` Output plain-text as-is, appropriate for CLI |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* * `error_log` Output to error log as configured in php.ini |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
* Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* <code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* </code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* @var string|callable |
5 | 343 |
* @see SMTP::$Debugoutput |
344 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
public $Debugoutput = 'echo'; |
5 | 346 |
|
347 |
/** |
|
348 |
* Whether to keep SMTP connection open after each message. |
|
349 |
* If this is set to true then to close the connection |
|
350 |
* requires an explicit call to smtpClose(). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
* @var boolean |
5 | 352 |
*/ |
353 |
public $SMTPKeepAlive = false; |
|
354 |
||
355 |
/** |
|
356 |
* Whether to split multiple to addresses into multiple messages |
|
357 |
* or send them all in one message. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
* Only supported in `mail` and `sendmail` transports, not in SMTP. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
* @var boolean |
5 | 360 |
*/ |
361 |
public $SingleTo = false; |
|
0 | 362 |
|
5 | 363 |
/** |
364 |
* Storage for addresses when SingleTo is enabled. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
* @TODO This should really not be public |
5 | 367 |
*/ |
368 |
public $SingleToArray = array(); |
|
369 |
||
370 |
/** |
|
371 |
* Whether to generate VERP addresses on send. |
|
372 |
* Only applicable when sending via SMTP. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* @link https://en.wikipedia.org/wiki/Variable_envelope_return_path |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* @link http://www.postfix.org/VERP_README.html Postfix VERP info |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* @var boolean |
5 | 376 |
*/ |
377 |
public $do_verp = false; |
|
378 |
||
379 |
/** |
|
380 |
* Whether to allow sending messages with an empty body. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @var boolean |
5 | 382 |
*/ |
383 |
public $AllowEmpty = false; |
|
0 | 384 |
|
5 | 385 |
/** |
386 |
* The default line ending. |
|
387 |
* @note The default remains "\n". We force CRLF where we know |
|
388 |
* it must be used via self::CRLF. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* @var string |
5 | 390 |
*/ |
391 |
public $LE = "\n"; |
|
0 | 392 |
|
5 | 393 |
/** |
394 |
* DKIM selector. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @var string |
5 | 396 |
*/ |
397 |
public $DKIM_selector = ''; |
|
0 | 398 |
|
5 | 399 |
/** |
400 |
* DKIM Identity. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
* Usually the email address used as the source of the email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* @var string |
5 | 403 |
*/ |
404 |
public $DKIM_identity = ''; |
|
405 |
||
406 |
/** |
|
407 |
* DKIM passphrase. |
|
408 |
* Used if your key is encrypted. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* @var string |
5 | 410 |
*/ |
411 |
public $DKIM_passphrase = ''; |
|
0 | 412 |
|
5 | 413 |
/** |
414 |
* DKIM signing domain name. |
|
415 |
* @example 'example.com' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* @var string |
5 | 417 |
*/ |
418 |
public $DKIM_domain = ''; |
|
419 |
||
420 |
/** |
|
421 |
* DKIM private key file path. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
* @var string |
5 | 423 |
*/ |
424 |
public $DKIM_private = ''; |
|
425 |
||
426 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* DKIM private key string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* If set, takes precedence over `$DKIM_private`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
public $DKIM_private_string = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
/** |
5 | 434 |
* Callback Action function name. |
435 |
* |
|
436 |
* The function that handles the result of the send email action. |
|
437 |
* It is called out by send() for each email sent. |
|
438 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
* Value can be any php callable: http://www.php.net/is_callable |
5 | 440 |
* |
441 |
* Parameters: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* boolean $result result of the send action |
5 | 443 |
* string $to email address of the recipient |
444 |
* string $cc cc email addresses |
|
445 |
* string $bcc bcc email addresses |
|
446 |
* string $subject the subject |
|
447 |
* string $body the email body |
|
448 |
* string $from email address of sender |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* @var string |
5 | 450 |
*/ |
451 |
public $action_function = ''; |
|
452 |
||
453 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* What to put in the X-Mailer header. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* Options: An empty string for PHPMailer default, whitespace for none, or a string to use |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @var string |
5 | 457 |
*/ |
458 |
public $XMailer = ''; |
|
459 |
||
460 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* Which validator to use by default when validating email addresses. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* May be a callable to inject your own validator, but there are several built-in validators. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* @see PHPMailer::validateAddress() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* @var string|callable |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
public static $validator = 'auto'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
/** |
5 | 470 |
* An instance of the SMTP sender class. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
* @var SMTP |
5 | 472 |
* @access protected |
473 |
*/ |
|
474 |
protected $smtp = null; |
|
475 |
||
476 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
* The array of 'to' names and addresses. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* @var array |
5 | 479 |
* @access protected |
480 |
*/ |
|
481 |
protected $to = array(); |
|
482 |
||
483 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
* The array of 'cc' names and addresses. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* @var array |
5 | 486 |
* @access protected |
487 |
*/ |
|
488 |
protected $cc = array(); |
|
489 |
||
490 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* The array of 'bcc' names and addresses. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @var array |
5 | 493 |
* @access protected |
494 |
*/ |
|
495 |
protected $bcc = array(); |
|
496 |
||
497 |
/** |
|
498 |
* The array of reply-to names and addresses. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* @var array |
5 | 500 |
* @access protected |
501 |
*/ |
|
502 |
protected $ReplyTo = array(); |
|
503 |
||
504 |
/** |
|
505 |
* An array of all kinds of addresses. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
* Includes all of $to, $cc, $bcc |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
* @var array |
5 | 508 |
* @access protected |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc |
5 | 510 |
*/ |
511 |
protected $all_recipients = array(); |
|
512 |
||
513 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
* An array of names and addresses queued for validation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* In send(), valid and non duplicate entries are moved to $all_recipients |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
* and one of $to, $cc, or $bcc. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* This array is used only for addresses with IDN. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* @see PHPMailer::$all_recipients |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
protected $RecipientsQueue = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* An array of reply-to names and addresses queued for validation. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* In send(), valid and non duplicate entries are moved to $ReplyTo. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* This array is used only for addresses with IDN. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* @var array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* @see PHPMailer::$ReplyTo |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
protected $ReplyToQueue = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
/** |
5 | 536 |
* The array of attachments. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
* @var array |
5 | 538 |
* @access protected |
539 |
*/ |
|
540 |
protected $attachment = array(); |
|
541 |
||
542 |
/** |
|
543 |
* The array of custom headers. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
544 |
* @var array |
5 | 545 |
* @access protected |
546 |
*/ |
|
547 |
protected $CustomHeader = array(); |
|
548 |
||
549 |
/** |
|
550 |
* The most recent Message-ID (including angular brackets). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* @var string |
5 | 552 |
* @access protected |
553 |
*/ |
|
554 |
protected $lastMessageID = ''; |
|
555 |
||
556 |
/** |
|
557 |
* The message's MIME type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
* @var string |
5 | 559 |
* @access protected |
560 |
*/ |
|
561 |
protected $message_type = ''; |
|
562 |
||
563 |
/** |
|
564 |
* The array of MIME boundary strings. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* @var array |
5 | 566 |
* @access protected |
567 |
*/ |
|
568 |
protected $boundary = array(); |
|
569 |
||
570 |
/** |
|
571 |
* The array of available languages. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* @var array |
5 | 573 |
* @access protected |
574 |
*/ |
|
575 |
protected $language = array(); |
|
576 |
||
577 |
/** |
|
578 |
* The number of errors encountered. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
* @var integer |
5 | 580 |
* @access protected |
581 |
*/ |
|
582 |
protected $error_count = 0; |
|
583 |
||
584 |
/** |
|
585 |
* The S/MIME certificate file path. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* @var string |
5 | 587 |
* @access protected |
588 |
*/ |
|
589 |
protected $sign_cert_file = ''; |
|
590 |
||
591 |
/** |
|
592 |
* The S/MIME key file path. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
* @var string |
5 | 594 |
* @access protected |
595 |
*/ |
|
596 |
protected $sign_key_file = ''; |
|
597 |
||
598 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
* The optional S/MIME extra certificates ("CA Chain") file path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
protected $sign_extracerts_file = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
/** |
5 | 606 |
* The S/MIME password for the key. |
607 |
* Used only if the key is encrypted. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
* @var string |
5 | 609 |
* @access protected |
610 |
*/ |
|
611 |
protected $sign_key_pass = ''; |
|
612 |
||
613 |
/** |
|
614 |
* Whether to throw exceptions for errors. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
* @var boolean |
5 | 616 |
* @access protected |
617 |
*/ |
|
618 |
protected $exceptions = false; |
|
619 |
||
620 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* Unique ID used for message ID and boundaries. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @var string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
protected $uniqueid = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
* Error severity: message only, continue processing. |
5 | 629 |
*/ |
630 |
const STOP_MESSAGE = 0; |
|
631 |
||
632 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
* Error severity: message, likely ok to continue processing. |
5 | 634 |
*/ |
635 |
const STOP_CONTINUE = 1; |
|
636 |
||
637 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* Error severity: message, plus full stop, critical error reached. |
5 | 639 |
*/ |
640 |
const STOP_CRITICAL = 2; |
|
641 |
||
642 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
* SMTP RFC standard line ending. |
5 | 644 |
*/ |
645 |
const CRLF = "\r\n"; |
|
646 |
||
647 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
* The maximum line length allowed by RFC 2822 section 2.1.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
* @var integer |
5 | 650 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
const MAX_LINE_LENGTH = 998; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
654 |
* Constructor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
655 |
* @param boolean $exceptions Should we throw external exceptions? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
656 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
public function __construct($exceptions = null) |
5 | 658 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
659 |
if ($exceptions !== null) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
$this->exceptions = (boolean)$exceptions; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
} |
0 | 662 |
} |
663 |
||
5 | 664 |
/** |
665 |
* Destructor. |
|
666 |
*/ |
|
667 |
public function __destruct() |
|
668 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
//Close any open SMTP connection nicely |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
$this->smtpClose(); |
0 | 671 |
} |
5 | 672 |
|
673 |
/** |
|
674 |
* Call mail() in a safe_mode-aware fashion. |
|
675 |
* Also, unless sendmail_path points to sendmail (or something that |
|
676 |
* claims to be sendmail), don't pass params (not a perfect fix, |
|
677 |
* but it will do) |
|
678 |
* @param string $to To |
|
679 |
* @param string $subject Subject |
|
680 |
* @param string $body Message Body |
|
681 |
* @param string $header Additional Header(s) |
|
682 |
* @param string $params Params |
|
683 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
* @return boolean |
5 | 685 |
*/ |
686 |
private function mailPassthru($to, $subject, $body, $header, $params) |
|
687 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
//Check overloading of mail function to avoid double-encoding |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
if (ini_get('mbstring.func_overload') & 1) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
$subject = $this->secureHeader($subject); |
5 | 691 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
$subject = $this->encodeHeader($this->secureHeader($subject)); |
5 | 693 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
//Can't use additional_parameters in safe_mode, calling mail() with null params breaks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
//@link http://php.net/manual/en/function.mail.php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
if (ini_get('safe_mode') or !$this->UseSendmailOptions or is_null($params)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
$result = @mail($to, $subject, $body, $header); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
$result = @mail($to, $subject, $body, $header, $params); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
return $result; |
5 | 703 |
} |
704 |
/** |
|
705 |
* Output debugging info via user-defined method. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug). |
5 | 707 |
* @see PHPMailer::$Debugoutput |
708 |
* @see PHPMailer::$SMTPDebug |
|
709 |
* @param string $str |
|
710 |
*/ |
|
711 |
protected function edebug($str) |
|
712 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
if ($this->SMTPDebug <= 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
//Avoid clash with built-in function names |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
call_user_func($this->Debugoutput, $str, $this->SMTPDebug); |
5 | 719 |
return; |
720 |
} |
|
721 |
switch ($this->Debugoutput) { |
|
722 |
case 'error_log': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
//Don't output, just log |
5 | 724 |
error_log($str); |
725 |
break; |
|
726 |
case 'html': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
//Cleans up output a bit for a better looking, HTML-safe output |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
echo htmlentities( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
preg_replace('/[\r\n]+/', '', $str), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
ENT_QUOTES, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
'UTF-8' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
. "<br>\n"; |
5 | 734 |
break; |
735 |
case 'echo': |
|
736 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
//Normalize line breaks |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
$str = preg_replace('/\r\n?/ms', "\n", $str); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
"\n", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
"\n \t ", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
trim($str) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
) . "\n"; |
5 | 744 |
} |
0 | 745 |
} |
746 |
||
5 | 747 |
/** |
748 |
* Sets message type to HTML or plain. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* @param boolean $isHtml True for HTML mode. |
5 | 750 |
* @return void |
751 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
public function isHTML($isHtml = true) |
5 | 753 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
if ($isHtml) { |
5 | 755 |
$this->ContentType = 'text/html'; |
756 |
} else { |
|
757 |
$this->ContentType = 'text/plain'; |
|
758 |
} |
|
0 | 759 |
} |
5 | 760 |
|
761 |
/** |
|
762 |
* Send messages using SMTP. |
|
763 |
* @return void |
|
764 |
*/ |
|
765 |
public function isSMTP() |
|
766 |
{ |
|
767 |
$this->Mailer = 'smtp'; |
|
0 | 768 |
} |
5 | 769 |
|
770 |
/** |
|
771 |
* Send messages using PHP's mail() function. |
|
772 |
* @return void |
|
773 |
*/ |
|
774 |
public function isMail() |
|
775 |
{ |
|
776 |
$this->Mailer = 'mail'; |
|
0 | 777 |
} |
5 | 778 |
|
779 |
/** |
|
780 |
* Send messages using $Sendmail. |
|
781 |
* @return void |
|
782 |
*/ |
|
783 |
public function isSendmail() |
|
784 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
$ini_sendmail_path = ini_get('sendmail_path'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
if (!stristr($ini_sendmail_path, 'sendmail')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
$this->Sendmail = '/usr/sbin/sendmail'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
$this->Sendmail = $ini_sendmail_path; |
5 | 791 |
} |
792 |
$this->Mailer = 'sendmail'; |
|
0 | 793 |
} |
5 | 794 |
|
795 |
/** |
|
796 |
* Send messages using qmail. |
|
797 |
* @return void |
|
798 |
*/ |
|
799 |
public function isQmail() |
|
800 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
801 |
$ini_sendmail_path = ini_get('sendmail_path'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
803 |
if (!stristr($ini_sendmail_path, 'qmail')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
804 |
$this->Sendmail = '/var/qmail/bin/qmail-inject'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
$this->Sendmail = $ini_sendmail_path; |
5 | 807 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
$this->Mailer = 'qmail'; |
0 | 809 |
} |
5 | 810 |
|
811 |
/** |
|
812 |
* Add a "To" address. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
* @param string $address The email address to send to |
5 | 814 |
* @param string $name |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* @return boolean true on success, false if address already used or invalid in some way |
5 | 816 |
*/ |
817 |
public function addAddress($address, $name = '') |
|
818 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
return $this->addOrEnqueueAnAddress('to', $address, $name); |
5 | 820 |
} |
0 | 821 |
|
5 | 822 |
/** |
823 |
* Add a "CC" address. |
|
824 |
* @note: This function works with the SMTP mailer on win32, not with the "mail" mailer. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
* @param string $address The email address to send to |
5 | 826 |
* @param string $name |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* @return boolean true on success, false if address already used or invalid in some way |
5 | 828 |
*/ |
829 |
public function addCC($address, $name = '') |
|
830 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
return $this->addOrEnqueueAnAddress('cc', $address, $name); |
5 | 832 |
} |
0 | 833 |
|
5 | 834 |
/** |
835 |
* Add a "BCC" address. |
|
836 |
* @note: This function works with the SMTP mailer on win32, not with the "mail" mailer. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* @param string $address The email address to send to |
5 | 838 |
* @param string $name |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
* @return boolean true on success, false if address already used or invalid in some way |
5 | 840 |
*/ |
841 |
public function addBCC($address, $name = '') |
|
842 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
return $this->addOrEnqueueAnAddress('bcc', $address, $name); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
* Add a "Reply-To" address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
* @param string $address The email address to reply to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
* @param string $name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
* @return boolean true on success, false if address already used or invalid in some way |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
public function addReplyTo($address, $name = '') |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
return $this->addOrEnqueueAnAddress('Reply-To', $address, $name); |
0 | 855 |
} |
5 | 856 |
|
857 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
* Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
* be modified after calling this function), addition of such addresses is delayed until send(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* Addresses that have been added already return false, but do not throw exceptions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* @param string $address The email address to send, resp. to reply to |
5 | 864 |
* @param string $name |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* @throws phpmailerException |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* @return boolean true on success, false if address already used or invalid in some way |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
* @access protected |
5 | 868 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
protected function addOrEnqueueAnAddress($kind, $address, $name) |
5 | 870 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
$address = trim($address); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
if (($pos = strrpos($address, '@')) === false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
// At-sign is misssing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
$error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
$this->setError($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
$this->edebug($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
if ($this->exceptions) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
throw new phpmailerException($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
882 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
$params = array($kind, $address, $name); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
if ($kind != 'Reply-To') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
if (!array_key_exists($address, $this->RecipientsQueue)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
$this->RecipientsQueue[$address] = $params; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
if (!array_key_exists($address, $this->ReplyToQueue)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
$this->ReplyToQueue[$address] = $params; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
898 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
// Immediately add standard addresses without IDN. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
return call_user_func_array(array($this, 'addAnAddress'), $params); |
0 | 901 |
} |
902 |
||
5 | 903 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
* Add an address to one of the recipient arrays or to the ReplyTo array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
* Addresses that have been added already return false, but do not throw exceptions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* @param string $address The email address to send, resp. to reply to |
5 | 908 |
* @param string $name |
909 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
* @return boolean true on success, false if address already used or invalid in some way |
5 | 911 |
* @access protected |
912 |
*/ |
|
913 |
protected function addAnAddress($kind, $address, $name = '') |
|
914 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
$error_message = $this->lang('Invalid recipient kind: ') . $kind; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
$this->setError($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
$this->edebug($error_message); |
5 | 919 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
throw new phpmailerException($error_message); |
5 | 921 |
} |
922 |
return false; |
|
923 |
} |
|
924 |
if (!$this->validateAddress($address)) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
$error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
$this->setError($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
$this->edebug($error_message); |
5 | 928 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
throw new phpmailerException($error_message); |
5 | 930 |
} |
931 |
return false; |
|
932 |
} |
|
933 |
if ($kind != 'Reply-To') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
if (!array_key_exists(strtolower($address), $this->all_recipients)) { |
5 | 935 |
array_push($this->$kind, array($address, $name)); |
936 |
$this->all_recipients[strtolower($address)] = true; |
|
937 |
return true; |
|
938 |
} |
|
939 |
} else { |
|
940 |
if (!array_key_exists(strtolower($address), $this->ReplyTo)) { |
|
941 |
$this->ReplyTo[strtolower($address)] = array($address, $name); |
|
942 |
return true; |
|
943 |
} |
|
944 |
} |
|
945 |
return false; |
|
946 |
} |
|
947 |
||
948 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
* Parse and validate a string containing one or more RFC822-style comma-separated email addresses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
* of the form "display name <address>" into an array of name/address pairs. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
* Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* Note that quotes in the name part are removed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* @param string $addrstr The address list string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
* @param bool $useimap Whether to use the IMAP extension to parse the list |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
public function parseAddresses($addrstr, $useimap = true) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
$addresses = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
if ($useimap and function_exists('imap_rfc822_parse_adrlist')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
//Use this built-in parser if it's available |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
$list = imap_rfc822_parse_adrlist($addrstr, ''); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
foreach ($list as $address) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
if ($address->host != '.SYNTAX-ERROR.') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
if ($this->validateAddress($address->mailbox . '@' . $address->host)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
$addresses[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
'name' => (property_exists($address, 'personal') ? $address->personal : ''), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
'address' => $address->mailbox . '@' . $address->host |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
//Use this simpler parser |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
$list = explode(',', $addrstr); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
foreach ($list as $address) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
$address = trim($address); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
//Is there a separate name part? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
if (strpos($address, '<') === false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
//No separate name, just use the whole thing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
if ($this->validateAddress($address)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
$addresses[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
'name' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
'address' => $address |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
list($name, $email) = explode('<', $address); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
$email = trim(str_replace('>', '', $email)); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
if ($this->validateAddress($email)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
$addresses[] = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
'name' => trim(str_replace(array('"', "'"), '', $name)), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
'address' => $email |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
return $addresses; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
/** |
5 | 1004 |
* Set the From and FromName properties. |
1005 |
* @param string $address |
|
1006 |
* @param string $name |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* @param boolean $auto Whether to also set the Sender address, defaults to true |
5 | 1008 |
* @throws phpmailerException |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
* @return boolean |
5 | 1010 |
*/ |
1011 |
public function setFrom($address, $name = '', $auto = true) |
|
1012 |
{ |
|
1013 |
$address = trim($address); |
|
1014 |
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
// Don't validate now addresses with IDN. Will be done in send(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
if (($pos = strrpos($address, '@')) === false or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
(!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
!$this->validateAddress($address)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
$error_message = $this->lang('invalid_address') . " (setFrom) $address"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
$this->setError($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
$this->edebug($error_message); |
5 | 1022 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
throw new phpmailerException($error_message); |
5 | 1024 |
} |
1025 |
return false; |
|
1026 |
} |
|
1027 |
$this->From = $address; |
|
1028 |
$this->FromName = $name; |
|
1029 |
if ($auto) { |
|
1030 |
if (empty($this->Sender)) { |
|
1031 |
$this->Sender = $address; |
|
1032 |
} |
|
1033 |
} |
|
1034 |
return true; |
|
1035 |
} |
|
1036 |
||
1037 |
/** |
|
1038 |
* Return the Message-ID header of the last email. |
|
1039 |
* Technically this is the value from the last time the headers were created, |
|
1040 |
* but it's also the message ID of the last sent message except in |
|
1041 |
* pathological cases. |
|
1042 |
* @return string |
|
1043 |
*/ |
|
1044 |
public function getLastMessageID() |
|
1045 |
{ |
|
1046 |
return $this->lastMessageID; |
|
1047 |
} |
|
1048 |
||
1049 |
/** |
|
1050 |
* Check that a string looks like an email address. |
|
1051 |
* @param string $address The email address to check |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* @param string|callable $patternselect A selector for the validation pattern to use : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
* * `auto` Pick best pattern automatically; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
* * `pcre` Use old PCRE implementation; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
* * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
* * `noregex` Don't use a regex: super fast, really dumb. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
* Alternatively you may pass in a callable to inject your own validator, for example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
* PHPMailer::validateAddress('user@example.com', function($address) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
* return (strpos($address, '@') !== false); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
* You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
* @return boolean |
5 | 1065 |
* @static |
1066 |
* @access public |
|
1067 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
public static function validateAddress($address, $patternselect = null) |
5 | 1069 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
if (is_null($patternselect)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
$patternselect = self::$validator; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
if (is_callable($patternselect)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
return call_user_func($patternselect, $address); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
//Reject line breaks in addresses; it's valid RFC5322, but not RFC5321 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1079 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1080 |
if (!$patternselect or $patternselect == 'auto') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
//Check this constant first so it works when extension_loaded() is disabled by safe mode |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
//Constant was added in PHP 5.2.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
if (defined('PCRE_VERSION')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
//This pattern can get stuck in a recursive loop in PCRE <= 8.0.2 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
if (version_compare(PCRE_VERSION, '8.0.3') >= 0) { |
5 | 1086 |
$patternselect = 'pcre8'; |
1087 |
} else { |
|
1088 |
$patternselect = 'pcre'; |
|
1089 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
} elseif (function_exists('extension_loaded') and extension_loaded('pcre')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
//Fall back to older PCRE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
$patternselect = 'pcre'; |
5 | 1093 |
} else { |
1094 |
//Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension |
|
1095 |
if (version_compare(PHP_VERSION, '5.2.0') >= 0) { |
|
1096 |
$patternselect = 'php'; |
|
1097 |
} else { |
|
1098 |
$patternselect = 'noregex'; |
|
1099 |
} |
|
1100 |
} |
|
1101 |
} |
|
1102 |
switch ($patternselect) { |
|
1103 |
case 'pcre8': |
|
1104 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
* Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains. |
5 | 1106 |
* @link http://squiloople.com/2009/12/20/email-address-validation/ |
1107 |
* @copyright 2009-2010 Michael Rushton |
|
1108 |
* Feel free to use and redistribute this code. But please keep this copyright notice. |
|
1109 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
return (boolean)preg_match( |
5 | 1111 |
'/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' . |
1112 |
'((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' . |
|
1113 |
'(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' . |
|
1114 |
'([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' . |
|
1115 |
'(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' . |
|
1116 |
'(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' . |
|
1117 |
'|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' . |
|
1118 |
'|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' . |
|
1119 |
'|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', |
|
1120 |
$address |
|
1121 |
); |
|
1122 |
case 'pcre': |
|
1123 |
//An older regex that doesn't need a recent PCRE |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
return (boolean)preg_match( |
5 | 1125 |
'/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' . |
1126 |
'[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' . |
|
1127 |
'(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' . |
|
1128 |
'@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' . |
|
1129 |
'(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' . |
|
1130 |
'[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' . |
|
1131 |
'::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' . |
|
1132 |
'[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' . |
|
1133 |
'::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' . |
|
1134 |
'|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD', |
|
1135 |
$address |
|
1136 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
case 'html5': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
* This is the pattern used in the HTML5 spec for validation of 'email' type form input elements. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
return (boolean)preg_match( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
'/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
'[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
$address |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
); |
5 | 1147 |
case 'noregex': |
1148 |
//No PCRE! Do something _very_ approximate! |
|
1149 |
//Check the address is 3 chars or longer and contains an @ that's not the first or last char |
|
1150 |
return (strlen($address) >= 3 |
|
1151 |
and strpos($address, '@') >= 1 |
|
1152 |
and strpos($address, '@') != strlen($address) - 1); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
case 'php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL); |
5 | 1156 |
} |
1157 |
} |
|
1158 |
||
1159 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
* Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
* "intl" and "mbstring" PHP extensions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* @return bool "true" if required functions for IDN support are present |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
public function idnSupported() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
// @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
* Converts IDN in given email address to its ASCII form, also known as punycode, if possible. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
* Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
* This function silently returns unmodified address if: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* - Conversion to punycode is impossible (e.g. required PHP functions are not available) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* or fails for any reason (e.g. domain has characters not allowed in an IDN) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
* @see PHPMailer::$CharSet |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1178 |
* @param string $address The email address to convert |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
* @return string The encoded address in ASCII form |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
public function punyencodeAddress($address) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
// Verify we have required functions, CharSet, and at-sign. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
if ($this->idnSupported() and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
!empty($this->CharSet) and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
($pos = strrpos($address, '@')) !== false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
$domain = substr($address, ++$pos); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
// Verify CharSet string is a valid one, and domain properly encoded in this CharSet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
$domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
idn_to_ascii($domain)) !== false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
return substr($address, 0, $pos) . $punycode; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1196 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
return $address; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
/** |
5 | 1202 |
* Create a message and send it. |
1203 |
* Uses the sending method specified by $Mailer. |
|
1204 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
* @return boolean false on error - See the ErrorInfo property for details of the error. |
5 | 1206 |
*/ |
1207 |
public function send() |
|
1208 |
{ |
|
1209 |
try { |
|
1210 |
if (!$this->preSend()) { |
|
1211 |
return false; |
|
1212 |
} |
|
1213 |
return $this->postSend(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
} catch (phpmailerException $exc) { |
5 | 1215 |
$this->mailHeader = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
$this->setError($exc->getMessage()); |
5 | 1217 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
throw $exc; |
5 | 1219 |
} |
1220 |
return false; |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
1224 |
/** |
|
1225 |
* Prepare a message for sending. |
|
1226 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @return boolean |
5 | 1228 |
*/ |
1229 |
public function preSend() |
|
1230 |
{ |
|
1231 |
try { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
$this->error_count = 0; // Reset errors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
$this->mailHeader = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
// Dequeue recipient and Reply-To addresses with IDN |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
$params[1] = $this->punyencodeAddress($params[1]); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
call_user_func_array(array($this, 'addAnAddress'), $params); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
} |
5 | 1240 |
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { |
1241 |
throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL); |
|
1242 |
} |
|
1243 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
// Validate From, Sender, and ConfirmReadingTo addresses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1245 |
foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
$this->$address_kind = trim($this->$address_kind); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1247 |
if (empty($this->$address_kind)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1248 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1249 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
$this->$address_kind = $this->punyencodeAddress($this->$address_kind); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
if (!$this->validateAddress($this->$address_kind)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
$error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->$address_kind; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
$this->setError($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
$this->edebug($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
if ($this->exceptions) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
throw new phpmailerException($error_message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
|
5 | 1262 |
// Set whether the message is multipart/alternative |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
if ($this->alternativeExists()) { |
5 | 1264 |
$this->ContentType = 'multipart/alternative'; |
1265 |
} |
|
1266 |
||
1267 |
$this->setMessageType(); |
|
1268 |
// Refuse to send an empty message unless we are specifically allowing it |
|
1269 |
if (!$this->AllowEmpty and empty($this->Body)) { |
|
1270 |
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL); |
|
1271 |
} |
|
1272 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1273 |
// Create body before headers in case body makes changes to headers (e.g. altering transfer encoding) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1274 |
$this->MIMEHeader = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1275 |
$this->MIMEBody = $this->createBody(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1276 |
// createBody may have added some headers, so retain them |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
$tempheaders = $this->MIMEHeader; |
5 | 1278 |
$this->MIMEHeader = $this->createHeader(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
$this->MIMEHeader .= $tempheaders; |
5 | 1280 |
|
1281 |
// To capture the complete message when using mail(), create |
|
1282 |
// an extra header list which createHeader() doesn't fold in |
|
1283 |
if ($this->Mailer == 'mail') { |
|
1284 |
if (count($this->to) > 0) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
$this->mailHeader .= $this->addrAppend('To', $this->to); |
5 | 1286 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
$this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;'); |
5 | 1288 |
} |
1289 |
$this->mailHeader .= $this->headerLine( |
|
1290 |
'Subject', |
|
1291 |
$this->encodeHeader($this->secureHeader(trim($this->Subject))) |
|
1292 |
); |
|
1293 |
} |
|
1294 |
||
1295 |
// Sign with DKIM if enabled |
|
1296 |
if (!empty($this->DKIM_domain) |
|
1297 |
&& !empty($this->DKIM_selector) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
&& (!empty($this->DKIM_private_string) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1299 |
|| (!empty($this->DKIM_private) && file_exists($this->DKIM_private)) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1300 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
) { |
5 | 1302 |
$header_dkim = $this->DKIM_Add( |
1303 |
$this->MIMEHeader . $this->mailHeader, |
|
1304 |
$this->encodeHeader($this->secureHeader($this->Subject)), |
|
1305 |
$this->MIMEBody |
|
1306 |
); |
|
1307 |
$this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF . |
|
1308 |
str_replace("\r\n", "\n", $header_dkim) . self::CRLF; |
|
1309 |
} |
|
1310 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
} catch (phpmailerException $exc) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
$this->setError($exc->getMessage()); |
5 | 1313 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
throw $exc; |
5 | 1315 |
} |
1316 |
return false; |
|
1317 |
} |
|
1318 |
} |
|
1319 |
||
1320 |
/** |
|
1321 |
* Actually send a message. |
|
1322 |
* Send the email via the selected mechanism |
|
1323 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
* @return boolean |
5 | 1325 |
*/ |
1326 |
public function postSend() |
|
1327 |
{ |
|
1328 |
try { |
|
1329 |
// Choose the mailer and send through it |
|
1330 |
switch ($this->Mailer) { |
|
1331 |
case 'sendmail': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
case 'qmail': |
5 | 1333 |
return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody); |
1334 |
case 'smtp': |
|
1335 |
return $this->smtpSend($this->MIMEHeader, $this->MIMEBody); |
|
1336 |
case 'mail': |
|
1337 |
return $this->mailSend($this->MIMEHeader, $this->MIMEBody); |
|
1338 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
$sendMethod = $this->Mailer.'Send'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
if (method_exists($this, $sendMethod)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
|
5 | 1344 |
return $this->mailSend($this->MIMEHeader, $this->MIMEBody); |
1345 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
} catch (phpmailerException $exc) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
$this->setError($exc->getMessage()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
$this->edebug($exc->getMessage()); |
5 | 1349 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
throw $exc; |
5 | 1351 |
} |
1352 |
} |
|
1353 |
return false; |
|
1354 |
} |
|
1355 |
||
1356 |
/** |
|
1357 |
* Send mail using the $Sendmail program. |
|
1358 |
* @param string $header The message headers |
|
1359 |
* @param string $body The message body |
|
1360 |
* @see PHPMailer::$Sendmail |
|
1361 |
* @throws phpmailerException |
|
1362 |
* @access protected |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
* @return boolean |
5 | 1364 |
*/ |
1365 |
protected function sendmailSend($header, $body) |
|
1366 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
// CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
if (!empty($this->Sender) and self::isShellSafe($this->Sender)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
if ($this->Mailer == 'qmail') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
$sendmailFmt = '%s -f%s'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
$sendmailFmt = '%s -oi -f%s -t'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
} |
5 | 1374 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
if ($this->Mailer == 'qmail') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
$sendmailFmt = '%s'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
$sendmailFmt = '%s -oi -t'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
} |
5 | 1380 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
// TODO: If possible, this should be changed to escapeshellarg. Needs thorough testing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
$sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
if ($this->SingleTo) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
foreach ($this->SingleToArray as $toAddr) { |
5 | 1387 |
if (!@$mail = popen($sendmail, 'w')) { |
1388 |
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
1389 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
fputs($mail, 'To: ' . $toAddr . "\n"); |
5 | 1391 |
fputs($mail, $header); |
1392 |
fputs($mail, $body); |
|
1393 |
$result = pclose($mail); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
$this->doCallback( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
($result == 0), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
array($toAddr), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
$this->cc, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
$this->bcc, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
$this->Subject, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
$body, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
$this->From |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
); |
5 | 1403 |
if ($result != 0) { |
1404 |
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
1405 |
} |
|
1406 |
} |
|
1407 |
} else { |
|
1408 |
if (!@$mail = popen($sendmail, 'w')) { |
|
1409 |
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
1410 |
} |
|
1411 |
fputs($mail, $header); |
|
1412 |
fputs($mail, $body); |
|
1413 |
$result = pclose($mail); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
$this->doCallback( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
($result == 0), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
$this->to, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
$this->cc, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
$this->bcc, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
$this->Subject, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
$body, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
$this->From |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
); |
5 | 1423 |
if ($result != 0) { |
1424 |
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL); |
|
1425 |
} |
|
1426 |
} |
|
1427 |
return true; |
|
1428 |
} |
|
1429 |
||
1430 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
* @param string $string The string to be validated |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
* @see https://github.com/PHPMailer/PHPMailer/issues/924 CVE-2016-10045 bug report |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
* @return boolean |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1439 |
protected static function isShellSafe($string) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
// Future-proof |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
if (escapeshellcmd($string) !== $string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
or !in_array(escapeshellarg($string), array("'$string'", "\"$string\"")) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
$length = strlen($string); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
for ($i = 0; $i < $length; $i++) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
$c = $string[$i]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1452 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1453 |
// All other characters have a special meaning in at least one common shell, including = and +. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
// Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
// Note that this does permit non-Latin alphanumeric characters based on the current locale. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
if (!ctype_alnum($c) && strpos('@_-.', $c) === false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1462 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
/** |
5 | 1465 |
* Send mail using the PHP mail() function. |
1466 |
* @param string $header The message headers |
|
1467 |
* @param string $body The message body |
|
1468 |
* @link http://www.php.net/manual/en/book.mail.php |
|
1469 |
* @throws phpmailerException |
|
1470 |
* @access protected |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
* @return boolean |
5 | 1472 |
*/ |
1473 |
protected function mailSend($header, $body) |
|
1474 |
{ |
|
1475 |
$toArr = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
foreach ($this->to as $toaddr) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
$toArr[] = $this->addrFormat($toaddr); |
5 | 1478 |
} |
1479 |
$to = implode(', ', $toArr); |
|
1480 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
$params = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
//This sets the SMTP envelope sender which gets turned into a return-path header by the receiver |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
if (!empty($this->Sender) and $this->validateAddress($this->Sender)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
// CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
if (self::isShellSafe($this->Sender)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
$params = sprintf('-f%s', $this->Sender); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
} |
5 | 1488 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
if (!empty($this->Sender) and !ini_get('safe_mode') and $this->validateAddress($this->Sender)) { |
5 | 1490 |
$old_from = ini_get('sendmail_from'); |
1491 |
ini_set('sendmail_from', $this->Sender); |
|
1492 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
$result = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
if ($this->SingleTo and count($toArr) > 1) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
foreach ($toArr as $toAddr) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
$result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
$this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From); |
5 | 1498 |
} |
1499 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
$result = $this->mailPassthru($to, $this->Subject, $body, $header, $params); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
$this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From); |
5 | 1502 |
} |
1503 |
if (isset($old_from)) { |
|
1504 |
ini_set('sendmail_from', $old_from); |
|
1505 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
if (!$result) { |
5 | 1507 |
throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL); |
1508 |
} |
|
1509 |
return true; |
|
0 | 1510 |
} |
5 | 1511 |
|
1512 |
/** |
|
1513 |
* Get an instance to use for SMTP operations. |
|
1514 |
* Override this function to load your own SMTP implementation |
|
1515 |
* @return SMTP |
|
1516 |
*/ |
|
1517 |
public function getSMTPInstance() |
|
1518 |
{ |
|
1519 |
if (!is_object($this->smtp)) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
require_once( 'class-smtp.php' ); |
5 | 1521 |
$this->smtp = new SMTP; |
1522 |
} |
|
1523 |
return $this->smtp; |
|
1524 |
} |
|
1525 |
||
1526 |
/** |
|
1527 |
* Send mail via SMTP. |
|
1528 |
* Returns false if there is a bad MAIL FROM, RCPT, or DATA input. |
|
1529 |
* Uses the PHPMailerSMTP class by default. |
|
1530 |
* @see PHPMailer::getSMTPInstance() to use a different class. |
|
1531 |
* @param string $header The message headers |
|
1532 |
* @param string $body The message body |
|
1533 |
* @throws phpmailerException |
|
1534 |
* @uses SMTP |
|
1535 |
* @access protected |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
* @return boolean |
5 | 1537 |
*/ |
1538 |
protected function smtpSend($header, $body) |
|
1539 |
{ |
|
1540 |
$bad_rcpt = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1541 |
if (!$this->smtpConnect($this->SMTPOptions)) { |
5 | 1542 |
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL); |
1543 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1544 |
if (!empty($this->Sender) and $this->validateAddress($this->Sender)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
$smtp_from = $this->Sender; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1546 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1547 |
$smtp_from = $this->From; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1548 |
} |
5 | 1549 |
if (!$this->smtp->mail($smtp_from)) { |
1550 |
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError())); |
|
1551 |
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL); |
|
1552 |
} |
|
1553 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
// Attempt to send to all recipients |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
foreach (array($this->to, $this->cc, $this->bcc) as $togroup) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
foreach ($togroup as $to) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
if (!$this->smtp->recipient($to[0])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
$error = $this->smtp->getError(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
$bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
$isSent = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
$isSent = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1564 |
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From); |
5 | 1565 |
} |
1566 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
// Only send the DATA command if we have viable recipients |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) { |
5 | 1570 |
throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL); |
1571 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
if ($this->SMTPKeepAlive) { |
5 | 1573 |
$this->smtp->reset(); |
1574 |
} else { |
|
1575 |
$this->smtp->quit(); |
|
1576 |
$this->smtp->close(); |
|
1577 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
//Create error message for any bad addresses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
if (count($bad_rcpt) > 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
$errstr = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
foreach ($bad_rcpt as $bad) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
$errstr .= $bad['to'] . ': ' . $bad['error']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1584 |
throw new phpmailerException( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
$this->lang('recipients_failed') . $errstr, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
self::STOP_CONTINUE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
} |
5 | 1589 |
return true; |
1590 |
} |
|
1591 |
||
1592 |
/** |
|
1593 |
* Initiate a connection to an SMTP server. |
|
1594 |
* Returns false if the operation failed. |
|
1595 |
* @param array $options An array of options compatible with stream_context_create() |
|
1596 |
* @uses SMTP |
|
1597 |
* @access public |
|
1598 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
* @return boolean |
5 | 1600 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1601 |
public function smtpConnect($options = null) |
5 | 1602 |
{ |
1603 |
if (is_null($this->smtp)) { |
|
1604 |
$this->smtp = $this->getSMTPInstance(); |
|
1605 |
} |
|
1606 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1607 |
//If no options are provided, use whatever is set in the instance |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1608 |
if (is_null($options)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1609 |
$options = $this->SMTPOptions; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1610 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1612 |
// Already connected? |
5 | 1613 |
if ($this->smtp->connected()) { |
1614 |
return true; |
|
1615 |
} |
|
1616 |
||
1617 |
$this->smtp->setTimeout($this->Timeout); |
|
1618 |
$this->smtp->setDebugLevel($this->SMTPDebug); |
|
1619 |
$this->smtp->setDebugOutput($this->Debugoutput); |
|
1620 |
$this->smtp->setVerp($this->do_verp); |
|
1621 |
$hosts = explode(';', $this->Host); |
|
1622 |
$lastexception = null; |
|
1623 |
||
1624 |
foreach ($hosts as $hostentry) { |
|
1625 |
$hostinfo = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
// Not a valid host entry |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
// $hostinfo[2]: optional ssl or tls prefix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
// $hostinfo[3]: the hostname |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
// $hostinfo[4]: optional port number |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
// The host string prefix can temporarily override the current setting for SMTPSecure |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
// If it's not specified, the default value is used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
$prefix = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
$secure = $this->SMTPSecure; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
$tls = ($this->SMTPSecure == 'tls'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
$prefix = 'ssl://'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
$tls = false; // Can't have SSL and TLS at the same time |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
$secure = 'ssl'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
} elseif ($hostinfo[2] == 'tls') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
$tls = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
// tls doesn't use a prefix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
$secure = 'tls'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1647 |
//Do we need the OpenSSL extension? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
$sslext = defined('OPENSSL_ALGO_SHA1'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1649 |
if ('tls' === $secure or 'ssl' === $secure) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
if (!$sslext) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1655 |
$host = $hostinfo[3]; |
5 | 1656 |
$port = $this->Port; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
$tport = (integer)$hostinfo[4]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
if ($tport > 0 and $tport < 65536) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
$port = $tport; |
5 | 1660 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { |
5 | 1662 |
try { |
1663 |
if ($this->Helo) { |
|
1664 |
$hello = $this->Helo; |
|
1665 |
} else { |
|
1666 |
$hello = $this->serverHostname(); |
|
1667 |
} |
|
1668 |
$this->smtp->hello($hello); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
//Automatically enable TLS encryption if: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1670 |
// * it's not disabled |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
// * we have openssl extension |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
// * we are not already using SSL |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1673 |
// * the server offers STARTTLS |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
$tls = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
} |
5 | 1677 |
if ($tls) { |
1678 |
if (!$this->smtp->startTLS()) { |
|
1679 |
throw new phpmailerException($this->lang('connect_host')); |
|
1680 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
// We must resend EHLO after TLS negotiation |
5 | 1682 |
$this->smtp->hello($hello); |
1683 |
} |
|
1684 |
if ($this->SMTPAuth) { |
|
1685 |
if (!$this->smtp->authenticate( |
|
1686 |
$this->Username, |
|
1687 |
$this->Password, |
|
1688 |
$this->AuthType, |
|
1689 |
$this->Realm, |
|
1690 |
$this->Workstation |
|
1691 |
) |
|
1692 |
) { |
|
1693 |
throw new phpmailerException($this->lang('authenticate')); |
|
1694 |
} |
|
1695 |
} |
|
1696 |
return true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1697 |
} catch (phpmailerException $exc) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
$lastexception = $exc; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
$this->edebug($exc->getMessage()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1700 |
// We must have connected, but then failed TLS or Auth, so close connection nicely |
5 | 1701 |
$this->smtp->quit(); |
1702 |
} |
|
1703 |
} |
|
1704 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
// If we get here, all connection attempts have failed, so close connection hard |
5 | 1706 |
$this->smtp->close(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1707 |
// As we've caught all exceptions, just report whatever the last one was |
5 | 1708 |
if ($this->exceptions and !is_null($lastexception)) { |
1709 |
throw $lastexception; |
|
1710 |
} |
|
1711 |
return false; |
|
1712 |
} |
|
1713 |
||
1714 |
/** |
|
1715 |
* Close the active SMTP session if one exists. |
|
1716 |
* @return void |
|
1717 |
*/ |
|
1718 |
public function smtpClose() |
|
1719 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
if (is_a($this->smtp, 'SMTP')) { |
5 | 1721 |
if ($this->smtp->connected()) { |
1722 |
$this->smtp->quit(); |
|
1723 |
$this->smtp->close(); |
|
1724 |
} |
|
1725 |
} |
|
0 | 1726 |
} |
5 | 1727 |
|
1728 |
/** |
|
1729 |
* Set the language for error messages. |
|
1730 |
* Returns false if it cannot load the language file. |
|
1731 |
* The default language is English. |
|
1732 |
* @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr") |
|
1733 |
* @param string $lang_path Path to the language file directory, with trailing separator (slash) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
* @return boolean |
5 | 1735 |
* @access public |
1736 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
public function setLanguage($langcode = 'en', $lang_path = '') |
5 | 1738 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
// Backwards compatibility for renamed language codes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
$renamed_langcodes = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
'br' => 'pt_br', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
'cz' => 'cs', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
'dk' => 'da', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
'no' => 'nb', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
'se' => 'sv', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
if (isset($renamed_langcodes[$langcode])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
$langcode = $renamed_langcodes[$langcode]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
// Define full set of translatable strings in English |
5 | 1753 |
$PHPMAILER_LANG = array( |
1754 |
'authenticate' => 'SMTP Error: Could not authenticate.', |
|
1755 |
'connect_host' => 'SMTP Error: Could not connect to SMTP host.', |
|
1756 |
'data_not_accepted' => 'SMTP Error: data not accepted.', |
|
1757 |
'empty_message' => 'Message body empty', |
|
1758 |
'encoding' => 'Unknown encoding: ', |
|
1759 |
'execute' => 'Could not execute: ', |
|
1760 |
'file_access' => 'Could not access file: ', |
|
1761 |
'file_open' => 'File Error: Could not open file: ', |
|
1762 |
'from_failed' => 'The following From address failed: ', |
|
1763 |
'instantiate' => 'Could not instantiate mail function.', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
'invalid_address' => 'Invalid address: ', |
5 | 1765 |
'mailer_not_supported' => ' mailer is not supported.', |
1766 |
'provide_address' => 'You must provide at least one recipient email address.', |
|
1767 |
'recipients_failed' => 'SMTP Error: The following recipients failed: ', |
|
1768 |
'signing' => 'Signing Error: ', |
|
1769 |
'smtp_connect_failed' => 'SMTP connect() failed.', |
|
1770 |
'smtp_error' => 'SMTP server error: ', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
'variable_set' => 'Cannot set or reset variable: ', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
'extension_missing' => 'Extension missing: ' |
5 | 1773 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
if (empty($lang_path)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
// Calculate an absolute path so it can work if CWD is not here |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
$lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
//Validate $langcode |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
if (!preg_match('/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
$langcode = 'en'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
$foundlang = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
$lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
// There is no English translation file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
if ($langcode != 'en') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
// Make sure language file path is readable |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
if (!is_readable($lang_file)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
$foundlang = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
// Overwrite language-specific strings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
// This way we'll never have missing translation keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
$foundlang = include $lang_file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
} |
5 | 1794 |
} |
1795 |
$this->language = $PHPMAILER_LANG; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
return (boolean)$foundlang; // Returns false if language not found |
5 | 1797 |
} |
1798 |
||
1799 |
/** |
|
1800 |
* Get the array of strings for the current language. |
|
1801 |
* @return array |
|
1802 |
*/ |
|
1803 |
public function getTranslations() |
|
1804 |
{ |
|
1805 |
return $this->language; |
|
1806 |
} |
|
1807 |
||
1808 |
/** |
|
1809 |
* Create recipient headers. |
|
1810 |
* @access public |
|
1811 |
* @param string $type |
|
1812 |
* @param array $addr An array of recipient, |
|
1813 |
* where each recipient is a 2-element indexed array with element 0 containing an address |
|
1814 |
* and element 1 containing a name, like: |
|
1815 |
* array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User')) |
|
1816 |
* @return string |
|
1817 |
*/ |
|
1818 |
public function addrAppend($type, $addr) |
|
1819 |
{ |
|
1820 |
$addresses = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
foreach ($addr as $address) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
$addresses[] = $this->addrFormat($address); |
5 | 1823 |
} |
1824 |
return $type . ': ' . implode(', ', $addresses) . $this->LE; |
|
1825 |
} |
|
1826 |
||
1827 |
/** |
|
1828 |
* Format an address for use in a message header. |
|
1829 |
* @access public |
|
1830 |
* @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name |
|
1831 |
* like array('joe@example.com', 'Joe User') |
|
1832 |
* @return string |
|
1833 |
*/ |
|
1834 |
public function addrFormat($addr) |
|
1835 |
{ |
|
1836 |
if (empty($addr[1])) { // No name provided |
|
1837 |
return $this->secureHeader($addr[0]); |
|
1838 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1839 |
return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader( |
5 | 1840 |
$addr[0] |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1841 |
) . '>'; |
5 | 1842 |
} |
1843 |
} |
|
1844 |
||
1845 |
/** |
|
1846 |
* Word-wrap message. |
|
1847 |
* For use with mailers that do not automatically perform wrapping |
|
1848 |
* and for quoted-printable encoded messages. |
|
1849 |
* Original written by philippe. |
|
1850 |
* @param string $message The message to wrap |
|
1851 |
* @param integer $length The line length to wrap to |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1852 |
* @param boolean $qp_mode Whether to run in Quoted-Printable mode |
5 | 1853 |
* @access public |
1854 |
* @return string |
|
1855 |
*/ |
|
1856 |
public function wrapText($message, $length, $qp_mode = false) |
|
1857 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
if ($qp_mode) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1859 |
$soft_break = sprintf(' =%s', $this->LE); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1860 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1861 |
$soft_break = $this->LE; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1862 |
} |
5 | 1863 |
// If utf-8 encoding is used, we will need to make sure we don't |
1864 |
// split multibyte characters when we wrap |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1865 |
$is_utf8 = (strtolower($this->CharSet) == 'utf-8'); |
5 | 1866 |
$lelen = strlen($this->LE); |
1867 |
$crlflen = strlen(self::CRLF); |
|
1868 |
||
1869 |
$message = $this->fixEOL($message); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1870 |
//Remove a trailing line break |
5 | 1871 |
if (substr($message, -$lelen) == $this->LE) { |
1872 |
$message = substr($message, 0, -$lelen); |
|
1873 |
} |
|
1874 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
//Split message into lines |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
$lines = explode($this->LE, $message); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
//Message will be rebuilt in here |
5 | 1878 |
$message = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
foreach ($lines as $line) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
$words = explode(' ', $line); |
5 | 1881 |
$buf = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1882 |
$firstword = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1883 |
foreach ($words as $word) { |
5 | 1884 |
if ($qp_mode and (strlen($word) > $length)) { |
1885 |
$space_left = $length - strlen($buf) - $crlflen; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
if (!$firstword) { |
5 | 1887 |
if ($space_left > 20) { |
1888 |
$len = $space_left; |
|
1889 |
if ($is_utf8) { |
|
1890 |
$len = $this->utf8CharBoundary($word, $len); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1891 |
} elseif (substr($word, $len - 1, 1) == '=') { |
5 | 1892 |
$len--; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
} elseif (substr($word, $len - 2, 1) == '=') { |
5 | 1894 |
$len -= 2; |
1895 |
} |
|
1896 |
$part = substr($word, 0, $len); |
|
1897 |
$word = substr($word, $len); |
|
1898 |
$buf .= ' ' . $part; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1899 |
$message .= $buf . sprintf('=%s', self::CRLF); |
5 | 1900 |
} else { |
1901 |
$message .= $buf . $soft_break; |
|
1902 |
} |
|
1903 |
$buf = ''; |
|
1904 |
} |
|
1905 |
while (strlen($word) > 0) { |
|
1906 |
if ($length <= 0) { |
|
1907 |
break; |
|
1908 |
} |
|
1909 |
$len = $length; |
|
1910 |
if ($is_utf8) { |
|
1911 |
$len = $this->utf8CharBoundary($word, $len); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
} elseif (substr($word, $len - 1, 1) == '=') { |
5 | 1913 |
$len--; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
} elseif (substr($word, $len - 2, 1) == '=') { |
5 | 1915 |
$len -= 2; |
1916 |
} |
|
1917 |
$part = substr($word, 0, $len); |
|
1918 |
$word = substr($word, $len); |
|
1919 |
||
1920 |
if (strlen($word) > 0) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
$message .= $part . sprintf('=%s', self::CRLF); |
5 | 1922 |
} else { |
1923 |
$buf = $part; |
|
1924 |
} |
|
1925 |
} |
|
1926 |
} else { |
|
1927 |
$buf_o = $buf; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1928 |
if (!$firstword) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
$buf .= ' '; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1930 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1931 |
$buf .= $word; |
5 | 1932 |
|
1933 |
if (strlen($buf) > $length and $buf_o != '') { |
|
1934 |
$message .= $buf_o . $soft_break; |
|
1935 |
$buf = $word; |
|
1936 |
} |
|
1937 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
$firstword = false; |
5 | 1939 |
} |
1940 |
$message .= $buf . self::CRLF; |
|
1941 |
} |
|
1942 |
||
1943 |
return $message; |
|
1944 |
} |
|
1945 |
||
1946 |
/** |
|
1947 |
* Find the last character boundary prior to $maxLength in a utf-8 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1948 |
* quoted-printable encoded string. |
5 | 1949 |
* Original written by Colin Brown. |
1950 |
* @access public |
|
1951 |
* @param string $encodedText utf-8 QP text |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
* @param integer $maxLength Find the last character boundary prior to this length |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1953 |
* @return integer |
5 | 1954 |
*/ |
1955 |
public function utf8CharBoundary($encodedText, $maxLength) |
|
1956 |
{ |
|
1957 |
$foundSplitPos = false; |
|
1958 |
$lookBack = 3; |
|
1959 |
while (!$foundSplitPos) { |
|
1960 |
$lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
$encodedCharPos = strpos($lastChunk, '='); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
if (false !== $encodedCharPos) { |
5 | 1963 |
// Found start of encoded character byte within $lookBack block. |
1964 |
// Check the encoded byte value (the 2 chars after the '=') |
|
1965 |
$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); |
|
1966 |
$dec = hexdec($hex); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
if ($dec < 128) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1968 |
// Single byte character. |
5 | 1969 |
// If the encoded char was found at pos 0, it will fit |
1970 |
// otherwise reduce maxLength to start of the encoded char |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
if ($encodedCharPos > 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
$maxLength = $maxLength - ($lookBack - $encodedCharPos); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
} |
5 | 1974 |
$foundSplitPos = true; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
} elseif ($dec >= 192) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1976 |
// First byte of a multi byte character |
5 | 1977 |
// Reduce maxLength to split at start of character |
1978 |
$maxLength = $maxLength - ($lookBack - $encodedCharPos); |
|
1979 |
$foundSplitPos = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
} elseif ($dec < 192) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
// Middle byte of a multi byte character, look further back |
5 | 1982 |
$lookBack += 3; |
1983 |
} |
|
1984 |
} else { |
|
1985 |
// No encoded character found |
|
1986 |
$foundSplitPos = true; |
|
1987 |
} |
|
1988 |
} |
|
1989 |
return $maxLength; |
|
0 | 1990 |
} |
1991 |
||
5 | 1992 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
* Apply word wrapping to the message body. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
* Wraps the message body to the number of chars set in the WordWrap property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1995 |
* You should only do this to plain-text bodies as wrapping HTML tags may break them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1996 |
* This is called automatically by createBody(), so you don't need to call it yourself. |
5 | 1997 |
* @access public |
1998 |
* @return void |
|
1999 |
*/ |
|
2000 |
public function setWordWrap() |
|
2001 |
{ |
|
2002 |
if ($this->WordWrap < 1) { |
|
2003 |
return; |
|
2004 |
} |
|
0 | 2005 |
|
5 | 2006 |
switch ($this->message_type) { |
2007 |
case 'alt': |
|
2008 |
case 'alt_inline': |
|
2009 |
case 'alt_attach': |
|
2010 |
case 'alt_inline_attach': |
|
2011 |
$this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap); |
|
2012 |
break; |
|
2013 |
default: |
|
2014 |
$this->Body = $this->wrapText($this->Body, $this->WordWrap); |
|
2015 |
break; |
|
2016 |
} |
|
0 | 2017 |
} |
2018 |
||
5 | 2019 |
/** |
2020 |
* Assemble message headers. |
|
2021 |
* @access public |
|
2022 |
* @return string The assembled headers |
|
2023 |
*/ |
|
2024 |
public function createHeader() |
|
2025 |
{ |
|
2026 |
$result = ''; |
|
2027 |
||
2028 |
if ($this->MessageDate == '') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
$this->MessageDate = self::rfcDate(); |
5 | 2030 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
$result .= $this->headerLine('Date', $this->MessageDate); |
5 | 2032 |
|
2033 |
// To be created automatically by mail() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
if ($this->SingleTo) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
if ($this->Mailer != 'mail') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
foreach ($this->to as $toaddr) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
$this->SingleToArray[] = $this->addrFormat($toaddr); |
5 | 2038 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
if (count($this->to) > 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
if ($this->Mailer != 'mail') { |
5 | 2043 |
$result .= $this->addrAppend('To', $this->to); |
2044 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
} elseif (count($this->cc) == 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
$result .= $this->headerLine('To', 'undisclosed-recipients:;'); |
5 | 2047 |
} |
2048 |
} |
|
2049 |
||
2050 |
$result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName))); |
|
2051 |
||
2052 |
// sendmail and mail() extract Cc from the header before sending |
|
2053 |
if (count($this->cc) > 0) { |
|
2054 |
$result .= $this->addrAppend('Cc', $this->cc); |
|
2055 |
} |
|
2056 |
||
2057 |
// sendmail and mail() extract Bcc from the header before sending |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
if (( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
$this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
and count($this->bcc) > 0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
) { |
5 | 2063 |
$result .= $this->addrAppend('Bcc', $this->bcc); |
2064 |
} |
|
2065 |
||
2066 |
if (count($this->ReplyTo) > 0) { |
|
2067 |
$result .= $this->addrAppend('Reply-To', $this->ReplyTo); |
|
2068 |
} |
|
2069 |
||
2070 |
// mail() sets the subject itself |
|
2071 |
if ($this->Mailer != 'mail') { |
|
2072 |
$result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject))); |
|
2073 |
} |
|
2074 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
// Only allow a custom message ID if it conforms to RFC 5322 section 3.6.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
// https://tools.ietf.org/html/rfc5322#section-3.6.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
if ('' != $this->MessageID and preg_match('/^<.*@.*>$/', $this->MessageID)) { |
5 | 2078 |
$this->lastMessageID = $this->MessageID; |
2079 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
$this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname()); |
5 | 2081 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
$result .= $this->headerLine('Message-ID', $this->lastMessageID); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
if (!is_null($this->Priority)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
$result .= $this->headerLine('X-Priority', $this->Priority); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
} |
5 | 2086 |
if ($this->XMailer == '') { |
2087 |
$result .= $this->headerLine( |
|
2088 |
'X-Mailer', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer)' |
5 | 2090 |
); |
2091 |
} else { |
|
2092 |
$myXmailer = trim($this->XMailer); |
|
2093 |
if ($myXmailer) { |
|
2094 |
$result .= $this->headerLine('X-Mailer', $myXmailer); |
|
2095 |
} |
|
2096 |
} |
|
0 | 2097 |
|
5 | 2098 |
if ($this->ConfirmReadingTo != '') { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
$result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>'); |
5 | 2100 |
} |
2101 |
||
2102 |
// Add custom headers |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
foreach ($this->CustomHeader as $header) { |
5 | 2104 |
$result .= $this->headerLine( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
trim($header[0]), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
$this->encodeHeader(trim($header[1])) |
5 | 2107 |
); |
2108 |
} |
|
2109 |
if (!$this->sign_key_file) { |
|
2110 |
$result .= $this->headerLine('MIME-Version', '1.0'); |
|
2111 |
$result .= $this->getMailMIME(); |
|
2112 |
} |
|
2113 |
||
2114 |
return $result; |
|
2115 |
} |
|
2116 |
||
2117 |
/** |
|
2118 |
* Get the message MIME type headers. |
|
2119 |
* @access public |
|
2120 |
* @return string |
|
2121 |
*/ |
|
2122 |
public function getMailMIME() |
|
2123 |
{ |
|
2124 |
$result = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2125 |
$ismultipart = true; |
5 | 2126 |
switch ($this->message_type) { |
2127 |
case 'inline': |
|
2128 |
$result .= $this->headerLine('Content-Type', 'multipart/related;'); |
|
2129 |
$result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
2130 |
break; |
|
2131 |
case 'attach': |
|
2132 |
case 'inline_attach': |
|
2133 |
case 'alt_attach': |
|
2134 |
case 'alt_inline_attach': |
|
2135 |
$result .= $this->headerLine('Content-Type', 'multipart/mixed;'); |
|
2136 |
$result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
2137 |
break; |
|
2138 |
case 'alt': |
|
2139 |
case 'alt_inline': |
|
2140 |
$result .= $this->headerLine('Content-Type', 'multipart/alternative;'); |
|
2141 |
$result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); |
|
2142 |
break; |
|
2143 |
default: |
|
2144 |
// Catches case 'plain': and case '': |
|
2145 |
$result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2146 |
$ismultipart = false; |
5 | 2147 |
break; |
2148 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2149 |
// RFC1341 part 5 says 7bit is assumed if not specified |
5 | 2150 |
if ($this->Encoding != '7bit') { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2151 |
// RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2152 |
if ($ismultipart) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2153 |
if ($this->Encoding == '8bit') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2154 |
$result .= $this->headerLine('Content-Transfer-Encoding', '8bit'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2155 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2156 |
// The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2158 |
$result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
} |
5 | 2160 |
} |
2161 |
||
2162 |
if ($this->Mailer != 'mail') { |
|
2163 |
$result .= $this->LE; |
|
2164 |
} |
|
2165 |
||
2166 |
return $result; |
|
2167 |
} |
|
2168 |
||
2169 |
/** |
|
2170 |
* Returns the whole MIME message. |
|
2171 |
* Includes complete headers and body. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
* Only valid post preSend(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
* @see PHPMailer::preSend() |
5 | 2174 |
* @access public |
2175 |
* @return string |
|
2176 |
*/ |
|
2177 |
public function getSentMIMEMessage() |
|
2178 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2179 |
return rtrim($this->MIMEHeader . $this->mailHeader, "\n\r") . self::CRLF . self::CRLF . $this->MIMEBody; |
5 | 2180 |
} |
2181 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
* Create unique ID |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2184 |
* @return string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2185 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2186 |
protected function generateId() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2187 |
return md5(uniqid(time())); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2188 |
} |
5 | 2189 |
|
2190 |
/** |
|
2191 |
* Assemble the message body. |
|
2192 |
* Returns an empty string on failure. |
|
2193 |
* @access public |
|
2194 |
* @throws phpmailerException |
|
2195 |
* @return string The assembled message body |
|
2196 |
*/ |
|
2197 |
public function createBody() |
|
2198 |
{ |
|
2199 |
$body = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
//Create unique IDs and preset boundaries |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
$this->uniqueid = $this->generateId(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2202 |
$this->boundary[1] = 'b1_' . $this->uniqueid; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
$this->boundary[2] = 'b2_' . $this->uniqueid; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
$this->boundary[3] = 'b3_' . $this->uniqueid; |
5 | 2205 |
|
2206 |
if ($this->sign_key_file) { |
|
2207 |
$body .= $this->getMailMIME() . $this->LE; |
|
0 | 2208 |
} |
2209 |
||
5 | 2210 |
$this->setWordWrap(); |
0 | 2211 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
$bodyEncoding = $this->Encoding; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2213 |
$bodyCharSet = $this->CharSet; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2214 |
//Can we do a 7-bit downgrade? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
$bodyEncoding = '7bit'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
//All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
$bodyCharSet = 'us-ascii'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2220 |
//If lines are too long, and we're not already using an encoding that will shorten them, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
//change to quoted-printable transfer encoding for the body part only |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
$bodyEncoding = 'quoted-printable'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2224 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2226 |
$altBodyEncoding = $this->Encoding; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2227 |
$altBodyCharSet = $this->CharSet; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
//Can we do a 7-bit downgrade? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2229 |
if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
$altBodyEncoding = '7bit'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
//All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
$altBodyCharSet = 'us-ascii'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
//If lines are too long, and we're not already using an encoding that will shorten them, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
//change to quoted-printable transfer encoding for the alt body part only |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
$altBodyEncoding = 'quoted-printable'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
//Use this as a preamble in all multipart message types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
$mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE; |
5 | 2241 |
switch ($this->message_type) { |
2242 |
case 'inline': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2243 |
$body .= $mimepre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2246 |
$body .= $this->LE . $this->LE; |
2247 |
$body .= $this->attachAll('inline', $this->boundary[1]); |
|
2248 |
break; |
|
2249 |
case 'attach': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2250 |
$body .= $mimepre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2253 |
$body .= $this->LE . $this->LE; |
2254 |
$body .= $this->attachAll('attachment', $this->boundary[1]); |
|
2255 |
break; |
|
2256 |
case 'inline_attach': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2257 |
$body .= $mimepre; |
5 | 2258 |
$body .= $this->textLine('--' . $this->boundary[1]); |
2259 |
$body .= $this->headerLine('Content-Type', 'multipart/related;'); |
|
2260 |
$body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); |
|
2261 |
$body .= $this->LE; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2262 |
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2264 |
$body .= $this->LE . $this->LE; |
2265 |
$body .= $this->attachAll('inline', $this->boundary[2]); |
|
2266 |
$body .= $this->LE; |
|
2267 |
$body .= $this->attachAll('attachment', $this->boundary[1]); |
|
2268 |
break; |
|
2269 |
case 'alt': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
$body .= $mimepre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
$body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
$body .= $this->encodeString($this->AltBody, $altBodyEncoding); |
5 | 2273 |
$body .= $this->LE . $this->LE; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
$body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2276 |
$body .= $this->LE . $this->LE; |
2277 |
if (!empty($this->Ical)) { |
|
2278 |
$body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', ''); |
|
2279 |
$body .= $this->encodeString($this->Ical, $this->Encoding); |
|
2280 |
$body .= $this->LE . $this->LE; |
|
2281 |
} |
|
2282 |
$body .= $this->endBoundary($this->boundary[1]); |
|
2283 |
break; |
|
2284 |
case 'alt_inline': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
$body .= $mimepre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2286 |
$body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
$body .= $this->encodeString($this->AltBody, $altBodyEncoding); |
5 | 2288 |
$body .= $this->LE . $this->LE; |
2289 |
$body .= $this->textLine('--' . $this->boundary[1]); |
|
2290 |
$body .= $this->headerLine('Content-Type', 'multipart/related;'); |
|
2291 |
$body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); |
|
2292 |
$body .= $this->LE; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2293 |
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2294 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2295 |
$body .= $this->LE . $this->LE; |
2296 |
$body .= $this->attachAll('inline', $this->boundary[2]); |
|
2297 |
$body .= $this->LE; |
|
2298 |
$body .= $this->endBoundary($this->boundary[1]); |
|
2299 |
break; |
|
2300 |
case 'alt_attach': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2301 |
$body .= $mimepre; |
5 | 2302 |
$body .= $this->textLine('--' . $this->boundary[1]); |
2303 |
$body .= $this->headerLine('Content-Type', 'multipart/alternative;'); |
|
2304 |
$body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); |
|
2305 |
$body .= $this->LE; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2306 |
$body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2307 |
$body .= $this->encodeString($this->AltBody, $altBodyEncoding); |
5 | 2308 |
$body .= $this->LE . $this->LE; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2309 |
$body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2310 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2311 |
$body .= $this->LE . $this->LE; |
2312 |
$body .= $this->endBoundary($this->boundary[2]); |
|
2313 |
$body .= $this->LE; |
|
2314 |
$body .= $this->attachAll('attachment', $this->boundary[1]); |
|
2315 |
break; |
|
2316 |
case 'alt_inline_attach': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
$body .= $mimepre; |
5 | 2318 |
$body .= $this->textLine('--' . $this->boundary[1]); |
2319 |
$body .= $this->headerLine('Content-Type', 'multipart/alternative;'); |
|
2320 |
$body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); |
|
2321 |
$body .= $this->LE; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
$body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
$body .= $this->encodeString($this->AltBody, $altBodyEncoding); |
5 | 2324 |
$body .= $this->LE . $this->LE; |
2325 |
$body .= $this->textLine('--' . $this->boundary[2]); |
|
2326 |
$body .= $this->headerLine('Content-Type', 'multipart/related;'); |
|
2327 |
$body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"'); |
|
2328 |
$body .= $this->LE; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2329 |
$body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2330 |
$body .= $this->encodeString($this->Body, $bodyEncoding); |
5 | 2331 |
$body .= $this->LE . $this->LE; |
2332 |
$body .= $this->attachAll('inline', $this->boundary[3]); |
|
2333 |
$body .= $this->LE; |
|
2334 |
$body .= $this->endBoundary($this->boundary[2]); |
|
2335 |
$body .= $this->LE; |
|
2336 |
$body .= $this->attachAll('attachment', $this->boundary[1]); |
|
2337 |
break; |
|
2338 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2339 |
// Catch case 'plain' and case '', applies to simple `text/plain` and `text/html` body content types |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
//Reset the `Encoding` property in case we changed it for line length reasons |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
$this->Encoding = $bodyEncoding; |
5 | 2342 |
$body .= $this->encodeString($this->Body, $this->Encoding); |
2343 |
break; |
|
2344 |
} |
|
0 | 2345 |
|
5 | 2346 |
if ($this->isError()) { |
2347 |
$body = ''; |
|
2348 |
} elseif ($this->sign_key_file) { |
|
2349 |
try { |
|
2350 |
if (!defined('PKCS7_TEXT')) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
throw new phpmailerException($this->lang('extension_missing') . 'openssl'); |
5 | 2352 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2353 |
// @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1 |
5 | 2354 |
$file = tempnam(sys_get_temp_dir(), 'mail'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2355 |
if (false === file_put_contents($file, $body)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2356 |
throw new phpmailerException($this->lang('signing') . ' Could not write temp file'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2357 |
} |
5 | 2358 |
$signed = tempnam(sys_get_temp_dir(), 'signed'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2359 |
//Workaround for PHP bug https://bugs.php.net/bug.php?id=69197 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2360 |
if (empty($this->sign_extracerts_file)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
$sign = @openssl_pkcs7_sign( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2362 |
$file, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2363 |
$signed, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2364 |
'file://' . realpath($this->sign_cert_file), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2366 |
null |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2369 |
$sign = @openssl_pkcs7_sign( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2370 |
$file, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2371 |
$signed, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2372 |
'file://' . realpath($this->sign_cert_file), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2373 |
array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2374 |
null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
PKCS7_DETACHED, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
$this->sign_extracerts_file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2377 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2378 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2379 |
if ($sign) { |
5 | 2380 |
@unlink($file); |
2381 |
$body = file_get_contents($signed); |
|
2382 |
@unlink($signed); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2383 |
//The message returned by openssl contains both headers and body, so need to split them up |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2384 |
$parts = explode("\n\n", $body, 2); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2385 |
$this->MIMEHeader .= $parts[0] . $this->LE . $this->LE; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
$body = $parts[1]; |
5 | 2387 |
} else { |
2388 |
@unlink($file); |
|
2389 |
@unlink($signed); |
|
2390 |
throw new phpmailerException($this->lang('signing') . openssl_error_string()); |
|
2391 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
} catch (phpmailerException $exc) { |
5 | 2393 |
$body = ''; |
2394 |
if ($this->exceptions) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
throw $exc; |
5 | 2396 |
} |
2397 |
} |
|
2398 |
} |
|
2399 |
return $body; |
|
0 | 2400 |
} |
2401 |
||
5 | 2402 |
/** |
2403 |
* Return the start of a message boundary. |
|
2404 |
* @access protected |
|
2405 |
* @param string $boundary |
|
2406 |
* @param string $charSet |
|
2407 |
* @param string $contentType |
|
2408 |
* @param string $encoding |
|
2409 |
* @return string |
|
2410 |
*/ |
|
2411 |
protected function getBoundary($boundary, $charSet, $contentType, $encoding) |
|
2412 |
{ |
|
2413 |
$result = ''; |
|
2414 |
if ($charSet == '') { |
|
2415 |
$charSet = $this->CharSet; |
|
2416 |
} |
|
2417 |
if ($contentType == '') { |
|
2418 |
$contentType = $this->ContentType; |
|
2419 |
} |
|
2420 |
if ($encoding == '') { |
|
2421 |
$encoding = $this->Encoding; |
|
2422 |
} |
|
2423 |
$result .= $this->textLine('--' . $boundary); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
$result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet); |
5 | 2425 |
$result .= $this->LE; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2426 |
// RFC1341 part 5 says 7bit is assumed if not specified |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2427 |
if ($encoding != '7bit') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2428 |
$result .= $this->headerLine('Content-Transfer-Encoding', $encoding); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2429 |
} |
5 | 2430 |
$result .= $this->LE; |
0 | 2431 |
|
5 | 2432 |
return $result; |
0 | 2433 |
} |
2434 |
||
5 | 2435 |
/** |
2436 |
* Return the end of a message boundary. |
|
2437 |
* @access protected |
|
2438 |
* @param string $boundary |
|
2439 |
* @return string |
|
2440 |
*/ |
|
2441 |
protected function endBoundary($boundary) |
|
2442 |
{ |
|
2443 |
return $this->LE . '--' . $boundary . '--' . $this->LE; |
|
0 | 2444 |
} |
2445 |
||
5 | 2446 |
/** |
2447 |
* Set the message type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2448 |
* PHPMailer only supports some preset message types, not arbitrary MIME structures. |
5 | 2449 |
* @access protected |
2450 |
* @return void |
|
2451 |
*/ |
|
2452 |
protected function setMessageType() |
|
2453 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
$type = array(); |
5 | 2455 |
if ($this->alternativeExists()) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2456 |
$type[] = 'alt'; |
5 | 2457 |
} |
2458 |
if ($this->inlineImageExists()) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2459 |
$type[] = 'inline'; |
5 | 2460 |
} |
2461 |
if ($this->attachmentExists()) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
$type[] = 'attach'; |
5 | 2463 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2464 |
$this->message_type = implode('_', $type); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
if ($this->message_type == '') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
//The 'plain' message_type refers to the message having a single body element, not that it is plain-text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
$this->message_type = 'plain'; |
5 | 2468 |
} |
0 | 2469 |
} |
2470 |
||
5 | 2471 |
/** |
2472 |
* Format a header line. |
|
2473 |
* @access public |
|
2474 |
* @param string $name |
|
2475 |
* @param string $value |
|
2476 |
* @return string |
|
2477 |
*/ |
|
2478 |
public function headerLine($name, $value) |
|
2479 |
{ |
|
2480 |
return $name . ': ' . $value . $this->LE; |
|
0 | 2481 |
} |
2482 |
||
5 | 2483 |
/** |
2484 |
* Return a formatted mail line. |
|
2485 |
* @access public |
|
2486 |
* @param string $value |
|
2487 |
* @return string |
|
2488 |
*/ |
|
2489 |
public function textLine($value) |
|
2490 |
{ |
|
2491 |
return $value . $this->LE; |
|
0 | 2492 |
} |
2493 |
||
5 | 2494 |
/** |
2495 |
* Add an attachment from a path on the filesystem. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
* Never use a user-supplied path to a file! |
5 | 2497 |
* Returns false if the file could not be found or read. |
2498 |
* @param string $path Path to the attachment. |
|
2499 |
* @param string $name Overrides the attachment name. |
|
2500 |
* @param string $encoding File encoding (see $Encoding). |
|
2501 |
* @param string $type File extension (MIME) type. |
|
2502 |
* @param string $disposition Disposition to use |
|
2503 |
* @throws phpmailerException |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2504 |
* @return boolean |
5 | 2505 |
*/ |
2506 |
public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') |
|
2507 |
{ |
|
2508 |
try { |
|
2509 |
if (!@is_file($path)) { |
|
2510 |
throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE); |
|
2511 |
} |
|
2512 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2513 |
// If a MIME type is not specified, try to work it out from the file name |
5 | 2514 |
if ($type == '') { |
2515 |
$type = self::filenameToType($path); |
|
2516 |
} |
|
0 | 2517 |
|
5 | 2518 |
$filename = basename($path); |
2519 |
if ($name == '') { |
|
2520 |
$name = $filename; |
|
2521 |
} |
|
2522 |
||
2523 |
$this->attachment[] = array( |
|
2524 |
0 => $path, |
|
2525 |
1 => $filename, |
|
2526 |
2 => $name, |
|
2527 |
3 => $encoding, |
|
2528 |
4 => $type, |
|
2529 |
5 => false, // isStringAttachment |
|
2530 |
6 => $disposition, |
|
2531 |
7 => 0 |
|
2532 |
); |
|
2533 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
} catch (phpmailerException $exc) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2535 |
$this->setError($exc->getMessage()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2536 |
$this->edebug($exc->getMessage()); |
5 | 2537 |
if ($this->exceptions) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2538 |
throw $exc; |
5 | 2539 |
} |
2540 |
return false; |
|
2541 |
} |
|
2542 |
return true; |
|
0 | 2543 |
} |
2544 |
||
5 | 2545 |
/** |
2546 |
* Return the array of attachments. |
|
2547 |
* @return array |
|
2548 |
*/ |
|
2549 |
public function getAttachments() |
|
2550 |
{ |
|
2551 |
return $this->attachment; |
|
0 | 2552 |
} |
2553 |
||
5 | 2554 |
/** |
2555 |
* Attach all file, string, and binary attachments to the message. |
|
2556 |
* Returns an empty string on failure. |
|
2557 |
* @access protected |
|
2558 |
* @param string $disposition_type |
|
2559 |
* @param string $boundary |
|
2560 |
* @return string |
|
2561 |
*/ |
|
2562 |
protected function attachAll($disposition_type, $boundary) |
|
2563 |
{ |
|
2564 |
// Return text of body |
|
2565 |
$mime = array(); |
|
2566 |
$cidUniq = array(); |
|
2567 |
$incl = array(); |
|
2568 |
||
2569 |
// Add all attachments |
|
2570 |
foreach ($this->attachment as $attachment) { |
|
2571 |
// Check if it is a valid disposition_filter |
|
2572 |
if ($attachment[6] == $disposition_type) { |
|
2573 |
// Check for string attachment |
|
2574 |
$string = ''; |
|
2575 |
$path = ''; |
|
2576 |
$bString = $attachment[5]; |
|
2577 |
if ($bString) { |
|
2578 |
$string = $attachment[0]; |
|
2579 |
} else { |
|
2580 |
$path = $attachment[0]; |
|
2581 |
} |
|
2582 |
||
2583 |
$inclhash = md5(serialize($attachment)); |
|
2584 |
if (in_array($inclhash, $incl)) { |
|
2585 |
continue; |
|
2586 |
} |
|
2587 |
$incl[] = $inclhash; |
|
2588 |
$name = $attachment[2]; |
|
2589 |
$encoding = $attachment[3]; |
|
2590 |
$type = $attachment[4]; |
|
2591 |
$disposition = $attachment[6]; |
|
2592 |
$cid = $attachment[7]; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2593 |
if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) { |
5 | 2594 |
continue; |
2595 |
} |
|
2596 |
$cidUniq[$cid] = true; |
|
0 | 2597 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
$mime[] = sprintf('--%s%s', $boundary, $this->LE); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
//Only include a filename property if we have one |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
if (!empty($name)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2601 |
$mime[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
'Content-Type: %s; name="%s"%s', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
$type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2604 |
$this->encodeHeader($this->secureHeader($name)), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
$this->LE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2606 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2607 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2608 |
$mime[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2609 |
'Content-Type: %s%s', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
$type, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
$this->LE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2612 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2613 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2614 |
// RFC1341 part 5 says 7bit is assumed if not specified |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2615 |
if ($encoding != '7bit') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2616 |
$mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2617 |
} |
5 | 2618 |
|
2619 |
if ($disposition == 'inline') { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2620 |
$mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE); |
5 | 2621 |
} |
2622 |
||
2623 |
// If a filename contains any of these chars, it should be quoted, |
|
2624 |
// but not otherwise: RFC2183 & RFC2045 5.1 |
|
2625 |
// Fixes a warning in IETF's msglint MIME checker |
|
2626 |
// Allow for bypassing the Content-Disposition header totally |
|
2627 |
if (!(empty($disposition))) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2628 |
$encoded_name = $this->encodeHeader($this->secureHeader($name)); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2629 |
if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) { |
5 | 2630 |
$mime[] = sprintf( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2631 |
'Content-Disposition: %s; filename="%s"%s', |
5 | 2632 |
$disposition, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2633 |
$encoded_name, |
5 | 2634 |
$this->LE . $this->LE |
2635 |
); |
|
2636 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2637 |
if (!empty($encoded_name)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2638 |
$mime[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2639 |
'Content-Disposition: %s; filename=%s%s', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2640 |
$disposition, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2641 |
$encoded_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2642 |
$this->LE . $this->LE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2643 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2645 |
$mime[] = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
'Content-Disposition: %s%s', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
$disposition, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
$this->LE . $this->LE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
} |
5 | 2651 |
} |
2652 |
} else { |
|
2653 |
$mime[] = $this->LE; |
|
2654 |
} |
|
2655 |
||
2656 |
// Encode as string attachment |
|
2657 |
if ($bString) { |
|
2658 |
$mime[] = $this->encodeString($string, $encoding); |
|
2659 |
if ($this->isError()) { |
|
2660 |
return ''; |
|
2661 |
} |
|
2662 |
$mime[] = $this->LE . $this->LE; |
|
2663 |
} else { |
|
2664 |
$mime[] = $this->encodeFile($path, $encoding); |
|
2665 |
if ($this->isError()) { |
|
2666 |
return ''; |
|
2667 |
} |
|
2668 |
$mime[] = $this->LE . $this->LE; |
|
2669 |
} |
|
2670 |
} |
|
2671 |
} |
|
2672 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2673 |
$mime[] = sprintf('--%s--%s', $boundary, $this->LE); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2674 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2675 |
return implode('', $mime); |
0 | 2676 |
} |
2677 |
||
5 | 2678 |
/** |
2679 |
* Encode a file attachment in requested format. |
|
2680 |
* Returns an empty string on failure. |
|
2681 |
* @param string $path The full path to the file |
|
2682 |
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
|
2683 |
* @throws phpmailerException |
|
2684 |
* @access protected |
|
2685 |
* @return string |
|
2686 |
*/ |
|
2687 |
protected function encodeFile($path, $encoding = 'base64') |
|
2688 |
{ |
|
2689 |
try { |
|
2690 |
if (!is_readable($path)) { |
|
2691 |
throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE); |
|
2692 |
} |
|
2693 |
$magic_quotes = get_magic_quotes_runtime(); |
|
2694 |
if ($magic_quotes) { |
|
2695 |
if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
set_magic_quotes_runtime(false); |
5 | 2697 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2698 |
//Doesn't exist in PHP 5.4, but we don't need to check because |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2699 |
//get_magic_quotes_runtime always returns false in 5.4+ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
//so it will never get here |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
ini_set('magic_quotes_runtime', false); |
5 | 2702 |
} |
2703 |
} |
|
2704 |
$file_buffer = file_get_contents($path); |
|
2705 |
$file_buffer = $this->encodeString($file_buffer, $encoding); |
|
2706 |
if ($magic_quotes) { |
|
2707 |
if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
2708 |
set_magic_quotes_runtime($magic_quotes); |
|
2709 |
} else { |
|
2710 |
ini_set('magic_quotes_runtime', $magic_quotes); |
|
2711 |
} |
|
2712 |
} |
|
2713 |
return $file_buffer; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2714 |
} catch (Exception $exc) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2715 |
$this->setError($exc->getMessage()); |
5 | 2716 |
return ''; |
0 | 2717 |
} |
5 | 2718 |
} |
2719 |
||
2720 |
/** |
|
2721 |
* Encode a string in requested format. |
|
2722 |
* Returns an empty string on failure. |
|
2723 |
* @param string $str The text to encode |
|
2724 |
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
|
2725 |
* @access public |
|
2726 |
* @return string |
|
2727 |
*/ |
|
2728 |
public function encodeString($str, $encoding = 'base64') |
|
2729 |
{ |
|
2730 |
$encoded = ''; |
|
2731 |
switch (strtolower($encoding)) { |
|
2732 |
case 'base64': |
|
2733 |
$encoded = chunk_split(base64_encode($str), 76, $this->LE); |
|
2734 |
break; |
|
2735 |
case '7bit': |
|
2736 |
case '8bit': |
|
2737 |
$encoded = $this->fixEOL($str); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2738 |
// Make sure it ends with a line break |
5 | 2739 |
if (substr($encoded, -(strlen($this->LE))) != $this->LE) { |
2740 |
$encoded .= $this->LE; |
|
2741 |
} |
|
2742 |
break; |
|
2743 |
case 'binary': |
|
2744 |
$encoded = $str; |
|
2745 |
break; |
|
2746 |
case 'quoted-printable': |
|
2747 |
$encoded = $this->encodeQP($str); |
|
2748 |
break; |
|
2749 |
default: |
|
2750 |
$this->setError($this->lang('encoding') . $encoding); |
|
2751 |
break; |
|
0 | 2752 |
} |
5 | 2753 |
return $encoded; |
0 | 2754 |
} |
2755 |
||
5 | 2756 |
/** |
2757 |
* Encode a header string optimally. |
|
2758 |
* Picks shortest of Q, B, quoted-printable or none. |
|
2759 |
* @access public |
|
2760 |
* @param string $str |
|
2761 |
* @param string $position |
|
2762 |
* @return string |
|
2763 |
*/ |
|
2764 |
public function encodeHeader($str, $position = 'text') |
|
2765 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2766 |
$matchcount = 0; |
5 | 2767 |
switch (strtolower($position)) { |
2768 |
case 'phrase': |
|
2769 |
if (!preg_match('/[\200-\377]/', $str)) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
// Can't use addslashes as we don't know the value of magic_quotes_sybase |
5 | 2771 |
$encoded = addcslashes($str, "\0..\37\177\\\""); |
2772 |
if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { |
|
2773 |
return ($encoded); |
|
2774 |
} else { |
|
2775 |
return ("\"$encoded\""); |
|
2776 |
} |
|
2777 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
$matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
5 | 2779 |
break; |
2780 |
/** @noinspection PhpMissingBreakStatementInspection */ |
|
2781 |
case 'comment': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2782 |
$matchcount = preg_match_all('/[()"]/', $str, $matches); |
5 | 2783 |
// Intentional fall-through |
2784 |
case 'text': |
|
2785 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
$matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
5 | 2787 |
break; |
2788 |
} |
|
0 | 2789 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2790 |
//There are no chars that need encoding |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2791 |
if ($matchcount == 0) { |
5 | 2792 |
return ($str); |
2793 |
} |
|
0 | 2794 |
|
5 | 2795 |
$maxlen = 75 - 7 - strlen($this->CharSet); |
2796 |
// Try to select the encoding which should produce the shortest output |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2797 |
if ($matchcount > strlen($str) / 3) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2798 |
// More than a third of the content will need encoding, so B encoding will be most efficient |
5 | 2799 |
$encoding = 'B'; |
2800 |
if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) { |
|
2801 |
// Use a custom function which correctly encodes and wraps long |
|
2802 |
// multibyte strings without breaking lines within a character |
|
2803 |
$encoded = $this->base64EncodeWrapMB($str, "\n"); |
|
2804 |
} else { |
|
2805 |
$encoded = base64_encode($str); |
|
2806 |
$maxlen -= $maxlen % 4; |
|
2807 |
$encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
|
2808 |
} |
|
0 | 2809 |
} else { |
5 | 2810 |
$encoding = 'Q'; |
2811 |
$encoded = $this->encodeQ($str, $position); |
|
2812 |
$encoded = $this->wrapText($encoded, $maxlen, true); |
|
2813 |
$encoded = str_replace('=' . self::CRLF, "\n", trim($encoded)); |
|
0 | 2814 |
} |
2815 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
$encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded); |
5 | 2817 |
$encoded = trim(str_replace("\n", $this->LE, $encoded)); |
2818 |
||
2819 |
return $encoded; |
|
2820 |
} |
|
0 | 2821 |
|
5 | 2822 |
/** |
2823 |
* Check if a string contains multi-byte characters. |
|
2824 |
* @access public |
|
2825 |
* @param string $str multi-byte text to wrap encode |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2826 |
* @return boolean |
5 | 2827 |
*/ |
2828 |
public function hasMultiBytes($str) |
|
2829 |
{ |
|
2830 |
if (function_exists('mb_strlen')) { |
|
2831 |
return (strlen($str) > mb_strlen($str, $this->CharSet)); |
|
2832 |
} else { // Assume no multibytes (we can't handle without mbstring functions anyway) |
|
2833 |
return false; |
|
2834 |
} |
|
2835 |
} |
|
0 | 2836 |
|
5 | 2837 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
* Does a string contain any 8-bit chars (in any charset)? |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
* @param string $text |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
* @return boolean |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
public function has8bitChars($text) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
return (boolean)preg_match('/[\x80-\xFF]/', $text); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
/** |
5 | 2848 |
* Encode and wrap long multibyte strings for mail headers |
2849 |
* without breaking lines within a character. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
* Adapted from a function by paravoid |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283 |
5 | 2852 |
* @access public |
2853 |
* @param string $str multi-byte text to wrap encode |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
* @param string $linebreak string to use as linefeed/end-of-line |
5 | 2855 |
* @return string |
2856 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
public function base64EncodeWrapMB($str, $linebreak = null) |
5 | 2858 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
$start = '=?' . $this->CharSet . '?B?'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
$end = '?='; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
$encoded = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
if ($linebreak === null) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
$linebreak = $this->LE; |
0 | 2864 |
} |
2865 |
||
5 | 2866 |
$mb_length = mb_strlen($str, $this->CharSet); |
2867 |
// Each line must have length <= 75, including $start and $end |
|
2868 |
$length = 75 - strlen($start) - strlen($end); |
|
2869 |
// Average multi-byte ratio |
|
2870 |
$ratio = $mb_length / strlen($str); |
|
2871 |
// Base64 has a 4:3 ratio |
|
2872 |
$avgLength = floor($length * $ratio * .75); |
|
2873 |
||
2874 |
for ($i = 0; $i < $mb_length; $i += $offset) { |
|
2875 |
$lookBack = 0; |
|
2876 |
do { |
|
2877 |
$offset = $avgLength - $lookBack; |
|
2878 |
$chunk = mb_substr($str, $i, $offset, $this->CharSet); |
|
2879 |
$chunk = base64_encode($chunk); |
|
2880 |
$lookBack++; |
|
2881 |
} while (strlen($chunk) > $length); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
$encoded .= $chunk . $linebreak; |
5 | 2883 |
} |
2884 |
||
2885 |
// Chomp the last linefeed |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
$encoded = substr($encoded, 0, -strlen($linebreak)); |
5 | 2887 |
return $encoded; |
2888 |
} |
|
0 | 2889 |
|
5 | 2890 |
/** |
2891 |
* Encode a string in quoted-printable format. |
|
2892 |
* According to RFC2045 section 6.7. |
|
2893 |
* @access public |
|
2894 |
* @param string $string The text to encode |
|
2895 |
* @param integer $line_max Number of chars allowed on a line before wrapping |
|
2896 |
* @return string |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2897 |
* @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment |
5 | 2898 |
*/ |
2899 |
public function encodeQP($string, $line_max = 76) |
|
2900 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2901 |
// Use native function if it's available (>= PHP5.3) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
if (function_exists('quoted_printable_encode')) { |
5 | 2903 |
return quoted_printable_encode($string); |
0 | 2904 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
// Fall back to a pure PHP implementation |
5 | 2906 |
$string = str_replace( |
2907 |
array('%20', '%0D%0A.', '%0D%0A', '%'), |
|
2908 |
array(' ', "\r\n=2E", "\r\n", '='), |
|
2909 |
rawurlencode($string) |
|
2910 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2911 |
return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string); |
5 | 2912 |
} |
2913 |
||
2914 |
/** |
|
2915 |
* Backward compatibility wrapper for an old QP encoding function that was removed. |
|
2916 |
* @see PHPMailer::encodeQP() |
|
2917 |
* @access public |
|
2918 |
* @param string $string |
|
2919 |
* @param integer $line_max |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
* @param boolean $space_conv |
5 | 2921 |
* @return string |
2922 |
* @deprecated Use encodeQP instead. |
|
2923 |
*/ |
|
2924 |
public function encodeQPphp( |
|
2925 |
$string, |
|
2926 |
$line_max = 76, |
|
2927 |
/** @noinspection PhpUnusedParameterInspection */ $space_conv = false |
|
2928 |
) { |
|
2929 |
return $this->encodeQP($string, $line_max); |
|
0 | 2930 |
} |
2931 |
||
5 | 2932 |
/** |
2933 |
* Encode a string using Q encoding. |
|
2934 |
* @link http://tools.ietf.org/html/rfc2047 |
|
2935 |
* @param string $str the text to encode |
|
2936 |
* @param string $position Where the text is going to be used, see the RFC for what that means |
|
2937 |
* @access public |
|
2938 |
* @return string |
|
2939 |
*/ |
|
2940 |
public function encodeQ($str, $position = 'text') |
|
2941 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2942 |
// There should not be any EOL in the string |
5 | 2943 |
$pattern = ''; |
2944 |
$encoded = str_replace(array("\r", "\n"), '', $str); |
|
2945 |
switch (strtolower($position)) { |
|
2946 |
case 'phrase': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
// RFC 2047 section 5.3 |
5 | 2948 |
$pattern = '^A-Za-z0-9!*+\/ -'; |
2949 |
break; |
|
2950 |
/** @noinspection PhpMissingBreakStatementInspection */ |
|
2951 |
case 'comment': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2952 |
// RFC 2047 section 5.2 |
5 | 2953 |
$pattern = '\(\)"'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2954 |
// intentional fall-through |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2955 |
// for this reason we build the $pattern without including delimiters and [] |
5 | 2956 |
case 'text': |
2957 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2958 |
// RFC 2047 section 5.1 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2959 |
// Replace every high ascii, control, =, ? and _ characters |
5 | 2960 |
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern; |
2961 |
break; |
|
0 | 2962 |
} |
5 | 2963 |
$matches = array(); |
2964 |
if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2965 |
// If the string contains an '=', make sure it's the first thing we replace |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2966 |
// so as to avoid double-encoding |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2967 |
$eqkey = array_search('=', $matches[0]); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2968 |
if (false !== $eqkey) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2969 |
unset($matches[0][$eqkey]); |
5 | 2970 |
array_unshift($matches[0], '='); |
2971 |
} |
|
2972 |
foreach (array_unique($matches[0]) as $char) { |
|
2973 |
$encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); |
|
2974 |
} |
|
0 | 2975 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
// Replace every spaces to _ (more readable than =20) |
5 | 2977 |
return str_replace(' ', '_', $encoded); |
0 | 2978 |
} |
2979 |
||
5 | 2980 |
/** |
2981 |
* Add a string or binary attachment (non-filesystem). |
|
2982 |
* This method can be used to attach ascii or binary data, |
|
2983 |
* such as a BLOB record from a database. |
|
2984 |
* @param string $string String attachment data. |
|
2985 |
* @param string $filename Name of the attachment. |
|
2986 |
* @param string $encoding File encoding (see $Encoding). |
|
2987 |
* @param string $type File extension (MIME) type. |
|
2988 |
* @param string $disposition Disposition to use |
|
2989 |
* @return void |
|
2990 |
*/ |
|
2991 |
public function addStringAttachment( |
|
2992 |
$string, |
|
2993 |
$filename, |
|
2994 |
$encoding = 'base64', |
|
2995 |
$type = '', |
|
2996 |
$disposition = 'attachment' |
|
2997 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2998 |
// If a MIME type is not specified, try to work it out from the file name |
5 | 2999 |
if ($type == '') { |
3000 |
$type = self::filenameToType($filename); |
|
0 | 3001 |
} |
5 | 3002 |
// Append to $attachment array |
3003 |
$this->attachment[] = array( |
|
3004 |
0 => $string, |
|
3005 |
1 => $filename, |
|
3006 |
2 => basename($filename), |
|
3007 |
3 => $encoding, |
|
3008 |
4 => $type, |
|
3009 |
5 => true, // isStringAttachment |
|
3010 |
6 => $disposition, |
|
3011 |
7 => 0 |
|
3012 |
); |
|
0 | 3013 |
} |
3014 |
||
5 | 3015 |
/** |
3016 |
* Add an embedded (inline) attachment from a file. |
|
3017 |
* This can include images, sounds, and just about any other document type. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* These differ from 'regular' attachments in that they are intended to be |
5 | 3019 |
* displayed inline with the message, not just attached for download. |
3020 |
* This is used in HTML messages that embed the images |
|
3021 |
* the HTML refers to using the $cid value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3022 |
* Never use a user-supplied path to a file! |
5 | 3023 |
* @param string $path Path to the attachment. |
3024 |
* @param string $cid Content ID of the attachment; Use this to reference |
|
3025 |
* the content when using an embedded image in HTML. |
|
3026 |
* @param string $name Overrides the attachment name. |
|
3027 |
* @param string $encoding File encoding (see $Encoding). |
|
3028 |
* @param string $type File MIME type. |
|
3029 |
* @param string $disposition Disposition to use |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
* @return boolean True on successfully adding an attachment |
5 | 3031 |
*/ |
3032 |
public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline') |
|
3033 |
{ |
|
3034 |
if (!@is_file($path)) { |
|
3035 |
$this->setError($this->lang('file_access') . $path); |
|
3036 |
return false; |
|
3037 |
} |
|
0 | 3038 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
// If a MIME type is not specified, try to work it out from the file name |
5 | 3040 |
if ($type == '') { |
3041 |
$type = self::filenameToType($path); |
|
3042 |
} |
|
3043 |
||
3044 |
$filename = basename($path); |
|
3045 |
if ($name == '') { |
|
3046 |
$name = $filename; |
|
3047 |
} |
|
3048 |
||
3049 |
// Append to $attachment array |
|
3050 |
$this->attachment[] = array( |
|
3051 |
0 => $path, |
|
3052 |
1 => $filename, |
|
3053 |
2 => $name, |
|
3054 |
3 => $encoding, |
|
3055 |
4 => $type, |
|
3056 |
5 => false, // isStringAttachment |
|
3057 |
6 => $disposition, |
|
3058 |
7 => $cid |
|
3059 |
); |
|
3060 |
return true; |
|
0 | 3061 |
} |
3062 |
||
5 | 3063 |
/** |
3064 |
* Add an embedded stringified attachment. |
|
3065 |
* This can include images, sounds, and just about any other document type. |
|
3066 |
* Be sure to set the $type to an image type for images: |
|
3067 |
* JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'. |
|
3068 |
* @param string $string The attachment binary data. |
|
3069 |
* @param string $cid Content ID of the attachment; Use this to reference |
|
3070 |
* the content when using an embedded image in HTML. |
|
3071 |
* @param string $name |
|
3072 |
* @param string $encoding File encoding (see $Encoding). |
|
3073 |
* @param string $type MIME type. |
|
3074 |
* @param string $disposition Disposition to use |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
* @return boolean True on successfully adding an attachment |
5 | 3076 |
*/ |
3077 |
public function addStringEmbeddedImage( |
|
3078 |
$string, |
|
3079 |
$cid, |
|
3080 |
$name = '', |
|
3081 |
$encoding = 'base64', |
|
3082 |
$type = '', |
|
3083 |
$disposition = 'inline' |
|
3084 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
// If a MIME type is not specified, try to work it out from the name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
if ($type == '' and !empty($name)) { |
5 | 3087 |
$type = self::filenameToType($name); |
3088 |
} |
|
0 | 3089 |
|
5 | 3090 |
// Append to $attachment array |
3091 |
$this->attachment[] = array( |
|
3092 |
0 => $string, |
|
3093 |
1 => $name, |
|
3094 |
2 => $name, |
|
3095 |
3 => $encoding, |
|
3096 |
4 => $type, |
|
3097 |
5 => true, // isStringAttachment |
|
3098 |
6 => $disposition, |
|
3099 |
7 => $cid |
|
3100 |
); |
|
3101 |
return true; |
|
0 | 3102 |
} |
3103 |
||
5 | 3104 |
/** |
3105 |
* Check if an inline attachment is present. |
|
3106 |
* @access public |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3107 |
* @return boolean |
5 | 3108 |
*/ |
3109 |
public function inlineImageExists() |
|
3110 |
{ |
|
3111 |
foreach ($this->attachment as $attachment) { |
|
3112 |
if ($attachment[6] == 'inline') { |
|
3113 |
return true; |
|
3114 |
} |
|
3115 |
} |
|
3116 |
return false; |
|
0 | 3117 |
} |
3118 |
||
5 | 3119 |
/** |
3120 |
* Check if an attachment (non-inline) is present. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
* @return boolean |
5 | 3122 |
*/ |
3123 |
public function attachmentExists() |
|
3124 |
{ |
|
3125 |
foreach ($this->attachment as $attachment) { |
|
3126 |
if ($attachment[6] == 'attachment') { |
|
3127 |
return true; |
|
3128 |
} |
|
3129 |
} |
|
3130 |
return false; |
|
3131 |
} |
|
3132 |
||
3133 |
/** |
|
3134 |
* Check if this message has an alternative body set. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3135 |
* @return boolean |
5 | 3136 |
*/ |
3137 |
public function alternativeExists() |
|
3138 |
{ |
|
3139 |
return !empty($this->AltBody); |
|
3140 |
} |
|
3141 |
||
3142 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
* Clear queued addresses of given kind. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
* @access protected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3145 |
* @param string $kind 'to', 'cc', or 'bcc' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3146 |
* @return void |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3147 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3148 |
public function clearQueuedAddresses($kind) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3149 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3150 |
$RecipientsQueue = $this->RecipientsQueue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3151 |
foreach ($RecipientsQueue as $address => $params) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
if ($params[0] == $kind) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
unset($this->RecipientsQueue[$address]); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3155 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3156 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3157 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3158 |
/** |
5 | 3159 |
* Clear all To recipients. |
3160 |
* @return void |
|
3161 |
*/ |
|
3162 |
public function clearAddresses() |
|
3163 |
{ |
|
3164 |
foreach ($this->to as $to) { |
|
3165 |
unset($this->all_recipients[strtolower($to[0])]); |
|
3166 |
} |
|
3167 |
$this->to = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3168 |
$this->clearQueuedAddresses('to'); |
5 | 3169 |
} |
3170 |
||
3171 |
/** |
|
3172 |
* Clear all CC recipients. |
|
3173 |
* @return void |
|
3174 |
*/ |
|
3175 |
public function clearCCs() |
|
3176 |
{ |
|
3177 |
foreach ($this->cc as $cc) { |
|
3178 |
unset($this->all_recipients[strtolower($cc[0])]); |
|
3179 |
} |
|
3180 |
$this->cc = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3181 |
$this->clearQueuedAddresses('cc'); |
5 | 3182 |
} |
0 | 3183 |
|
5 | 3184 |
/** |
3185 |
* Clear all BCC recipients. |
|
3186 |
* @return void |
|
3187 |
*/ |
|
3188 |
public function clearBCCs() |
|
3189 |
{ |
|
3190 |
foreach ($this->bcc as $bcc) { |
|
3191 |
unset($this->all_recipients[strtolower($bcc[0])]); |
|
3192 |
} |
|
3193 |
$this->bcc = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
$this->clearQueuedAddresses('bcc'); |
5 | 3195 |
} |
3196 |
||
3197 |
/** |
|
3198 |
* Clear all ReplyTo recipients. |
|
3199 |
* @return void |
|
3200 |
*/ |
|
3201 |
public function clearReplyTos() |
|
3202 |
{ |
|
3203 |
$this->ReplyTo = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
$this->ReplyToQueue = array(); |
5 | 3205 |
} |
0 | 3206 |
|
5 | 3207 |
/** |
3208 |
* Clear all recipient types. |
|
3209 |
* @return void |
|
3210 |
*/ |
|
3211 |
public function clearAllRecipients() |
|
3212 |
{ |
|
3213 |
$this->to = array(); |
|
3214 |
$this->cc = array(); |
|
3215 |
$this->bcc = array(); |
|
3216 |
$this->all_recipients = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3217 |
$this->RecipientsQueue = array(); |
5 | 3218 |
} |
0 | 3219 |
|
5 | 3220 |
/** |
3221 |
* Clear all filesystem, string, and binary attachments. |
|
3222 |
* @return void |
|
3223 |
*/ |
|
3224 |
public function clearAttachments() |
|
3225 |
{ |
|
3226 |
$this->attachment = array(); |
|
3227 |
} |
|
3228 |
||
3229 |
/** |
|
3230 |
* Clear all custom headers. |
|
3231 |
* @return void |
|
3232 |
*/ |
|
3233 |
public function clearCustomHeaders() |
|
3234 |
{ |
|
3235 |
$this->CustomHeader = array(); |
|
0 | 3236 |
} |
3237 |
||
5 | 3238 |
/** |
3239 |
* Add an error message to the error container. |
|
3240 |
* @access protected |
|
3241 |
* @param string $msg |
|
3242 |
* @return void |
|
3243 |
*/ |
|
3244 |
protected function setError($msg) |
|
3245 |
{ |
|
3246 |
$this->error_count++; |
|
3247 |
if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { |
|
3248 |
$lasterror = $this->smtp->getError(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
if (!empty($lasterror['error'])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
$msg .= $this->lang('smtp_error') . $lasterror['error']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
if (!empty($lasterror['detail'])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
$msg .= ' Detail: '. $lasterror['detail']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
if (!empty($lasterror['smtp_code'])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
$msg .= ' SMTP code: ' . $lasterror['smtp_code']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
if (!empty($lasterror['smtp_code_ex'])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
$msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
} |
5 | 3260 |
} |
0 | 3261 |
} |
5 | 3262 |
$this->ErrorInfo = $msg; |
0 | 3263 |
} |
3264 |
||
5 | 3265 |
/** |
3266 |
* Return an RFC 822 formatted date. |
|
3267 |
* @access public |
|
3268 |
* @return string |
|
3269 |
* @static |
|
3270 |
*/ |
|
3271 |
public static function rfcDate() |
|
3272 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
// Set the time zone to whatever the default is to avoid 500 errors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3274 |
// Will default to UTC if it's not set properly in php.ini |
5 | 3275 |
date_default_timezone_set(@date_default_timezone_get()); |
3276 |
return date('D, j M Y H:i:s O'); |
|
0 | 3277 |
} |
3278 |
||
5 | 3279 |
/** |
3280 |
* Get the server hostname. |
|
3281 |
* Returns 'localhost.localdomain' if unknown. |
|
3282 |
* @access protected |
|
3283 |
* @return string |
|
3284 |
*/ |
|
3285 |
protected function serverHostname() |
|
3286 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
$result = 'localhost.localdomain'; |
5 | 3288 |
if (!empty($this->Hostname)) { |
3289 |
$result = $this->Hostname; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
} elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) { |
5 | 3291 |
$result = $_SERVER['SERVER_NAME']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
} elseif (function_exists('gethostname') && gethostname() !== false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
$result = gethostname(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
} elseif (php_uname('n') !== false) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
$result = php_uname('n'); |
5 | 3296 |
} |
3297 |
return $result; |
|
0 | 3298 |
} |
3299 |
||
5 | 3300 |
/** |
3301 |
* Get an error message in the current language. |
|
3302 |
* @access protected |
|
3303 |
* @param string $key |
|
3304 |
* @return string |
|
3305 |
*/ |
|
3306 |
protected function lang($key) |
|
3307 |
{ |
|
3308 |
if (count($this->language) < 1) { |
|
3309 |
$this->setLanguage('en'); // set the default language |
|
3310 |
} |
|
3311 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
if (array_key_exists($key, $this->language)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
if ($key == 'smtp_connect_failed') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
//Include a link to troubleshooting docs on SMTP connection failure |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
//this is by far the biggest cause of support questions |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
//but it's usually not PHPMailer's fault. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3318 |
} |
5 | 3319 |
return $this->language[$key]; |
3320 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3321 |
//Return the key as a fallback |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
return $key; |
5 | 3323 |
} |
3324 |
} |
|
3325 |
||
3326 |
/** |
|
3327 |
* Check if an error occurred. |
|
3328 |
* @access public |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
* @return boolean True if an error did occur. |
5 | 3330 |
*/ |
3331 |
public function isError() |
|
3332 |
{ |
|
3333 |
return ($this->error_count > 0); |
|
3334 |
} |
|
3335 |
||
3336 |
/** |
|
3337 |
* Ensure consistent line endings in a string. |
|
3338 |
* Changes every end of line from CRLF, CR or LF to $this->LE. |
|
3339 |
* @access public |
|
3340 |
* @param string $str String to fixEOL |
|
3341 |
* @return string |
|
3342 |
*/ |
|
3343 |
public function fixEOL($str) |
|
3344 |
{ |
|
3345 |
// Normalise to \n |
|
3346 |
$nstr = str_replace(array("\r\n", "\r"), "\n", $str); |
|
3347 |
// Now convert LE as needed |
|
3348 |
if ($this->LE !== "\n") { |
|
3349 |
$nstr = str_replace("\n", $this->LE, $nstr); |
|
3350 |
} |
|
3351 |
return $nstr; |
|
3352 |
} |
|
3353 |
||
3354 |
/** |
|
3355 |
* Add a custom header. |
|
3356 |
* $name value can be overloaded to contain |
|
3357 |
* both header name and value (name:value) |
|
3358 |
* @access public |
|
3359 |
* @param string $name Custom header name |
|
3360 |
* @param string $value Header value |
|
3361 |
* @return void |
|
3362 |
*/ |
|
3363 |
public function addCustomHeader($name, $value = null) |
|
3364 |
{ |
|
3365 |
if ($value === null) { |
|
3366 |
// Value passed in as name:value |
|
3367 |
$this->CustomHeader[] = explode(':', $name, 2); |
|
3368 |
} else { |
|
3369 |
$this->CustomHeader[] = array($name, $value); |
|
3370 |
} |
|
0 | 3371 |
} |
3372 |
||
5 | 3373 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
* Returns all custom headers. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
public function getCustomHeaders() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
return $this->CustomHeader; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3383 |
* Create a message body from an HTML string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3384 |
* Automatically inlines images and creates a plain-text version by converting the HTML, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3385 |
* overwriting any existing values in Body and AltBody. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3386 |
* Do not source $message content from user input! |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
* $basedir is prepended when handling relative URLs, e.g. <img src="/images/a.png"> and must not be empty |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
* will look for an image file in $basedir/images/a.png and convert it to inline. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
* If you don't provide a $basedir, relative paths will be left untouched (and thus probably break in email) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
* If you don't want to apply these transformations to your HTML, just set Body and AltBody directly. |
5 | 3391 |
* @access public |
3392 |
* @param string $message HTML message string |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
* @param string $basedir Absolute path to a base directory to prepend to relative paths to images |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
* @param boolean|callable $advanced Whether to use the internal HTML to text converter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
* or your own custom converter @see PHPMailer::html2text() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
* @return string $message The transformed message Body |
5 | 3397 |
*/ |
3398 |
public function msgHTML($message, $basedir = '', $advanced = false) |
|
3399 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
if (array_key_exists(2, $images)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
// Ensure $basedir has a trailing / |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3404 |
$basedir .= '/'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
foreach ($images[2] as $imgindex => $url) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
// Convert data URIs into embedded images |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
$data = substr($url, strpos($url, ',')); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
if ($match[2]) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3411 |
$data = base64_decode($data); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
$data = rawurldecode($data); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
$cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
$message = str_replace( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3418 |
$images[0][$imgindex], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
$images[1][$imgindex] . '="cid:' . $cid . '"', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
$message |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3421 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
if ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
// Only process relative URLs if a basedir is provided (i.e. no absolute local paths) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
!empty($basedir) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
// Ignore URLs containing parent dir traversal (..) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3429 |
&& (strpos($url, '..') === false) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3430 |
// Do not change urls that are already inline images |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3431 |
&& substr($url, 0, 4) !== 'cid:' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
// Do not change absolute URLs, including anonymous protocol |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
&& !preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
) { |
5 | 3435 |
$filename = basename($url); |
3436 |
$directory = dirname($url); |
|
3437 |
if ($directory == '.') { |
|
3438 |
$directory = ''; |
|
3439 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
$cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2 |
5 | 3441 |
if (strlen($directory) > 1 && substr($directory, -1) != '/') { |
3442 |
$directory .= '/'; |
|
3443 |
} |
|
3444 |
if ($this->addEmbeddedImage( |
|
3445 |
$basedir . $directory . $filename, |
|
3446 |
$cid, |
|
3447 |
$filename, |
|
3448 |
'base64', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3449 |
self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION)) |
5 | 3450 |
) |
3451 |
) { |
|
3452 |
$message = preg_replace( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3453 |
'/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3454 |
$images[1][$imgindex] . '="cid:' . $cid . '"', |
5 | 3455 |
$message |
3456 |
); |
|
3457 |
} |
|
3458 |
} |
|
3459 |
} |
|
3460 |
} |
|
3461 |
$this->isHTML(true); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
// Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better |
5 | 3463 |
$this->Body = $this->normalizeBreaks($message); |
3464 |
$this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced)); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3465 |
if (!$this->alternativeExists()) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
$this->AltBody = 'To view this email message, open it in a program that understands HTML!' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
self::CRLF . self::CRLF; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
} |
5 | 3469 |
return $this->Body; |
0 | 3470 |
} |
3471 |
||
5 | 3472 |
/** |
3473 |
* Convert an HTML string into plain text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3474 |
* This is used by msgHTML(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3475 |
* Note - older versions of this function used a bundled advanced converter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3476 |
* which was been removed for license reasons in #232. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3477 |
* Example usage: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3478 |
* <code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3479 |
* // Use default conversion |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3480 |
* $plain = $mail->html2text($html); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3481 |
* // Use your own custom converter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3482 |
* $plain = $mail->html2text($html, function($html) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3483 |
* $converter = new MyHtml2text($html); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3484 |
* return $converter->get_text(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3485 |
* }); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3486 |
* </code> |
5 | 3487 |
* @param string $html The HTML text to convert |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3488 |
* @param boolean|callable $advanced Any boolean value to use the internal converter, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3489 |
* or provide your own callable for custom conversion. |
5 | 3490 |
* @return string |
3491 |
*/ |
|
3492 |
public function html2text($html, $advanced = false) |
|
3493 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3494 |
if (is_callable($advanced)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3495 |
return call_user_func($advanced, $html); |
5 | 3496 |
} |
3497 |
return html_entity_decode( |
|
3498 |
trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))), |
|
3499 |
ENT_QUOTES, |
|
3500 |
$this->CharSet |
|
3501 |
); |
|
0 | 3502 |
} |
3503 |
||
5 | 3504 |
/** |
3505 |
* Get the MIME type for a file extension. |
|
3506 |
* @param string $ext File extension |
|
3507 |
* @access public |
|
3508 |
* @return string MIME type of file. |
|
3509 |
* @static |
|
3510 |
*/ |
|
3511 |
public static function _mime_types($ext = '') |
|
3512 |
{ |
|
3513 |
$mimes = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3514 |
'xl' => 'application/excel', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3515 |
'js' => 'application/javascript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3516 |
'hqx' => 'application/mac-binhex40', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3517 |
'cpt' => 'application/mac-compactpro', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3518 |
'bin' => 'application/macbinary', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
'doc' => 'application/msword', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
'word' => 'application/msword', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3525 |
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3526 |
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3527 |
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3529 |
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3530 |
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', |
5 | 3531 |
'class' => 'application/octet-stream', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3532 |
'dll' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3533 |
'dms' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3534 |
'exe' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3535 |
'lha' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3536 |
'lzh' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3537 |
'psd' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3538 |
'sea' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
'so' => 'application/octet-stream', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
'oda' => 'application/oda', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
'pdf' => 'application/pdf', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
'ai' => 'application/postscript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
'eps' => 'application/postscript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
'ps' => 'application/postscript', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
'smi' => 'application/smil', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
'smil' => 'application/smil', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
'mif' => 'application/vnd.mif', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
'xls' => 'application/vnd.ms-excel', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
'ppt' => 'application/vnd.ms-powerpoint', |
5 | 3550 |
'wbxml' => 'application/vnd.wap.wbxml', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3551 |
'wmlc' => 'application/vnd.wap.wmlc', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3552 |
'dcr' => 'application/x-director', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
'dir' => 'application/x-director', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
'dxr' => 'application/x-director', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
'dvi' => 'application/x-dvi', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3556 |
'gtar' => 'application/x-gtar', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3557 |
'php3' => 'application/x-httpd-php', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
'php4' => 'application/x-httpd-php', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3559 |
'php' => 'application/x-httpd-php', |
5 | 3560 |
'phtml' => 'application/x-httpd-php', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
'phps' => 'application/x-httpd-php-source', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
'swf' => 'application/x-shockwave-flash', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3563 |
'sit' => 'application/x-stuffit', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
'tar' => 'application/x-tar', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3565 |
'tgz' => 'application/x-tar', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
'xht' => 'application/xhtml+xml', |
5 | 3567 |
'xhtml' => 'application/xhtml+xml', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
'zip' => 'application/zip', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
'mid' => 'audio/midi', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
'midi' => 'audio/midi', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
'mp2' => 'audio/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
'mp3' => 'audio/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
'mpga' => 'audio/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
'aif' => 'audio/x-aiff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
'aifc' => 'audio/x-aiff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
'aiff' => 'audio/x-aiff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
'ram' => 'audio/x-pn-realaudio', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
'rm' => 'audio/x-pn-realaudio', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
'rpm' => 'audio/x-pn-realaudio-plugin', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
'ra' => 'audio/x-realaudio', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
'wav' => 'audio/x-wav', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
'bmp' => 'image/bmp', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
'gif' => 'image/gif', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
'jpeg' => 'image/jpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
'jpe' => 'image/jpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
'jpg' => 'image/jpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
'png' => 'image/png', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
'tiff' => 'image/tiff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
'tif' => 'image/tiff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
'eml' => 'message/rfc822', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
'css' => 'text/css', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
'html' => 'text/html', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
'htm' => 'text/html', |
5 | 3594 |
'shtml' => 'text/html', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
'log' => 'text/plain', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
'text' => 'text/plain', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
'txt' => 'text/plain', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
'rtx' => 'text/richtext', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3599 |
'rtf' => 'text/rtf', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3600 |
'vcf' => 'text/vcard', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3601 |
'vcard' => 'text/vcard', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
'xml' => 'text/xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3603 |
'xsl' => 'text/xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
'mpeg' => 'video/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
'mpe' => 'video/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
'mpg' => 'video/mpeg', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3607 |
'mov' => 'video/quicktime', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
'qt' => 'video/quicktime', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
'rv' => 'video/vnd.rn-realvideo', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
'avi' => 'video/x-msvideo', |
5 | 3611 |
'movie' => 'video/x-sgi-movie' |
3612 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3613 |
if (array_key_exists(strtolower($ext), $mimes)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
return $mimes[strtolower($ext)]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3616 |
return 'application/octet-stream'; |
5 | 3617 |
} |
0 | 3618 |
|
5 | 3619 |
/** |
3620 |
* Map a file name to a MIME type. |
|
3621 |
* Defaults to 'application/octet-stream', i.e.. arbitrary binary data. |
|
3622 |
* @param string $filename A file name or full path, does not need to exist as a file |
|
3623 |
* @return string |
|
3624 |
* @static |
|
3625 |
*/ |
|
3626 |
public static function filenameToType($filename) |
|
3627 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
// In case the path is a URL, strip any query string before getting extension |
5 | 3629 |
$qpos = strpos($filename, '?'); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
if (false !== $qpos) { |
5 | 3631 |
$filename = substr($filename, 0, $qpos); |
3632 |
} |
|
3633 |
$pathinfo = self::mb_pathinfo($filename); |
|
3634 |
return self::_mime_types($pathinfo['extension']); |
|
0 | 3635 |
} |
3636 |
||
5 | 3637 |
/** |
3638 |
* Multi-byte-safe pathinfo replacement. |
|
3639 |
* Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe. |
|
3640 |
* Works similarly to the one in PHP >= 5.2.0 |
|
3641 |
* @link http://www.php.net/manual/en/function.pathinfo.php#107461 |
|
3642 |
* @param string $path A filename or path, does not need to exist as a file |
|
3643 |
* @param integer|string $options Either a PATHINFO_* constant, |
|
3644 |
* or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2 |
|
3645 |
* @return string|array |
|
3646 |
* @static |
|
3647 |
*/ |
|
3648 |
public static function mb_pathinfo($path, $options = null) |
|
3649 |
{ |
|
3650 |
$ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => ''); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
$pathinfo = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
if (array_key_exists(1, $pathinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
$ret['dirname'] = $pathinfo[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3656 |
if (array_key_exists(2, $pathinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3657 |
$ret['basename'] = $pathinfo[2]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3658 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3659 |
if (array_key_exists(5, $pathinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3660 |
$ret['extension'] = $pathinfo[5]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3661 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
if (array_key_exists(3, $pathinfo)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
$ret['filename'] = $pathinfo[3]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
} |
5 | 3665 |
} |
3666 |
switch ($options) { |
|
3667 |
case PATHINFO_DIRNAME: |
|
3668 |
case 'dirname': |
|
3669 |
return $ret['dirname']; |
|
3670 |
case PATHINFO_BASENAME: |
|
3671 |
case 'basename': |
|
3672 |
return $ret['basename']; |
|
3673 |
case PATHINFO_EXTENSION: |
|
3674 |
case 'extension': |
|
3675 |
return $ret['extension']; |
|
3676 |
case PATHINFO_FILENAME: |
|
3677 |
case 'filename': |
|
3678 |
return $ret['filename']; |
|
3679 |
default: |
|
3680 |
return $ret; |
|
0 | 3681 |
} |
3682 |
} |
|
5 | 3683 |
|
3684 |
/** |
|
3685 |
* Set or reset instance properties. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
* You should avoid this function - it's more verbose, less efficient, more error-prone and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
* harder to debug than setting properties directly. |
5 | 3688 |
* Usage Example: |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3689 |
* `$mail->set('SMTPSecure', 'tls');` |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
* is the same as: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
* `$mail->SMTPSecure = 'tls';` |
5 | 3692 |
* @access public |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3693 |
* @param string $name The property name to set |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
* @param mixed $value The value to set the property to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
* @return boolean |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
* @TODO Should this not be using the __set() magic function? |
5 | 3697 |
*/ |
3698 |
public function set($name, $value = '') |
|
3699 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3700 |
if (property_exists($this, $name)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
$this->$name = $value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3704 |
$this->setError($this->lang('variable_set') . $name); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3705 |
return false; |
5 | 3706 |
} |
0 | 3707 |
} |
5 | 3708 |
|
3709 |
/** |
|
3710 |
* Strip newlines to prevent header injection. |
|
3711 |
* @access public |
|
3712 |
* @param string $str |
|
3713 |
* @return string |
|
3714 |
*/ |
|
3715 |
public function secureHeader($str) |
|
3716 |
{ |
|
3717 |
return trim(str_replace(array("\r", "\n"), '', $str)); |
|
3718 |
} |
|
3719 |
||
3720 |
/** |
|
3721 |
* Normalize line breaks in a string. |
|
3722 |
* Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format. |
|
3723 |
* Defaults to CRLF (for message bodies) and preserves consecutive breaks. |
|
3724 |
* @param string $text |
|
3725 |
* @param string $breaktype What kind of line break to use, defaults to CRLF |
|
3726 |
* @return string |
|
3727 |
* @access public |
|
3728 |
* @static |
|
3729 |
*/ |
|
3730 |
public static function normalizeBreaks($text, $breaktype = "\r\n") |
|
3731 |
{ |
|
3732 |
return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text); |
|
3733 |
} |
|
3734 |
||
3735 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3736 |
* Set the public and private key files and password for S/MIME signing. |
5 | 3737 |
* @access public |
3738 |
* @param string $cert_filename |
|
3739 |
* @param string $key_filename |
|
3740 |
* @param string $key_pass Password for private key |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
* @param string $extracerts_filename Optional path to chain certificate |
5 | 3742 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '') |
5 | 3744 |
{ |
3745 |
$this->sign_cert_file = $cert_filename; |
|
3746 |
$this->sign_key_file = $key_filename; |
|
3747 |
$this->sign_key_pass = $key_pass; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
$this->sign_extracerts_file = $extracerts_filename; |
5 | 3749 |
} |
0 | 3750 |
|
5 | 3751 |
/** |
3752 |
* Quoted-Printable-encode a DKIM header. |
|
3753 |
* @access public |
|
3754 |
* @param string $txt |
|
3755 |
* @return string |
|
3756 |
*/ |
|
3757 |
public function DKIM_QP($txt) |
|
3758 |
{ |
|
3759 |
$line = ''; |
|
3760 |
for ($i = 0; $i < strlen($txt); $i++) { |
|
3761 |
$ord = ord($txt[$i]); |
|
3762 |
if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) { |
|
3763 |
$line .= $txt[$i]; |
|
3764 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3765 |
$line .= '=' . sprintf('%02X', $ord); |
5 | 3766 |
} |
3767 |
} |
|
3768 |
return $line; |
|
0 | 3769 |
} |
3770 |
||
5 | 3771 |
/** |
3772 |
* Generate a DKIM signature. |
|
3773 |
* @access public |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
* @param string $signHeader |
5 | 3775 |
* @throws phpmailerException |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
* @return string The DKIM signature value |
5 | 3777 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3778 |
public function DKIM_Sign($signHeader) |
5 | 3779 |
{ |
3780 |
if (!defined('PKCS7_TEXT')) { |
|
3781 |
if ($this->exceptions) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3782 |
throw new phpmailerException($this->lang('extension_missing') . 'openssl'); |
5 | 3783 |
} |
3784 |
return ''; |
|
3785 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3786 |
$privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3787 |
if ('' != $this->DKIM_passphrase) { |
5 | 3788 |
$privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); |
3789 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3790 |
$privKey = openssl_pkey_get_private($privKeyStr); |
5 | 3791 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3792 |
//Workaround for missing digest algorithms in old PHP & OpenSSL versions |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
//@link http://stackoverflow.com/a/11117338/333340 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
if (version_compare(PHP_VERSION, '5.3.0') >= 0 and |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3795 |
in_array('sha256WithRSAEncryption', openssl_get_md_methods(true))) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3796 |
if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3797 |
openssl_pkey_free($privKey); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3798 |
return base64_encode($signature); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3799 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3800 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
$pinfo = openssl_pkey_get_details($privKey); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3802 |
$hash = hash('sha256', $signHeader); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3803 |
//'Magic' constant for SHA256 from RFC3447 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3804 |
//@link https://tools.ietf.org/html/rfc3447#page-43 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
$t = '3031300d060960864801650304020105000420' . $hash; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3806 |
$pslen = $pinfo['bits'] / 8 - (strlen($t) / 2 + 3); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
$eb = pack('H*', '0001' . str_repeat('FF', $pslen) . '00' . $t); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3809 |
if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
openssl_pkey_free($privKey); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
return base64_encode($signature); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3812 |
} |
5 | 3813 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
openssl_pkey_free($privKey); |
5 | 3815 |
return ''; |
3816 |
} |
|
0 | 3817 |
|
5 | 3818 |
/** |
3819 |
* Generate a DKIM canonicalization header. |
|
3820 |
* @access public |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3821 |
* @param string $signHeader Header |
5 | 3822 |
* @return string |
3823 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
public function DKIM_HeaderC($signHeader) |
5 | 3825 |
{ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
$signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
$lines = explode("\r\n", $signHeader); |
5 | 3828 |
foreach ($lines as $key => $line) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
list($heading, $value) = explode(':', $line, 2); |
5 | 3830 |
$heading = strtolower($heading); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3831 |
$value = preg_replace('/\s{2,}/', ' ', $value); // Compress useless spaces |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
$lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value |
5 | 3833 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
$signHeader = implode("\r\n", $lines); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3835 |
return $signHeader; |
0 | 3836 |
} |
3837 |
||
5 | 3838 |
/** |
3839 |
* Generate a DKIM canonicalization body. |
|
3840 |
* @access public |
|
3841 |
* @param string $body Message Body |
|
3842 |
* @return string |
|
3843 |
*/ |
|
3844 |
public function DKIM_BodyC($body) |
|
3845 |
{ |
|
3846 |
if ($body == '') { |
|
3847 |
return "\r\n"; |
|
3848 |
} |
|
3849 |
// stabilize line endings |
|
3850 |
$body = str_replace("\r\n", "\n", $body); |
|
3851 |
$body = str_replace("\n", "\r\n", $body); |
|
3852 |
// END stabilize line endings |
|
3853 |
while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { |
|
3854 |
$body = substr($body, 0, strlen($body) - 2); |
|
3855 |
} |
|
3856 |
return $body; |
|
0 | 3857 |
} |
3858 |
||
5 | 3859 |
/** |
3860 |
* Create the DKIM header and body in a new message header. |
|
3861 |
* @access public |
|
3862 |
* @param string $headers_line Header lines |
|
3863 |
* @param string $subject Subject |
|
3864 |
* @param string $body Body |
|
3865 |
* @return string |
|
3866 |
*/ |
|
3867 |
public function DKIM_Add($headers_line, $subject, $body) |
|
3868 |
{ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
$DKIMsignatureType = 'rsa-sha256'; // Signature & hash algorithms |
5 | 3870 |
$DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
3871 |
$DKIMquery = 'dns/txt'; // Query method |
|
3872 |
$DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
|
3873 |
$subject_header = "Subject: $subject"; |
|
3874 |
$headers = explode($this->LE, $headers_line); |
|
3875 |
$from_header = ''; |
|
3876 |
$to_header = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
$date_header = ''; |
5 | 3878 |
$current = ''; |
3879 |
foreach ($headers as $header) { |
|
3880 |
if (strpos($header, 'From:') === 0) { |
|
3881 |
$from_header = $header; |
|
3882 |
$current = 'from_header'; |
|
3883 |
} elseif (strpos($header, 'To:') === 0) { |
|
3884 |
$to_header = $header; |
|
3885 |
$current = 'to_header'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3886 |
} elseif (strpos($header, 'Date:') === 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3887 |
$date_header = $header; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
$current = 'date_header'; |
5 | 3889 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
if (!empty($$current) && strpos($header, ' =?') === 0) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
$$current .= $header; |
5 | 3892 |
} else { |
3893 |
$current = ''; |
|
3894 |
} |
|
3895 |
} |
|
3896 |
} |
|
3897 |
$from = str_replace('|', '=7C', $this->DKIM_QP($from_header)); |
|
3898 |
$to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
$date = str_replace('|', '=7C', $this->DKIM_QP($date_header)); |
5 | 3900 |
$subject = str_replace( |
3901 |
'|', |
|
3902 |
'=7C', |
|
3903 |
$this->DKIM_QP($subject_header) |
|
3904 |
); // Copied header fields (dkim-quoted-printable) |
|
3905 |
$body = $this->DKIM_BodyC($body); |
|
3906 |
$DKIMlen = strlen($body); // Length of body |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
$DKIMb64 = base64_encode(pack('H*', hash('sha256', $body))); // Base64 of packed binary SHA-256 hash of body |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
if ('' == $this->DKIM_identity) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3909 |
$ident = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
$ident = ' i=' . $this->DKIM_identity . ';'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3912 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
$dkimhdrs = 'DKIM-Signature: v=1; a=' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
$DKIMsignatureType . '; q=' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
$DKIMquery . '; l=' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
$DKIMlen . '; s=' . |
5 | 3917 |
$this->DKIM_selector . |
3918 |
";\r\n" . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
"\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
"\th=From:To:Date:Subject;\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
"\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" . |
5 | 3922 |
"\tz=$from\r\n" . |
3923 |
"\t|$to\r\n" . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
"\t|$date\r\n" . |
5 | 3925 |
"\t|$subject;\r\n" . |
3926 |
"\tbh=" . $DKIMb64 . ";\r\n" . |
|
3927 |
"\tb="; |
|
3928 |
$toSign = $this->DKIM_HeaderC( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3929 |
$from_header . "\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3930 |
$to_header . "\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3931 |
$date_header . "\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3932 |
$subject_header . "\r\n" . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3933 |
$dkimhdrs |
5 | 3934 |
); |
3935 |
$signed = $this->DKIM_Sign($toSign); |
|
3936 |
return $dkimhdrs . $signed . "\r\n"; |
|
0 | 3937 |
} |
3938 |
||
5 | 3939 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3940 |
* Detect if a string contains a line longer than the maximum line length allowed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
* @param string $str |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3942 |
* @return boolean |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3943 |
* @static |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3944 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3945 |
public static function hasLineLongerThanMax($str) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3946 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3947 |
//+2 to include CRLF line break for a 1000 total |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3948 |
return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3949 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3951 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3952 |
* Allows for public read access to 'to' property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3953 |
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3954 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3955 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3956 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3957 |
public function getToAddresses() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3958 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3959 |
return $this->to; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3960 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3961 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3963 |
* Allows for public read access to 'cc' property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3964 |
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3965 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3966 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3967 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3968 |
public function getCcAddresses() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
return $this->cc; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
* Allows for public read access to 'bcc' property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
public function getBccAddresses() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
return $this->bcc; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
* Allows for public read access to 'ReplyTo' property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
public function getReplyToAddresses() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3992 |
return $this->ReplyTo; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3993 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3995 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
* Allows for public read access to 'all_recipients' property. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
* @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
* @access public |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4001 |
public function getAllRecipientAddresses() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4002 |
{ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4003 |
return $this->all_recipients; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4004 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4005 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4006 |
/** |
5 | 4007 |
* Perform a callback. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4008 |
* @param boolean $isSent |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4009 |
* @param array $to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
* @param array $cc |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
* @param array $bcc |
5 | 4012 |
* @param string $subject |
4013 |
* @param string $body |
|
4014 |
* @param string $from |
|
4015 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4016 |
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from) |
5 | 4017 |
{ |
4018 |
if (!empty($this->action_function) && is_callable($this->action_function)) { |
|
4019 |
$params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); |
|
4020 |
call_user_func_array($this->action_function, $params); |
|
4021 |
} |
|
0 | 4022 |
} |
4023 |
} |
|
4024 |
||
4025 |
/** |
|
5 | 4026 |
* PHPMailer exception handler |
0 | 4027 |
* @package PHPMailer |
4028 |
*/ |
|
5 | 4029 |
class phpmailerException extends Exception |
4030 |
{ |
|
4031 |
/** |
|
4032 |
* Prettify error message output |
|
4033 |
* @return string |
|
4034 |
*/ |
|
4035 |
public function errorMessage() |
|
4036 |
{ |
|
4037 |
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; |
|
4038 |
return $errorMsg; |
|
4039 |
} |
|
0 | 4040 |
} |