123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace Symfony\Component\Mime\Encoder;
- use Symfony\Component\Mime\Exception\AddressEncoderException;
- final class IdnAddressEncoder implements AddressEncoderInterface
- {
-
- public function encodeString(string $address): string
- {
- $i = strrpos($address, '@');
- if (false !== $i) {
- $local = substr($address, 0, $i);
- $domain = substr($address, $i + 1);
- if (preg_match('/[^\x00-\x7F]/', $local)) {
- throw new AddressEncoderException(sprintf('Non-ASCII characters not supported in local-part os "%s".', $address));
- }
- if (preg_match('/[^\x00-\x7F]/', $domain)) {
- $address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46));
- }
- }
- return $address;
- }
- }
|