NativeQpContentEncoder.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 (QP) Transfer Encoding in Swift Mailer using the PHP core function.
  11. *
  12. * @package Swift
  13. * @subpackage Mime
  14. * @author Lars Strojny
  15. */
  16. class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder
  17. {
  18. /**
  19. * Notify this observer that the entity's charset has changed.
  20. *
  21. * @param string $charset
  22. */
  23. public function charsetChanged($charset)
  24. {
  25. if ($charset !== 'utf-8') {
  26. throw new RuntimeException(
  27. sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $charset));
  28. }
  29. }
  30. /**
  31. * Encode $in to $out.
  32. *
  33. * @param Swift_OutputByteStream $os to read from
  34. * @param Swift_InputByteStream $is to write to
  35. * @param integer $firstLineOffset
  36. * @param integer $maxLineLength 0 indicates the default length for this encoding
  37. */
  38. public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
  39. {
  40. $string = '';
  41. while (false !== $bytes = $os->read(8192)) {
  42. $string .= $bytes;
  43. }
  44. $is->write($this->encodeString($string));
  45. }
  46. /**
  47. * Get the MIME name of this content encoding scheme.
  48. *
  49. * @return string
  50. */
  51. public function getName()
  52. {
  53. return 'quoted-printable';
  54. }
  55. /**
  56. * Encode a given string to produce an encoded string.
  57. *
  58. * @param string $string
  59. * @param integer $firstLineOffset if first line needs to be shorter
  60. * @param integer $maxLineLength 0 indicates the default length for this encoding
  61. *
  62. * @return string
  63. */
  64. public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
  65. {
  66. return quoted_printable_encode($string);
  67. }
  68. }