Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /*
  4:  * This file is part of SwiftMailer.
  5:  * (c) 2004-2009 Chris Corbyn
  6:  *
  7:  * For the full copyright and license information, please view the LICENSE
  8:  * file that was distributed with this source code.
  9:  */
 10: 
 11: /**
 12:  * A collection of MIME headers.
 13:  *
 14:  * @package Swift
 15:  * @subpackage Mime
 16:  *
 17:  * @author Chris Corbyn
 18:  */
 19: class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
 20: {
 21:     /** HeaderFactory */
 22:     private $_factory;
 23: 
 24:     /** Collection of set Headers */
 25:     private $_headers = array();
 26: 
 27:     /** Field ordering details */
 28:     private $_order = array();
 29: 
 30:     /** List of fields which are required to be displayed */
 31:     private $_required = array();
 32: 
 33:     /** The charset used by Headers */
 34:     private $_charset;
 35: 
 36:     /**
 37:      * Create a new SimpleHeaderSet with the given $factory.
 38:      *
 39:      * @param Swift_Mime_HeaderFactory $factory
 40:      * @param string                   $charset
 41:      */
 42:     public function __construct(Swift_Mime_HeaderFactory $factory, $charset = null)
 43:     {
 44:         $this->_factory = $factory;
 45:         if (isset($charset)) {
 46:             $this->setCharset($charset);
 47:         }
 48:     }
 49: 
 50:     /**
 51:      * Set the charset used by these headers.
 52:      *
 53:      * @param string $charset
 54:      */
 55:     public function setCharset($charset)
 56:     {
 57:         $this->_charset = $charset;
 58:         $this->_factory->charsetChanged($charset);
 59:         $this->_notifyHeadersOfCharset($charset);
 60:     }
 61: 
 62:     /**
 63:      * Add a new Mailbox Header with a list of $addresses.
 64:      *
 65:      * @param string       $name
 66:      * @param array|string $addresses
 67:      */
 68:     public function addMailboxHeader($name, $addresses = null)
 69:     {
 70:         $this->_storeHeader($name,
 71:         $this->_factory->createMailboxHeader($name, $addresses));
 72:     }
 73: 
 74:     /**
 75:      * Add a new Date header using $timestamp (UNIX time).
 76:      *
 77:      * @param string $name
 78:      * @param int    $timestamp
 79:      */
 80:     public function addDateHeader($name, $timestamp = null)
 81:     {
 82:         $this->_storeHeader($name,
 83:         $this->_factory->createDateHeader($name, $timestamp));
 84:     }
 85: 
 86:     /**
 87:      * Add a new basic text header with $name and $value.
 88:      *
 89:      * @param string $name
 90:      * @param string $value
 91:      */
 92:     public function addTextHeader($name, $value = null)
 93:     {
 94:         $this->_storeHeader($name,
 95:         $this->_factory->createTextHeader($name, $value));
 96:     }
 97: 
 98:     /**
 99:      * Add a new ParameterizedHeader with $name, $value and $params.
100:      *
101:      * @param string $name
102:      * @param string $value
103:      * @param array  $params
104:      */
105:     public function addParameterizedHeader($name, $value = null, $params = array())
106:     {
107:         $this->_storeHeader($name,
108:             $this->_factory->createParameterizedHeader($name, $value,
109:             $params));
110:     }
111: 
112:     /**
113:      * Add a new ID header for Message-ID or Content-ID.
114:      *
115:      * @param string       $name
116:      * @param string|array $ids
117:      */
118:     public function addIdHeader($name, $ids = null)
119:     {
120:         $this->_storeHeader($name, $this->_factory->createIdHeader($name, $ids));
121:     }
122: 
123:     /**
124:      * Add a new Path header with an address (path) in it.
125:      *
126:      * @param string $name
127:      * @param string $path
128:      */
129:     public function addPathHeader($name, $path = null)
130:     {
131:         $this->_storeHeader($name, $this->_factory->createPathHeader($name, $path));
132:     }
133: 
134:     /**
135:      * Returns true if at least one header with the given $name exists.
136:      *
137:      * If multiple headers match, the actual one may be specified by $index.
138:      *
139:      * @param string $name
140:      * @param int    $index
141:      *
142:      * @return boolean
143:      */
144:     public function has($name, $index = 0)
145:     {
146:         $lowerName = strtolower($name);
147: 
148:         return array_key_exists($lowerName, $this->_headers)
149:             && array_key_exists($index, $this->_headers[$lowerName]);
150:     }
151: 
152:     /**
153:      * Set a header in the HeaderSet.
154:      *
155:      * The header may be a previously fetched header via {@link get()} or it may
156:      * be one that has been created separately.
157:      *
158:      * If $index is specified, the header will be inserted into the set at this
159:      * offset.
160:      *
161:      * @param Swift_Mime_Header $header
162:      * @param int               $index
163:      */
164:     public function set(Swift_Mime_Header $header, $index = 0)
165:     {
166:         $this->_storeHeader($header->getFieldName(), $header, $index);
167:     }
168: 
169:     /**
170:      * Get the header with the given $name.
171:      *
172:      * If multiple headers match, the actual one may be specified by $index.
173:      * Returns NULL if none present.
174:      *
175:      * @param string $name
176:      * @param int    $index
177:      *
178:      * @return Swift_Mime_Header
179:      */
180:     public function get($name, $index = 0)
181:     {
182:         if ($this->has($name, $index)) {
183:             $lowerName = strtolower($name);
184: 
185:             return $this->_headers[$lowerName][$index];
186:         }
187:     }
188: 
189:     /**
190:      * Get all headers with the given $name.
191:      *
192:      * @param string $name
193:      *
194:      * @return array
195:      */
196:     public function getAll($name = null)
197:     {
198:         if (!isset($name)) {
199:             $headers = array();
200:             foreach ($this->_headers as $collection) {
201:                 $headers = array_merge($headers, $collection);
202:             }
203: 
204:             return $headers;
205:         }
206: 
207:         $lowerName = strtolower($name);
208:         if (!array_key_exists($lowerName, $this->_headers)) {
209:             return array();
210:         }
211: 
212:         return $this->_headers[$lowerName];
213:     }
214: 
215:     /**
216:      * Remove the header with the given $name if it's set.
217:      *
218:      * If multiple headers match, the actual one may be specified by $index.
219:      *
220:      * @param string $name
221:      * @param int    $index
222:      */
223:     public function remove($name, $index = 0)
224:     {
225:         $lowerName = strtolower($name);
226:         unset($this->_headers[$lowerName][$index]);
227:     }
228: 
229:     /**
230:      * Remove all headers with the given $name.
231:      *
232:      * @param string $name
233:      */
234:     public function removeAll($name)
235:     {
236:         $lowerName = strtolower($name);
237:         unset($this->_headers[$lowerName]);
238:     }
239: 
240:     /**
241:      * Create a new instance of this HeaderSet.
242:      *
243:      * @return Swift_Mime_HeaderSet
244:      */
245:     public function newInstance()
246:     {
247:         return new self($this->_factory);
248:     }
249: 
250:     /**
251:      * Define a list of Header names as an array in the correct order.
252:      *
253:      * These Headers will be output in the given order where present.
254:      *
255:      * @param array $sequence
256:      */
257:     public function defineOrdering(array $sequence)
258:     {
259:         $this->_order = array_flip(array_map('strtolower', $sequence));
260:     }
261: 
262:     /**
263:      * Set a list of header names which must always be displayed when set.
264:      *
265:      * Usually headers without a field value won't be output unless set here.
266:      *
267:      * @param array $names
268:      */
269:     public function setAlwaysDisplayed(array $names)
270:     {
271:         $this->_required = array_flip(array_map('strtolower', $names));
272:     }
273: 
274:     /**
275:      * Notify this observer that the entity's charset has changed.
276:      *
277:      * @param string $charset
278:      */
279:     public function charsetChanged($charset)
280:     {
281:         $this->setCharset($charset);
282:     }
283: 
284:     /**
285:      * Returns a string with a representation of all headers.
286:      *
287:      * @return string
288:      */
289:     public function toString()
290:     {
291:         $string = '';
292:         $headers = $this->_headers;
293:         if ($this->_canSort()) {
294:             uksort($headers, array($this, '_sortHeaders'));
295:         }
296:         foreach ($headers as $collection) {
297:             foreach ($collection as $header) {
298:                 if ($this->_isDisplayed($header) || $header->getFieldBody() != '') {
299:                     $string .= $header->toString();
300:                 }
301:             }
302:         }
303: 
304:         return $string;
305:     }
306: 
307:     /**
308:      * Returns a string representation of this object.
309:      *
310:      * @return string
311:      *
312:      * @see toString()
313:      */
314:     public function __toString()
315:     {
316:         return $this->toString();
317:     }
318: 
319:     // -- Private methods
320: 
321:     /** Save a Header to the internal collection */
322:     private function _storeHeader($name, Swift_Mime_Header $header, $offset = null)
323:     {
324:         if (!isset($this->_headers[strtolower($name)])) {
325:             $this->_headers[strtolower($name)] = array();
326:         }
327:         if (!isset($offset)) {
328:             $this->_headers[strtolower($name)][] = $header;
329:         } else {
330:             $this->_headers[strtolower($name)][$offset] = $header;
331:         }
332:     }
333: 
334:     /** Test if the headers can be sorted */
335:     private function _canSort()
336:     {
337:         return count($this->_order) > 0;
338:     }
339: 
340:     /** uksort() algorithm for Header ordering */
341:     private function _sortHeaders($a, $b)
342:     {
343:         $lowerA = strtolower($a);
344:         $lowerB = strtolower($b);
345:         $aPos = array_key_exists($lowerA, $this->_order)
346:             ? $this->_order[$lowerA]
347:             : -1;
348:         $bPos = array_key_exists($lowerB, $this->_order)
349:             ? $this->_order[$lowerB]
350:             : -1;
351: 
352:         if ($aPos == -1) {
353:             return 1;
354:         } elseif ($bPos == -1) {
355:             return -1;
356:         }
357: 
358:         return ($aPos < $bPos) ? -1 : 1;
359:     }
360: 
361:     /** Test if the given Header is always displayed */
362:     private function _isDisplayed(Swift_Mime_Header $header)
363:     {
364:         return array_key_exists(strtolower($header->getFieldName()), $this->_required);
365:     }
366: 
367:     /** Notify all Headers of the new charset */
368:     private function _notifyHeadersOfCharset($charset)
369:     {
370:         foreach ($this->_headers as $headerGroup) {
371:             foreach ($headerGroup as $header) {
372:                 $header->setCharset($charset);
373:             }
374:         }
375:     }
376: }
377: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen