1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* @see https://github.com/zendframework/zend-mail for the canonical source repository
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Mail\Header;
class ContentTransferEncoding implements HeaderInterface
{
/**
* Allowed Content-Transfer-Encoding parameters specified by RFC 1521
* (reduced set)
* @var array
*/
protected static $allowedTransferEncodings = [
'7bit',
'8bit',
'quoted-printable',
'base64',
'binary',
/*
* not implemented:
* x-token: 'X-'
*/
];
/**
* @var string
*/
protected $transferEncoding;
/**
* @var array
*/
protected $parameters = [];
public static function fromString($headerLine)
{
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
$value = HeaderWrap::mimeDecodeValue($value);
// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-transfer-encoding') {
throw new Exception\InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string');
}
$header = new static();
$header->setTransferEncoding($value);
return $header;
}
public function getFieldName()
{
return 'Content-Transfer-Encoding';
}
public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
{
return $this->transferEncoding;
}
public function setEncoding($encoding)
{
// Header must be always in US-ASCII
return $this;
}
public function getEncoding()
{
return 'ASCII';
}
public function toString()
{
return 'Content-Transfer-Encoding: ' . $this->getFieldValue();
}
/**
* Set the content transfer encoding
*
* @param string $transferEncoding
* @throws Exception\InvalidArgumentException
* @return $this
*/
public function setTransferEncoding($transferEncoding)
{
// Per RFC 1521, the value of the header is not case sensitive
$transferEncoding = strtolower($transferEncoding);
if (! in_array($transferEncoding, static::$allowedTransferEncodings)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects one of "'. implode(', ', static::$allowedTransferEncodings) . '"; received "%s"',
__METHOD__,
(string) $transferEncoding
));
}
$this->transferEncoding = $transferEncoding;
return $this;
}
/**
* Retrieve the content transfer encoding
*
* @return string
*/
public function getTransferEncoding()
{
return $this->transferEncoding;
}
}