QpHeaderEncoder.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * Handles Quoted Printable (Q) Header Encoding in Swift Mailer.
  11. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_HeaderEncoder
  15. {
  16. /**
  17. * Creates a new QpHeaderEncoder for the given CharacterStream.
  18. *
  19. * @param Swift_CharacterStream $charStream to use for reading characters
  20. */
  21. public function __construct(Swift_CharacterStream $charStream)
  22. {
  23. parent::__construct($charStream);
  24. }
  25. protected function initSafeMap()
  26. {
  27. foreach (array_merge(
  28. range(0x61, 0x7A), range(0x41, 0x5A),
  29. range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
  30. ) as $byte) {
  31. $this->_safeMap[$byte] = chr($byte);
  32. }
  33. }
  34. /**
  35. * Get the name of this encoding scheme.
  36. *
  37. * Returns the string 'Q'.
  38. *
  39. * @return string
  40. */
  41. public function getName()
  42. {
  43. return 'Q';
  44. }
  45. /**
  46. * Takes an unencoded string and produces a QP encoded string from it.
  47. *
  48. * @param string $string string to encode
  49. * @param int $firstLineOffset optional
  50. * @param int $maxLineLength optional, 0 indicates the default of 76 chars
  51. *
  52. * @return string
  53. */
  54. public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
  55. {
  56. return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
  57. parent::encodeString($string, $firstLineOffset, $maxLineLength)
  58. );
  59. }
  60. }