protected function decode($value) { $decoded = ''; $parts = imap_mime_header_decode($value); try { foreach ($parts as $part) { $charset = 'default' == $part->charset ? 'auto' : $part->charset; //Ajout COGIVEA fix encoding : $charset = $this->charset != '' && $charset == 'auto' ? $this->charset : $charset; //print $part->text."#".$this->charset."/".$charset."#"."\n"; // imap_utf8 doesn't seem to work properly, so use Transcoder instead // Got from: https://github.com/Sawered/imap/commit/e739b7221c6e57521b38f7b56f78ba399acda888 and changed to UndetectableEncodingException try { $decoded .= Transcoder::create()->transcode($part->text, $charset); } catch (IllegalCharacterException $e) { //no warn, itis reality //FIX COGIVEA } catch (UndetectableEncodingException $e) { //no warn, it is reality, handle it somehow $decoded = imap_utf8($part->text); } } } catch (Exception $e) { } return $decoded; }
protected function decode($value) { if (empty($value) || ($value = '')) { return ''; } $decoded = ''; $parts = imap_mime_header_decode($value); foreach ($parts as $part) { $charset = 'default' == $part->charset ? 'auto' : $part->charset; // imap_utf8 doesn't seem to work properly, so use Transcoder instead try { $decoded .= Transcoder::create()->transcode($part->text, $charset); } catch (\Ddeboer\Transcoder\Exception\UndetectableEncodingException $ex) { $decoded .= $part->text; } catch (\Ddeboer\Transcoder\Exception\UnsupportedEncodingException $ex) { $decoded .= $part->text; } catch (\Ddeboer\Transcoder\Exception\IllegalCharacterException $ex) { // force transcoding using iconv and ignore. $decoded .= @iconv($charset, 'UTF-8//IGNORE', $part->text); } catch (\Exception $ex) { // maybe any kind of exception. $decoded .= $part->text; } } return $decoded; }
protected function decode($value) { $decoded = ''; $parts = imap_mime_header_decode($value); foreach ($parts as $part) { $charset = 'default' == $part->charset ? 'auto' : $part->charset; // imap_utf8 doesn't seem to work properly, so use Transcoder instead $decoded .= Transcoder::create()->transcode($part->text, $charset); } return $decoded; }
/** * Get attachment filename * * @return string */ public function getFilename() { /*return $this->parameters->get('filename') ?: $this->parameters->get('name');*/ $fname = $this->parameters->get('filename') ?: $this->parameters->get('name'); //RFCs 2047, 2231 and 5987 //http://tools.ietf.org/html/rfc5987 $matches = []; if (preg_match("@^([^']+)''(.*)@ui", $fname, $matches)) { $fname = urldecode($matches[2]); try { $fname = Transcoder::create()->transcode($fname, $matches[1], "UTF-8//IGNORE"); } catch (Exception $e) { $fname = 'filename_wrong_enc'; } } return $fname; }
/** * Get decoded part content * * @return string */ public function getDecodedContent($keepUnseen = false) { if (null === $this->decodedContent) { switch ($this->getEncoding()) { case self::ENCODING_BASE64: $this->decodedContent = base64_decode($this->getContent($keepUnseen)); break; case self::ENCODING_QUOTED_PRINTABLE: $this->decodedContent = quoted_printable_decode($this->getContent($keepUnseen)); break; case self::ENCODING_7BIT: case self::ENCODING_8BIT: case self::ENCODING_BINARY: $this->decodedContent = $this->getContent($keepUnseen); break; default: throw new \UnexpectedValueException('Cannot decode ' . $this->getEncoding()); } // If this part is a text part, try to convert its encoding to UTF-8. // We don't want to convert an attachment's encoding. if ($this->getType() === self::TYPE_TEXT && strtolower($this->getCharset()) != 'utf-8') { $this->decodedContent = Transcoder::create()->transcode($this->decodedContent, $this->getCharset()); } } return $this->decodedContent; }
public function getDecodedName() { return Transcoder::create()->transcode($this->name, "UTF7-IMAP"); }
/** * @dataProvider getStrings */ public function testTranscode($string, $encoding) { $result = $this->transcoder->transcode($string, 'UTF-8', $encoding); $this->assertEquals($string, $this->transcoder->transcode($result, $encoding)); }