/usr/share/php/Horde/Mime/Headers/Element.php is in php-horde-mime 2.10.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | <?php
/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Mime
*/
/**
* This class represents a single header element.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Mime
* @since 2.5.0
*
* @property-read string $name Header name.
* @property-read string $value_single The first header value.
*/
abstract class Horde_Mime_Headers_Element
implements IteratorAggregate
{
/**
* Header name (UTF-8, although limited to US-ASCII subset by RFCs).
*
* @var string
*/
protected $_name;
/**
* Header values.
*
* @var array
*/
protected $_values = array();
/**
* Constructor.
*
* @param string $name Header name.
* @param mixed $value Header value(s).
*/
public function __construct($name, $value)
{
$this->_name = trim($name);
if (strpos($this->_name, ' ') !== false) {
throw new InvalidArgumentException('Invalid header name');
}
$this->setValue($value);
}
/**
*/
public function __get($name)
{
switch ($name) {
case 'name':
return $this->_name;
case 'value_single':
return reset($this->_values);
}
}
/**
* Set the value of the header.
*
* @param mixed $value Header value(s).
*/
final public function setValue($value)
{
$this->_setValue($value);
}
/**
* TODO
*/
abstract protected function _setValue($value);
/**
* Returns the encoded string value(s) needed when sending the header text
* to a RFC compliant mail submission server.
*
* @param array $opts Additional options:
* - charset: (string) Charset to encode to.
* DEFAULT: UTF-8
*
* @return array An array of string values.
*/
final public function sendEncode(array $opts = array())
{
return $this->_sendEncode(array_merge(array(
'charset' => 'UTF-8'
), $opts));
}
/**
* TODO
*/
protected function _sendEncode($opts)
{
return $this->_values;
}
/**
* Perform sanity checking on a header value.
*
* @param string $data The header data.
*
* @return string The cleaned header data.
*/
protected function _sanityCheck($data)
{
$charset_test = array(
'windows-1252',
Horde_Mime_Headers::$defaultCharset
);
if (!Horde_String::validUtf8($data)) {
/* Appears to be a PHP error with the internal String structure
* which prevents accurate manipulation of the string. Copying
* the data to a new variable fixes things. */
$data = substr($data, 0);
/* Assumption: broken charset in headers is generally either
* UTF-8 or ISO-8859-1/Windows-1252. Test these charsets
* first before using default charset. This may be a
* Western-centric approach, but it's better than nothing. */
foreach ($charset_test as $charset) {
$tmp = Horde_String::convertCharset($data, $charset, 'UTF-8');
if (Horde_String::validUtf8($tmp)) {
return $tmp;
}
}
}
/* Ensure no null characters exist in header data. */
return str_replace("\0", '', $data);
}
/**
* If true, indicates the contents of the header is the default value.
*
* @since 2.8.0
*
* @return boolean True if this header is the default value.
*/
public function isDefault()
{
return false;
}
/* Static methods */
/**
* Return list of explicit header names handled by this driver.
*
* @return array Header list.
*/
public static function getHandles()
{
return array();
}
/* IteratorAggregate method */
/**
*/
public function getIterator()
{
return new ArrayIterator($this->_values);
}
}
|