You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

3 years ago
  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. }