Browse code

Updated libraries (e-mail, template)

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