[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/ -> PathHeader.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  use Egulias\EmailValidator\Validation\RFCValidation;
  13  
  14  /**
  15   * A Path Header in Swift Mailer, such a Return-Path.
  16   *
  17   * @author Chris Corbyn
  18   */
  19  class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
  20  {
  21      /**
  22       * The address in this Header (if specified).
  23       *
  24       * @var string
  25       */
  26      private $address;
  27  
  28      /**
  29       * The strict EmailValidator.
  30       *
  31       * @var EmailValidator
  32       */
  33      private $emailValidator;
  34  
  35      private $addressEncoder;
  36  
  37      /**
  38       * Creates a new PathHeader with the given $name.
  39       *
  40       * @param string $name
  41       */
  42      public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null)
  43      {
  44          $this->setFieldName($name);
  45          $this->emailValidator = $emailValidator;
  46          $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder();
  47      }
  48  
  49      /**
  50       * Get the type of Header that this instance represents.
  51       *
  52       * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX
  53       * @see TYPE_DATE, TYPE_ID, TYPE_PATH
  54       *
  55       * @return int
  56       */
  57      public function getFieldType()
  58      {
  59          return self::TYPE_PATH;
  60      }
  61  
  62      /**
  63       * Set the model for the field body.
  64       * This method takes a string for an address.
  65       *
  66       * @param string $model
  67       *
  68       * @throws Swift_RfcComplianceException
  69       */
  70      public function setFieldBodyModel($model)
  71      {
  72          $this->setAddress($model);
  73      }
  74  
  75      /**
  76       * Get the model for the field body.
  77       * This method returns a string email address.
  78       *
  79       * @return mixed
  80       */
  81      public function getFieldBodyModel()
  82      {
  83          return $this->getAddress();
  84      }
  85  
  86      /**
  87       * Set the Address which should appear in this Header.
  88       *
  89       * @param string $address
  90       *
  91       * @throws Swift_RfcComplianceException
  92       */
  93      public function setAddress($address)
  94      {
  95          if (null === $address) {
  96              $this->address = null;
  97          } elseif ('' == $address) {
  98              $this->address = '';
  99          } else {
 100              $this->assertValidAddress($address);
 101              $this->address = $address;
 102          }
 103          $this->setCachedValue(null);
 104      }
 105  
 106      /**
 107       * Get the address which is used in this Header (if any).
 108       *
 109       * Null is returned if no address is set.
 110       *
 111       * @return string
 112       */
 113      public function getAddress()
 114      {
 115          return $this->address;
 116      }
 117  
 118      /**
 119       * Get the string value of the body in this Header.
 120       *
 121       * This is not necessarily RFC 2822 compliant since folding white space will
 122       * not be added at this stage (see {@link toString()} for that).
 123       *
 124       * @see toString()
 125       *
 126       * @return string
 127       */
 128      public function getFieldBody()
 129      {
 130          if (!$this->getCachedValue()) {
 131              if (isset($this->address)) {
 132                  $address = $this->addressEncoder->encodeString($this->address);
 133                  $this->setCachedValue('<'.$address.'>');
 134              }
 135          }
 136  
 137          return $this->getCachedValue();
 138      }
 139  
 140      /**
 141       * Throws an Exception if the address passed does not comply with RFC 2822.
 142       *
 143       * @param string $address
 144       *
 145       * @throws Swift_RfcComplianceException If address is invalid
 146       */
 147      private function assertValidAddress($address)
 148      {
 149          if (!$this->emailValidator->isValid($address, new RFCValidation())) {
 150              throw new Swift_RfcComplianceException(
 151                  'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
 152              );
 153          }
 154      }
 155  }


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