<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[33124] trunk: Update PHPMailer to 5.2.10 from 5.2.7.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/33124">33124</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/33124","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-07-08 17:15:02 +0000 (Wed, 08 Jul 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Update PHPMailer to 5.2.10 from 5.2.7.
Includes two modifications for WordPress:
* Removes support for NTLM in `class-smtp.php` since the required client (`extras/ntlm_sasl_client.php`) is not distributed as part of WordPress.
* Requires `class-smtp.php` for backwards compatibility with direct (non-wp_mail()) uses of PHPMailer, as the autoloader isn't used. See <a href="https://core.trac.wordpress.org/changeset/27385">[27385]</a>.
This also includes a change to our `MockMailer` for unit tests. It now overrides `postSend() instead of `send()`, and `preSend()`.
`preSend()` resets `$this->Encoding` because PHPMailer doesn't clean up after itself / presets all variables. This becomes an issue when `PHPMailer::createBody()` sets `$this->Encoding = 'quoted-printable'` (away from it's default of 8bit) when it encounters a line longer than 998 characters. `Tests_Comment::test_comment_field_lengths` is such a case.
props MattyRob, dd32.
fixes <a href="https://core.trac.wordpress.org/ticket/28909">#28909</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclassphpmailerphp">trunk/src/wp-includes/class-phpmailer.php</a></li>
<li><a href="#trunksrcwpincludesclasssmtpphp">trunk/src/wp-includes/class-smtp.php</a></li>
<li><a href="#trunktestsphpunitincludesmockmailerphp">trunk/tests/phpunit/includes/mock-mailer.php</a></li>
<li><a href="#trunktestsphpunittestsmailphp">trunk/tests/phpunit/tests/mail.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclassphpmailerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-phpmailer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-phpmailer.php 2015-07-08 16:04:11 UTC (rev 33123)
+++ trunk/src/wp-includes/class-phpmailer.php 2015-07-08 17:15:02 UTC (rev 33124)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,15 +1,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * PHPMailer - PHP email creation and transport class.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * PHP Version 5.0.0
- * Version 5.2.7
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * PHP Version 5
</ins><span class="cx" style="display: block; padding: 0 10px"> * @package PHPMailer
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @link https://github.com/PHPMailer/PHPMailer/
- * @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
+ * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
</ins><span class="cx" style="display: block; padding: 0 10px"> * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
</span><span class="cx" style="display: block; padding: 0 10px"> * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
</span><span class="cx" style="display: block; padding: 0 10px"> * @author Brent R. Matzelle (original founder)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @copyright 2013 Marcus Bointon
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @copyright 2012 - 2014 Marcus Bointon
</ins><span class="cx" style="display: block; padding: 0 10px"> * @copyright 2010 - 2012 Jim Jagielski
</span><span class="cx" style="display: block; padding: 0 10px"> * @copyright 2004 - 2009 Andy Prevost
</span><span class="cx" style="display: block; padding: 0 10px"> * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,21 +17,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * FITNESS FOR A PARTICULAR PURPOSE.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if (version_compare(PHP_VERSION, '5.0.0', '<')) {
- exit("Sorry, PHPMailer will only run on PHP version 5 or greater!\n");
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * PHPMailer - PHP email creation and transport class.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * PHP Version 5.0.0
</del><span class="cx" style="display: block; padding: 0 10px"> * @package PHPMailer
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
</ins><span class="cx" style="display: block; padding: 0 10px"> * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
</span><span class="cx" style="display: block; padding: 0 10px"> * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
</span><span class="cx" style="display: block; padding: 0 10px"> * @author Brent R. Matzelle (original founder)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @copyright 2013 Marcus Bointon
- * @copyright 2010 - 2012 Jim Jagielski
- * @copyright 2004 - 2009 Andy Prevost
</del><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class PHPMailer
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -40,12 +31,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The PHPMailer Version number.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Version = '5.2.7';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Version = '5.2.10';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Email priority.
</span><span class="cx" style="display: block; padding: 0 10px"> * Options: 1 = High, 3 = Normal, 5 = low.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $Priority = 3;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -97,6 +88,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The Return-Path of the message.
</span><span class="cx" style="display: block; padding: 0 10px"> * If empty, it will be set to either From or Sender.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated Email senders should never set a return-path header;
+ * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
+ * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $ReturnPath = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -155,7 +149,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Word-wrap the message body to this number of chars.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $WordWrap = 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,7 +170,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether mail() uses a fully sendmail-compatible MTA.
</span><span class="cx" style="display: block; padding: 0 10px"> * One which supports sendmail's "-oi -f" options.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $UseSendmailOptions = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -222,6 +217,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * You can also specify a different port
</span><span class="cx" style="display: block; padding: 0 10px"> * for each host by using this format: [hostname:port]
</span><span class="cx" style="display: block; padding: 0 10px"> * (e.g. "smtp1.example.com:25;smtp2.example.com").
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * You can also specify encryption type, for example:
+ * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
</ins><span class="cx" style="display: block; padding: 0 10px"> * Hosts will be tried in order.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -229,8 +226,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The default SMTP server port.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int
- * @Todo Why is this needed when the SMTP class takes care of it?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type integer
+ * @TODO Why is this needed when the SMTP class takes care of it?
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $Port = 25;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -243,22 +240,36 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public $Helo = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The secure connection prefix.
- * Options: "", "ssl" or "tls"
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * What kind of encryption to use on the SMTP connection.
+ * Options: '', 'ssl' or 'tls'
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SMTPSecure = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Whether to enable TLS encryption automatically if a server supports it,
+ * even if `SMTPSecure` is not set to 'tls'.
+ * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
+ * @type boolean
+ */
+ public $SMTPAutoTLS = true;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Whether to use SMTP authentication.
</span><span class="cx" style="display: block; padding: 0 10px"> * Uses the Username and Password properties.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see PHPMailer::$Username
</span><span class="cx" style="display: block; padding: 0 10px"> * @see PHPMailer::$Password
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SMTPAuth = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Options array passed to stream_context_create when connecting via SMTP.
+ * @type array
+ */
+ public $SMTPOptions = array();
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * SMTP username.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -293,45 +304,60 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The SMTP server timeout in seconds.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Timeout = 10;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Timeout = 300;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * SMTP class debug output mode.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Options: 0 = off, 1 = commands, 2 = commands and data
- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Debug output level.
+ * Options:
+ * * `0` No output
+ * * `1` Commands
+ * * `2` Data and commands
+ * * `3` As 2 plus connection status
+ * * `4` Low-level data output
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see SMTP::$do_debug
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SMTPDebug = 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The function/method to use for debugging output.
- * Options: "echo" or "error_log"
- * @type string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * How to handle debug output.
+ * Options:
+ * * `echo` Output plain-text as-is, appropriate for CLI
+ * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
+ * * `error_log` Output to error log as configured in php.ini
+ *
+ * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
+ * <code>
+ * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
+ * </code>
+ * @type string|callable
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see SMTP::$Debugoutput
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Debugoutput = "echo";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Debugoutput = 'echo';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to keep SMTP connection open after each message.
</span><span class="cx" style="display: block; padding: 0 10px"> * If this is set to true then to close the connection
</span><span class="cx" style="display: block; padding: 0 10px"> * requires an explicit call to smtpClose().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SMTPKeepAlive = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to split multiple to addresses into multiple messages
</span><span class="cx" style="display: block; padding: 0 10px"> * or send them all in one message.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SingleTo = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Storage for addresses when SingleTo is enabled.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type array
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @todo This should really not be public
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @TODO This should really not be public
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SingleToArray = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,13 +365,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to generate VERP addresses on send.
</span><span class="cx" style="display: block; padding: 0 10px"> * Only applicable when sending via SMTP.
</span><span class="cx" style="display: block; padding: 0 10px"> * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link http://www.postfix.org/VERP_README.html Postfix VERP info
+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $do_verp = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to allow sending messages with an empty body.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $AllowEmpty = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -396,28 +423,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The function that handles the result of the send email action.
</span><span class="cx" style="display: block; padding: 0 10px"> * It is called out by send() for each email sent.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Value can be:
- * - 'function_name' for function names
- * - 'Class::Method' for static method calls
- * - array($object, 'Method') for calling methods on $object
- * See http://php.net/is_callable manual page for more details.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Value can be any php callable: http://www.php.net/is_callable
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Parameters:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * bool $result result of the send action
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * boolean $result result of the send action
</ins><span class="cx" style="display: block; padding: 0 10px"> * string $to email address of the recipient
</span><span class="cx" style="display: block; padding: 0 10px"> * string $cc cc email addresses
</span><span class="cx" style="display: block; padding: 0 10px"> * string $bcc bcc email addresses
</span><span class="cx" style="display: block; padding: 0 10px"> * string $subject the subject
</span><span class="cx" style="display: block; padding: 0 10px"> * string $body the email body
</span><span class="cx" style="display: block; padding: 0 10px"> * string $from email address of sender
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $action_function = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * What to use in the X-Mailer header.
- * Options: null for default, whitespace for none, or a string to use
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * What to put in the X-Mailer header.
+ * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $XMailer = '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -459,7 +481,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * An array of all kinds of addresses.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Includes all of $to, $cc, $bcc, $replyto
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Includes all of $to, $cc, $bcc
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type array
</span><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -529,6 +551,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected $sign_key_file = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The optional S/MIME extra certificates ("CA Chain") file path.
+ * @type string
+ * @access protected
+ */
+ protected $sign_extracerts_file = '';
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * The S/MIME password for the key.
</span><span class="cx" style="display: block; padding: 0 10px"> * Used only if the key is encrypted.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -538,38 +567,51 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to throw exceptions for errors.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected $exceptions = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Error severity: message only, continue processing
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Unique ID used for message ID and boundaries.
+ * @type string
+ * @access protected
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $uniqueid = '';
+
+ /**
+ * Error severity: message only, continue processing.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> const STOP_MESSAGE = 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Error severity: message, likely ok to continue processing
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Error severity: message, likely ok to continue processing.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const STOP_CONTINUE = 1;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Error severity: message, plus full stop, critical error reached
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Error severity: message, plus full stop, critical error reached.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const STOP_CRITICAL = 2;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * SMTP RFC standard line ending
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * SMTP RFC standard line ending.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const CRLF = "\r\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Constructor
- * @param bool $exceptions Should we throw external exceptions?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The maximum line length allowed by RFC 2822 section 2.1.1
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const MAX_LINE_LENGTH = 998;
+
+ /**
+ * Constructor.
+ * @param boolean $exceptions Should we throw external exceptions?
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> public function __construct($exceptions = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->exceptions = ($exceptions == true);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->exceptions = (boolean)$exceptions;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -577,7 +619,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function __destruct()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Close any open SMTP connection nicely
+ if ($this->Mailer == 'smtp') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtpClose();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -593,53 +636,75 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $header Additional Header(s)
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $params Params
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function mailPassthru($to, $subject, $body, $header, $params)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Check overloading of mail function to avoid double-encoding
+ if (ini_get('mbstring.func_overload') & 1) {
+ $subject = $this->secureHeader($subject);
+ } else {
+ $subject = $this->encodeHeader($this->secureHeader($subject));
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = @mail($to, $subject, $body, $header);
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rt = @mail($to, $this->encodeHeader($this->secureHeader($subject)), $body, $header, $params);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = @mail($to, $subject, $body, $header, $params);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $rt;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $result;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Output debugging info via user-defined method.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Only if debug output is enabled.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see PHPMailer::$Debugoutput
</span><span class="cx" style="display: block; padding: 0 10px"> * @see PHPMailer::$SMTPDebug
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $str
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function edebug($str)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!$this->SMTPDebug) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->SMTPDebug <= 0) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Avoid clash with built-in function names
+ if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
+ call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> switch ($this->Debugoutput) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'error_log':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Don't output, just log
</ins><span class="cx" style="display: block; padding: 0 10px"> error_log($str);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'html':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Cleans up output a bit for a better looking display that's HTML-safe
- echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Cleans up output a bit for a better looking, HTML-safe output
+ echo htmlentities(
+ preg_replace('/[\r\n]+/', '', $str),
+ ENT_QUOTES,
+ 'UTF-8'
+ )
+ . "<br>\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'echo':
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Just echoes exactly what was received
- echo $str;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Normalize line breaks
+ $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
+ echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
+ "\n",
+ "\n \t ",
+ trim($str)
+ ) . "\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Sets message type to HTML or plain.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $ishtml True for HTML mode.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $isHtml True for HTML mode.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function isHTML($ishtml = true)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function isHTML($isHtml = true)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($ishtml) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($isHtml) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->ContentType = 'text/html';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->ContentType = 'text/plain';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -670,8 +735,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function isSendmail()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
- $this->Sendmail = '/var/qmail/bin/sendmail';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $ini_sendmail_path = ini_get('sendmail_path');
+
+ if (!stristr($ini_sendmail_path, 'sendmail')) {
+ $this->Sendmail = '/usr/sbin/sendmail';
+ } else {
+ $this->Sendmail = $ini_sendmail_path;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->Mailer = 'sendmail';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -682,17 +751,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function isQmail()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (stristr(ini_get('sendmail_path'), 'qmail')) {
- $this->Sendmail = '/var/qmail/bin/sendmail';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $ini_sendmail_path = ini_get('sendmail_path');
+
+ if (!stristr($ini_sendmail_path, 'qmail')) {
+ $this->Sendmail = '/var/qmail/bin/qmail-inject';
+ } else {
+ $this->Sendmail = $ini_sendmail_path;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->Mailer = 'sendmail';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->Mailer = 'qmail';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Add a "To" address.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool true on success, false if address already used
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean true on success, false if address already used
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addAddress($address, $name = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -704,7 +777,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool true on success, false if address already used
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean true on success, false if address already used
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addCC($address, $name = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -716,7 +789,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool true on success, false if address already used
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean true on success, false if address already used
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addBCC($address, $name = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -727,7 +800,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Add a "Reply-to" address.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addReplyTo($address, $name = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -741,27 +814,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address The email address to send to
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool true on success, false if address already used or invalid in some way
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean true on success, false if address already used or invalid in some way
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function addAnAddress($kind, $address, $name = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException('Invalid recipient array: ' . $kind);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
</del><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $address = trim($address);
</span><span class="cx" style="display: block; padding: 0 10px"> $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->validateAddress($address)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setError($this->lang('invalid_address') . ': ' . $address);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug($this->lang('invalid_address') . ': ' . $address);
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->edebug($this->lang('invalid_address') . ': ' . $address);
</del><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ($kind != 'Reply-To') {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -783,9 +856,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Set the From and FromName properties.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $auto Whether to also set the Sender address, defaults to true
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $auto Whether to also set the Sender address, defaults to true
</ins><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setFrom($address, $name = '', $auto = true)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -793,10 +866,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->validateAddress($address)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setError($this->lang('invalid_address') . ': ' . $address);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug($this->lang('invalid_address') . ': ' . $address);
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->edebug($this->lang('invalid_address') . ': ' . $address);
</del><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->From = $address;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -825,27 +898,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Check that a string looks like an email address.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $address The email address to check
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $patternselect A selector for the validation pattern to use :
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 'auto' - pick best one automatically;
- * 'pcre8' - use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
- * 'pcre' - use old PCRE implementation;
- * 'php' - use PHP built-in FILTER_VALIDATE_EMAIL; faster, less thorough;
- * 'noregex' - super fast, really dumb.
- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * * `auto` Pick strictest one automatically;
+ * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
+ * * `pcre` Use old PCRE implementation;
+ * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
+ * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
+ * * `noregex` Don't use a regex: super fast, really dumb.
+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> * @static
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function validateAddress($address, $patternselect = 'auto')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($patternselect == 'auto') {
- if (defined(
- 'PCRE_VERSION'
- )
- ) { //Check this instead of extension_loaded so it works when that function is disabled
- if (version_compare(PCRE_VERSION, '8.0') >= 0) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$patternselect or $patternselect == 'auto') {
+ //Check this constant first so it works when extension_loaded() is disabled by safe mode
+ //Constant was added in PHP 5.2.4
+ if (defined('PCRE_VERSION')) {
+ //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
+ if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $patternselect = 'pcre8';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $patternselect = 'pcre';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
+ //Fall back to older PCRE
+ $patternselect = 'pcre';
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
</span><span class="cx" style="display: block; padding: 0 10px"> if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -858,14 +935,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> switch ($patternselect) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'pcre8':
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
- * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
- * not allow a@b type valid addresses :(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @link http://squiloople.com/2009/12/20/email-address-validation/
</span><span class="cx" style="display: block; padding: 0 10px"> * @copyright 2009-2010 Michael Rushton
</span><span class="cx" style="display: block; padding: 0 10px"> * Feel free to use and redistribute this code. But please keep this copyright notice.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return (bool)preg_match(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return (boolean)preg_match(
</ins><span class="cx" style="display: block; padding: 0 10px"> '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
</span><span class="cx" style="display: block; padding: 0 10px"> '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
</span><span class="cx" style="display: block; padding: 0 10px"> '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -877,10 +952,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
</span><span class="cx" style="display: block; padding: 0 10px"> $address
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case 'pcre':
</span><span class="cx" style="display: block; padding: 0 10px"> //An older regex that doesn't need a recent PCRE
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return (bool)preg_match(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return (boolean)preg_match(
</ins><span class="cx" style="display: block; padding: 0 10px"> '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
</span><span class="cx" style="display: block; padding: 0 10px"> '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
</span><span class="cx" style="display: block; padding: 0 10px"> '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -893,27 +967,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
</span><span class="cx" style="display: block; padding: 0 10px"> $address
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
- case 'php':
- default:
- return (bool)filter_var($address, FILTER_VALIDATE_EMAIL);
- break;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'html5':
+ /**
+ * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
+ * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
+ */
+ return (boolean)preg_match(
+ '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
+ '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
+ $address
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'noregex':
</span><span class="cx" style="display: block; padding: 0 10px"> //No PCRE! Do something _very_ approximate!
</span><span class="cx" style="display: block; padding: 0 10px"> //Check the address is 3 chars or longer and contains an @ that's not the first or last char
</span><span class="cx" style="display: block; padding: 0 10px"> return (strlen($address) >= 3
</span><span class="cx" style="display: block; padding: 0 10px"> and strpos($address, '@') >= 1
</span><span class="cx" style="display: block; padding: 0 10px"> and strpos($address, '@') != strlen($address) - 1);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'php':
+ default:
+ return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Create a message and send it.
</span><span class="cx" style="display: block; padding: 0 10px"> * Uses the sending method specified by $Mailer.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns false on error - Use the ErrorInfo variable to view description of the error.
</del><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean false on error - See the ErrorInfo property for details of the error.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function send()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -922,11 +1002,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->postSend();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (phpmailerException $e) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->mailHeader = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->setError($e->getMessage());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError($exc->getMessage());
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw $e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw $exc;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -935,12 +1015,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Prepare a message for sending.
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function preSend()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->mailHeader = "";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->mailHeader = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -950,23 +1030,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->ContentType = 'multipart/alternative';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error_count = 0; // reset errors
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->error_count = 0; // Reset errors
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->setMessageType();
</span><span class="cx" style="display: block; padding: 0 10px"> // Refuse to send an empty message unless we are specifically allowing it
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->AllowEmpty and empty($this->Body)) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
+ $this->MIMEHeader = '';
+ $this->MIMEBody = $this->createBody();
+ // createBody may have added some headers, so retain them
+ $tempheaders = $this->MIMEHeader;
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->MIMEHeader = $this->createHeader();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->MIMEBody = $this->createBody();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->MIMEHeader .= $tempheaders;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // To capture the complete message when using mail(), create
</span><span class="cx" style="display: block; padding: 0 10px"> // an extra header list which createHeader() doesn't fold in
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Mailer == 'mail') {
</span><span class="cx" style="display: block; padding: 0 10px"> if (count($this->to) > 0) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->mailHeader .= $this->addrAppend("To", $this->to);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->mailHeader .= $this->addrAppend('To', $this->to);
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->mailHeader .= $this->headerLine("To", "undisclosed-recipients:;");
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->mailHeader .= $this->headerLine(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Subject',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -978,7 +1063,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if (!empty($this->DKIM_domain)
</span><span class="cx" style="display: block; padding: 0 10px"> && !empty($this->DKIM_private)
</span><span class="cx" style="display: block; padding: 0 10px"> && !empty($this->DKIM_selector)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- && !empty($this->DKIM_domain)
</del><span class="cx" style="display: block; padding: 0 10px"> && file_exists($this->DKIM_private)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $header_dkim = $this->DKIM_Add(
</span><span class="cx" style="display: block; padding: 0 10px"> $this->MIMEHeader . $this->mailHeader,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -989,11 +1073,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- } catch (phpmailerException $e) {
- $this->setError($e->getMessage());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
+ $this->setError($exc->getMessage());
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw $e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw $exc;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1003,28 +1086,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Actually send a message.
</span><span class="cx" style="display: block; padding: 0 10px"> * Send the email via the selected mechanism
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function postSend()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo 'called';
</ins><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> // Choose the mailer and send through it
</span><span class="cx" style="display: block; padding: 0 10px"> switch ($this->Mailer) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'sendmail':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'qmail':
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
</span><span class="cx" style="display: block; padding: 0 10px"> case 'smtp':
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
</span><span class="cx" style="display: block; padding: 0 10px"> case 'mail':
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $sendMethod = $this->Mailer.'Send';
+ if (method_exists($this, $sendMethod)) {
+ return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (phpmailerException $e) {
- $this->setError($e->getMessage());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
+ $this->setError($exc->getMessage());
+ $this->edebug($exc->getMessage());
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw $e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw $exc;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->edebug($e->getMessage() . "\n");
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1036,27 +1126,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see PHPMailer::$Sendmail
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function sendmailSend($header, $body)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Sender != '') {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->Mailer == 'qmail') {
+ $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
+ } else {
+ $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->Mailer == 'qmail') {
+ $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
+ } else {
+ $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->SingleTo === true) {
- foreach ($this->SingleToArray as $val) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->SingleTo) {
+ foreach ($this->SingleToArray as $toAddr) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!@$mail = popen($sendmail, 'w')) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- fputs($mail, "To: " . $val . "\n");
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ fputs($mail, 'To: ' . $toAddr . "\n");
</ins><span class="cx" style="display: block; padding: 0 10px"> fputs($mail, $header);
</span><span class="cx" style="display: block; padding: 0 10px"> fputs($mail, $body);
</span><span class="cx" style="display: block; padding: 0 10px"> $result = pclose($mail);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // implement call back function if it exists
- $isSent = ($result == 0) ? 1 : 0;
- $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->doCallback(
+ ($result == 0),
+ array($toAddr),
+ $this->cc,
+ $this->bcc,
+ $this->Subject,
+ $body,
+ $this->From
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($result != 0) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1068,9 +1172,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> fputs($mail, $header);
</span><span class="cx" style="display: block; padding: 0 10px"> fputs($mail, $body);
</span><span class="cx" style="display: block; padding: 0 10px"> $result = pclose($mail);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // implement call back function if it exists
- $isSent = ($result == 0) ? 1 : 0;
- $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($result != 0) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1085,43 +1187,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @link http://www.php.net/manual/en/book.mail.php
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function mailSend($header, $body)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $toArr = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ($this->to as $t) {
- $toArr[] = $this->addrFormat($t);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ($this->to as $toaddr) {
+ $toArr[] = $this->addrFormat($toaddr);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $to = implode(', ', $toArr);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (empty($this->Sender)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $params = " ";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $params = ' ';
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $params = sprintf("-f%s", $this->Sender);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $params = sprintf('-f%s', $this->Sender);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Sender != '' and !ini_get('safe_mode')) {
</span><span class="cx" style="display: block; padding: 0 10px"> $old_from = ini_get('sendmail_from');
</span><span class="cx" style="display: block; padding: 0 10px"> ini_set('sendmail_from', $this->Sender);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rt = false;
- if ($this->SingleTo === true && count($toArr) > 1) {
- foreach ($toArr as $val) {
- $rt = $this->mailPassthru($val, $this->Subject, $body, $header, $params);
- // implement call back function if it exists
- $isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = false;
+ if ($this->SingleTo && count($toArr) > 1) {
+ foreach ($toArr as $toAddr) {
+ $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
+ $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $rt = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
- // implement call back function if it exists
- $isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
+ $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if (isset($old_from)) {
</span><span class="cx" style="display: block; padding: 0 10px"> ini_set('sendmail_from', $old_from);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!$rt) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$result) {
</ins><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1135,7 +1233,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function getSMTPInstance()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!is_object($this->smtp)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- require_once 'class-smtp.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ require_once( 'class-smtp.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtp = new SMTP;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->smtp;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1151,62 +1249,59 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><span class="cx" style="display: block; padding: 0 10px"> * @uses SMTP
</span><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function smtpSend($header, $body)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $bad_rcpt = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- if (!$this->smtpConnect()) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$this->smtpConnect($this->SMTPOptions)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ('' == $this->Sender) {
+ $smtp_from = $this->From;
+ } else {
+ $smtp_from = $this->Sender;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!$this->smtp->mail($smtp_from)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Attempt to send attach all recipients
- foreach ($this->to as $to) {
- if (!$this->smtp->recipient($to[0])) {
- $bad_rcpt[] = $to[0];
- $isSent = 0;
- } else {
- $isSent = 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Attempt to send to all recipients
+ foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
+ foreach ($togroup as $to) {
+ if (!$this->smtp->recipient($to[0])) {
+ $error = $this->smtp->getError();
+ $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
+ $isSent = false;
+ } else {
+ $isSent = true;
+ }
+ $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body, $this->From);
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ($this->cc as $cc) {
- if (!$this->smtp->recipient($cc[0])) {
- $bad_rcpt[] = $cc[0];
- $isSent = 0;
- } else {
- $isSent = 1;
- }
- $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body, $this->From);
- }
- foreach ($this->bcc as $bcc) {
- if (!$this->smtp->recipient($bcc[0])) {
- $bad_rcpt[] = $bcc[0];
- $isSent = 0;
- } else {
- $isSent = 1;
- }
- $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body, $this->From);
- }
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (count($bad_rcpt) > 0) { //Create error message for any bad addresses
- throw new phpmailerException($this->lang('recipients_failed') . implode(', ', $bad_rcpt));
- }
- if (!$this->smtp->data($header . $body)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only send the DATA command if we have viable recipients
+ if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->SMTPKeepAlive == true) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->SMTPKeepAlive) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->reset();
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->quit();
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->close();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Create error message for any bad addresses
+ if (count($bad_rcpt) > 0) {
+ $errstr = '';
+ foreach ($bad_rcpt as $bad) {
+ $errstr .= $bad['to'] . ': ' . $bad['error'];
+ }
+ throw new phpmailerException(
+ $this->lang('recipients_failed') . $errstr,
+ self::STOP_CONTINUE
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1217,7 +1312,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @uses SMTP
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function smtpConnect($options = array())
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1225,7 +1320,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp = $this->getSMTPInstance();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Already connected?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Already connected?
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->smtp->connected()) {
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1234,25 +1329,47 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->setDebugLevel($this->SMTPDebug);
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->setDebugOutput($this->Debugoutput);
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->setVerp($this->do_verp);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $tls = ($this->SMTPSecure == 'tls');
- $ssl = ($this->SMTPSecure == 'ssl');
</del><span class="cx" style="display: block; padding: 0 10px"> $hosts = explode(';', $this->Host);
</span><span class="cx" style="display: block; padding: 0 10px"> $lastexception = null;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ($hosts as $hostentry) {
</span><span class="cx" style="display: block; padding: 0 10px"> $hostinfo = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $host = $hostentry;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
+ // Not a valid host entry
+ continue;
+ }
+ // $hostinfo[2]: optional ssl or tls prefix
+ // $hostinfo[3]: the hostname
+ // $hostinfo[4]: optional port number
+ // The host string prefix can temporarily override the current setting for SMTPSecure
+ // If it's not specified, the default value is used
+ $prefix = '';
+ $secure = $this->SMTPSecure;
+ $tls = ($this->SMTPSecure == 'tls');
+ if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
+ $prefix = 'ssl://';
+ $tls = false; // Can't have SSL and TLS at the same time
+ $secure = 'ssl';
+ } elseif ($hostinfo[2] == 'tls') {
+ $tls = true;
+ // tls doesn't use a prefix
+ $secure = 'tls';
+ }
+ //Do we need the OpenSSL extension?
+ $sslext = defined('OPENSSL_ALGO_SHA1');
+ if ('tls' === $secure or 'ssl' === $secure) {
+ //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
+ if (!$sslext) {
+ throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
+ }
+ }
+ $host = $hostinfo[3];
</ins><span class="cx" style="display: block; padding: 0 10px"> $port = $this->Port;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (preg_match(
- '/^(.+):([0-9]+)$/',
- $hostentry,
- $hostinfo
- )
- ) { //If $hostentry contains 'address:port', override default
- $host = $hostinfo[1];
- $port = $hostinfo[2];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $tport = (integer)$hostinfo[4];
+ if ($tport > 0 and $tport < 65536) {
+ $port = $tport;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->smtp->connect(($ssl ? 'ssl://' : '') . $host, $port, $this->Timeout, $options)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Helo) {
</span><span class="cx" style="display: block; padding: 0 10px"> $hello = $this->Helo;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1260,12 +1377,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $hello = $this->serverHostname();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->hello($hello);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Automatically enable TLS encryption if:
+ // * it's not disabled
+ // * we have openssl extension
+ // * we are not already using SSL
+ // * the server offers STARTTLS
+ if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
+ $tls = true;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($tls) {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->smtp->startTLS()) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('connect_host'));
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //We must resend HELO after tls negotiation
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // We must resend HELO after tls negotiation
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->hello($hello);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->SMTPAuth) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1281,16 +1405,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (phpmailerException $e) {
- $lastexception = $e;
- //We must have connected, but then failed TLS or Auth, so close connection nicely
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
+ $lastexception = $exc;
+ $this->edebug($exc->getMessage());
+ // We must have connected, but then failed TLS or Auth, so close connection nicely
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->quit();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If we get here, all connection attempts have failed, so close connection hard
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If we get here, all connection attempts have failed, so close connection hard
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->smtp->close();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //As we've caught all exceptions, just report whatever the last one was
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // As we've caught all exceptions, just report whatever the last one was
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions and !is_null($lastexception)) {
</span><span class="cx" style="display: block; padding: 0 10px"> throw $lastexception;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1317,12 +1442,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The default language is English.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $lang_path Path to the language file directory, with trailing separator (slash)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function setLanguage($langcode = 'en', $lang_path = 'language/')
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function setLanguage($langcode = 'en', $lang_path = '')
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Define full set of translatable strings
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Define full set of translatable strings in English
</ins><span class="cx" style="display: block; padding: 0 10px"> $PHPMAILER_LANG = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'authenticate' => 'SMTP Error: Could not authenticate.',
</span><span class="cx" style="display: block; padding: 0 10px"> 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1341,16 +1466,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'signing' => 'Signing Error: ',
</span><span class="cx" style="display: block; padding: 0 10px"> 'smtp_connect_failed' => 'SMTP connect() failed.',
</span><span class="cx" style="display: block; padding: 0 10px"> 'smtp_error' => 'SMTP server error: ',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'variable_set' => 'Cannot set or reset variable: '
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'variable_set' => 'Cannot set or reset variable: ',
+ 'extension_missing' => 'Extension missing: '
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Overwrite language-specific strings.
- //This way we'll never have missing translations - no more "language string failed to load"!
- $l = true;
- if ($langcode != 'en') { //There is no English translation file
- $l = @include $lang_path . 'phpmailer.lang-' . $langcode . '.php';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (empty($lang_path)) {
+ // Calculate an absolute path so it can work if CWD is not here
+ $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $foundlang = true;
+ $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
+ // There is no English translation file
+ if ($langcode != 'en') {
+ // Make sure language file path is readable
+ if (!is_readable($lang_file)) {
+ $foundlang = false;
+ } else {
+ // Overwrite language-specific strings.
+ // This way we'll never have missing translation keys.
+ $foundlang = include $lang_file;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->language = $PHPMAILER_LANG;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return ($l == true); //Returns false if language not found
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return (boolean)$foundlang; // Returns false if language not found
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1375,8 +1512,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function addrAppend($type, $addr)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $addresses = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ($addr as $a) {
- $addresses[] = $this->addrFormat($a);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ($addr as $address) {
+ $addresses[] = $this->addrFormat($address);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $type . ': ' . implode(', ', $addresses) . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1393,9 +1530,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if (empty($addr[1])) { // No name provided
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->secureHeader($addr[0]);
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . " <" . $this->secureHeader(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
</ins><span class="cx" style="display: block; padding: 0 10px"> $addr[0]
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ) . ">";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ ) . '>';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1406,47 +1543,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Original written by philippe.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $message The message to wrap
</span><span class="cx" style="display: block; padding: 0 10px"> * @param integer $length The line length to wrap to
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $qp_mode Whether to run in Quoted-Printable mode
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $qp_mode Whether to run in Quoted-Printable mode
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function wrapText($message, $length, $qp_mode = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($qp_mode) {
+ $soft_break = sprintf(' =%s', $this->LE);
+ } else {
+ $soft_break = $this->LE;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> // If utf-8 encoding is used, we will need to make sure we don't
</span><span class="cx" style="display: block; padding: 0 10px"> // split multibyte characters when we wrap
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $is_utf8 = (strtolower($this->CharSet) == "utf-8");
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
</ins><span class="cx" style="display: block; padding: 0 10px"> $lelen = strlen($this->LE);
</span><span class="cx" style="display: block; padding: 0 10px"> $crlflen = strlen(self::CRLF);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $message = $this->fixEOL($message);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Remove a trailing line break
</ins><span class="cx" style="display: block; padding: 0 10px"> if (substr($message, -$lelen) == $this->LE) {
</span><span class="cx" style="display: block; padding: 0 10px"> $message = substr($message, 0, -$lelen);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Split message into lines
+ $lines = explode($this->LE, $message);
+ //Message will be rebuilt in here
</ins><span class="cx" style="display: block; padding: 0 10px"> $message = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- for ($i = 0; $i < count($line); $i++) {
- $line_part = explode(' ', $line[$i]);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ($lines as $line) {
+ $words = explode(' ', $line);
</ins><span class="cx" style="display: block; padding: 0 10px"> $buf = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- for ($e = 0; $e < count($line_part); $e++) {
- $word = $line_part[$e];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $firstword = true;
+ foreach ($words as $word) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($qp_mode and (strlen($word) > $length)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $space_left = $length - strlen($buf) - $crlflen;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($e != 0) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$firstword) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($space_left > 20) {
</span><span class="cx" style="display: block; padding: 0 10px"> $len = $space_left;
</span><span class="cx" style="display: block; padding: 0 10px"> if ($is_utf8) {
</span><span class="cx" style="display: block; padding: 0 10px"> $len = $this->utf8CharBoundary($word, $len);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (substr($word, $len - 1, 1) == "=") {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (substr($word, $len - 1, 1) == '=') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $len--;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (substr($word, $len - 2, 1) == "=") {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (substr($word, $len - 2, 1) == '=') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $len -= 2;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $part = substr($word, 0, $len);
</span><span class="cx" style="display: block; padding: 0 10px"> $word = substr($word, $len);
</span><span class="cx" style="display: block; padding: 0 10px"> $buf .= ' ' . $part;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $message .= $buf . sprintf("=%s", self::CRLF);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message .= $buf . sprintf('=%s', self::CRLF);
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $message .= $buf . $soft_break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1459,29 +1603,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $len = $length;
</span><span class="cx" style="display: block; padding: 0 10px"> if ($is_utf8) {
</span><span class="cx" style="display: block; padding: 0 10px"> $len = $this->utf8CharBoundary($word, $len);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (substr($word, $len - 1, 1) == "=") {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (substr($word, $len - 1, 1) == '=') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $len--;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (substr($word, $len - 2, 1) == "=") {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (substr($word, $len - 2, 1) == '=') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $len -= 2;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $part = substr($word, 0, $len);
</span><span class="cx" style="display: block; padding: 0 10px"> $word = substr($word, $len);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (strlen($word) > 0) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $message .= $part . sprintf("=%s", self::CRLF);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message .= $part . sprintf('=%s', self::CRLF);
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $buf = $part;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $buf_o = $buf;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $buf .= ($e == 0) ? $word : (' ' . $word);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$firstword) {
+ $buf .= ' ';
+ }
+ $buf .= $word;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if (strlen($buf) > $length and $buf_o != '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $message .= $buf_o . $soft_break;
</span><span class="cx" style="display: block; padding: 0 10px"> $buf = $word;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $firstword = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $message .= $buf . self::CRLF;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1491,12 +1639,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Find the last character boundary prior to $maxLength in a utf-8
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * quoted (printable) encoded string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * quoted-printable encoded string.
</ins><span class="cx" style="display: block; padding: 0 10px"> * Original written by Colin Brown.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $encodedText utf-8 QP text
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $maxLength find last character boundary prior to this length
- * @return int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param integer $maxLength Find the last character boundary prior to this length
+ * @return integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function utf8CharBoundary($encodedText, $maxLength)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1504,23 +1652,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $lookBack = 3;
</span><span class="cx" style="display: block; padding: 0 10px"> while (!$foundSplitPos) {
</span><span class="cx" style="display: block; padding: 0 10px"> $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $encodedCharPos = strpos($lastChunk, "=");
- if ($encodedCharPos !== false) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encodedCharPos = strpos($lastChunk, '=');
+ if (false !== $encodedCharPos) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Found start of encoded character byte within $lookBack block.
</span><span class="cx" style="display: block; padding: 0 10px"> // Check the encoded byte value (the 2 chars after the '=')
</span><span class="cx" style="display: block; padding: 0 10px"> $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
</span><span class="cx" style="display: block; padding: 0 10px"> $dec = hexdec($hex);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($dec < 128) { // Single byte character.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($dec < 128) {
+ // Single byte character.
</ins><span class="cx" style="display: block; padding: 0 10px"> // If the encoded char was found at pos 0, it will fit
</span><span class="cx" style="display: block; padding: 0 10px"> // otherwise reduce maxLength to start of the encoded char
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $maxLength = ($encodedCharPos == 0) ? $maxLength :
- $maxLength - ($lookBack - $encodedCharPos);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($encodedCharPos > 0) {
+ $maxLength = $maxLength - ($lookBack - $encodedCharPos);
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $foundSplitPos = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ($dec >= 192) { // First byte of a multi byte character
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ($dec >= 192) {
+ // First byte of a multi byte character
</ins><span class="cx" style="display: block; padding: 0 10px"> // Reduce maxLength to split at start of character
</span><span class="cx" style="display: block; padding: 0 10px"> $maxLength = $maxLength - ($lookBack - $encodedCharPos);
</span><span class="cx" style="display: block; padding: 0 10px"> $foundSplitPos = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ($dec < 192) {
+ // Middle byte of a multi byte character, look further back
</ins><span class="cx" style="display: block; padding: 0 10px"> $lookBack += 3;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1531,9 +1683,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $maxLength;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Set the body wrapping.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Apply word wrapping to the message body.
+ * Wraps the message body to the number of chars set in the WordWrap property.
+ * You should only do this to plain-text bodies as wrapping HTML tags may break them.
+ * This is called automatically by createBody(), so you don't need to call it yourself.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1565,38 +1719,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $result = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Set the boundaries
- $uniq_id = md5(uniqid(time()));
- $this->boundary[1] = 'b1_' . $uniq_id;
- $this->boundary[2] = 'b2_' . $uniq_id;
- $this->boundary[3] = 'b3_' . $uniq_id;
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ($this->MessageDate == '') {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result .= $this->headerLine('Date', self::rfcDate());
- } else {
- $result .= $this->headerLine('Date', $this->MessageDate);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->MessageDate = self::rfcDate();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result .= $this->headerLine('Date', $this->MessageDate);
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->ReturnPath) {
- $result .= $this->headerLine('Return-Path', '<' . trim($this->ReturnPath) . '>');
- } elseif ($this->Sender == '') {
- $result .= $this->headerLine('Return-Path', '<' . trim($this->From) . '>');
- } else {
- $result .= $this->headerLine('Return-Path', '<' . trim($this->Sender) . '>');
- }
</del><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // To be created automatically by mail()
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->Mailer != 'mail') {
- if ($this->SingleTo === true) {
- foreach ($this->to as $t) {
- $this->SingleToArray[] = $this->addrFormat($t);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($this->SingleTo) {
+ if ($this->Mailer != 'mail') {
+ foreach ($this->to as $toaddr) {
+ $this->SingleToArray[] = $this->addrFormat($toaddr);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- if (count($this->to) > 0) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ } else {
+ if (count($this->to) > 0) {
+ if ($this->Mailer != 'mail') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->addrAppend('To', $this->to);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (count($this->cc) == 0) {
- $result .= $this->headerLine('To', 'undisclosed-recipients:;');
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (count($this->cc) == 0) {
+ $result .= $this->headerLine('To', 'undisclosed-recipients:;');
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1608,7 +1750,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // sendmail and mail() extract Bcc from the header before sending
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ((
+ $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
+ )
+ and count($this->bcc) > 0
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->addrAppend('Bcc', $this->bcc);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1624,9 +1770,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->MessageID != '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->lastMessageID = $this->MessageID;
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->lastMessageID = sprintf("<%s@%s>", $uniq_id, $this->ServerHostname());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->ServerHostname());
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result .= $this->headerLine('Message-ID', $this->lastMessageID);
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->headerLine('X-Priority', $this->Priority);
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->XMailer == '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->headerLine(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1645,10 +1791,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Add custom headers
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- for ($index = 0; $index < count($this->CustomHeader); $index++) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ($this->CustomHeader as $header) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->headerLine(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- trim($this->CustomHeader[$index][0]),
- $this->encodeHeader(trim($this->CustomHeader[$index][1]))
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ trim($header[0]),
+ $this->encodeHeader(trim($header[1]))
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->sign_key_file) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1667,6 +1813,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function getMailMIME()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $result = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $ismultipart = true;
</ins><span class="cx" style="display: block; padding: 0 10px"> switch ($this->message_type) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'inline':
</span><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->headerLine('Content-Type', 'multipart/related;');
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1687,11 +1834,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><span class="cx" style="display: block; padding: 0 10px"> // Catches case 'plain': and case '':
</span><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $ismultipart = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //RFC1341 part 5 says 7bit is assumed if not specified
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC1341 part 5 says 7bit is assumed if not specified
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->Encoding != '7bit') {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
+ if ($ismultipart) {
+ if ($this->Encoding == '8bit') {
+ $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
+ }
+ // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
+ } else {
+ $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Mailer != 'mail') {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1704,8 +1860,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Returns the whole MIME message.
</span><span class="cx" style="display: block; padding: 0 10px"> * Includes complete headers and body.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Only valid post PreSend().
- * @see PHPMailer::PreSend()
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Only valid post preSend().
+ * @see PHPMailer::preSend()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1714,7 +1870,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Assemble the message body.
</span><span class="cx" style="display: block; padding: 0 10px"> * Returns an empty string on failure.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1725,6 +1880,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function createBody()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $body = '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Create unique IDs and preset boundaries
+ $this->uniqueid = md5(uniqid(time()));
+ $this->boundary[1] = 'b1_' . $this->uniqueid;
+ $this->boundary[2] = 'b2_' . $this->uniqueid;
+ $this->boundary[3] = 'b3_' . $this->uniqueid;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->sign_key_file) {
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->getMailMIME() . $this->LE;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1732,37 +1892,67 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setWordWrap();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bodyEncoding = $this->Encoding;
+ $bodyCharSet = $this->CharSet;
+ //Can we do a 7-bit downgrade?
+ if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
+ $bodyEncoding = '7bit';
+ $bodyCharSet = 'us-ascii';
+ }
+ //If lines are too long, change to quoted-printable transfer encoding
+ if (self::hasLineLongerThanMax($this->Body)) {
+ $this->Encoding = 'quoted-printable';
+ $bodyEncoding = 'quoted-printable';
+ }
+
+ $altBodyEncoding = $this->Encoding;
+ $altBodyCharSet = $this->CharSet;
+ //Can we do a 7-bit downgrade?
+ if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
+ $altBodyEncoding = '7bit';
+ $altBodyCharSet = 'us-ascii';
+ }
+ //If lines are too long, change to quoted-printable transfer encoding
+ if (self::hasLineLongerThanMax($this->AltBody)) {
+ $altBodyEncoding = 'quoted-printable';
+ }
+ //Use this as a preamble in all multipart message types
+ $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
</ins><span class="cx" style="display: block; padding: 0 10px"> switch ($this->message_type) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'inline':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[1], '', '', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
+ $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('inline', $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'attach':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[1], '', '', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
+ $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('attachment', $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'inline_attach':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine('--' . $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->headerLine('Content-Type', 'multipart/related;');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[2], '', '', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('inline', $this->boundary[2]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('attachment', $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'alt':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[1], '', 'text/plain', '');
- $body .= $this->encodeString($this->AltBody, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
+ $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
+ $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[1], '', 'text/html', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> if (!empty($this->Ical)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1772,49 +1962,52 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->endBoundary($this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'alt_inline':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[1], '', 'text/plain', '');
- $body .= $this->encodeString($this->AltBody, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
+ $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
+ $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine('--' . $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->headerLine('Content-Type', 'multipart/related;');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[2], '', 'text/html', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('inline', $this->boundary[2]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->endBoundary($this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'alt_attach':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine('--' . $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[2], '', 'text/plain', '');
- $body .= $this->encodeString($this->AltBody, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
+ $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[2], '', 'text/html', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->endBoundary($this->boundary[2]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('attachment', $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'alt_inline_attach':
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $mimepre;
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine('--' . $this->boundary[1]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[2], '', 'text/plain', '');
- $body .= $this->encodeString($this->AltBody, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
+ $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine('--' . $this->boundary[2]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->headerLine('Content-Type', 'multipart/related;');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->getBoundary($this->boundary[3], '', 'text/html', '');
- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE . $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->attachAll('inline', $this->boundary[3]);
</span><span class="cx" style="display: block; padding: 0 10px"> $body .= $this->LE;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1824,7 +2017,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><span class="cx" style="display: block; padding: 0 10px"> // catch case 'plain' and case ''
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $body .= $this->encodeString($this->Body, $this->Encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $body .= $this->encodeString($this->Body, $bodyEncoding);
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1833,31 +2026,51 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ($this->sign_key_file) {
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!defined('PKCS7_TEXT')) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw new phpmailerException($this->lang('extension_missing') . 'openssl');
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
</ins><span class="cx" style="display: block; padding: 0 10px"> $file = tempnam(sys_get_temp_dir(), 'mail');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- file_put_contents($file, $body); //TODO check this worked
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (false === file_put_contents($file, $body)) {
+ throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $signed = tempnam(sys_get_temp_dir(), 'signed');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (@openssl_pkcs7_sign(
- $file,
- $signed,
- 'file://' . realpath($this->sign_cert_file),
- array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
- null
- )
- ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
+ if (empty($this->sign_extracerts_file)) {
+ $sign = @openssl_pkcs7_sign(
+ $file,
+ $signed,
+ 'file://' . realpath($this->sign_cert_file),
+ array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
+ null
+ );
+ } else {
+ $sign = @openssl_pkcs7_sign(
+ $file,
+ $signed,
+ 'file://' . realpath($this->sign_cert_file),
+ array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
+ null,
+ PKCS7_DETACHED,
+ $this->sign_extracerts_file
+ );
+ }
+ if ($sign) {
</ins><span class="cx" style="display: block; padding: 0 10px"> @unlink($file);
</span><span class="cx" style="display: block; padding: 0 10px"> $body = file_get_contents($signed);
</span><span class="cx" style="display: block; padding: 0 10px"> @unlink($signed);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //The message returned by openssl contains both headers and body, so need to split them up
+ $parts = explode("\n\n", $body, 2);
+ $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
+ $body = $parts[1];
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> @unlink($file);
</span><span class="cx" style="display: block; padding: 0 10px"> @unlink($signed);
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('signing') . openssl_error_string());
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (phpmailerException $e) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $body = '';
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw $e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw $exc;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1886,9 +2099,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $encoding = $this->Encoding;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->textLine('--' . $boundary);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->LE;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC1341 part 5 says 7bit is assumed if not specified
+ if ($encoding != '7bit') {
+ $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $result .= $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $result;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1914,19 +2130,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function setMessageType()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->message_type = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $type = array();
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->alternativeExists()) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->message_type[] = "alt";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $type[] = 'alt';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->inlineImageExists()) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->message_type[] = "inline";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $type[] = 'inline';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->attachmentExists()) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->message_type[] = "attach";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $type[] = 'attach';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->message_type = implode("_", $this->message_type);
- if ($this->message_type == "") {
- $this->message_type = "plain";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->message_type = implode('_', $type);
+ if ($this->message_type == '') {
+ $this->message_type = 'plain';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1962,7 +2178,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $type File extension (MIME) type.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $disposition Disposition to use
</span><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1971,7 +2187,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If a MIME type is not specified, try to work it out from the file name
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If a MIME type is not specified, try to work it out from the file name
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($type == '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $type = self::filenameToType($path);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1992,12 +2208,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 7 => 0
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (phpmailerException $e) {
- $this->setError($e->getMessage());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (phpmailerException $exc) {
+ $this->setError($exc->getMessage());
+ $this->edebug($exc->getMessage());
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw $e;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw $exc;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->edebug($e->getMessage() . "\n");
</del><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2056,17 +2272,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $cidUniq[$cid] = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $mime[] = sprintf("--%s%s", $boundary, $this->LE);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $mime[] = sprintf('--%s%s', $boundary, $this->LE);
</ins><span class="cx" style="display: block; padding: 0 10px"> $mime[] = sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "Content-Type: %s; name=\"%s\"%s",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Content-Type: %s; name="%s"%s',
</ins><span class="cx" style="display: block; padding: 0 10px"> $type,
</span><span class="cx" style="display: block; padding: 0 10px"> $this->encodeHeader($this->secureHeader($name)),
</span><span class="cx" style="display: block; padding: 0 10px"> $this->LE
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC1341 part 5 says 7bit is assumed if not specified
+ if ($encoding != '7bit') {
+ $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ($disposition == 'inline') {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If a filename contains any of these chars, it should be quoted,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2074,18 +2293,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Fixes a warning in IETF's msglint MIME checker
</span><span class="cx" style="display: block; padding: 0 10px"> // Allow for bypassing the Content-Disposition header totally
</span><span class="cx" style="display: block; padding: 0 10px"> if (!(empty($disposition))) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $name)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded_name = $this->encodeHeader($this->secureHeader($name));
+ if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $mime[] = sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "Content-Disposition: %s; filename=\"%s\"%s",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Content-Disposition: %s; filename="%s"%s',
</ins><span class="cx" style="display: block; padding: 0 10px"> $disposition,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->encodeHeader($this->secureHeader($name)),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded_name,
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->LE . $this->LE
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $mime[] = sprintf(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "Content-Disposition: %s; filename=%s%s",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Content-Disposition: %s; filename=%s%s',
</ins><span class="cx" style="display: block; padding: 0 10px"> $disposition,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->encodeHeader($this->secureHeader($name)),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded_name,
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->LE . $this->LE
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2110,9 +2330,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return implode("", $mime);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return implode('', $mime);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2134,9 +2354,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $magic_quotes = get_magic_quotes_runtime();
</span><span class="cx" style="display: block; padding: 0 10px"> if ($magic_quotes) {
</span><span class="cx" style="display: block; padding: 0 10px"> if (version_compare(PHP_VERSION, '5.3.0', '<')) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- set_magic_quotes_runtime(0);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ set_magic_quotes_runtime(false);
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ini_set('magic_quotes_runtime', 0);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Doesn't exist in PHP 5.4, but we don't need to check because
+ //get_magic_quotes_runtime always returns false in 5.4+
+ //so it will never get here
+ ini_set('magic_quotes_runtime', false);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $file_buffer = file_get_contents($path);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2149,8 +2372,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $file_buffer;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } catch (Exception $e) {
- $this->setError($e->getMessage());
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } catch (Exception $exc) {
+ $this->setError($exc->getMessage());
</ins><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2173,7 +2396,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> case '7bit':
</span><span class="cx" style="display: block; padding: 0 10px"> case '8bit':
</span><span class="cx" style="display: block; padding: 0 10px"> $encoded = $this->fixEOL($str);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Make sure it ends with a line break
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Make sure it ends with a line break
</ins><span class="cx" style="display: block; padding: 0 10px"> if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
</span><span class="cx" style="display: block; padding: 0 10px"> $encoded .= $this->LE;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2201,11 +2424,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function encodeHeader($str, $position = 'text')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $x = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $matchcount = 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> switch (strtolower($position)) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'phrase':
</span><span class="cx" style="display: block; padding: 0 10px"> if (!preg_match('/[\200-\377]/', $str)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Can't use addslashes as we don't know what value has magic_quotes_sybase
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Can't use addslashes as we don't know the value of magic_quotes_sybase
</ins><span class="cx" style="display: block; padding: 0 10px"> $encoded = addcslashes($str, "\0..\37\177\\\"");
</span><span class="cx" style="display: block; padding: 0 10px"> if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
</span><span class="cx" style="display: block; padding: 0 10px"> return ($encoded);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2213,26 +2436,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return ("\"$encoded\"");
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> /** @noinspection PhpMissingBreakStatementInspection */
</span><span class="cx" style="display: block; padding: 0 10px"> case 'comment':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $x = preg_match_all('/[()"]/', $str, $matches);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $matchcount = preg_match_all('/[()"]/', $str, $matches);
</ins><span class="cx" style="display: block; padding: 0 10px"> // Intentional fall-through
</span><span class="cx" style="display: block; padding: 0 10px"> case 'text':
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($x == 0) { //There are no chars that need encoding
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //There are no chars that need encoding
+ if ($matchcount == 0) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return ($str);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $maxlen = 75 - 7 - strlen($this->CharSet);
</span><span class="cx" style="display: block; padding: 0 10px"> // Try to select the encoding which should produce the shortest output
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($x > strlen($str) / 3) {
- //More than a third of the content will need encoding, so B encoding will be most efficient
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($matchcount > strlen($str) / 3) {
+ // More than a third of the content will need encoding, so B encoding will be most efficient
</ins><span class="cx" style="display: block; padding: 0 10px"> $encoding = 'B';
</span><span class="cx" style="display: block; padding: 0 10px"> if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Use a custom function which correctly encodes and wraps long
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2250,7 +2474,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $encoded = preg_replace('/^(.*)$/m', " =?" . $this->CharSet . "?$encoding?\\1?=", $encoded);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
</ins><span class="cx" style="display: block; padding: 0 10px"> $encoded = trim(str_replace("\n", $this->LE, $encoded));
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $encoded;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2260,7 +2484,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Check if a string contains multi-byte characters.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $str multi-byte text to wrap encode
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function hasMultiBytes($str)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2272,21 +2496,32 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Does a string contain any 8-bit chars (in any charset)?
+ * @param string $text
+ * @return boolean
+ */
+ public function has8bitChars($text)
+ {
+ return (boolean)preg_match('/[\x80-\xFF]/', $text);
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Encode and wrap long multibyte strings for mail headers
</span><span class="cx" style="display: block; padding: 0 10px"> * without breaking lines within a character.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Adapted from a function by paravoid
+ * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $str multi-byte text to wrap encode
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $lf string to use as linefeed/end-of-line
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $linebreak string to use as linefeed/end-of-line
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function base64EncodeWrapMB($str, $lf = null)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function base64EncodeWrapMB($str, $linebreak = null)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $start = "=?" . $this->CharSet . "?B?";
- $end = "?=";
- $encoded = "";
- if ($lf === null) {
- $lf = $this->LE;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $start = '=?' . $this->CharSet . '?B?';
+ $end = '?=';
+ $encoded = '';
+ if ($linebreak === null) {
+ $linebreak = $this->LE;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $mb_length = mb_strlen($str, $this->CharSet);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2305,11 +2540,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $chunk = base64_encode($chunk);
</span><span class="cx" style="display: block; padding: 0 10px"> $lookBack++;
</span><span class="cx" style="display: block; padding: 0 10px"> } while (strlen($chunk) > $length);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $encoded .= $chunk . $lf;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded .= $chunk . $linebreak;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Chomp the last linefeed
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $encoded = substr($encoded, 0, -strlen($lf));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $encoded = substr($encoded, 0, -strlen($linebreak));
</ins><span class="cx" style="display: block; padding: 0 10px"> return $encoded;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2320,21 +2555,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $string The text to encode
</span><span class="cx" style="display: block; padding: 0 10px"> * @param integer $line_max Number of chars allowed on a line before wrapping
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @link PHP version adapted from http://www.php.net/manual/en/function.quoted-printable-decode.php#89417
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function encodeQP($string, $line_max = 76)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
- return quoted_printable_encode($string);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Use native function if it's available (>= PHP5.3)
+ if (function_exists('quoted_printable_encode')) {
+ return $this->fixEOL(quoted_printable_encode($string));
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Fall back to a pure PHP implementation
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Fall back to a pure PHP implementation
</ins><span class="cx" style="display: block; padding: 0 10px"> $string = str_replace(
</span><span class="cx" style="display: block; padding: 0 10px"> array('%20', '%0D%0A.', '%0D%0A', '%'),
</span><span class="cx" style="display: block; padding: 0 10px"> array(' ', "\r\n=2E", "\r\n", '='),
</span><span class="cx" style="display: block; padding: 0 10px"> rawurlencode($string)
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $string;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->fixEOL($string);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2343,7 +2579,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $string
</span><span class="cx" style="display: block; padding: 0 10px"> * @param integer $line_max
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $space_conv
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $space_conv
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> * @deprecated Use encodeQP instead.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2365,41 +2601,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function encodeQ($str, $position = 'text')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //There should not be any EOL in the string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // There should not be any EOL in the string
</ins><span class="cx" style="display: block; padding: 0 10px"> $pattern = '';
</span><span class="cx" style="display: block; padding: 0 10px"> $encoded = str_replace(array("\r", "\n"), '', $str);
</span><span class="cx" style="display: block; padding: 0 10px"> switch (strtolower($position)) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'phrase':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //RFC 2047 section 5.3
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC 2047 section 5.3
</ins><span class="cx" style="display: block; padding: 0 10px"> $pattern = '^A-Za-z0-9!*+\/ -';
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> /** @noinspection PhpMissingBreakStatementInspection */
</span><span class="cx" style="display: block; padding: 0 10px"> case 'comment':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //RFC 2047 section 5.2
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC 2047 section 5.2
</ins><span class="cx" style="display: block; padding: 0 10px"> $pattern = '\(\)"';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //intentional fall-through
- //for this reason we build the $pattern without including delimiters and []
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // intentional fall-through
+ // for this reason we build the $pattern without including delimiters and []
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'text':
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //RFC 2047 section 5.1
- //Replace every high ascii, control, =, ? and _ characters
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // RFC 2047 section 5.1
+ // Replace every high ascii, control, =, ? and _ characters
</ins><span class="cx" style="display: block; padding: 0 10px"> $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $matches = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If the string contains an '=', make sure it's the first thing we replace
- //so as to avoid double-encoding
- $s = array_search('=', $matches[0]);
- if ($s !== false) {
- unset($matches[0][$s]);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If the string contains an '=', make sure it's the first thing we replace
+ // so as to avoid double-encoding
+ $eqkey = array_search('=', $matches[0]);
+ if (false !== $eqkey) {
+ unset($matches[0][$eqkey]);
</ins><span class="cx" style="display: block; padding: 0 10px"> array_unshift($matches[0], '=');
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> foreach (array_unique($matches[0]) as $char) {
</span><span class="cx" style="display: block; padding: 0 10px"> $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Replace every spaces to _ (more readable than =20)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Replace every spaces to _ (more readable than =20)
</ins><span class="cx" style="display: block; padding: 0 10px"> return str_replace(' ', '_', $encoded);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2422,7 +2658,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $type = '',
</span><span class="cx" style="display: block; padding: 0 10px"> $disposition = 'attachment'
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If a MIME type is not specified, try to work it out from the file name
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If a MIME type is not specified, try to work it out from the file name
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($type == '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $type = self::filenameToType($filename);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2442,7 +2678,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Add an embedded (inline) attachment from a file.
</span><span class="cx" style="display: block; padding: 0 10px"> * This can include images, sounds, and just about any other document type.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * These differ from 'regular' attachmants in that they are intended to be
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * These differ from 'regular' attachments in that they are intended to be
</ins><span class="cx" style="display: block; padding: 0 10px"> * displayed inline with the message, not just attached for download.
</span><span class="cx" style="display: block; padding: 0 10px"> * This is used in HTML messages that embed the images
</span><span class="cx" style="display: block; padding: 0 10px"> * the HTML refers to using the $cid value.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2453,7 +2689,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $encoding File encoding (see $Encoding).
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $type File MIME type.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $disposition Disposition to use
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True on successfully adding an attachment
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True on successfully adding an attachment
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2462,7 +2698,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If a MIME type is not specified, try to work it out from the file name
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If a MIME type is not specified, try to work it out from the file name
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($type == '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $type = self::filenameToType($path);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2498,7 +2734,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $encoding File encoding (see $Encoding).
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $type MIME type.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $disposition Disposition to use
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True on successfully adding an attachment
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True on successfully adding an attachment
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function addStringEmbeddedImage(
</span><span class="cx" style="display: block; padding: 0 10px"> $string,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2508,7 +2744,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $type = '',
</span><span class="cx" style="display: block; padding: 0 10px"> $disposition = 'inline'
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //If a MIME type is not specified, try to work it out from the name
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If a MIME type is not specified, try to work it out from the name
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($type == '') {
</span><span class="cx" style="display: block; padding: 0 10px"> $type = self::filenameToType($name);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2530,7 +2766,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Check if an inline attachment is present.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function inlineImageExists()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2544,7 +2780,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Check if an attachment (non-inline) is present.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function attachmentExists()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2558,7 +2794,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Check if this message has an alternative body set.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function alternativeExists()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2651,8 +2887,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->error_count++;
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $lasterror = $this->smtp->getError();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
- $msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!empty($lasterror['error'])) {
+ $msg .= $this->lang('smtp_error') . $lasterror['error'];
+ if (!empty($lasterror['detail'])) {
+ $msg .= ' Detail: '. $lasterror['detail'];
+ }
+ if (!empty($lasterror['smtp_code'])) {
+ $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
+ }
+ if (!empty($lasterror['smtp_code_ex'])) {
+ $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->ErrorInfo = $msg;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2666,8 +2911,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function rfcDate()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Set the time zone to whatever the default is to avoid 500 errors
- //Will default to UTC if it's not set properly in php.ini
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set the time zone to whatever the default is to avoid 500 errors
+ // Will default to UTC if it's not set properly in php.ini
</ins><span class="cx" style="display: block; padding: 0 10px"> date_default_timezone_set(@date_default_timezone_get());
</span><span class="cx" style="display: block; padding: 0 10px"> return date('D, j M Y H:i:s O');
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2680,14 +2925,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function serverHostname()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = 'localhost.localdomain';
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!empty($this->Hostname)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $this->Hostname;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif (isset($_SERVER['SERVER_NAME'])) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $result = $_SERVER['SERVER_NAME'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } else {
- $result = 'localhost.localdomain';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif (function_exists('gethostname') && gethostname() !== false) {
+ $result = gethostname();
+ } elseif (php_uname('n') !== false) {
+ $result = php_uname('n');
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> return $result;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2703,17 +2950,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setLanguage('en'); // set the default language
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (isset($this->language[$key])) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (array_key_exists($key, $this->language)) {
+ if ($key == 'smtp_connect_failed') {
+ //Include a link to troubleshooting docs on SMTP connection failure
+ //this is by far the biggest cause of support questions
+ //but it's usually not PHPMailer's fault.
+ return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->language[$key];
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return 'Language string failed to load: ' . $key;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Return the key as a fallback
+ return $key;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Check if an error occurred.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True if an error did occur.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True if an error did occur.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function isError()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2758,6 +3012,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns all custom headers
+ *
+ * @return array
+ */
+ public function getCustomHeaders()
+ {
+ return $this->CustomHeader;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Create a message from an HTML string.
</span><span class="cx" style="display: block; padding: 0 10px"> * Automatically makes modifications for inline images and backgrounds
</span><span class="cx" style="display: block; padding: 0 10px"> * and creates a plain-text version by converting the HTML.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2765,22 +3029,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $message HTML message string
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $basedir baseline directory for path
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $advanced Whether to use the advanced HTML to text converter
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean|callable $advanced Whether to use the internal HTML to text converter
+ * or your own custom converter @see html2text()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string $message
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function msgHTML($message, $basedir = '', $advanced = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
</ins><span class="cx" style="display: block; padding: 0 10px"> if (isset($images[2])) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ($images[2] as $i => $url) {
- // do not change urls for absolute images (thanks to corvuscorax)
- if (!preg_match('#^[A-z]+://#', $url)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ($images[2] as $imgindex => $url) {
+ // Convert data URIs into embedded images
+ if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
+ $data = substr($url, strpos($url, ','));
+ if ($match[2]) {
+ $data = base64_decode($data);
+ } else {
+ $data = rawurldecode($data);
+ }
+ $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
+ if ($this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1])) {
+ $message = str_replace(
+ $images[0][$imgindex],
+ $images[1][$imgindex] . '="cid:' . $cid . '"',
+ $message
+ );
+ }
+ } elseif (!preg_match('#^[A-z]+://#', $url)) {
+ // Do not change urls for absolute images (thanks to corvuscorax)
</ins><span class="cx" style="display: block; padding: 0 10px"> $filename = basename($url);
</span><span class="cx" style="display: block; padding: 0 10px"> $directory = dirname($url);
</span><span class="cx" style="display: block; padding: 0 10px"> if ($directory == '.') {
</span><span class="cx" style="display: block; padding: 0 10px"> $directory = '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cid = md5($url) . '@phpmailer.0'; //RFC2392 S 2
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
</ins><span class="cx" style="display: block; padding: 0 10px"> if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
</span><span class="cx" style="display: block; padding: 0 10px"> $basedir .= '/';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2792,12 +3073,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $cid,
</span><span class="cx" style="display: block; padding: 0 10px"> $filename,
</span><span class="cx" style="display: block; padding: 0 10px"> 'base64',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- self::_mime_types(self::mb_pathinfo($filename, PATHINFO_EXTENSION))
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
</ins><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $message = preg_replace(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "/" . $images[1][$i] . "=[\"']" . preg_quote($url, '/') . "[\"']/Ui",
- $images[1][$i] . "=\"cid:" . $cid . "\"",
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
+ $images[1][$imgindex] . '="cid:' . $cid . '"',
</ins><span class="cx" style="display: block; padding: 0 10px"> $message
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2805,27 +3086,40 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->isHTML(true);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
+ $this->Body = $this->normalizeBreaks($message);
+ $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
</ins><span class="cx" style="display: block; padding: 0 10px"> if (empty($this->AltBody)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
+ self::CRLF . self::CRLF;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
- $this->Body = $this->normalizeBreaks($message);
- $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
</del><span class="cx" style="display: block; padding: 0 10px"> return $this->Body;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Convert an HTML string into plain text.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This is used by msgHTML().
+ * Note - older versions of this function used a bundled advanced converter
+ * which was been removed for license reasons in #232
+ * Example usage:
+ * <code>
+ * // Use default conversion
+ * $plain = $mail->html2text($html);
+ * // Use your own custom converter
+ * $plain = $mail->html2text($html, function($html) {
+ * $converter = new MyHtml2text($html);
+ * return $converter->get_text();
+ * });
+ * </code>
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The HTML text to convert
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $advanced Should this use the more complex html2text converter or just a simple one?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean|callable $advanced Any boolean value to use the internal converter,
+ * or provide your own callable for custom conversion.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function html2text($html, $advanced = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($advanced) {
- require_once 'extras/class.html2text.php';
- $h = new html2text($html);
- return $h->get_text();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (is_callable($advanced)) {
+ return call_user_func($advanced, $html);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return html_entity_decode(
</span><span class="cx" style="display: block; padding: 0 10px"> trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2844,94 +3138,99 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function _mime_types($ext = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $mimes = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'xl' => 'application/excel',
- 'hqx' => 'application/mac-binhex40',
- 'cpt' => 'application/mac-compactpro',
- 'bin' => 'application/macbinary',
- 'doc' => 'application/msword',
- 'word' => 'application/msword',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'xl' => 'application/excel',
+ 'js' => 'application/javascript',
+ 'hqx' => 'application/mac-binhex40',
+ 'cpt' => 'application/mac-compactpro',
+ 'bin' => 'application/macbinary',
+ 'doc' => 'application/msword',
+ 'word' => 'application/msword',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'class' => 'application/octet-stream',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'dll' => 'application/octet-stream',
- 'dms' => 'application/octet-stream',
- 'exe' => 'application/octet-stream',
- 'lha' => 'application/octet-stream',
- 'lzh' => 'application/octet-stream',
- 'psd' => 'application/octet-stream',
- 'sea' => 'application/octet-stream',
- 'so' => 'application/octet-stream',
- 'oda' => 'application/oda',
- 'pdf' => 'application/pdf',
- 'ai' => 'application/postscript',
- 'eps' => 'application/postscript',
- 'ps' => 'application/postscript',
- 'smi' => 'application/smil',
- 'smil' => 'application/smil',
- 'mif' => 'application/vnd.mif',
- 'xls' => 'application/vnd.ms-excel',
- 'ppt' => 'application/vnd.ms-powerpoint',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'dll' => 'application/octet-stream',
+ 'dms' => 'application/octet-stream',
+ 'exe' => 'application/octet-stream',
+ 'lha' => 'application/octet-stream',
+ 'lzh' => 'application/octet-stream',
+ 'psd' => 'application/octet-stream',
+ 'sea' => 'application/octet-stream',
+ 'so' => 'application/octet-stream',
+ 'oda' => 'application/oda',
+ 'pdf' => 'application/pdf',
+ 'ai' => 'application/postscript',
+ 'eps' => 'application/postscript',
+ 'ps' => 'application/postscript',
+ 'smi' => 'application/smil',
+ 'smil' => 'application/smil',
+ 'mif' => 'application/vnd.mif',
+ 'xls' => 'application/vnd.ms-excel',
+ 'ppt' => 'application/vnd.ms-powerpoint',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'wbxml' => 'application/vnd.wap.wbxml',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'wmlc' => 'application/vnd.wap.wmlc',
- 'dcr' => 'application/x-director',
- 'dir' => 'application/x-director',
- 'dxr' => 'application/x-director',
- 'dvi' => 'application/x-dvi',
- 'gtar' => 'application/x-gtar',
- 'php3' => 'application/x-httpd-php',
- 'php4' => 'application/x-httpd-php',
- 'php' => 'application/x-httpd-php',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'wmlc' => 'application/vnd.wap.wmlc',
+ 'dcr' => 'application/x-director',
+ 'dir' => 'application/x-director',
+ 'dxr' => 'application/x-director',
+ 'dvi' => 'application/x-dvi',
+ 'gtar' => 'application/x-gtar',
+ 'php3' => 'application/x-httpd-php',
+ 'php4' => 'application/x-httpd-php',
+ 'php' => 'application/x-httpd-php',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'phtml' => 'application/x-httpd-php',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'phps' => 'application/x-httpd-php-source',
- 'js' => 'application/x-javascript',
- 'swf' => 'application/x-shockwave-flash',
- 'sit' => 'application/x-stuffit',
- 'tar' => 'application/x-tar',
- 'tgz' => 'application/x-tar',
- 'xht' => 'application/xhtml+xml',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'phps' => 'application/x-httpd-php-source',
+ 'swf' => 'application/x-shockwave-flash',
+ 'sit' => 'application/x-stuffit',
+ 'tar' => 'application/x-tar',
+ 'tgz' => 'application/x-tar',
+ 'xht' => 'application/xhtml+xml',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'xhtml' => 'application/xhtml+xml',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'zip' => 'application/zip',
- 'mid' => 'audio/midi',
- 'midi' => 'audio/midi',
- 'mp2' => 'audio/mpeg',
- 'mp3' => 'audio/mpeg',
- 'mpga' => 'audio/mpeg',
- 'aif' => 'audio/x-aiff',
- 'aifc' => 'audio/x-aiff',
- 'aiff' => 'audio/x-aiff',
- 'ram' => 'audio/x-pn-realaudio',
- 'rm' => 'audio/x-pn-realaudio',
- 'rpm' => 'audio/x-pn-realaudio-plugin',
- 'ra' => 'audio/x-realaudio',
- 'wav' => 'audio/x-wav',
- 'bmp' => 'image/bmp',
- 'gif' => 'image/gif',
- 'jpeg' => 'image/jpeg',
- 'jpe' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
- 'png' => 'image/png',
- 'tiff' => 'image/tiff',
- 'tif' => 'image/tiff',
- 'eml' => 'message/rfc822',
- 'css' => 'text/css',
- 'html' => 'text/html',
- 'htm' => 'text/html',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'zip' => 'application/zip',
+ 'mid' => 'audio/midi',
+ 'midi' => 'audio/midi',
+ 'mp2' => 'audio/mpeg',
+ 'mp3' => 'audio/mpeg',
+ 'mpga' => 'audio/mpeg',
+ 'aif' => 'audio/x-aiff',
+ 'aifc' => 'audio/x-aiff',
+ 'aiff' => 'audio/x-aiff',
+ 'ram' => 'audio/x-pn-realaudio',
+ 'rm' => 'audio/x-pn-realaudio',
+ 'rpm' => 'audio/x-pn-realaudio-plugin',
+ 'ra' => 'audio/x-realaudio',
+ 'wav' => 'audio/x-wav',
+ 'bmp' => 'image/bmp',
+ 'gif' => 'image/gif',
+ 'jpeg' => 'image/jpeg',
+ 'jpe' => 'image/jpeg',
+ 'jpg' => 'image/jpeg',
+ 'png' => 'image/png',
+ 'tiff' => 'image/tiff',
+ 'tif' => 'image/tiff',
+ 'eml' => 'message/rfc822',
+ 'css' => 'text/css',
+ 'html' => 'text/html',
+ 'htm' => 'text/html',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'shtml' => 'text/html',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'log' => 'text/plain',
- 'text' => 'text/plain',
- 'txt' => 'text/plain',
- 'rtx' => 'text/richtext',
- 'rtf' => 'text/rtf',
- 'xml' => 'text/xml',
- 'xsl' => 'text/xml',
- 'mpeg' => 'video/mpeg',
- 'mpe' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
- 'mov' => 'video/quicktime',
- 'qt' => 'video/quicktime',
- 'rv' => 'video/vnd.rn-realvideo',
- 'avi' => 'video/x-msvideo',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'log' => 'text/plain',
+ 'text' => 'text/plain',
+ 'txt' => 'text/plain',
+ 'rtx' => 'text/richtext',
+ 'rtf' => 'text/rtf',
+ 'vcf' => 'text/vcard',
+ 'vcard' => 'text/vcard',
+ 'xml' => 'text/xml',
+ 'xsl' => 'text/xml',
+ 'mpeg' => 'video/mpeg',
+ 'mpe' => 'video/mpeg',
+ 'mpg' => 'video/mpeg',
+ 'mov' => 'video/quicktime',
+ 'qt' => 'video/quicktime',
+ 'rv' => 'video/vnd.rn-realvideo',
+ 'avi' => 'video/x-msvideo',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'movie' => 'video/x-sgi-movie'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (array_key_exists(strtolower($ext), $mimes)) {
+ return $mimes[strtolower($ext)];
+ }
+ return 'application/octet-stream';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2943,9 +3242,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public static function filenameToType($filename)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //In case the path is a URL, strip any query string before getting extension
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // In case the path is a URL, strip any query string before getting extension
</ins><span class="cx" style="display: block; padding: 0 10px"> $qpos = strpos($filename, '?');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($qpos !== false) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (false !== $qpos) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $filename = substr($filename, 0, $qpos);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $pathinfo = self::mb_pathinfo($filename);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2966,37 +3265,34 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public static function mb_pathinfo($path, $options = null)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $m = array();
- preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m);
- if (array_key_exists(1, $m)) {
- $ret['dirname'] = $m[1];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $pathinfo = array();
+ if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
+ if (array_key_exists(1, $pathinfo)) {
+ $ret['dirname'] = $pathinfo[1];
+ }
+ if (array_key_exists(2, $pathinfo)) {
+ $ret['basename'] = $pathinfo[2];
+ }
+ if (array_key_exists(5, $pathinfo)) {
+ $ret['extension'] = $pathinfo[5];
+ }
+ if (array_key_exists(3, $pathinfo)) {
+ $ret['filename'] = $pathinfo[3];
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (array_key_exists(2, $m)) {
- $ret['basename'] = $m[2];
- }
- if (array_key_exists(5, $m)) {
- $ret['extension'] = $m[5];
- }
- if (array_key_exists(3, $m)) {
- $ret['filename'] = $m[3];
- }
</del><span class="cx" style="display: block; padding: 0 10px"> switch ($options) {
</span><span class="cx" style="display: block; padding: 0 10px"> case PATHINFO_DIRNAME:
</span><span class="cx" style="display: block; padding: 0 10px"> case 'dirname':
</span><span class="cx" style="display: block; padding: 0 10px"> return $ret['dirname'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case PATHINFO_BASENAME:
</span><span class="cx" style="display: block; padding: 0 10px"> case 'basename':
</span><span class="cx" style="display: block; padding: 0 10px"> return $ret['basename'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case PATHINFO_EXTENSION:
</span><span class="cx" style="display: block; padding: 0 10px"> case 'extension':
</span><span class="cx" style="display: block; padding: 0 10px"> return $ret['extension'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case PATHINFO_FILENAME:
</span><span class="cx" style="display: block; padding: 0 10px"> case 'filename':
</span><span class="cx" style="display: block; padding: 0 10px"> return $ret['filename'];
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><span class="cx" style="display: block; padding: 0 10px"> default:
</span><span class="cx" style="display: block; padding: 0 10px"> return $ret;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3004,33 +3300,27 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Set or reset instance properties.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * You should avoid this function - it's more verbose, less efficient, more error-prone and
+ * harder to debug than setting properties directly.
</ins><span class="cx" style="display: block; padding: 0 10px"> * Usage Example:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * $page->set('X-Priority', '3');
- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * `$mail->set('SMTPSecure', 'tls');`
+ * is the same as:
+ * `$mail->SMTPSecure = 'tls';`
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $name
- * @param mixed $value
- * NOTE: will not work with arrays, there are no arrays to set/reset
- * @throws phpmailerException
- * @return bool
- * @todo Should this not be using __set() magic function?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $name The property name to set
+ * @param mixed $value The value to set the property to
+ * @return boolean
+ * @TODO Should this not be using the __set() magic function?
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function set($name, $value = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- try {
- if (isset($this->$name)) {
- $this->$name = $value;
- } else {
- throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
- }
- } catch (Exception $e) {
- $this->setError($e->getMessage());
- if ($e->getCode() == self::STOP_CRITICAL) {
- return false;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (property_exists($this, $name)) {
+ $this->$name = $value;
+ return true;
+ } else {
+ $this->setError($this->lang('variable_set') . $name);
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return true;
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3061,17 +3351,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Set the private key file and password for S/MIME signing.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set the public and private key files and password for S/MIME signing.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $cert_filename
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $key_filename
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $key_pass Password for private key
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $extracerts_filename Optional path to chain certificate
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function sign($cert_filename, $key_filename, $key_pass)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sign_cert_file = $cert_filename;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sign_key_file = $key_filename;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->sign_key_pass = $key_pass;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->sign_extracerts_file = $extracerts_filename;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3088,7 +3380,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
</span><span class="cx" style="display: block; padding: 0 10px"> $line .= $txt[$i];
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $line .= "=" . sprintf("%02X", $ord);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $line .= '=' . sprintf('%02X', $ord);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $line;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3097,15 +3389,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Generate a DKIM signature.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $s Header
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $signHeader
</ins><span class="cx" style="display: block; padding: 0 10px"> * @throws phpmailerException
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function DKIM_Sign($s)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function DKIM_Sign($signHeader)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!defined('PKCS7_TEXT')) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->exceptions) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- throw new phpmailerException($this->lang("signing") . ' OpenSSL extension missing.');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ throw new phpmailerException($this->lang('extension_missing') . 'openssl');
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3115,7 +3407,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $privKey = $privKeyStr;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (openssl_sign($s, $signature, $privKey)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (openssl_sign($signHeader, $signature, $privKey)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return base64_encode($signature);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3124,21 +3416,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Generate a DKIM canonicalization header.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $s Header
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $signHeader Header
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function DKIM_HeaderC($s)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function DKIM_HeaderC($signHeader)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $s = preg_replace("/\r\n\s+/", " ", $s);
- $lines = explode("\r\n", $s);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
+ $lines = explode("\r\n", $signHeader);
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ($lines as $key => $line) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- list($heading, $value) = explode(":", $line, 2);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ list($heading, $value) = explode(':', $line, 2);
</ins><span class="cx" style="display: block; padding: 0 10px"> $heading = strtolower($heading);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = preg_replace("/\s+/", " ", $value); // Compress useless spaces
- $lines[$key] = $heading . ":" . trim($value); // Don't forget to remove WSP around the value
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
+ $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $s = implode("\r\n", $lines);
- return $s;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $signHeader = implode("\r\n", $lines);
+ return $signHeader;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3189,8 +3481,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $to_header = $header;
</span><span class="cx" style="display: block; padding: 0 10px"> $current = 'to_header';
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($current && strpos($header, ' =?') === 0) {
- $current .= $header;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!empty($$current) && strpos($header, ' =?') === 0) {
+ $$current .= $header;
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $current = '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3205,17 +3497,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ); // Copied header fields (dkim-quoted-printable)
</span><span class="cx" style="display: block; padding: 0 10px"> $body = $this->DKIM_BodyC($body);
</span><span class="cx" style="display: block; padding: 0 10px"> $DKIMlen = strlen($body); // Length of body
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $DKIMb64 = base64_encode(pack("H*", sha1($body))); // Base64 of packed binary SHA-1 hash of body
- $ident = ($this->DKIM_identity == '') ? '' : " i=" . $this->DKIM_identity . ";";
- $dkimhdrs = "DKIM-Signature: v=1; a=" .
- $DKIMsignatureType . "; q=" .
- $DKIMquery . "; l=" .
- $DKIMlen . "; s=" .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
+ if ('' == $this->DKIM_identity) {
+ $ident = '';
+ } else {
+ $ident = ' i=' . $this->DKIM_identity . ';';
+ }
+ $dkimhdrs = 'DKIM-Signature: v=1; a=' .
+ $DKIMsignatureType . '; q=' .
+ $DKIMquery . '; l=' .
+ $DKIMlen . '; s=' .
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->DKIM_selector .
</span><span class="cx" style="display: block; padding: 0 10px"> ";\r\n" .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n" .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
</ins><span class="cx" style="display: block; padding: 0 10px"> "\th=From:To:Subject;\r\n" .
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n" .
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
</ins><span class="cx" style="display: block; padding: 0 10px"> "\tz=$from\r\n" .
</span><span class="cx" style="display: block; padding: 0 10px"> "\t|$to\r\n" .
</span><span class="cx" style="display: block; padding: 0 10px"> "\t|$subject;\r\n" .
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3229,16 +3525,78 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Detect if a string contains a line longer than the maximum line length allowed.
+ * @param string $str
+ * @return boolean
+ * @static
+ */
+ public static function hasLineLongerThanMax($str)
+ {
+ //+2 to include CRLF line break for a 1000 total
+ return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
+ }
+
+ /**
+ * Allows for public read access to 'to' property.
+ * @access public
+ * @return array
+ */
+ public function getToAddresses()
+ {
+ return $this->to;
+ }
+
+ /**
+ * Allows for public read access to 'cc' property.
+ * @access public
+ * @return array
+ */
+ public function getCcAddresses()
+ {
+ return $this->cc;
+ }
+
+ /**
+ * Allows for public read access to 'bcc' property.
+ * @access public
+ * @return array
+ */
+ public function getBccAddresses()
+ {
+ return $this->bcc;
+ }
+
+ /**
+ * Allows for public read access to 'ReplyTo' property.
+ * @access public
+ * @return array
+ */
+ public function getReplyToAddresses()
+ {
+ return $this->ReplyTo;
+ }
+
+ /**
+ * Allows for public read access to 'all_recipients' property.
+ * @access public
+ * @return array
+ */
+ public function getAllRecipientAddresses()
+ {
+ return $this->all_recipients;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Perform a callback.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $isSent
- * @param string $to
- * @param string $cc
- * @param string $bcc
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $isSent
+ * @param array $to
+ * @param array $cc
+ * @param array $bcc
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $subject
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $body
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $from
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from = null)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!empty($this->action_function) && is_callable($this->action_function)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
</span></span></pre></div>
<a id="trunksrcwpincludesclasssmtpphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-smtp.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-smtp.php 2015-07-08 16:04:11 UTC (rev 33123)
+++ trunk/src/wp-includes/class-smtp.php 2015-07-08 17:15:02 UTC (rev 33124)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,108 +1,154 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * PHPMailer RFC821 SMTP email transport class.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Version 5.2.7
- * PHP version 5.0.0
- * @category PHP
- * @package PHPMailer
- * @link https://github.com/PHPMailer/PHPMailer/
- * @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * PHP Version 5
+ * @package PHPMailer
+ * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
+ * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
</ins><span class="cx" style="display: block; padding: 0 10px"> * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
</span><span class="cx" style="display: block; padding: 0 10px"> * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @copyright 2013 Marcus Bointon
- * @copyright 2004 - 2008 Andy Prevost
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @author Brent R. Matzelle (original founder)
+ * @copyright 2014 Marcus Bointon
</ins><span class="cx" style="display: block; padding: 0 10px"> * @copyright 2010 - 2012 Jim Jagielski
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @copyright 2004 - 2009 Andy Prevost
+ * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
+ * @note This program is distributed in the hope that it will be useful - WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * PHPMailer RFC821 SMTP email transport class.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
- * Implements RFC 821 SMTP commands
- * and provides some utility methods for sending mail to an SMTP server.
- *
- * PHP Version 5.0.0
- *
- * @category PHP
- * @package PHPMailer
- * @link https://github.com/PHPMailer/PHPMailer/blob/master/class.smtp.php
- * @author Chris Ryan <unknown@example.com>
- * @author Marcus Bointon <phpmailer@synchromedia.co.uk>
- * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
+ * @package PHPMailer
+ * @author Chris Ryan
+ * @author Marcus Bointon <phpmailer@synchromedia.co.uk>
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> class SMTP
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The PHPMailer SMTP Version number.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The PHPMailer SMTP version number.
+ * @type string
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- const VERSION = '5.2.7';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const VERSION = '5.2.10';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * SMTP line break constant.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const CRLF = "\r\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The SMTP port to use if one is not specified.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> const DEFAULT_SMTP_PORT = 25;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The maximum line length allowed by RFC 2822 section 2.1.1
+ * @type integer
+ */
+ const MAX_LINE_LENGTH = 998;
+
+ /**
+ * Debug level for no output
+ */
+ const DEBUG_OFF = 0;
+
+ /**
+ * Debug level to show client -> server messages
+ */
+ const DEBUG_CLIENT = 1;
+
+ /**
+ * Debug level to show client -> server and server -> client messages
+ */
+ const DEBUG_SERVER = 2;
+
+ /**
+ * Debug level to show connection status, client -> server and server -> client messages
+ */
+ const DEBUG_CONNECTION = 3;
+
+ /**
+ * Debug level to show all messages
+ */
+ const DEBUG_LOWLEVEL = 4;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * The PHPMailer SMTP Version number.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @deprecated This should be a constant
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated Use the `VERSION` constant instead
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see SMTP::VERSION
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Version = '5.2.7';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Version = '5.2.10';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * SMTP server port number.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type int
- * @deprecated This is only ever ued as default value, so should be a constant
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type integer
+ * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see SMTP::DEFAULT_SMTP_PORT
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $SMTP_PORT = 25;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * SMTP reply line ending
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * SMTP reply line ending.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @deprecated Use the class constant instead
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated Use the `CRLF` constant instead
</ins><span class="cx" style="display: block; padding: 0 10px"> * @see SMTP::CRLF
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $CRLF = "\r\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Debug output level.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Options: 0 for no output, 1 for commands, 2 for data and commands
- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Options:
+ * * self::DEBUG_OFF (`0`) No debug output, default
+ * * self::DEBUG_CLIENT (`1`) Client commands
+ * * self::DEBUG_SERVER (`2`) Client commands and server responses
+ * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
+ * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $do_debug = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $do_debug = self::DEBUG_OFF;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The function/method to use for debugging output.
- * Options: 'echo', 'html' or 'error_log'
- * @type string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * How to handle debug output.
+ * Options:
+ * * `echo` Output plain-text as-is, appropriate for CLI
+ * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
+ * * `error_log` Output to error log as configured in php.ini
+ *
+ * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
+ * <code>
+ * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
+ * </code>
+ * @type string|callable
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $Debugoutput = 'echo';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Whether to use VERP.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
+ * @link http://www.postfix.org/VERP_README.html Info on VERP
+ * @type boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public $do_verp = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The SMTP timeout value for reads, in seconds.
- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The timeout value for connection, in seconds.
+ * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
+ * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure.
+ * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Timeout = 15;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Timeout = 300;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * The SMTP timelimit value for reads, in seconds.
- * @type int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * How long to wait for commands to complete, in seconds.
+ * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
+ * @type integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $Timelimit = 30;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $Timelimit = 300;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The socket for the server connection.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,43 +157,58 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected $smtp_conn;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Error message, if any, for the last call.
- * @type string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Error information, if any, for the last SMTP command.
+ * @type array
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $error = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $error = array(
+ 'error' => '',
+ 'detail' => '',
+ 'smtp_code' => '',
+ 'smtp_code_ex' => ''
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * The reply the server sent to us for HELO.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * If null, no HELO string has yet been received.
+ * @type string|null
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $helo_rply = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $helo_rply = null;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * The set of SMTP extensions sent in reply to EHLO command.
+ * Indexes of the array are extension names.
+ * Value at index 'HELO' or 'EHLO' (according to command that was sent)
+ * represents the server name. In case of HELO it is the only element of the array.
+ * Other values can be boolean TRUE or an array containing extension options.
+ * If null, no HELO/EHLO string has yet been received.
+ * @type array|null
+ */
+ protected $server_caps = null;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * The most recent reply received from the server.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected $last_reply = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Constructor.
- * @access public
- */
- public function __construct()
- {
- $this->smtp_conn = 0;
- $this->error = null;
- $this->helo_rply = null;
-
- $this->do_debug = 0;
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Output debugging info via a user-selected method.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see SMTP::$Debugoutput
+ * @see SMTP::$do_debug
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $str Debug string to output
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param integer $level The debug level of this message; see DEBUG_* constants
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return void
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected function edebug($str)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected function edebug($str, $level = 0)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($level > $this->do_debug) {
+ return;
+ }
+ //Avoid clash with built-in function names
+ if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
+ call_user_func($this->Debugoutput, $str, $this->do_debug);
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> switch ($this->Debugoutput) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'error_log':
</span><span class="cx" style="display: block; padding: 0 10px"> //Don't output, just log
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,94 +225,115 @@
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'echo':
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //Just echoes whatever was received
- echo $str;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Normalize line breaks
+ $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
+ echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
+ "\n",
+ "\n \t ",
+ trim($str)
+ )."\n";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Connect to an SMTP server.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $host SMTP server IP or host name
- * @param int $port The port number to connect to
- * @param int $timeout How long to wait for the connection to open
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $host SMTP server IP or host name
+ * @param integer $port The port number to connect to
+ * @param integer $timeout How long to wait for the connection to open
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param array $options An array of options for stream_context_create()
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function connect($host, $port = null, $timeout = 30, $options = array())
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ static $streamok;
+ //This is enabled by default since 5.0.0 but some providers disable it
+ //Check this once and cache the result
+ if (is_null($streamok)) {
+ $streamok = function_exists('stream_socket_client');
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> // Clear errors to avoid confusion
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = null;
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError('');
</ins><span class="cx" style="display: block; padding: 0 10px"> // Make sure we are __not__ connected
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->connected()) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Already connected, generate error
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = array('error' => 'Already connected to a server');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError('Already connected to a server');
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> if (empty($port)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $port = self::DEFAULT_SMTP_PORT;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Connect to the SMTP server
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug(
+ "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
+ self::DEBUG_CONNECTION
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $errno = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $errstr = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $socket_context = stream_context_create($options);
- //Suppress errors; connection failures are handled at a higher level
- $this->smtp_conn = @stream_socket_client(
- $host . ":" . $port,
- $errno,
- $errstr,
- $timeout,
- STREAM_CLIENT_CONNECT,
- $socket_context
- );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($streamok) {
+ $socket_context = stream_context_create($options);
+ //Suppress errors; connection failures are handled at a higher level
+ $this->smtp_conn = @stream_socket_client(
+ $host . ":" . $port,
+ $errno,
+ $errstr,
+ $timeout,
+ STREAM_CLIENT_CONNECT,
+ $socket_context
+ );
+ } else {
+ //Fall back to fsockopen which should work in more places, but is missing some features
+ $this->edebug(
+ "Connection: stream_socket_client not available, falling back to fsockopen",
+ self::DEBUG_CONNECTION
+ );
+ $this->smtp_conn = fsockopen(
+ $host,
+ $port,
+ $errno,
+ $errstr,
+ $timeout
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> // Verify we connected properly
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (empty($this->smtp_conn)) {
- $this->error = array(
- 'error' => 'Failed to connect to server',
- 'errno' => $errno,
- 'errstr' => $errstr
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!is_resource($this->smtp_conn)) {
+ $this->setError(
+ 'Failed to connect to server',
+ $errno,
+ $errstr
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 1) {
- $this->edebug(
- 'SMTP -> ERROR: ' . $this->error['error']
- . ": $errstr ($errno)"
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug(
+ 'SMTP ERROR: ' . $this->error['error']
+ . ": $errstr ($errno)",
+ self::DEBUG_CLIENT
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
</ins><span class="cx" style="display: block; padding: 0 10px"> // SMTP server can take longer to respond, give longer timeout for first read
</span><span class="cx" style="display: block; padding: 0 10px"> // Windows does not have support for this timeout function
</span><span class="cx" style="display: block; padding: 0 10px"> if (substr(PHP_OS, 0, 3) != 'WIN') {
</span><span class="cx" style="display: block; padding: 0 10px"> $max = ini_get('max_execution_time');
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($max != 0 && $timeout > $max) { // Don't bother if unlimited
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Don't bother if unlimited
+ if ($max != 0 && $timeout > $max) {
</ins><span class="cx" style="display: block; padding: 0 10px"> @set_time_limit($timeout);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> stream_set_timeout($this->smtp_conn, $timeout, 0);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> // Get any announcement
</span><span class="cx" style="display: block; padding: 0 10px"> $announce = $this->get_lines();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- if ($this->do_debug >= 2) {
- $this->edebug('SMTP -> FROM SERVER:' . $announce);
- }
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Initiate a TLS (encrypted) session.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function startTLS()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!$this->sendCommand("STARTTLS", "STARTTLS", 220)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Begin encrypted connection
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,8 +341,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->smtp_conn,
</span><span class="cx" style="display: block; padding: 0 10px"> true,
</span><span class="cx" style="display: block; padding: 0 10px"> STREAM_CRYPTO_METHOD_TLS_CLIENT
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- )
- ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ )) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -276,19 +357,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $realm The auth realm for NTLM
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $workstation The auth workstation for NTLM
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True if successfully authenticated.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True if successfully authenticated.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function authenticate(
</span><span class="cx" style="display: block; padding: 0 10px"> $username,
</span><span class="cx" style="display: block; padding: 0 10px"> $password,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $authtype = 'LOGIN',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $authtype = null,
</ins><span class="cx" style="display: block; padding: 0 10px"> $realm = '',
</span><span class="cx" style="display: block; padding: 0 10px"> $workstation = ''
</span><span class="cx" style="display: block; padding: 0 10px"> ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (empty($authtype)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!$this->server_caps) {
+ $this->setError('Authentication is not allowed before HELO/EHLO');
+ return false;
+ }
+
+ if (array_key_exists('EHLO', $this->server_caps)) {
+ // SMTP extensions are available. Let's try to find a proper authentication method
+
+ if (!array_key_exists('AUTH', $this->server_caps)) {
+ $this->setError('Authentication is not allowed at this stage');
+ // 'at this stage' means that auth may be allowed after the stage changes
+ // e.g. after STARTTLS
+ return false;
+ }
+
+ self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
+ self::edebug(
+ 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
+ self::DEBUG_LOWLEVEL
+ );
+
+ if (empty($authtype)) {
+ foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) {
+ if (in_array($method, $this->server_caps['AUTH'])) {
+ $authtype = $method;
+ break;
+ }
+ }
+ if (empty($authtype)) {
+ $this->setError('No supported authentication methods found');
+ return false;
+ }
+ self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
+ }
+
+ if (!in_array($authtype, $this->server_caps['AUTH'])) {
+ $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
+ return false;
+ }
+ } elseif (empty($authtype)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $authtype = 'LOGIN';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> switch ($authtype) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'PLAIN':
</span><span class="cx" style="display: block; padding: 0 10px"> // Start authentication
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -317,59 +436,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- case 'NTLM':
- /*
- * ntlm_sasl_client.php
- * Bundled with Permission
- *
- * How to telnet in windows:
- * http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
- * PROTOCOL Docs http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
- */
- require_once 'extras/ntlm_sasl_client.php';
- $temp = new stdClass();
- $ntlm_client = new ntlm_sasl_client_class;
- //Check that functions are available
- if (!$ntlm_client->Initialize($temp)) {
- $this->error = array('error' => $temp->error);
- if ($this->do_debug >= 1) {
- $this->edebug(
- 'You need to enable some modules in your php.ini file: '
- . $this->error['error']
- );
- }
- return false;
- }
- //msg1
- $msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1
-
- if (!$this->sendCommand(
- 'AUTH NTLM',
- 'AUTH NTLM ' . base64_encode($msg1),
- 334
- )
- ) {
- return false;
- }
-
- //Though 0 based, there is a white space after the 3 digit number
- //msg2
- $challenge = substr($this->last_reply, 3);
- $challenge = base64_decode($challenge);
- $ntlm_res = $ntlm_client->NTLMResponse(
- substr($challenge, 24, 8),
- $password
- );
- //msg3
- $msg3 = $ntlm_client->TypeMsg3(
- $ntlm_res,
- $username,
- $realm,
- $workstation
- );
- // send encoded username
- return $this->sendCommand('Username', base64_encode($msg3), 235);
- break;
</del><span class="cx" style="display: block; padding: 0 10px"> case 'CRAM-MD5':
</span><span class="cx" style="display: block; padding: 0 10px"> // Start authentication
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -383,7 +449,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // send encoded credentials
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->sendCommand('Username', base64_encode($response), 235);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- break;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ default:
+ $this->setError("Authentication method \"$authtype\" is not supported");
+ return false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -411,13 +479,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Eliminates the need to install mhash to compute a HMAC
</span><span class="cx" style="display: block; padding: 0 10px"> // by Lance Rushing
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $b = 64; // byte length for md5
- if (strlen($key) > $b) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bytelen = 64; // byte length for md5
+ if (strlen($key) > $bytelen) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $key = pack('H*', md5($key));
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $key = str_pad($key, $b, chr(0x00));
- $ipad = str_pad('', $b, chr(0x36));
- $opad = str_pad('', $b, chr(0x5c));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $key = str_pad($key, $bytelen, chr(0x00));
+ $ipad = str_pad('', $bytelen, chr(0x36));
+ $opad = str_pad('', $bytelen, chr(0x5c));
</ins><span class="cx" style="display: block; padding: 0 10px"> $k_ipad = $key ^ $ipad;
</span><span class="cx" style="display: block; padding: 0 10px"> $k_opad = $key ^ $opad;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -427,19 +495,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Check connection state.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True if connected.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True if connected.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function connected()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!empty($this->smtp_conn)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (is_resource($this->smtp_conn)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $sock_status = stream_get_meta_data($this->smtp_conn);
</span><span class="cx" style="display: block; padding: 0 10px"> if ($sock_status['eof']) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // the socket is valid but we are not connected
- if ($this->do_debug >= 1) {
- $this->edebug(
- 'SMTP -> NOTICE: EOF caught while checking if connected'
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // The socket is valid but we are not connected
+ $this->edebug(
+ 'SMTP NOTICE: EOF caught while checking if connected',
+ self::DEBUG_CLIENT
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->close();
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -457,12 +524,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function close()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = null; // so there is no confusion
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError('');
+ $this->server_caps = null;
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->helo_rply = null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!empty($this->smtp_conn)) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (is_resource($this->smtp_conn)) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // close the connection and cleanup
</span><span class="cx" style="display: block; padding: 0 10px"> fclose($this->smtp_conn);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->smtp_conn = 0;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->smtp_conn = null; //Makes for cleaner serialization
+ $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -476,111 +545,101 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements rfc 821: DATA <CRLF>
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $msg_data Message data to send
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function data($msg_data)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //This will use the standard timelimit
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!$this->sendCommand('DATA', 'DATA', 354)) {
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /* The server is ready to accept data!
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * according to rfc821 we should not send more than 1000
- * including the CRLF
- * characters on a single line so we will break the data up
- * into lines by \r and/or \n then if needed we will break
- * each of those into smaller lines to fit within the limit.
- * in addition we will be looking for lines that start with
- * a period '.' and append and additional period '.' to that
- * line. NOTE: this does not count towards limit.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF)
+ * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
+ * smaller lines to fit within the limit.
+ * We will also look for lines that start with a '.' and prepend an additional '.'.
+ * NOTE: this does not count towards line-length limit.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Normalize the line breaks before exploding
- $msg_data = str_replace("\r\n", "\n", $msg_data);
- $msg_data = str_replace("\r", "\n", $msg_data);
- $lines = explode("\n", $msg_data);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Normalize line breaks before exploding
+ $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /* We need to find a good way to determine if headers are
- * in the msg_data or if it is a straight msg body
- * currently I am assuming rfc822 definitions of msg headers
- * and if the first field of the first line (':' separated)
- * does not contain a space then it _should_ be a header
- * and we can process all lines before a blank "" line as
- * headers.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
+ * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
+ * process all lines before a blank line as headers.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $field = substr($lines[0], 0, strpos($lines[0], ':'));
</span><span class="cx" style="display: block; padding: 0 10px"> $in_headers = false;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if (!empty($field) && !strstr($field, ' ')) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if (!empty($field) && strpos($field, ' ') === false) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $in_headers = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- //RFC 2822 section 2.1.1 limit
- $max_line_length = 998;
-
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ($lines as $line) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $lines_out = null;
- if ($line == '' && $in_headers) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $lines_out = array();
+ if ($in_headers and $line == '') {
</ins><span class="cx" style="display: block; padding: 0 10px"> $in_headers = false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // ok we need to break this line up into several smaller lines
- while (strlen($line) > $max_line_length) {
- $pos = strrpos(substr($line, 0, $max_line_length), ' ');
-
- // Patch to fix DOS attack
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Break this line up into several smaller lines if it's too long
+ //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
+ while (isset($line[self::MAX_LINE_LENGTH])) {
+ //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
+ //so as to avoid breaking in the middle of a word
+ $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
+ //Deliberately matches both false and 0
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!$pos) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $pos = $max_line_length - 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //No nice break found, add a hard break
+ $pos = self::MAX_LINE_LENGTH - 1;
</ins><span class="cx" style="display: block; padding: 0 10px"> $lines_out[] = substr($line, 0, $pos);
</span><span class="cx" style="display: block; padding: 0 10px"> $line = substr($line, $pos);
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Break at the found point
</ins><span class="cx" style="display: block; padding: 0 10px"> $lines_out[] = substr($line, 0, $pos);
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Move along by the amount we dealt with
</ins><span class="cx" style="display: block; padding: 0 10px"> $line = substr($line, $pos + 1);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- /* If processing headers add a LWSP-char to the front of new line
- * rfc822 on long msg headers
- */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($in_headers) {
</span><span class="cx" style="display: block; padding: 0 10px"> $line = "\t" . $line;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $lines_out[] = $line;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // send the lines to the server
- while (list(, $line_out) = @each($lines_out)) {
- if (strlen($line_out) > 0) {
- if (substr($line_out, 0, 1) == '.') {
- $line_out = '.' . $line_out;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Send the lines to the server
+ foreach ($lines_out as $line_out) {
+ //RFC2821 section 4.5.2
+ if (!empty($line_out) and $line_out[0] == '.') {
+ $line_out = '.' . $line_out;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->client_send($line_out . self::CRLF);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Message data has been sent, complete the command
- return $this->sendCommand('DATA END', '.', 250);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Message data has been sent, complete the command
+ //Increase timelimit for end of DATA command
+ $savetimelimit = $this->Timelimit;
+ $this->Timelimit = $this->Timelimit * 2;
+ $result = $this->sendCommand('DATA END', '.', 250);
+ //Restore timelimit
+ $this->Timelimit = $savetimelimit;
+ return $result;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP HELO or EHLO command.
</span><span class="cx" style="display: block; padding: 0 10px"> * Used to identify the sending server to the receiving server.
</span><span class="cx" style="display: block; padding: 0 10px"> * This makes sure that client and server are in a known state.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Implements from RFC 821: HELO <SP> <domain> <CRLF>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Implements RFC 821: HELO <SP> <domain> <CRLF>
</ins><span class="cx" style="display: block; padding: 0 10px"> * and RFC 2821 EHLO.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $host The host name or IP to connect to
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function hello($host = '')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Try extended hello first (RFC 2821)
- if (!$this->sendHello('EHLO', $host)) {
- if (!$this->sendHello('HELO', $host)) {
- return false;
- }
- }
-
- return true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ //Try extended hello first (RFC 2821)
+ return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -588,18 +647,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Low-level implementation used by hello()
</span><span class="cx" style="display: block; padding: 0 10px"> * @see hello()
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $hello The HELO string
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $host The hostname to say we are
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $host The hostname to say we are
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function sendHello($hello, $host)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
</span><span class="cx" style="display: block; padding: 0 10px"> $this->helo_rply = $this->last_reply;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($noerror) {
+ $this->parseHelloFields($hello);
+ } else {
+ $this->server_caps = null;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> return $noerror;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Parse a reply to HELO/EHLO command to discover server extensions.
+ * In case of HELO, the only parameter that can be discovered is a server name.
+ * @access protected
+ * @param string $type - 'HELO' or 'EHLO'
+ */
+ protected function parseHelloFields($type)
+ {
+ $this->server_caps = array();
+ $lines = explode("\n", $this->last_reply);
+ foreach ($lines as $n => $s) {
+ $s = trim(substr($s, 4));
+ if (!$s) {
+ continue;
+ }
+ $fields = explode(' ', $s);
+ if (!empty($fields)) {
+ if (!$n) {
+ $name = $type;
+ $fields = $fields[0];
+ } else {
+ $name = array_shift($fields);
+ if ($name == 'SIZE') {
+ $fields = ($fields) ? $fields[0] : 0;
+ }
+ }
+ $this->server_caps[$name] = ($fields ? $fields : true);
+ }
+ }
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP MAIL command.
</span><span class="cx" style="display: block; padding: 0 10px"> * Starts a mail transaction from the email address specified in
</span><span class="cx" style="display: block; padding: 0 10px"> * $from. Returns true if successful or false otherwise. If True
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -608,7 +703,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $from Source address of this message
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function mail($from)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -624,35 +719,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP QUIT command.
</span><span class="cx" style="display: block; padding: 0 10px"> * Closes the socket if there is no error or the $close_on_error argument is true.
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements from rfc 821: QUIT <CRLF>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $close_on_error Should the connection close if an error occurs?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $close_on_error Should the connection close if an error occurs?
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function quit($close_on_error = true)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $e = $this->error; //Save any error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $err = $this->error; //Save any error
</ins><span class="cx" style="display: block; padding: 0 10px"> if ($noerror or $close_on_error) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->close();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = $e; //Restore any error from the quit command
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->error = $err; //Restore any error from the quit command
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $noerror;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP RCPT command.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Sets the TO argument to $to.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Sets the TO argument to $toaddr.
</ins><span class="cx" style="display: block; padding: 0 10px"> * Returns true if the recipient was accepted false if it was rejected.
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $to The address the message is being sent to
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $toaddr The address the message is being sent to
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function recipient($to)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function recipient($toaddr)
</ins><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->sendCommand(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'RCPT TO ',
- 'RCPT TO:<' . $to . '>',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'RCPT TO',
+ 'RCPT TO:<' . $toaddr . '>',
</ins><span class="cx" style="display: block; padding: 0 10px"> array(250, 251)
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -662,7 +757,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Abort any transaction that is currently in progress.
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements rfc 821: RSET <CRLF>
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True on success.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True on success.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function reset()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -673,44 +768,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Send a command to an SMTP server and check its return code.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $command The command name - not sent to the server
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $commandstring The actual command to send
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|array $expect One or more expected integer success codes
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param integer|array $expect One or more expected integer success codes
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access protected
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True on success.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean True on success.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function sendCommand($command, $commandstring, $expect)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="cx" style="display: block; padding: 0 10px"> if (!$this->connected()) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = array(
- "error" => "Called $command without being connected"
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError("Called $command without being connected");
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> $this->client_send($commandstring . self::CRLF);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $reply = $this->get_lines();
- $code = substr($reply, 0, 3);
-
- if ($this->do_debug >= 2) {
- $this->edebug('SMTP -> FROM SERVER:' . $reply);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->last_reply = $this->get_lines();
+ // Fetch SMTP code and possible error code explanation
+ $matches = array();
+ if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
+ $code = $matches[1];
+ $code_ex = (count($matches) > 2 ? $matches[2] : null);
+ // Cut off error code from each response line
+ $detail = preg_replace(
+ "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
+ '',
+ $this->last_reply
+ );
+ } else {
+ // Fall back to simple parsing if regex fails
+ $code = substr($this->last_reply, 0, 3);
+ $code_ex = null;
+ $detail = substr($this->last_reply, 4);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if (!in_array($code, (array)$expect)) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->last_reply = null;
- $this->error = array(
- "error" => "$command command failed",
- "smtp_code" => $code,
- "detail" => substr($reply, 4)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError(
+ "$command command failed",
+ $detail,
+ $code,
+ $code_ex
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 1) {
- $this->edebug(
- 'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $reply
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug(
+ 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
+ self::DEBUG_CLIENT
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->last_reply = $reply;
- $this->error = null;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError('');
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -725,52 +830,48 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $from The address the message is from
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function sendAndMail($from)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $this->sendCommand("SAML", "SAML FROM:$from", 250);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->sendCommand('SAML', "SAML FROM:$from", 250);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP VRFY command.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $name The name to verify
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function verify($name)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $this->sendCommand("VRFY", "VRFY $name", array(250, 251));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP NOOP command.
</span><span class="cx" style="display: block; padding: 0 10px"> * Used to keep keep-alives alive, doesn't actually do anything
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function noop()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return $this->sendCommand("NOOP", "NOOP", 250);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->sendCommand('NOOP', 'NOOP', 250);
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an SMTP TURN command.
</span><span class="cx" style="display: block; padding: 0 10px"> * This is an optional command for SMTP that this class does not support.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * This method is here to make the RFC821 Definition
- * complete for this class and __may__ be implemented in future
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * This method is here to make the RFC821 Definition complete for this class
+ * and _may_ be implemented in future
</ins><span class="cx" style="display: block; padding: 0 10px"> * Implements from rfc 821: TURN <CRLF>
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function turn()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->error = array(
- 'error' => 'The SMTP TURN command is not implemented'
- );
- if ($this->do_debug >= 1) {
- $this->edebug('SMTP -> NOTICE: ' . $this->error['error']);
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->setError('The SMTP TURN command is not implemented');
+ $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -778,13 +879,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Send raw data to the server.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $data The data to send
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return int|bool The number of bytes sent to the server or FALSE on error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return integer|boolean The number of bytes sent to the server or false on error
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function client_send($data)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 1) {
- $this->edebug("CLIENT -> SMTP: $data");
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
</ins><span class="cx" style="display: block; padding: 0 10px"> return fwrite($this->smtp_conn, $data);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -799,6 +898,57 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get SMTP extensions available on the server
+ * @access public
+ * @return array|null
+ */
+ public function getServerExtList()
+ {
+ return $this->server_caps;
+ }
+
+ /**
+ * A multipurpose method
+ * The method works in three ways, dependent on argument value and current state
+ * 1. HELO/EHLO was not sent - returns null and set up $this->error
+ * 2. HELO was sent
+ * $name = 'HELO': returns server name
+ * $name = 'EHLO': returns boolean false
+ * $name = any string: returns null and set up $this->error
+ * 3. EHLO was sent
+ * $name = 'HELO'|'EHLO': returns server name
+ * $name = any string: if extension $name exists, returns boolean True
+ * or its options. Otherwise returns boolean False
+ * In other words, one can use this method to detect 3 conditions:
+ * - null returned: handshake was not or we don't know about ext (refer to $this->error)
+ * - false returned: the requested feature exactly not exists
+ * - positive value returned: the requested feature exists
+ * @param string $name Name of SMTP extension or 'HELO'|'EHLO'
+ * @return mixed
+ */
+ public function getServerExt($name)
+ {
+ if (!$this->server_caps) {
+ $this->setError('No HELO/EHLO was sent');
+ return null;
+ }
+
+ // the tight logic knot ;)
+ if (!array_key_exists($name, $this->server_caps)) {
+ if ($name == 'HELO') {
+ return $this->server_caps['EHLO'];
+ }
+ if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
+ return false;
+ }
+ $this->setError('HELO handshake was used. Client knows nothing about server extensions');
+ return null;
+ }
+
+ return $this->server_caps[$name];
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Get the last reply from the server.
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @return string
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -819,51 +969,43 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function get_lines()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // If the connection is bad, give up straight away
+ if (!is_resource($this->smtp_conn)) {
+ return '';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = '';
</span><span class="cx" style="display: block; padding: 0 10px"> $endtime = 0;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If the connection is bad, give up now
- if (!is_resource($this->smtp_conn)) {
- return $data;
- }
</del><span class="cx" style="display: block; padding: 0 10px"> stream_set_timeout($this->smtp_conn, $this->Timeout);
</span><span class="cx" style="display: block; padding: 0 10px"> if ($this->Timelimit > 0) {
</span><span class="cx" style="display: block; padding: 0 10px"> $endtime = time() + $this->Timelimit;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
</span><span class="cx" style="display: block; padding: 0 10px"> $str = @fgets($this->smtp_conn, 515);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 4) {
- $this->edebug("SMTP -> get_lines(): \$data was \"$data\"");
- $this->edebug("SMTP -> get_lines(): \$str is \"$str\"");
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
+ $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
</ins><span class="cx" style="display: block; padding: 0 10px"> $data .= $str;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 4) {
- $this->edebug("SMTP -> get_lines(): \$data is \"$data\"");
- }
- // if 4th character is a space, we are done reading, break the loop
- if (substr($str, 3, 1) == ' ') {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
+ // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
+ if ((isset($str[3]) and $str[3] == ' ')) {
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Timed-out? Log and break
</span><span class="cx" style="display: block; padding: 0 10px"> $info = stream_get_meta_data($this->smtp_conn);
</span><span class="cx" style="display: block; padding: 0 10px"> if ($info['timed_out']) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($this->do_debug >= 4) {
- $this->edebug(
- 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)'
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->edebug(
+ 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
+ self::DEBUG_LOWLEVEL
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> // Now check if reads took too long
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ($endtime) {
- if (time() > $endtime) {
- if ($this->do_debug >= 4) {
- $this->edebug(
- 'SMTP -> get_lines(): timelimit reached ('
- . $this->Timelimit . ' sec)'
- );
- }
- break;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ($endtime and time() > $endtime) {
+ $this->edebug(
+ 'SMTP -> get_lines(): timelimit reached ('.
+ $this->Timelimit . ' sec)',
+ self::DEBUG_LOWLEVEL
+ );
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return $data;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -871,7 +1013,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Enable or disable VERP address generation.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $enabled
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param boolean $enabled
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setVerp($enabled = false)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -880,7 +1022,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Get VERP address generation mode.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return boolean
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function getVerp()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -888,8 +1030,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Set error messages and codes.
+ * @param string $message The error message
+ * @param string $detail Further detail on the error
+ * @param string $smtp_code An associated SMTP error code
+ * @param string $smtp_code_ex Extended SMTP code
+ */
+ protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
+ {
+ $this->error = array(
+ 'error' => $message,
+ 'detail' => $detail,
+ 'smtp_code' => $smtp_code,
+ 'smtp_code_ex' => $smtp_code_ex
+ );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Set debug output method.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $method The function/method to use for debugging output.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setDebugOutput($method = 'echo')
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -907,7 +1066,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Set debug output level.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $level
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param integer $level
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setDebugLevel($level = 0)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -916,7 +1075,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Get debug output level.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function getDebugLevel()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -925,7 +1084,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Set SMTP timeout.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $timeout
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param integer $timeout
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function setTimeout($timeout = 0)
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -934,7 +1093,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Get SMTP timeout.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return int
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return integer
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function getTimeout()
</span><span class="cx" style="display: block; padding: 0 10px"> {
</span></span></pre></div>
<a id="trunktestsphpunitincludesmockmailerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/mock-mailer.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/mock-mailer.php 2015-07-08 16:04:11 UTC (rev 33123)
+++ trunk/tests/phpunit/includes/mock-mailer.php 2015-07-08 17:15:02 UTC (rev 33124)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,25 +4,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class MockPHPMailer extends PHPMailer {
</span><span class="cx" style="display: block; padding: 0 10px"> var $mock_sent = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function preSend() {
+ $this->Encoding = '8bit';
+ return parent::preSend();
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Override send() so mail isn't actually sent.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Override postSend() so mail isn't actually sent.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- function send() {
- try {
- if ( ! $this->preSend() )
- return false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ function postSend() {
+ $this->mock_sent[] = array(
+ 'to' => $this->to,
+ 'cc' => $this->cc,
+ 'bcc' => $this->bcc,
+ 'header' => $this->MIMEHeader,
+ 'body' => $this->MIMEBody,
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->mock_sent[] = array(
- 'to' => $this->to,
- 'cc' => $this->cc,
- 'bcc' => $this->bcc,
- 'header' => $this->MIMEHeader,
- 'body' => $this->MIMEBody,
- );
-
- return true;
- } catch ( phpmailerException $e ) {
- return false;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return true;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsmailphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/mail.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/mail.php 2015-07-08 16:04:11 UTC (rev 33123)
+++ trunk/tests/phpunit/tests/mail.php 2015-07-08 17:15:02 UTC (rev 33124)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,6 +9,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $GLOBALS['phpmailer']->mock_sent );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Send a mail with a 1000 char long line.
+ *
+ * `PHPMailer::createBody()` will set `$this->Encoding = 'quoted-printable'` (away from it's default of 8bit)
+ * when it encounters a line longer than 999 characters. But PHPMailer doesn't clean up after itself / presets
+ * all variables, which means that following tests would fail. To solve this issue we set `$this->Encoding`
+ * back to 8bit in `MockPHPMailer::preSend`.
+ *
+ */
+ function test_wp_mail_break_it() {
+ $content = str_repeat( 'A', 1000 );
+ wp_mail( "admin@example.org", 'Looong line testing', $content);
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function test_wp_mail_custom_boundaries() {
</span><span class="cx" style="display: block; padding: 0 10px"> $to = 'user@example.com';
</span><span class="cx" style="display: block; padding: 0 10px"> $subject = 'Test email with custom boundaries';
</span></span></pre>
</div>
</div>
</body>
</html>