diff --git a/lib/Address.php b/lib/Address.php index cfa96169a11f4b5df8afcfc8d5237f8e4a86e625..119659b278ff3b6f576ab15c67541ebe04460a84 100644 --- a/lib/Address.php +++ b/lib/Address.php @@ -79,6 +79,12 @@ class Address implements JsonSerializable { return null; } // Lets make sure the e-mail is valid UTF-8 at all times + // Try a soft conversion first (some installations, eg: Alpine linux, + // have issues with the '//IGNORE' option) + $utf8 = iconv('UTF-8', 'UTF-8', $email); + if ($utf8 !== false) { + return $utf8; + } $utf8 = iconv("UTF-8", "UTF-8//IGNORE", $email); if ($utf8 === false) { throw new \Exception("Email address <$email> could not be converted via iconv"); diff --git a/lib/Model/IMAPMessage.php b/lib/Model/IMAPMessage.php index ec97180d688ff5324f33c1878688a9343b44f523..1841d1cb274f9c70e58916741d3d4ca3bfba4426 100644 --- a/lib/Model/IMAPMessage.php +++ b/lib/Model/IMAPMessage.php @@ -273,7 +273,14 @@ class IMAPMessage implements IMessage, JsonSerializable { * @return string */ public function getSubject(): string { - return iconv("UTF-8", "UTF-8//IGNORE", $this->getEnvelope()->subject); + // Try a soft conversion first (some installations, eg: Alpine linux, + // have issues with the '//IGNORE' option) + $subject = $this->getEnvelope()->subject; + $utf8 = iconv('UTF-8', 'UTF-8', $subject); + if ($utf8 !== false) { + return $utf8; + } + return iconv("UTF-8", "UTF-8//IGNORE", $subject); } /**