Base64HeaderEncoder.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Base64 (B) Header Encoding in Swift Mailer.
  11. *
  12. * @package Swift
  13. * @subpackage Mime
  14. * @author Chris Corbyn
  15. */
  16. class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder
  17. {
  18. /**
  19. * Get the name of this encoding scheme.
  20. * Returns the string 'B'.
  21. *
  22. * @return string
  23. */
  24. public function getName()
  25. {
  26. return 'B';
  27. }
  28. /**
  29. * Takes an unencoded string and produces a Base64 encoded string from it.
  30. *
  31. * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of
  32. * default encodeString, otherwise pass to the parent method.
  33. *
  34. * @param string $string string to encode
  35. * @param integer $firstLineOffset
  36. * @param integer $maxLineLength optional, 0 indicates the default of 76 bytes
  37. * @param string $charset
  38. *
  39. * @return string
  40. */
  41. public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8')
  42. {
  43. if (strtolower($charset) === 'iso-2022-jp') {
  44. $old = mb_internal_encoding();
  45. mb_internal_encoding('utf-8');
  46. $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n");
  47. mb_internal_encoding($old);
  48. return $newstring;
  49. }
  50. return parent::encodeString($string, $firstLineOffset, $maxLineLength);
  51. }
  52. }