Ticket system bugfix character encoding is now read from parts and used to convert to UTF-8

This commit is contained in:
OpenXE 2023-01-29 19:06:08 +01:00
parent 00dc3414a2
commit da0b7d2720

View File

@ -97,6 +97,33 @@ final class MailMessagePartData implements MailMessagePartInterface, JsonSeriali
return $split[0];
}
/**
* @inheritDoc
*/
public function getCharset(): ?string
{
$header = $this->getHeader('content-type');
if ($header === null) {
return '';
}
$pattern = "/([a-zA-Z]*[\/]*[a-zA-Z]*);[a-zA-Z\n\t\r0-9 ]*charset=\"([a-zA-Z-0-9]+)\"/i";
$matches = array();
if (preg_match(
$pattern,
$header->getValue(),
$matches
)) {
if (count($matches) >= 3) {
return($matches[2]);
} else {
return(null);
}
}
else {
return(null);
}
}
/**
* @inheritDoc
*/
@ -116,17 +143,29 @@ final class MailMessagePartData implements MailMessagePartInterface, JsonSeriali
/**
* @return string|null
*/
public function getDecodedContent(): ?string
public function getDecodedContent(string $to_charset = 'UTF-8'): ?string
{
$result = '';
if ($this->content === null) {
return null;
}
$encodingHeader = $this->getHeader('content-transfer-encoding');
if ($encodingHeader === null ) {
return $this->content;
$result = $this->content;
}
return $this->decode($this->content, $encodingHeader->getValue());
$result = $this->decode($this->content, $encodingHeader->getValue());
$charset = $this->getCharset();
// throw new InvalidArgumentException('Charset is '.$charset." Text is: ".$result);
$converted = mb_convert_encoding(
$result,
$to_charset,
$charset
);
return($converted);
}
/**