You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is mainly as a reference to people coming across the same hair-pulling issue as I did.
When receiving an email in ISO-8859-1 encoding with special characters (such as the danish "æøå") I found that a QueryException will be thrown such as
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE6ftet ...' for column 'message' at row 1 (SQL: insert into `mailbox_inbound_emails` (`message`, `message_id`, `subject`, `text`, `from`, `updated_at`, `cr...
This is due to attempting to insert ISO-8859-1 characters into a utf8mb4 MySQL column.
It would be cool if the package had a way to handle this internally - however due to this (hopefully) being a generally rare issue with most clients using UTF-8 I can see why this might not be a priority.
For those interested I solved it by introducing a new method on a custom App\Email model:
<?phpnamespaceApp;
useBeyondCode\Mailbox\InboundEmail;
class Email extends InboundEmail
{
publicfunctionensureUtf8(): Email
{
$encoding = mb_detect_encoding($this->message, ['UTF-8', 'ISO-8859-1']); // Add more encodings to support hereif ($encoding !== 'UTF-8') {
$this->message = mb_convert_encoding($this->message, 'UTF-8', $encoding);
$this->mimeMessage = null;
}
return$this;
}
}
Hey there
This issue is mainly as a reference to people coming across the same hair-pulling issue as I did.
When receiving an email in ISO-8859-1 encoding with special characters (such as the danish "æøå") I found that a QueryException will be thrown such as
This is due to attempting to insert ISO-8859-1 characters into a utf8mb4 MySQL column.
It would be cool if the package had a way to handle this internally - however due to this (hopefully) being a generally rare issue with most clients using UTF-8 I can see why this might not be a priority.
For those interested I solved it by introducing a new method on a custom
App\Email
model:And in my
AppServiceProvider@boot
Hope this can help somebody else out there :-)
The text was updated successfully, but these errors were encountered: