Completed
Push — master ( dec5d6...5872b4 )
by Zaahid
04:39
created

SubjectConsumer::getSubConsumers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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