[ Index ]

MailPress 7.2

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

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/AddressEncoder/ -> IdnAddressEncoder.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2018 Christian Schmidt
   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   * An IDN email address encoder.
  13   *
  14   * Encodes the domain part of an address using IDN. This is compatible will all
  15   * SMTP servers.
  16   *
  17   * This encoder does not support email addresses with non-ASCII characters in
  18   * local-part (the substring before @). To send to such addresses, use
  19   * Swift_AddressEncoder_Utf8AddressEncoder together with
  20   * Swift_Transport_Esmtp_SmtpUtf8Handler. Your outbound SMTP server must support
  21   * the SMTPUTF8 extension.
  22   *
  23   * @author Christian Schmidt
  24   */
  25  class Swift_AddressEncoder_IdnAddressEncoder implements Swift_AddressEncoder
  26  {
  27      /**
  28       * Encodes the domain part of an address using IDN.
  29       *
  30       * @throws Swift_AddressEncoderException If local-part contains non-ASCII characters
  31       */
  32      public function encodeString(string $address): string
  33      {
  34          $i = strrpos($address, '@');
  35          if (false !== $i) {
  36              $local = substr($address, 0, $i);
  37              $domain = substr($address, $i + 1);
  38  
  39              if (preg_match('/[^\x00-\x7F]/', $local)) {
  40                  throw new Swift_AddressEncoderException('Non-ASCII characters not supported in local-part', $address);
  41              }
  42  
  43              if (preg_match('/[^\x00-\x7F]/', $domain)) {
  44                  $address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46));
  45              }
  46          }
  47  
  48          return $address;
  49      }
  50  }


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