Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/32'
Browse files Browse the repository at this point in the history
Close #32
  • Loading branch information
weierophinney committed May 14, 2018
2 parents ccf5d4c + cfaf7e7 commit 52ae5fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.1 - TBD
## 2.7.1 - 2018-05-14

### Added

Expand All @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#32](https://github.com/zendframework/zend-mime/pull/32) corrects a potential infinite loop when parsing lines consisting of only spaces and dots.

## 2.7.0 - 2017-11-28

Expand Down
24 changes: 15 additions & 9 deletions src/Mime.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,27 @@ public static function encodeQuotedPrintable(
$ptr = $lineLength;
}

// Try to prevent that the first character of a line is a dot
// Outlook Bug: http://engineering.como.com/ghost-vs-outlook/
while ($ptr > 1 && $ptr < strlen($str) && $str[$ptr] === '.') {
--$ptr;
}

// Ensure we are not splitting across an encoded character
$pos = strrpos(substr($str, 0, $ptr), '=');
if ($pos !== false && $pos >= $ptr - 2) {
$ptr = $pos;
}

// Check if there is a space at the end of the line and rewind
if ($ptr > 0 && $str[$ptr - 1] == ' ') {
--$ptr;
if (ord($str[0]) == 0x2E) { // 0x2E is a dot
$str = '=2E' . substr($str, 1);
$ptr += 2;
}

// copied from swiftmailer https://git.io/vAXU1
switch (ord(substr($str, $ptr - 1))) {
case 0x09: // Horizontal Tab
$str = substr_replace($str, '=09', $ptr - 1, 1);
$ptr += 2;
break;
case 0x20: // Space
$str = substr_replace($str, '=20', $ptr - 1, 1);
$ptr += 2;
break;
}

// Add string and continue
Expand Down
18 changes: 15 additions & 3 deletions test/MimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,29 @@ public function testQuotedPrintableNoDotAtBeginningOfLine()
$text = str_repeat('a', Mime\Mime::LINELENGTH) . '.bbb';
$qp = Mime\Mime::encodeQuotedPrintable($text);

$expected = str_repeat('a', Mime\Mime::LINELENGTH - 1) . "=\na.bbb";
$expected = str_repeat('a', Mime\Mime::LINELENGTH) . "=\n=2Ebbb";

$this->assertEquals($expected, $qp);
}

public function testQuotedPrintableSpacesAndDots()
{
$text = str_repeat(' ', Mime\Mime::LINELENGTH) . str_repeat('.', Mime\Mime::LINELENGTH);
$qp = Mime\Mime::encodeQuotedPrintable($text);

$expected = str_repeat(' ', Mime\Mime::LINELENGTH - 1)
. "=20=\n=2E"
. str_repeat('.', Mime\Mime::LINELENGTH - 1);

$this->assertEquals($expected, $qp);
}

public function testQuotedPrintableDoesNotBreakOctets()
{
$text = str_repeat('a', Mime\Mime::LINELENGTH - 3) . '=.bbb';
$text = str_repeat('a', Mime\Mime::LINELENGTH - 2) . '=.bbb';
$qp = Mime\Mime::encodeQuotedPrintable($text);

$expected = str_repeat('a', Mime\Mime::LINELENGTH - 3) . "=\n=3D.bbb";
$expected = str_repeat('a', Mime\Mime::LINELENGTH - 2) . "=\n=3D.bbb";

$this->assertEquals($expected, $qp);
}
Expand Down

0 comments on commit 52ae5fa

Please sign in to comment.