Skip to content

Commit

Permalink
[mms] Fix setting MIME IDs when a message/rfc822 part is the base of …
Browse files Browse the repository at this point in the history
…the part object.
  • Loading branch information
slusarz committed Jan 16, 2015
1 parent 7b9feee commit ad1b4f2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
21 changes: 18 additions & 3 deletions framework/Mime/lib/Horde/Mime/Part.php
Expand Up @@ -1604,8 +1604,7 @@ public function buildMimeIds($id = null, $rfc822 = false)
$this->setMimeId($id . '1');
} else {
if (empty($id) && ($this->getType() == 'message/rfc822')) {
$this->setMimeId('1');
$id = '1.';
$this->setMimeId('1.0');
} else {
$this->setMimeId($id . '0');
}
Expand Down Expand Up @@ -1664,12 +1663,28 @@ public function contentTypeMap($sort = true)
}

if ($sort) {
uksort($map, 'strnatcmp');
uksort($map, array($this, '_contentTypeMapSort'));
}

return $map;
}

/**
*/
protected function _contentTypeMapSort($a, $b)
{
if (substr($a, -2) === '.0') {
if (substr($a, 0, -2) == $b) {
return -1;
}
} elseif ((substr($b, 0, -2) === '.0') &&
(substr($b, 0, -2) == $a)) {
return 1;
}

return strnatcmp($a, $b);
}

/**
* Is this the base MIME part?
*
Expand Down
4 changes: 2 additions & 2 deletions framework/Mime/package.xml
Expand Up @@ -28,7 +28,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Fix setting MIME IDs when a message/rfc822 part is the base of the part object.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -1602,7 +1602,7 @@
<date>2014-12-29</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Fix setting MIME IDs when a message/rfc822 part is the base of the part object.
</notes>
</release>
</changelog>
Expand Down
25 changes: 25 additions & 0 deletions framework/Mime/test/Horde/Mime/PartTest.php
Expand Up @@ -696,6 +696,31 @@ public function setCharsetProvider()
);
}

public function testIdSortingInMessageRfc822Part()
{
$part = new Horde_Mime_Part();
$part->setType('message/rfc822');

$part1 = new Horde_Mime_Part();
$part1->setType('multipart/alternative');
$part->addPart($part1);

$part2 = new Horde_Mime_Part();
$part2->setType('text/plain');
$part1->addPart($part2);

$part3 = new Horde_Mime_Part();
$part3->setType('text/html');
$part1->addPart($part3);

$part->buildMimeIds();

$this->assertEquals(
array('1.0', '1', '1.1', '1.2'),
array_keys($part->contentTypeMap(true))
);
}

protected function _getTestPart()
{
$part = new Horde_Mime_Part();
Expand Down

0 comments on commit ad1b4f2

Please sign in to comment.