|
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\Consumer; |
|
9
|
|
|
|
|
10
|
|
|
use ZBateson\MailMimeParser\Header\IHeaderPart; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Represents a quoted part of a header value starting at a double quote, and |
|
14
|
|
|
* ending at the next double quote. |
|
15
|
|
|
* |
|
16
|
|
|
* A quoted-pair part in a header is a literal. There are no sub-consumers for |
|
17
|
|
|
* it and a Part\LiteralPart is returned. |
|
18
|
|
|
* |
|
19
|
|
|
* Newline characters (CR and LF) are stripped entirely from the quoted part. |
|
20
|
|
|
* This is based on the example at: |
|
21
|
|
|
* |
|
22
|
|
|
* https://tools.ietf.org/html/rfc822#section-3.1.1 |
|
23
|
|
|
* |
|
24
|
|
|
* And https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html in section 7.2.1 |
|
25
|
|
|
* splitting the boundary. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Zaahid Bateson |
|
28
|
|
|
*/ |
|
29
|
|
|
class QuotedStringConsumerService extends AbstractConsumerService |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Returns true if the token is a double quote. |
|
33
|
|
|
*/ |
|
34
|
108 |
|
protected function isStartToken(string $token) : bool |
|
35
|
|
|
{ |
|
36
|
108 |
|
return ($token === '"'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Returns true if the token is a double quote. |
|
41
|
|
|
*/ |
|
42
|
102 |
|
protected function isEndToken(string $token) : bool |
|
43
|
|
|
{ |
|
44
|
102 |
|
return ($token === '"'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Returns a single regex pattern for a double quote. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string[] |
|
51
|
|
|
*/ |
|
52
|
4 |
|
protected function getTokenSeparators() : array |
|
53
|
|
|
{ |
|
54
|
4 |
|
return ['\"']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Constructs a LiteralPart and returns it. |
|
59
|
|
|
*/ |
|
60
|
55 |
|
protected function getPartForToken(string $token, bool $isLiteral) : ?IHeaderPart |
|
61
|
|
|
{ |
|
62
|
55 |
|
return $this->partFactory->newToken($token, $isLiteral, true); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Overridden to combine all part values into a single string and return it |
|
67
|
|
|
* as an array with a single element. |
|
68
|
|
|
* |
|
69
|
|
|
* The returned IHeaderParts is an array containing a single |
|
70
|
|
|
* QuotedLiteralPart. |
|
71
|
|
|
* |
|
72
|
|
|
* @param IHeaderPart[] $parts |
|
73
|
|
|
* @return IHeaderPart[] |
|
74
|
|
|
*/ |
|
75
|
101 |
|
protected function processParts(array $parts) : array |
|
76
|
|
|
{ |
|
77
|
101 |
|
return [$this->partFactory->newQuotedLiteralPart($parts)]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|