|
45 | 45 | * @property array reply_to |
46 | 46 | * @property array in_reply_to |
47 | 47 | * @property array sender |
| 48 | + * @property string fallback_encoding |
48 | 49 | * |
49 | 50 | * @method integer getMsglist() |
50 | 51 | * @method integer setMsglist(integer $msglist) |
@@ -176,6 +177,12 @@ class Message { |
176 | 177 | public $attachments = []; |
177 | 178 | public $flags = []; |
178 | 179 |
|
| 180 | + /** |
| 181 | + * Fallback Encoding |
| 182 | + * @var string |
| 183 | + */ |
| 184 | + public $fallback_encoding = 'UTF-8'; |
| 185 | + |
179 | 186 | /** |
180 | 187 | * A list of all available and supported flags |
181 | 188 | * |
@@ -590,8 +597,7 @@ private function parseAddresses($list) { |
590 | 597 | if(is_array($personalParts)) { |
591 | 598 | $address->personal = ''; |
592 | 599 | foreach ($personalParts as $p) { |
593 | | - $encoding = (property_exists($p, 'charset')) ? $p->charset : $this->getEncoding($p->text); |
594 | | - $address->personal .= $this->convertEncoding($p->text, $encoding); |
| 600 | + $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
595 | 601 | } |
596 | 602 | } |
597 | 603 | } |
@@ -853,8 +859,8 @@ public function decodeString($string, $encoding) { |
853 | 859 | */ |
854 | 860 | public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") { |
855 | 861 |
|
856 | | - $from = EncodingAliases::get($from); |
857 | | - $to = EncodingAliases::get($to); |
| 862 | + $from = EncodingAliases::get($from, $this->fallback_encoding); |
| 863 | + $to = EncodingAliases::get($to, $this->fallback_encoding); |
858 | 864 |
|
859 | 865 | if ($from === $to) { |
860 | 866 | return $str; |
@@ -896,9 +902,11 @@ public function getEncoding($structure) { |
896 | 902 | if (property_exists($structure, 'parameters')) { |
897 | 903 | foreach ($structure->parameters as $parameter) { |
898 | 904 | if (strtolower($parameter->attribute) == "charset") { |
899 | | - return EncodingAliases::get($parameter->value); |
| 905 | + return EncodingAliases::get($parameter->value, $this->fallback_encoding); |
900 | 906 | } |
901 | 907 | } |
| 908 | + }elseif (property_exists($structure, 'charset')) { |
| 909 | + return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
902 | 910 | }elseif (is_string($structure) === true){ |
903 | 911 | return mb_detect_encoding($structure); |
904 | 912 | } |
|
0 commit comments