charset = $charset ?: 'utf-8'; } /** * Notify this observer that the entity's charset has changed. * * @param string $charset */ public function charsetChanged($charset) { $this->charset = $charset; } /** * Encode $in to $out. * * @param Swift_OutputByteStream $os to read from * @param Swift_InputByteStream $is to write to * @param int $firstLineOffset * @param int $maxLineLength 0 indicates the default length for this encoding * * @throws RuntimeException */ public function encodeByteStream( Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0, ) { if ('utf-8' !== $this->charset) { throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); } $string = ''; while (false !== $bytes = $os->read(8192)) { $string .= $bytes; } $is->write($this->encodeString($string)); } /** * Get the MIME name of this content encoding scheme. * * @return string */ public function getName() { return 'quoted-printable'; } /** * Encode a given string to produce an encoded string. * * @param string $string * @param int $firstLineOffset if first line needs to be shorter * @param int $maxLineLength 0 indicates the default length for this encoding * * @throws RuntimeException * * @return string */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) { if ('utf-8' !== $this->charset) { throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); } return $this->standardize(quoted_printable_encode($string)); } /** * Make sure CRLF is correct and HT/SPACE are in valid places. * * @param string $string * * @return string */ protected function standardize($string) { // transform CR or LF to CRLF $string = preg_replace('~=0D(?!=0A)|(?