Skip to content

Commit

Permalink
Possible decoding problem fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Sep 29, 2020
1 parent cb8daa8 commit c15e8ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
### Affected Classes
- NaN

## [2.1.3] - 2020-09-29
### Fixed
- Possible decoding problem fixed
- `Str::class` dependency removed from `Header::class`

### Affected Classes
- [Header::class](src/Header.php)

## [2.1.2] - 2020-09-28
### Fixed
- Dependency problem in `Attachement::getExtension()` fixed (#9)
Expand Down
16 changes: 12 additions & 4 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


use Carbon\Carbon;
use Illuminate\Support\Str;
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
use Webklex\PHPIMAP\Exceptions\MethodNotFoundException;

Expand Down Expand Up @@ -67,7 +66,7 @@ public function __construct($raw_header) {
*/
public function __call($method, $arguments) {
if(strtolower(substr($method, 0, 3)) === 'get') {
$name = Str::snake(substr($method, 3));
$name = preg_replace('/(.)(?=[A-Z])/u', '$1_', substr(strtolower($method), 3));

if(in_array($name, array_keys($this->attributes))) {
return $this->attributes[$name];
Expand Down Expand Up @@ -320,18 +319,27 @@ private function decode($value) {
if ($value !== null) {
if($decoder === 'utf-8' && extension_loaded('imap')) {
$value = \imap_utf8($value);
if (Str::startsWith(mb_strtolower($value), '=?utf-8?')) {
if (strpos(strtolower($value), '=?utf-8?') === 0) {
$value = mb_decode_mimeheader($value);
}
if ($this->notDecoded($original_value, $value)) {
$value = $this->mime_header_decode(imap_utf8($value));
$decoded_value = $this->mime_header_decode($value);
if (count($decoded_value) > 0) {
if(property_exists($decoded_value[0], "text")) {
$value = $decoded_value[0]->text;
}
}
}
}elseif($decoder === 'iconv') {
$value = iconv_mime_decode($value);
}else{
$value = mb_decode_mimeheader($value);
}

if (strpos(strtolower($value), '=?utf-8?') === 0) {
$value = mb_decode_mimeheader($value);
}

if ($this->notDecoded($original_value, $value)) {
$value = $this->convertEncoding($original_value, $this->getEncoding($original_value));
}
Expand Down

0 comments on commit c15e8ee

Please sign in to comment.