QpHeaderEncoder.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @package Swift
  13. * @subpackage Mime
  14. * @author Chris Corbyn
  15. */
  16. class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_HeaderEncoder
  17. {
  18. /**
  19. * Creates a new QpHeaderEncoder for the given CharacterStream.
  20. *
  21. * @param Swift_CharacterStream $charStream to use for reading characters
  22. */
  23. public function __construct(Swift_CharacterStream $charStream)
  24. {
  25. parent::__construct($charStream);
  26. }
  27. protected function initSafeMap()
  28. {
  29. foreach (array_merge(
  30. range(0x61, 0x7A), range(0x41, 0x5A),
  31. range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
  32. ) as $byte) {
  33. $this->_safeMap[$byte] = chr($byte);
  34. }
  35. }
  36. /**
  37. * Get the name of this encoding scheme.
  38. *
  39. * Returns the string 'Q'.
  40. *
  41. * @return string
  42. */
  43. public function getName()
  44. {
  45. return 'Q';
  46. }
  47. /**
  48. * Takes an unencoded string and produces a QP encoded string from it.
  49. *
  50. * @param string $string string to encode
  51. * @param integer $firstLineOffset optional
  52. * @param integer $maxLineLength optional, 0 indicates the default of 76 chars
  53. *
  54. * @return string
  55. */
  56. public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
  57. {
  58. return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
  59. parent::encodeString($string, $firstLineOffset, $maxLineLength)
  60. );
  61. }
  62. }