NativeQpContentEncoder.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder
  3. {
  4. /**
  5. * Notify this observer that the entity's charset has changed.
  6. * @param string $charset
  7. */
  8. public function charsetChanged($charset)
  9. {
  10. if ($charset !== 'utf-8') {
  11. throw new RuntimeException(
  12. sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $charset));
  13. }
  14. }
  15. /**
  16. * Encode $in to $out.
  17. * @param Swift_OutputByteStream $os to read from
  18. * @param Swift_InputByteStream $is to write to
  19. * @param int $firstLineOffset
  20. * @param int $maxLineLength - 0 indicates the default length for this encoding
  21. */
  22. public function encodeByteStream(
  23. Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
  24. $maxLineLength = 0)
  25. {
  26. $string = '';
  27. while (false !== $bytes = $os->read(8192)) {
  28. $string .= $bytes;
  29. }
  30. $is->write($this->encodeString($string));
  31. }
  32. /**
  33. * Get the MIME name of this content encoding scheme.
  34. * @return string
  35. */
  36. public function getName()
  37. {
  38. return 'quoted-printable';
  39. }
  40. /**
  41. * Encode a given string to produce an encoded string.
  42. * @param string $string
  43. * @param int $firstLineOffset if first line needs to be shorter
  44. * @param int $maxLineLength - 0 indicates the default length for this encoding
  45. * @return string
  46. */
  47. public function encodeString($string, $firstLineOffset = 0,
  48. $maxLineLength = 0)
  49. {
  50. return quoted_printable_encode($string);
  51. }
  52. }