PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/simpus/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Encoder/Rfc2231Encoder.php

https://gitlab.com/isdzulqor/Slis-Dev
PHP | 92 lines | 41 code | 11 blank | 40 comment | 5 complexity | 0e55568ed849b4537e2a1d60d5119bae MD5 | raw file
  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 RFC 2231 specified Encoding in Swift Mailer.
  11. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
  15. {
  16. /**
  17. * A character stream to use when reading a string as characters instead of bytes.
  18. *
  19. * @var Swift_CharacterStream
  20. */
  21. private $_charStream;
  22. /**
  23. * Creates a new Rfc2231Encoder using the given character stream instance.
  24. *
  25. * @param Swift_CharacterStream
  26. */
  27. public function __construct(Swift_CharacterStream $charStream)
  28. {
  29. $this->_charStream = $charStream;
  30. }
  31. /**
  32. * Takes an unencoded string and produces a string encoded according to
  33. * RFC 2231 from it.
  34. *
  35. * @param string $string
  36. * @param int $firstLineOffset
  37. * @param int $maxLineLength optional, 0 indicates the default of 75 bytes
  38. *
  39. * @return string
  40. */
  41. public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
  42. {
  43. $lines = array();
  44. $lineCount = 0;
  45. $lines[] = '';
  46. $currentLine = &$lines[$lineCount++];
  47. if (0 >= $maxLineLength) {
  48. $maxLineLength = 75;
  49. }
  50. $this->_charStream->flushContents();
  51. $this->_charStream->importString($string);
  52. $thisLineLength = $maxLineLength - $firstLineOffset;
  53. while (false !== $char = $this->_charStream->read(4)) {
  54. $encodedChar = rawurlencode($char);
  55. if (0 != strlen($currentLine)
  56. && strlen($currentLine.$encodedChar) > $thisLineLength) {
  57. $lines[] = '';
  58. $currentLine = &$lines[$lineCount++];
  59. $thisLineLength = $maxLineLength;
  60. }
  61. $currentLine .= $encodedChar;
  62. }
  63. return implode("\r\n", $lines);
  64. }
  65. /**
  66. * Updates the charset used.
  67. *
  68. * @param string $charset
  69. */
  70. public function charsetChanged($charset)
  71. {
  72. $this->_charStream->setCharacterSet($charset);
  73. }
  74. /**
  75. * Make a deep copy of object.
  76. */
  77. public function __clone()
  78. {
  79. $this->_charStream = clone $this->_charStream;
  80. }
  81. }