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
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Mime\Tests\Header;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Header\IdentificationHeader;
class IdentificationHeaderTest extends TestCase
{
public function testValueMatchesMsgIdSpec()
{
/* -- RFC 2822, 3.6.4.
message-id = "Message-ID:" msg-id CRLF
in-reply-to = "In-Reply-To:" 1*msg-id CRLF
references = "References:" 1*msg-id CRLF
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
id-left = dot-atom-text / no-fold-quote / obs-id-left
id-right = dot-atom-text / no-fold-literal / obs-id-right
no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
no-fold-literal = "[" *(dtext / quoted-pair) "]"
*/
$header = new IdentificationHeader('Message-ID', 'id-left@id-right');
$this->assertEquals('<id-left@id-right>', $header->getBodyAsString());
}
public function testIdCanBeRetrievedVerbatim()
{
$header = new IdentificationHeader('Message-ID', 'id-left@id-right');
$this->assertEquals('id-left@id-right', $header->getId());
}
public function testMultipleIdsCanBeSet()
{
$header = new IdentificationHeader('References', 'c@d');
$header->setIds(['a@b', 'x@y']);
$this->assertEquals(['a@b', 'x@y'], $header->getIds());
}
public function testSettingMultipleIdsProducesAListValue()
{
/* -- RFC 2822, 3.6.4.
The "References:" and "In-Reply-To:" field each contain one or more
unique message identifiers, optionally separated by CFWS.
.. SNIP ..
in-reply-to = "In-Reply-To:" 1*msg-id CRLF
references = "References:" 1*msg-id CRLF
*/
$header = new IdentificationHeader('References', ['a@b', 'x@y']);
$this->assertEquals('<a@b> <x@y>', $header->getBodyAsString());
}
public function testIdLeftCanBeQuoted()
{
/* -- RFC 2822, 3.6.4.
id-left = dot-atom-text / no-fold-quote / obs-id-left
*/
$header = new IdentificationHeader('References', '"ab"@c');
$this->assertEquals('"ab"@c', $header->getId());
$this->assertEquals('<"ab"@c>', $header->getBodyAsString());
}
public function testIdLeftCanContainAnglesAsQuotedPairs()
{
/* -- RFC 2822, 3.6.4.
no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
*/
$header = new IdentificationHeader('References', '"a\\<\\>b"@c');
$this->assertEquals('"a\\<\\>b"@c', $header->getId());
$this->assertEquals('<"a\\<\\>b"@c>', $header->getBodyAsString());
}
public function testIdLeftCanBeDotAtom()
{
$header = new IdentificationHeader('References', 'a.b+&%$.c@d');
$this->assertEquals('a.b+&%$.c@d', $header->getId());
$this->assertEquals('<a.b+&%$.c@d>', $header->getBodyAsString());
}
public function testInvalidIdLeftThrowsException()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Email "a b c@d" does not comply with addr-spec of RFC 2822.');
$header = new IdentificationHeader('References', 'a b c@d');
}
public function testIdRightCanBeDotAtom()
{
/* -- RFC 2822, 3.6.4.
id-right = dot-atom-text / no-fold-literal / obs-id-right
*/
$header = new IdentificationHeader('References', 'a@b.c+&%$.d');
$this->assertEquals('a@b.c+&%$.d', $header->getId());
$this->assertEquals('<a@b.c+&%$.d>', $header->getBodyAsString());
}
public function testIdRightCanBeLiteral()
{
/* -- RFC 2822, 3.6.4.
no-fold-literal = "[" *(dtext / quoted-pair) "]"
*/
$header = new IdentificationHeader('References', 'a@[1.2.3.4]');
$this->assertEquals('a@[1.2.3.4]', $header->getId());
$this->assertEquals('<a@[1.2.3.4]>', $header->getBodyAsString());
}
public function testIdRigthIsIdnEncoded()
{
$header = new IdentificationHeader('References', 'a@ä');
$this->assertEquals('a@ä', $header->getId());
$this->assertEquals('<a@xn--4ca>', $header->getBodyAsString());
}
public function testInvalidIdRightThrowsException()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Email "a@b c d" does not comply with addr-spec of RFC 2822.');
$header = new IdentificationHeader('References', 'a@b c d');
}
public function testMissingAtSignThrowsException()
{
$this->expectException('Exception');
$this->expectExceptionMessage('Email "abc" does not comply with addr-spec of RFC 2822.');
/* -- RFC 2822, 3.6.4.
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
*/
$header = new IdentificationHeader('References', 'abc');
}
public function testSetBody()
{
$header = new IdentificationHeader('Message-ID', 'c@d');
$header->setBody('a@b');
$this->assertEquals(['a@b'], $header->getIds());
}
public function testGetBody()
{
$header = new IdentificationHeader('Message-ID', 'a@b');
$this->assertEquals(['a@b'], $header->getBody());
}
public function testStringValue()
{
$header = new IdentificationHeader('References', ['a@b', 'x@y']);
$this->assertEquals('References: <a@b> <x@y>', $header->toString());
}
}