More efficient, more readable loops in wrapText
Add multibyte wordwrap test phpDoc cleanup in tests
This commit is contained in:
parent
93c8cd0536
commit
541cfec405
|
|
@ -1504,20 +1504,23 @@ class PHPMailer
|
|||
$crlflen = strlen(self::CRLF);
|
||||
|
||||
$message = $this->fixEOL($message);
|
||||
//Remove a trailing line break
|
||||
if (substr($message, -$lelen) == $this->LE) {
|
||||
$message = substr($message, 0, -$lelen);
|
||||
}
|
||||
|
||||
$line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
|
||||
//Split message into lines
|
||||
$lines = explode($this->LE, $message);
|
||||
//Message will be rebuilt in here
|
||||
$message = '';
|
||||
for ($i = 0; $i < count($line); $i++) {
|
||||
$line_part = explode(' ', $line[$i]);
|
||||
foreach ($lines as $line) {
|
||||
$words = explode(' ', $line);
|
||||
$buf = '';
|
||||
for ($e = 0; $e < count($line_part); $e++) {
|
||||
$word = $line_part[$e];
|
||||
$firstword = true;
|
||||
foreach ($words as $word) {
|
||||
if ($qp_mode and (strlen($word) > $length)) {
|
||||
$space_left = $length - strlen($buf) - $crlflen;
|
||||
if ($e != 0) {
|
||||
if (!$firstword) {
|
||||
if ($space_left > 20) {
|
||||
$len = $space_left;
|
||||
if ($is_utf8) {
|
||||
|
|
@ -1559,13 +1562,17 @@ class PHPMailer
|
|||
}
|
||||
} else {
|
||||
$buf_o = $buf;
|
||||
$buf .= ($e == 0) ? $word : (' ' . $word);
|
||||
if (!$firstword) {
|
||||
$buf .= ' ';
|
||||
}
|
||||
$buf .= $word;
|
||||
|
||||
if (strlen($buf) > $length and $buf_o != '') {
|
||||
$message .= $buf_o . $soft_break;
|
||||
$buf = $word;
|
||||
}
|
||||
}
|
||||
$firstword = false;
|
||||
}
|
||||
$message .= $buf . self::CRLF;
|
||||
}
|
||||
|
|
@ -1726,10 +1733,10 @@ class PHPMailer
|
|||
}
|
||||
|
||||
// Add custom headers
|
||||
for ($index = 0; $index < count($this->CustomHeader); $index++) {
|
||||
foreach ($this->CustomHeader as $header) {
|
||||
$result .= $this->headerLine(
|
||||
trim($this->CustomHeader[$index][0]),
|
||||
$this->encodeHeader(trim($this->CustomHeader[$index][1]))
|
||||
trim($header[0]),
|
||||
$this->encodeHeader(trim($header[1]))
|
||||
);
|
||||
}
|
||||
if (!$this->sign_key_file) {
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test CRAM-MD5 authentication
|
||||
* Test CRAM-MD5 authentication.
|
||||
* Needs a connection to a server that supports this auth mechanism, so commented out by default
|
||||
*/
|
||||
public function testAuthCRAMMD5()
|
||||
|
|
@ -326,7 +326,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test email address validation
|
||||
* Test email address validation.
|
||||
* Test addresses obtained from http://isemail.info
|
||||
* Some failing cases commented out that are apparently up for debate!
|
||||
*/
|
||||
|
|
@ -646,7 +646,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Try a plain message.
|
||||
* Word-wrap an ASCII message.
|
||||
*/
|
||||
public function testWordWrap()
|
||||
{
|
||||
|
|
@ -668,7 +668,29 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Try a plain message.
|
||||
* Word-wrap a multibyte message.
|
||||
*/
|
||||
public function testWordWrapMultibyte()
|
||||
{
|
||||
$this->Mail->WordWrap = 40;
|
||||
$my_body = str_repeat(
|
||||
'飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 飛兒樂 團光茫 ' .
|
||||
'飛飛兒樂 團光茫兒樂 團光茫飛兒樂 團光飛兒樂 團光茫飛兒樂 團光茫兒樂 團光茫 ' .
|
||||
'飛兒樂 團光茫飛兒樂 團飛兒樂 團光茫光茫飛兒樂 團光茫. ',
|
||||
10
|
||||
);
|
||||
$nBodyLen = strlen($my_body);
|
||||
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
|
||||
|
||||
$this->Mail->Body = $my_body;
|
||||
$this->Mail->Subject .= ': Wordwrap multibyte';
|
||||
|
||||
$this->buildBody();
|
||||
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test low priority.
|
||||
*/
|
||||
public function testLowPriority()
|
||||
{
|
||||
|
|
@ -749,7 +771,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Try a plain message.
|
||||
* Send an HTML message.
|
||||
*/
|
||||
public function testHtml()
|
||||
{
|
||||
|
|
@ -925,7 +947,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* iCal event test
|
||||
* iCal event test.
|
||||
*/
|
||||
public function testIcal()
|
||||
{
|
||||
|
|
@ -993,7 +1015,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test sending multiple messages with separate connections
|
||||
* Test sending multiple messages with separate connections.
|
||||
*/
|
||||
public function testMultipleSend()
|
||||
{
|
||||
|
|
@ -1010,7 +1032,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test sending using SendMail
|
||||
* Test sending using SendMail.
|
||||
*/
|
||||
public function testSendmailSend()
|
||||
{
|
||||
|
|
@ -1024,7 +1046,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test sending using Qmail
|
||||
* Test sending using Qmail.
|
||||
*/
|
||||
public function testQmailSend()
|
||||
{
|
||||
|
|
@ -1043,7 +1065,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test sending using PHP mail() function
|
||||
* Test sending using PHP mail() function.
|
||||
*/
|
||||
public function testMailSend()
|
||||
{
|
||||
|
|
@ -1060,7 +1082,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test sending an empty body
|
||||
* Test sending an empty body.
|
||||
*/
|
||||
public function testEmptyBody()
|
||||
{
|
||||
|
|
@ -1075,7 +1097,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test keepalive (sending multiple messages in a single connection)
|
||||
* Test keepalive (sending multiple messages in a single connection).
|
||||
*/
|
||||
public function testSmtpKeepAlive()
|
||||
{
|
||||
|
|
@ -1119,7 +1141,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test error handling
|
||||
* Test error handling.
|
||||
*/
|
||||
public function testError()
|
||||
{
|
||||
|
|
@ -1135,7 +1157,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test addressing
|
||||
* Test addressing.
|
||||
*/
|
||||
public function testAddressing()
|
||||
{
|
||||
|
|
@ -1166,7 +1188,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test address escaping
|
||||
* Test address escaping.
|
||||
*/
|
||||
public function testAddressEscaping()
|
||||
{
|
||||
|
|
@ -1181,7 +1203,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test BCC-only addressing
|
||||
* Test BCC-only addressing.
|
||||
*/
|
||||
public function testBCCAddressing()
|
||||
{
|
||||
|
|
@ -1193,7 +1215,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Encoding and charset tests
|
||||
* Encoding and charset tests.
|
||||
*/
|
||||
public function testEncodings()
|
||||
{
|
||||
|
|
@ -1227,6 +1249,9 @@ EOT;
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test base-64 encoding.
|
||||
*/
|
||||
public function testBase64()
|
||||
{
|
||||
$this->Mail->Subject .= ': Base-64 encoding';
|
||||
|
|
@ -1235,7 +1260,7 @@ EOT;
|
|||
$this->assertTrue($this->Mail->send(), 'Base64 encoding failed');
|
||||
}
|
||||
/**
|
||||
* S/MIME Signing tests
|
||||
* S/MIME Signing tests.
|
||||
*/
|
||||
public function testSigning()
|
||||
{
|
||||
|
|
@ -1280,7 +1305,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* DKIM Signing tests
|
||||
* DKIM Signing tests.
|
||||
*/
|
||||
public function testDKIM()
|
||||
{
|
||||
|
|
@ -1307,7 +1332,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test line break reformatting
|
||||
* Test line break reformatting.
|
||||
*/
|
||||
public function testLineBreaks()
|
||||
{
|
||||
|
|
@ -1323,7 +1348,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting and retrieving message ID
|
||||
* Test setting and retrieving message ID.
|
||||
*/
|
||||
public function testMessageID()
|
||||
{
|
||||
|
|
@ -1337,7 +1362,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Miscellaneous calls to improve test coverage and some small tests
|
||||
* Miscellaneous calls to improve test coverage and some small tests.
|
||||
*/
|
||||
public function testMiscellaneous()
|
||||
{
|
||||
|
|
@ -1379,7 +1404,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Use a fake POP3 server to test POP-before-SMTP auth
|
||||
* Use a fake POP3 server to test POP-before-SMTP auth.
|
||||
* With a known-good login
|
||||
*/
|
||||
public function testPopBeforeSmtpGood()
|
||||
|
|
@ -1400,7 +1425,7 @@ EOT;
|
|||
}
|
||||
|
||||
/**
|
||||
* Use a fake POP3 server to test POP-before-SMTP auth
|
||||
* Use a fake POP3 server to test POP-before-SMTP auth.
|
||||
* With a known-bad login
|
||||
*/
|
||||
public function testPopBeforeSmtpBad()
|
||||
|
|
|
|||
Loading…
Reference in New Issue