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\Message; |
9
|
|
|
|
10
|
|
|
use ZBateson\MailMimeParser\MailMimeParser; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Implementation of a non-mime message's uuencoded attachment part. |
14
|
|
|
* |
15
|
|
|
* @author Zaahid Bateson |
16
|
|
|
*/ |
17
|
|
|
class UUEncodedPart extends NonMimePart implements IUUEncodedPart |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var int the unix file permission |
21
|
|
|
*/ |
22
|
|
|
protected $mode = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string the name of the file in the uuencoding 'header'. |
26
|
|
|
*/ |
27
|
|
|
protected $filename = null; |
28
|
|
|
|
29
|
10 |
|
public function __construct(?int $mode = null, ?string $filename = null, ?IMimePart $parent = null, ?PartStreamContainer $streamContainer = null) |
30
|
|
|
{ |
31
|
10 |
|
if ($streamContainer === null) { |
32
|
|
|
$di = MailMimeParser::getDependencyContainer(); |
33
|
|
|
$streamContainer = $di[\ZBateson\MailMimeParser\Message\PartStreamContainer::class]; |
34
|
|
|
$streamFactory = $di[\ZBateson\MailMimeParser\Stream\StreamFactory::class]; |
35
|
|
|
$streamContainer->setStream($streamFactory->newMessagePartStream($this)); |
36
|
|
|
} |
37
|
10 |
|
parent::__construct( |
38
|
10 |
|
$streamContainer, |
39
|
10 |
|
$parent |
40
|
10 |
|
); |
41
|
10 |
|
$this->mode = $mode; |
42
|
10 |
|
$this->filename = $filename; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the filename included in the uuencoded 'begin' line for this |
47
|
|
|
* part. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
4 |
|
public function getFilename() : ?string |
52
|
|
|
{ |
53
|
4 |
|
return $this->filename; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return static |
58
|
|
|
*/ |
59
|
1 |
|
public function setFilename(string $filename) |
60
|
|
|
{ |
61
|
1 |
|
$this->filename = $filename; |
62
|
1 |
|
$this->notify(); |
63
|
1 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns false. |
68
|
|
|
* |
69
|
|
|
* Although the part may be plain text, there is no reliable way of |
70
|
|
|
* determining its type since uuencoded 'begin' lines only include a file |
71
|
|
|
* name and no mime type. The file name's extension may be a hint. |
72
|
|
|
* |
73
|
|
|
* @return false |
74
|
|
|
*/ |
75
|
3 |
|
public function isTextPart() : bool |
76
|
|
|
{ |
77
|
3 |
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns 'application/octet-stream'. |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
4 |
|
public function getContentType(string $default = 'application/octet-stream') : ?string |
86
|
|
|
{ |
87
|
4 |
|
return 'application/octet-stream'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns null |
92
|
|
|
*/ |
93
|
4 |
|
public function getCharset() : ?string |
94
|
|
|
{ |
95
|
4 |
|
return null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns 'attachment'. |
100
|
|
|
*/ |
101
|
4 |
|
public function getContentDisposition(?string $default = 'attachment') : ?string |
102
|
|
|
{ |
103
|
4 |
|
return 'attachment'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns 'x-uuencode'. |
108
|
|
|
*/ |
109
|
3 |
|
public function getContentTransferEncoding(?string $default = 'x-uuencode') : ?string |
110
|
|
|
{ |
111
|
3 |
|
return 'x-uuencode'; |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
public function getUnixFileMode() : ?int |
115
|
|
|
{ |
116
|
1 |
|
return $this->mode; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return static |
121
|
|
|
*/ |
122
|
1 |
|
public function setUnixFileMode(int $mode) |
123
|
|
|
{ |
124
|
1 |
|
$this->mode = $mode; |
125
|
1 |
|
$this->notify(); |
126
|
1 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|