QpMimeHeaderEncoder.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mime\Encoder;
  11. /**
  12. * @author Chris Corbyn
  13. */
  14. final class QpMimeHeaderEncoder extends QpEncoder implements MimeHeaderEncoderInterface
  15. {
  16. protected function initSafeMap(): void
  17. {
  18. foreach (array_merge(
  19. range(0x61, 0x7A), range(0x41, 0x5A),
  20. range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F]
  21. ) as $byte) {
  22. $this->safeMap[$byte] = \chr($byte);
  23. }
  24. }
  25. public function getName(): string
  26. {
  27. return 'Q';
  28. }
  29. public function encodeString(string $string, ?string $charset = 'utf-8', int $firstLineOffset = 0, int $maxLineLength = 0): string
  30. {
  31. return str_replace([' ', '=20', "=\r\n"], ['_', '_', "\r\n"],
  32. parent::encodeString($string, $charset, $firstLineOffset, $maxLineLength)
  33. );
  34. }
  35. }