12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?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;
- }
- }
|