|
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
|
|
|
|
|
8
|
|
|
namespace ZBateson\MailMimeParser\Header\Part; |
|
9
|
|
|
|
|
10
|
|
|
use Psr\Log\LoggerInterface; |
|
11
|
|
|
use ZBateson\MbWrapper\MbWrapper; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Represents a mime header comment -- text in a structured mime header |
|
15
|
|
|
* value existing within parentheses. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Zaahid Bateson |
|
18
|
|
|
*/ |
|
19
|
|
|
class CommentPart extends ContainerPart |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var HeaderPartFactory used to create intermediate parts. |
|
23
|
|
|
*/ |
|
24
|
|
|
protected HeaderPartFactory $partFactory; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string the contents of the comment |
|
28
|
17 |
|
*/ |
|
29
|
|
|
protected string $comment; |
|
30
|
17 |
|
|
|
31
|
17 |
|
public function __construct( |
|
32
|
17 |
|
LoggerInterface $logger, |
|
33
|
17 |
|
MbWrapper $charsetConverter, |
|
34
|
17 |
|
HeaderPartFactory $partFactory, |
|
35
|
|
|
array $children |
|
36
|
|
|
) { |
|
37
|
|
|
$this->partFactory = $partFactory; |
|
38
|
|
|
parent::__construct($logger, $charsetConverter, $children); |
|
39
|
|
|
$this->comment = $this->value; |
|
40
|
2 |
|
$this->value = ''; |
|
41
|
|
|
$this->isSpace = true; |
|
42
|
2 |
|
$this->canIgnoreSpacesBefore = true; |
|
43
|
|
|
$this->canIgnoreSpacesAfter = true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function getValueFromParts(array $parts) : string |
|
47
|
|
|
{ |
|
48
|
|
|
$partFactory = $this->partFactory; |
|
49
|
|
|
return parent::getValueFromParts(\array_map( |
|
50
|
|
|
function ($p) use ($partFactory) { |
|
51
|
|
|
if ($p instanceof CommentPart) { |
|
52
|
|
|
return $partFactory->newQuotedLiteralPart([$partFactory->newToken('(' . $p->getComment() . ')')]); |
|
53
|
|
|
} elseif ($p instanceof QuotedLiteralPart) { |
|
54
|
|
|
return $partFactory->newQuotedLiteralPart([$partFactory->newToken('"' . \str_replace('(["\\])', '\$1', $p->getValue()) . '"')]); |
|
55
|
|
|
} |
|
56
|
|
|
return $p; |
|
57
|
|
|
}, |
|
58
|
|
|
$parts |
|
59
|
|
|
)); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the comment's text. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getComment() : string |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->comment; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns an empty string. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getValue() : string |
|
74
|
|
|
{ |
|
75
|
|
|
return ''; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|