File indexing completed on 2024-12-22 05:36:50
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Mail 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** 0024 * @category Zend 0025 * @package Zend_Mail 0026 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0027 * @license http://framework.zend.com/license/new-bsd New BSD License 0028 */ 0029 final class Zend_Mail_Header_HeaderName 0030 { 0031 /** 0032 * No public constructor. 0033 */ 0034 private function __construct() 0035 { 0036 } 0037 0038 /** 0039 * Filter the header name according to RFC 2822 0040 * 0041 * @see http://www.rfc-base.org/txt/rfc-2822.txt (section 2.2) 0042 * @param string $name 0043 * @return string 0044 */ 0045 public static function filter($name) 0046 { 0047 $result = ''; 0048 $tot = strlen($name); 0049 for ($i = 0; $i < $tot; $i += 1) { 0050 $ord = ord($name[$i]); 0051 if ($ord > 32 && $ord < 127 && $ord !== 58) { 0052 $result .= $name[$i]; 0053 } 0054 } 0055 return $result; 0056 } 0057 0058 /** 0059 * Determine if the header name contains any invalid characters. 0060 * 0061 * @param string $name 0062 * @return bool 0063 */ 0064 public static function isValid($name) 0065 { 0066 $tot = strlen($name); 0067 for ($i = 0; $i < $tot; $i += 1) { 0068 $ord = ord($name[$i]); 0069 if ($ord < 33 || $ord > 126 || $ord === 58) { 0070 return false; 0071 } 0072 } 0073 return true; 0074 } 0075 0076 /** 0077 * Assert that the header name is valid. 0078 * 0079 * Raises an exception if invalid. 0080 * 0081 * @param string $name 0082 * @throws Exception\RuntimeException 0083 * @return void 0084 */ 0085 public static function assertValid($name) 0086 { 0087 if (! self::isValid($name)) { 0088 // require_once 'Zend/Mail/Exception.php'; 0089 throw new Zend_Mail_Exception('Invalid header name detected'); 0090 } 0091 } 0092 }