3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mail\Header
;
12 use Zend\Mail\Headers
;
14 class ContentTransferEncoding
implements HeaderInterface
17 * Allowed Content-Transfer-Encoding parameters specified by RFC 1521
21 protected static $allowedTransferEncodings = array(
37 protected $transferEncoding;
42 protected $parameters = array();
44 public static function fromString($headerLine)
46 $headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR
, 'UTF-8');
47 list($name, $value) = GenericHeader
::splitHeaderLine($headerLine);
49 // check to ensure proper header type for this factory
50 if (strtolower($name) !== 'content-transfer-encoding') {
51 throw new Exception\
InvalidArgumentException('Invalid header line for Content-Transfer-Encoding string');
54 $header = new static();
55 $header->setTransferEncoding($value);
60 public function getFieldName()
62 return 'Content-Transfer-Encoding';
65 public function getFieldValue($format = HeaderInterface
::FORMAT_RAW
)
67 return $this->transferEncoding
;
70 public function setEncoding($encoding)
72 // Header must be always in US-ASCII
76 public function getEncoding()
81 public function toString()
83 return 'Content-Transfer-Encoding: ' . $this->getFieldValue();
87 * Set the content transfer encoding
89 * @param string $transferEncoding
90 * @throws Exception\InvalidArgumentException
93 public function setTransferEncoding($transferEncoding)
95 if (!in_array($transferEncoding, self
::$allowedTransferEncodings)) {
96 throw new Exception\
InvalidArgumentException(sprintf(
97 '%s expects one of "'. implode(', ', self
::$allowedTransferEncodings) . '"; received "%s"',
99 (string) $transferEncoding
102 $this->transferEncoding
= $transferEncoding;
107 * Retrieve the content transfer encoding
111 public function getTransferEncoding()
113 return $this->transferEncoding
;