QpHeaderEncoder.php 1.9KB

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