1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
6
|
|
|
*/ |
7
|
|
|
namespace ZBateson\MailMimeParser\Header\Consumer; |
8
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Header\Part\HeaderPart; |
10
|
|
|
use ZBateson\MailMimeParser\Header\Part\Token; |
11
|
|
|
use Iterator; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Extends GenericConsumer to remove its sub consumers. |
15
|
|
|
* |
16
|
|
|
* Prior to this, subject headers were parsed using the GenericConsumer which |
17
|
|
|
* meant if the subject contained text within parantheses, it would not be |
18
|
|
|
* included as part of the returned value in a getHeaderValue. Mime-encoded |
19
|
|
|
* parts within quotes would be ignored, and backslash characters denoted an |
20
|
|
|
* escaped character. |
21
|
|
|
* |
22
|
|
|
* From testing in ThunderBird and Outlook web mail it seems quoting parts |
23
|
|
|
* doesn't have an effect (e.g. quoting a "mime-literal" encoded part still |
24
|
|
|
* comes out decoded), and parts in parantheses (comments) are displayed |
25
|
|
|
* normally. |
26
|
|
|
* |
27
|
|
|
* @author Zaahid Bateson |
28
|
|
|
*/ |
29
|
|
|
class SubjectConsumer extends GenericConsumer |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Returns an empty array |
33
|
|
|
* |
34
|
|
|
* @return AbstractConsumer[] the sub-consumers |
35
|
|
|
*/ |
36
|
2 |
|
protected function getSubConsumers() |
37
|
|
|
{ |
38
|
2 |
|
return []; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns an array of \ZBateson\MailMimeParser\Header\Part\HeaderPart for |
43
|
|
|
* the current token on the iterator. |
44
|
|
|
* |
45
|
|
|
* Overridden from AbstractConsumer to remove special filtering for |
46
|
|
|
* backslash escaping, which also seems to not apply to Subject headers at |
47
|
|
|
* least in ThunderBird's implementation. |
48
|
|
|
* |
49
|
|
|
* @param Iterator $tokens |
50
|
|
|
* @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]|array |
51
|
|
|
*/ |
52
|
2 |
|
protected function getTokenParts(Iterator $tokens) |
53
|
|
|
{ |
54
|
2 |
|
return $this->getConsumerTokenParts($tokens); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Overridden to not split out backslash characters and its next character |
59
|
|
|
* as a special case defined in AbastractConsumer |
60
|
|
|
* |
61
|
|
|
* @return string the regex pattern |
62
|
|
|
*/ |
63
|
2 |
|
protected function getTokenSplitPattern() |
64
|
|
|
{ |
65
|
2 |
|
$sChars = implode('|', $this->getAllTokenSeparators()); |
66
|
2 |
|
return '~(' . $sChars . ')~'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|