[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Mime/ -> SimpleHeaderFactory.php (source)

   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   * Creates MIME headers.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
  17  {
  18      /** The HeaderEncoder used by these headers */
  19      private $_encoder;
  20  
  21      /** The Encoder used by parameters */
  22      private $_paramEncoder;
  23  
  24      /** The Grammar */
  25      private $_grammar;
  26  
  27      /** The charset of created Headers */
  28      private $_charset;
  29  
  30      /**
  31       * Creates a new SimpleHeaderFactory using $encoder and $paramEncoder.
  32       *
  33       * @param Swift_Mime_HeaderEncoder $encoder
  34       * @param Swift_Encoder            $paramEncoder
  35       * @param Swift_Mime_Grammar       $grammar
  36       * @param string|null              $charset
  37       */
  38      public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, Swift_Mime_Grammar $grammar, $charset = null)
  39      {
  40          $this->_encoder = $encoder;
  41          $this->_paramEncoder = $paramEncoder;
  42          $this->_grammar = $grammar;
  43          $this->_charset = $charset;
  44      }
  45  
  46      /**
  47       * Create a new Mailbox Header with a list of $addresses.
  48       *
  49       * @param string            $name
  50       * @param array|string|null $addresses
  51       *
  52       * @return Swift_Mime_Header
  53       */
  54      public function createMailboxHeader($name, $addresses = null)
  55      {
  56          $header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder, $this->_grammar);
  57          if (isset($addresses)) {
  58              $header->setFieldBodyModel($addresses);
  59          }
  60          $this->_setHeaderCharset($header);
  61  
  62          return $header;
  63      }
  64  
  65      /**
  66       * Create a new Date header using $timestamp (UNIX time).
  67       *
  68       * @param string   $name
  69       * @param int|null $timestamp
  70       *
  71       * @return Swift_Mime_Header
  72       */
  73      public function createDateHeader($name, $timestamp = null)
  74      {
  75          $header = new Swift_Mime_Headers_DateHeader($name, $this->_grammar);
  76          if (isset($timestamp)) {
  77              $header->setFieldBodyModel($timestamp);
  78          }
  79          $this->_setHeaderCharset($header);
  80  
  81          return $header;
  82      }
  83  
  84      /**
  85       * Create a new basic text header with $name and $value.
  86       *
  87       * @param string $name
  88       * @param string $value
  89       *
  90       * @return Swift_Mime_Header
  91       */
  92      public function createTextHeader($name, $value = null)
  93      {
  94          $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder, $this->_grammar);
  95          if (isset($value)) {
  96              $header->setFieldBodyModel($value);
  97          }
  98          $this->_setHeaderCharset($header);
  99  
 100          return $header;
 101      }
 102  
 103      /**
 104       * Create a new ParameterizedHeader with $name, $value and $params.
 105       *
 106       * @param string $name
 107       * @param string $value
 108       * @param array  $params
 109       *
 110       * @return Swift_Mime_ParameterizedHeader
 111       */
 112      public function createParameterizedHeader($name, $value = null,
 113          $params = array())
 114      {
 115          $header = new Swift_Mime_Headers_ParameterizedHeader($name,
 116              $this->_encoder, (strtolower($name) == 'content-disposition')
 117                  ? $this->_paramEncoder
 118                  : null,
 119                  $this->_grammar
 120              );
 121          if (isset($value)) {
 122              $header->setFieldBodyModel($value);
 123          }
 124          foreach ($params as $k => $v) {
 125              $header->setParameter($k, $v);
 126          }
 127          $this->_setHeaderCharset($header);
 128  
 129          return $header;
 130      }
 131  
 132      /**
 133       * Create a new ID header for Message-ID or Content-ID.
 134       *
 135       * @param string       $name
 136       * @param string|array $ids
 137       *
 138       * @return Swift_Mime_Header
 139       */
 140      public function createIdHeader($name, $ids = null)
 141      {
 142          $header = new Swift_Mime_Headers_IdentificationHeader($name, $this->_grammar);
 143          if (isset($ids)) {
 144              $header->setFieldBodyModel($ids);
 145          }
 146          $this->_setHeaderCharset($header);
 147  
 148          return $header;
 149      }
 150  
 151      /**
 152       * Create a new Path header with an address (path) in it.
 153       *
 154       * @param string $name
 155       * @param string $path
 156       *
 157       * @return Swift_Mime_Header
 158       */
 159      public function createPathHeader($name, $path = null)
 160      {
 161          $header = new Swift_Mime_Headers_PathHeader($name, $this->_grammar);
 162          if (isset($path)) {
 163              $header->setFieldBodyModel($path);
 164          }
 165          $this->_setHeaderCharset($header);
 166  
 167          return $header;
 168      }
 169  
 170      /**
 171       * Notify this observer that the entity's charset has changed.
 172       *
 173       * @param string $charset
 174       */
 175      public function charsetChanged($charset)
 176      {
 177          $this->_charset = $charset;
 178          $this->_encoder->charsetChanged($charset);
 179          $this->_paramEncoder->charsetChanged($charset);
 180      }
 181  
 182      /**
 183       * Make a deep copy of object.
 184       */
 185      public function __clone()
 186      {
 187          $this->_encoder = clone $this->_encoder;
 188          $this->_paramEncoder = clone $this->_paramEncoder;
 189      }
 190  
 191      /** Apply the charset to the Header */
 192      private function _setHeaderCharset(Swift_Mime_Header $header)
 193      {
 194          if (isset($this->_charset)) {
 195              $header->setCharset($this->_charset);
 196          }
 197      }
 198  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1