[ Index ]

MailPress 7.1

[ 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       * @param DateTimeInterface|null $dateTime
  73       *
  74       * @return Swift_Mime_Header
  75       */
  76      public function createDateHeader($name, DateTimeInterface $dateTime = null)
  77      {
  78          $header = new Swift_Mime_Headers_DateHeader($name);
  79          if (isset($dateTime)) {
  80              $header->setFieldBodyModel($dateTime);
  81          }
  82          $this->setHeaderCharset($header);
  83  
  84          return $header;
  85      }
  86  
  87      /**
  88       * Create a new basic text header with $name and $value.
  89       *
  90       * @param string $name
  91       * @param string $value
  92       *
  93       * @return Swift_Mime_Header
  94       */
  95      public function createTextHeader($name, $value = null)
  96      {
  97          $header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->encoder);
  98          if (isset($value)) {
  99              $header->setFieldBodyModel($value);
 100          }
 101          $this->setHeaderCharset($header);
 102  
 103          return $header;
 104      }
 105  
 106      /**
 107       * Create a new ParameterizedHeader with $name, $value and $params.
 108       *
 109       * @param string $name
 110       * @param string $value
 111       * @param array  $params
 112       *
 113       * @return Swift_Mime_Headers_ParameterizedHeader
 114       */
 115      public function createParameterizedHeader($name, $value = null, $params = [])
 116      {
 117          $header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, ('content-disposition' == strtolower($name)) ? $this->paramEncoder : null);
 118          if (isset($value)) {
 119              $header->setFieldBodyModel($value);
 120          }
 121          foreach ($params as $k => $v) {
 122              $header->setParameter($k, $v);
 123          }
 124          $this->setHeaderCharset($header);
 125  
 126          return $header;
 127      }
 128  
 129      /**
 130       * Create a new ID header for Message-ID or Content-ID.
 131       *
 132       * @param string       $name
 133       * @param string|array $ids
 134       *
 135       * @return Swift_Mime_Header
 136       */
 137      public function createIdHeader($name, $ids = null)
 138      {
 139          $header = new Swift_Mime_Headers_IdentificationHeader($name, $this->emailValidator);
 140          if (isset($ids)) {
 141              $header->setFieldBodyModel($ids);
 142          }
 143          $this->setHeaderCharset($header);
 144  
 145          return $header;
 146      }
 147  
 148      /**
 149       * Create a new Path header with an address (path) in it.
 150       *
 151       * @param string $name
 152       * @param string $path
 153       *
 154       * @return Swift_Mime_Header
 155       */
 156      public function createPathHeader($name, $path = null)
 157      {
 158          $header = new Swift_Mime_Headers_PathHeader($name, $this->emailValidator);
 159          if (isset($path)) {
 160              $header->setFieldBodyModel($path);
 161          }
 162          $this->setHeaderCharset($header);
 163  
 164          return $header;
 165      }
 166  
 167      /**
 168       * Notify this observer that the entity's charset has changed.
 169       *
 170       * @param string $charset
 171       */
 172      public function charsetChanged($charset)
 173      {
 174          $this->charset = $charset;
 175          $this->encoder->charsetChanged($charset);
 176          $this->paramEncoder->charsetChanged($charset);
 177      }
 178  
 179      /**
 180       * Make a deep copy of object.
 181       */
 182      public function __clone()
 183      {
 184          $this->encoder = clone $this->encoder;
 185          $this->paramEncoder = clone $this->paramEncoder;
 186      }
 187  
 188      /** Apply the charset to the Header */
 189      private function setHeaderCharset(Swift_Mime_Header $header)
 190      {
 191          if (isset($this->charset)) {
 192              $header->setCharset($this->charset);
 193          }
 194      }
 195  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1