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\Message\Part; |
8
|
|
|
|
9
|
|
|
use Psr\Http\Message\StreamInterface; |
10
|
|
|
use ZBateson\MailMimeParser\Stream\StreamFactory; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A specialized NonMimePart representing a uuencoded part. |
14
|
|
|
* |
15
|
|
|
* This represents part of a message that is not a mime message. A multi-part |
16
|
|
|
* mime message may have a part with a Content-Transfer-Encoding of x-uuencode |
17
|
|
|
* but that would be represented by a normal MimePart. |
18
|
|
|
* |
19
|
|
|
* UUEncodedPart extends NonMimePart to return a Content-Transfer-Encoding of |
20
|
|
|
* x-uuencode, a Content-Type of application-octet-stream, and a |
21
|
|
|
* Content-Disposition of 'attachment'. It also expects a mode and filename to |
22
|
|
|
* initialize it, and adds 'filename' parts to the Content-Disposition and |
23
|
|
|
* 'name' to Content-Type. |
24
|
|
|
* |
25
|
|
|
* @author Zaahid Bateson |
26
|
|
|
*/ |
27
|
|
|
class UUEncodedPart extends NonMimePart |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var int the unix file permission |
31
|
|
|
*/ |
32
|
|
|
protected $mode = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string the name of the file in the uuencoding 'header'. |
36
|
|
|
*/ |
37
|
|
|
protected $filename = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param PartStreamFilterManager $partStreamFilterManager |
41
|
|
|
* @param StreamFactory $streamFactory |
42
|
|
|
* @param PartBuilder $partBuilder |
43
|
|
|
* @param StreamInterface $stream |
44
|
|
|
* @param StreamInterface $contentStream |
45
|
|
|
*/ |
46
|
1 |
|
public function __construct( |
47
|
|
|
PartStreamFilterManager $partStreamFilterManager, |
48
|
|
|
StreamFactory $streamFactory, |
49
|
|
|
PartBuilder $partBuilder, |
50
|
|
|
StreamInterface $stream = null, |
51
|
|
|
StreamInterface $contentStream = null |
52
|
|
|
) { |
53
|
1 |
|
parent::__construct($partStreamFilterManager, $streamFactory, $stream, $contentStream); |
54
|
1 |
|
$this->mode = $partBuilder->getProperty('mode'); |
|
|
|
|
55
|
1 |
|
$this->filename = $partBuilder->getProperty('filename'); |
56
|
1 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns the file mode included in the uuencoded header for this part. |
60
|
|
|
* |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
1 |
|
public function getUnixFileMode() |
64
|
|
|
{ |
65
|
1 |
|
return $this->mode; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns the filename included in the uuencoded header for this part. |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
1 |
|
public function getFilename() |
74
|
|
|
{ |
75
|
1 |
|
return $this->filename; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets the unix file mode for the uuencoded header. |
80
|
|
|
* |
81
|
|
|
* @param int $mode |
82
|
|
|
*/ |
83
|
|
|
public function setUnixFileMode($mode) |
84
|
|
|
{ |
85
|
|
|
$this->mode = $mode; |
86
|
|
|
$this->onChange(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets the filename included in the uuencoded header. |
91
|
|
|
* |
92
|
|
|
* @param string $filename |
93
|
|
|
*/ |
94
|
|
|
public function setFilename($filename) |
95
|
|
|
{ |
96
|
|
|
$this->filename = $filename; |
97
|
|
|
$this->onChange(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns false. |
102
|
|
|
* |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
1 |
|
public function isTextPart() |
106
|
|
|
{ |
107
|
1 |
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns text/plain |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
1 |
|
public function getContentType() |
116
|
|
|
{ |
117
|
1 |
|
return 'application/octet-stream'; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns null |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getCharset() |
126
|
|
|
{ |
127
|
|
|
return null; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns 'inline'. |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
1 |
|
public function getContentDisposition() |
136
|
|
|
{ |
137
|
1 |
|
return 'attachment'; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns 'x-uuencode'. |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
1 |
|
public function getContentTransferEncoding() |
146
|
|
|
{ |
147
|
1 |
|
return 'x-uuencode'; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.