[ Index ]

MailPress 7.2

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

title

Body

[close]

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


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1