Skip to content
Snippets Groups Projects
Commit ea362877 authored by Cyrille Bollu's avatar Cyrille Bollu
Browse files

Avoids using iconv with '//IGNORE' flag if possible

parent ba40c6e1
No related branches found
No related tags found
No related merge requests found
...@@ -79,6 +79,12 @@ class Address implements JsonSerializable { ...@@ -79,6 +79,12 @@ class Address implements JsonSerializable {
return null; return null;
} }
// Lets make sure the e-mail is valid UTF-8 at all times // 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); $utf8 = iconv("UTF-8", "UTF-8//IGNORE", $email);
if ($utf8 === false) { if ($utf8 === false) {
throw new \Exception("Email address <$email> could not be converted via iconv"); throw new \Exception("Email address <$email> could not be converted via iconv");
......
...@@ -273,7 +273,14 @@ class IMAPMessage implements IMessage, JsonSerializable { ...@@ -273,7 +273,14 @@ class IMAPMessage implements IMessage, JsonSerializable {
* @return string * @return string
*/ */
public function getSubject(): 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);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment