|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This file is part of SwiftMailer. 00005 * (c) 2004-2009 Chris Corbyn 00006 * 00007 * For the full copyright and license information, please view the LICENSE 00008 * file that was distributed with this source code. 00009 */ 00010 00011 //@require 'Swift/Mime/HeaderFactory.php'; 00012 //@require 'Swift/Mime/HeaderEncoder.php'; 00013 //@require 'Swift/Encoder.php'; 00014 //@require 'Swift/Mime/Headers/MailboxHeader.php'; 00015 //@require 'Swift/Mime/Headers/DateHeader.php'; 00016 //@require 'Swift/Mime/Headers/UnstructuredHeader.php'; 00017 //@require 'Swift/Mime/Headers/ParameterizedHeader.php'; 00018 //@require 'Swift/Mime/Headers/IdentificationHeader.php'; 00019 //@require 'Swift/Mime/Headers/PathHeader.php'; 00020 00021 /** 00022 * Creates MIME headers. 00023 * @package Swift 00024 * @subpackage Mime 00025 * @author Chris Corbyn 00026 */ 00027 class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory 00028 { 00029 00030 /** The HeaderEncoder used by these headers */ 00031 private $_encoder; 00032 00033 /** The Encoder used by parameters */ 00034 private $_paramEncoder; 00035 00036 /** The charset of created Headers */ 00037 private $_charset; 00038 00039 /** 00040 * Creates a new SimpleHeaderFactory using $encoder and $paramEncoder. 00041 * @param Swift_Mime_HeaderEncoder $encoder 00042 * @param Swift_Encoder $paramEncoder 00043 * @param string $charset 00044 */ 00045 public function __construct(Swift_Mime_HeaderEncoder $encoder, 00046 Swift_Encoder $paramEncoder, $charset = null) 00047 { 00048 $this->_encoder = $encoder; 00049 $this->_paramEncoder = $paramEncoder; 00050 $this->_charset = $charset; 00051 } 00052 00053 /** 00054 * Create a new Mailbox Header with a list of $addresses. 00055 * @param string $name 00056 * @param array|string $addresses 00057 * @return Swift_Mime_Header 00058 */ 00059 public function createMailboxHeader($name, $addresses = null) 00060 { 00061 $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder); 00062 if (isset($addresses)) 00063 { 00064 $header->setFieldBodyModel($addresses); 00065 } 00066 $this->_setHeaderCharset($header); 00067 return $header; 00068 } 00069 00070 /** 00071 * Create a new Date header using $timestamp (UNIX time). 00072 * @param string $name 00073 * @param int $timestamp 00074 * @return Swift_Mime_Header 00075 */ 00076 public function createDateHeader($name, $timestamp = null) 00077 { 00078 $header = new Swift_Mime_Headers_DateHeader($name); 00079 if (isset($timestamp)) 00080 { 00081 $header->setFieldBodyModel($timestamp); 00082 } 00083 $this->_setHeaderCharset($header); 00084 return $header; 00085 } 00086 00087 /** 00088 * Create a new basic text header with $name and $value. 00089 * @param string $name 00090 * @param string $value 00091 * @return Swift_Mime_Header 00092 */ 00093 public function createTextHeader($name, $value = null) 00094 { 00095 $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder); 00096 if (isset($value)) 00097 { 00098 $header->setFieldBodyModel($value); 00099 } 00100 $this->_setHeaderCharset($header); 00101 return $header; 00102 } 00103 00104 /** 00105 * Create a new ParameterizedHeader with $name, $value and $params. 00106 * @param string $name 00107 * @param string $value 00108 * @param array $params 00109 * @return Swift_Mime_ParameterizedHeader 00110 */ 00111 public function createParameterizedHeader($name, $value = null, 00112 $params = array()) 00113 { 00114 $header = new Swift_Mime_Headers_ParameterizedHeader($name, 00115 $this->_encoder, (strtolower($name) == 'content-disposition') 00116 ? $this->_paramEncoder 00117 : null 00118 ); 00119 if (isset($value)) 00120 { 00121 $header->setFieldBodyModel($value); 00122 } 00123 foreach ($params as $k => $v) 00124 { 00125 $header->setParameter($k, $v); 00126 } 00127 $this->_setHeaderCharset($header); 00128 return $header; 00129 } 00130 00131 /** 00132 * Create a new ID header for Message-ID or Content-ID. 00133 * @param string $name 00134 * @param string|array $ids 00135 * @return Swift_Mime_Header 00136 */ 00137 public function createIdHeader($name, $ids = null) 00138 { 00139 $header = new Swift_Mime_Headers_IdentificationHeader($name); 00140 if (isset($ids)) 00141 { 00142 $header->setFieldBodyModel($ids); 00143 } 00144 $this->_setHeaderCharset($header); 00145 return $header; 00146 } 00147 00148 /** 00149 * Create a new Path header with an address (path) in it. 00150 * @param string $name 00151 * @param string $path 00152 * @return Swift_Mime_Header 00153 */ 00154 public function createPathHeader($name, $path = null) 00155 { 00156 $header = new Swift_Mime_Headers_PathHeader($name); 00157 if (isset($path)) 00158 { 00159 $header->setFieldBodyModel($path); 00160 } 00161 $this->_setHeaderCharset($header); 00162 return $header; 00163 } 00164 00165 /** 00166 * Notify this observer that the entity's charset has changed. 00167 * @param string $charset 00168 */ 00169 public function charsetChanged($charset) 00170 { 00171 $this->_charset = $charset; 00172 $this->_encoder->charsetChanged($charset); 00173 $this->_paramEncoder->charsetChanged($charset); 00174 } 00175 00176 // -- Private methods 00177 00178 /** Apply the charset to the Header */ 00179 private function _setHeaderCharset(Swift_Mime_Header $header) 00180 { 00181 if (isset($this->_charset)) 00182 { 00183 $header->setCharset($this->_charset); 00184 } 00185 } 00186 00187 }
1.8.0