/usr/share/php/tests/Horde_Mime/Horde/Mime/HeadersTest.php is in php-horde-mime 2.2.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <?php
/**
* Tests for the Horde_Mime_Headers class.
*
* Copyright 2010-2013 Horde LLC (http://www.horde.org/)
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Mime
* @subpackage UnitTests
*/
/**
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Mime
* @subpackage UnitTests
*/
class Horde_Mime_HeadersTest extends PHPUnit_Framework_TestCase
{
public function testSerialize()
{
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('Subject', 'My Subject');
$hdrs->addHeader('To', 'recipient@example.com');
$hdrs->addHeader('Cc', 'null@example.com');
$hdrs->addHeader('Bcc', 'invisible@example.com');
$hdrs->addHeader('From', 'sender@example.com');
$stored = serialize($hdrs);
$hdrs2 = unserialize($stored);
$this->assertEquals(
'null@example.com',
$hdrs2->getValue('cc')
);
}
public function testHeaderDecode()
{
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader(
'Test',
'=?iso-8859-15?b?VmVyc2nzbg==?=',
array(
'decode' => true
)
);
$this->assertEquals(
'Versión',
$hdrs->getValue('Test')
);
}
public function testHeaderAutoDetectCharset()
{
$hdrs = Horde_Mime_Headers::parseHeaders(
// This string is in Windows-1252
'Test: ' . base64_decode('UnVubmVyc5IgQWxlcnQh=')
);
$this->assertEquals(
'Runners’ Alert!',
$hdrs->getValue('Test')
);
}
public function testHeaderCharsetConversion()
{
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('To', 'Empfänger <recipient@example.com>');
$hdr_array = $hdrs->toArray(array(
'charset' => 'iso-8859-1'
));
$this->assertEquals(
'=?iso-8859-1?b?RW1wZuRuZ2Vy?= <recipient@example.com>',
$hdr_array['To']
);
}
public function testMultipleContentType()
{
$hdrs = Horde_Mime_Headers::parseHeaders(
"Content-Type: multipart/mixed\n" .
"Content-Type: multipart/mixed\n"
);
$this->assertInternalType(
'string',
$hdrs->getValue('content-type', Horde_Mime_Headers::VALUE_BASE)
);
}
public function testMultivalueHeaders()
{
$hdrs = Horde_Mime_Headers::parseHeaders(
"To: recipient1@example.com, recipient2@example.com"
);
$this->assertEquals(
'recipient1@example.com, recipient2@example.com',
$hdrs->getValue('to')
);
$hdrs = Horde_Mime_Headers::parseHeaders(
"To: recipient1@example.com
To: recipient2@example.com"
);
$this->assertEquals(
'recipient1@example.com, recipient2@example.com',
$hdrs->getValue('to')
);
}
public function testAddHeaderWithGroup()
{
$email = 'Test: foo@example.com, bar@example.com;';
$rfc822 = new Horde_Mail_Rfc822();
$ob = $rfc822->parseAddressList($email);
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('To', $ob);
$this->assertEquals(
$email,
$hdrs->getValue('to')
);
}
public function testUnencodedMimeHeader()
{
// The header is base64 encoded to preserve charset data.
$hdr = 'RnJvbTogqSBWSUFHUkEgriBPZmZpY2lhbCBTaXRlIDxzbHVzYXJza2lAZ29sZGVud2FyZS5jb20+DQo=';
$hdrs = Horde_Mime_Headers::parseHeaders(base64_decode($hdr));
$this->assertEquals(
'© VIAGRA ® Official Site <slusarski@goldenware.com>',
$hdrs->getValue('from')
);
}
public function testUndisclosedHeaderParsing()
{
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('To', 'undisclosed-recipients');
$this->assertEquals(
'',
$hdrs->getValue('To')
);
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('To', 'undisclosed-recipients:');
$this->assertEquals(
'',
$hdrs->getValue('To')
);
$hdrs = new Horde_Mime_Headers();
$hdrs->addHeader('To', 'undisclosed-recipients:;');
$this->assertEquals(
'',
$hdrs->getValue('To')
);
}
public function testMultipleToAddresses()
{
$msg = file_get_contents(__DIR__ . '/fixtures/multiple_to.txt');
$hdrs = Horde_Mime_Headers::parseHeaders($msg);
$this->assertNotEmpty($hdrs->getValue('To'));
}
public function testBug12189()
{
$msg = file_get_contents(__DIR__ . '/fixtures/header_trailing_ws.txt');
$hdrs = Horde_Mime_Headers::parseHeaders($msg);
$this->assertNotNull($hdrs->getValue('From'));
}
}
|