|
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\Parser\Proxy; |
|
8
|
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Message\IMessagePart; |
|
10
|
|
|
use ZBateson\MailMimeParser\Parser\IParser; |
|
11
|
|
|
use ZBateson\MailMimeParser\Parser\PartBuilder; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Proxy between a MessagePart and a Parser. |
|
15
|
|
|
* |
|
16
|
|
|
* ParserPartProxy objects are responsible for ferrying requests from message |
|
17
|
|
|
* parts to a proxy as they're requested, and for maintaining state information |
|
18
|
|
|
* for a parser as necessary. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Zaahid Bateson |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class ParserPartProxy extends PartBuilder |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var IMessagePart The part. |
|
26
|
|
|
*/ |
|
27
|
|
|
private $part; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var IParser The parser. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $parser; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var PartBuilder The part's PartBuilder. |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $partBuilder; |
|
38
|
|
|
|
|
39
|
132 |
|
public function __construct( |
|
40
|
|
|
PartBuilder $partBuilder, |
|
41
|
|
|
IParser $parser |
|
42
|
|
|
) { |
|
43
|
132 |
|
$this->partBuilder = $partBuilder; |
|
44
|
132 |
|
$this->parser = $parser; |
|
45
|
132 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets the associated part. |
|
49
|
|
|
* |
|
50
|
|
|
* @param IMessagePart $part The part |
|
51
|
|
|
*/ |
|
52
|
105 |
|
public function setPart(IMessagePart $part) |
|
53
|
|
|
{ |
|
54
|
105 |
|
$this->part = $part; |
|
55
|
105 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Returns the IMessagePart associated with this proxy. |
|
59
|
|
|
* |
|
60
|
|
|
* @return IMessagePart the part. |
|
61
|
|
|
*/ |
|
62
|
105 |
|
public function getPart() |
|
63
|
|
|
{ |
|
64
|
105 |
|
return $this->part; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Requests the parser to parse this part's content, and call |
|
69
|
|
|
* setStreamContentStartPos/EndPos to setup this part's boundaries within |
|
70
|
|
|
* the main message's raw stream. |
|
71
|
|
|
* |
|
72
|
|
|
* The method first checks to see if the content has already been parsed, |
|
73
|
|
|
* and is safe to call multiple times. |
|
74
|
|
|
*/ |
|
75
|
109 |
|
public function parseContent() |
|
76
|
|
|
{ |
|
77
|
109 |
|
if (!$this->isContentParsed()) { |
|
78
|
109 |
|
$this->parser->parseContent($this); |
|
79
|
|
|
} |
|
80
|
109 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Parses everything under this part. |
|
84
|
|
|
* |
|
85
|
|
|
* For ParserPartProxy, this is just content, but sub-classes may override |
|
86
|
|
|
* this to parse all children as well for example. |
|
87
|
|
|
. */ |
|
88
|
3 |
|
public function parseAll() |
|
89
|
|
|
{ |
|
90
|
3 |
|
$this->parseContent(); |
|
91
|
3 |
|
} |
|
92
|
|
|
|
|
93
|
112 |
|
public function getParent() |
|
94
|
|
|
{ |
|
95
|
112 |
|
return $this->partBuilder->getParent(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
112 |
|
public function getHeaderContainer() |
|
99
|
|
|
{ |
|
100
|
112 |
|
return $this->partBuilder->getHeaderContainer(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
102 |
|
public function getStream() |
|
104
|
|
|
{ |
|
|
|
|
|
|
105
|
102 |
|
return $this->partBuilder->getStream(); |
|
106
|
|
|
} |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
103 |
|
public function getMessageResourceHandle() |
|
109
|
|
|
{ |
|
110
|
103 |
|
return $this->partBuilder->getMessageResourceHandle(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
101 |
|
public function getMessageResourceHandlePos() |
|
114
|
|
|
{ |
|
115
|
101 |
|
return $this->partBuilder->getMessageResourceHandlePos(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
98 |
|
public function getStreamPartStartPos() |
|
119
|
|
|
{ |
|
120
|
98 |
|
return $this->partBuilder->getStreamPartStartPos(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
98 |
|
public function getStreamPartLength() |
|
124
|
|
|
{ |
|
125
|
98 |
|
return $this->partBuilder->getStreamPartLength(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
102 |
|
public function getStreamContentStartPos() |
|
129
|
|
|
{ |
|
130
|
102 |
|
return $this->partBuilder->getStreamContentStartPos(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
102 |
|
public function getStreamContentLength() |
|
134
|
|
|
{ |
|
135
|
102 |
|
return $this->partBuilder->getStreamContentLength(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setStreamPartStartPos($streamPartStartPos) |
|
139
|
|
|
{ |
|
140
|
|
|
$this->partBuilder->setStreamPartStartPos($streamPartStartPos); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
73 |
|
public function setStreamPartEndPos($streamPartEndPos) |
|
144
|
|
|
{ |
|
145
|
73 |
|
$this->partBuilder->setStreamPartEndPos($streamPartEndPos); |
|
146
|
73 |
|
} |
|
147
|
|
|
|
|
148
|
103 |
|
public function setStreamContentStartPos($streamContentStartPos) |
|
149
|
|
|
{ |
|
150
|
103 |
|
$this->partBuilder->setStreamContentStartPos($streamContentStartPos); |
|
151
|
103 |
|
} |
|
152
|
|
|
|
|
153
|
103 |
|
public function setStreamPartAndContentEndPos($streamContentEndPos) |
|
154
|
|
|
{ |
|
155
|
103 |
|
$this->partBuilder->setStreamPartAndContentEndPos($streamContentEndPos); |
|
156
|
103 |
|
} |
|
157
|
|
|
|
|
158
|
109 |
|
public function isContentParsed() |
|
159
|
|
|
{ |
|
160
|
109 |
|
return $this->partBuilder->isContentParsed(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
73 |
|
public function isMime() |
|
164
|
|
|
{ |
|
165
|
73 |
|
return $this->partBuilder->isMime(); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|