Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

change: truncate values of long string fields to database field length #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

flexponsive
Copy link

@flexponsive flexponsive commented Feb 24, 2021

in the email_log table, some fields (addresses and subject) have type
'string', which means laravel creates them with a default length of 255
characters.

however, in case of many e-mails - e.g. in cc - the total length of a
header can exceed this character limit. theoretically, a single e-mail
address could be up to 320 characters long

before this patch, the length limit was not checked and e-mails would
not be logged. error message:

[previous exception] [object] (PDOException(code: 22001): SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'bcc' at row 1 at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:115)
[stacktrace]

this patch truncates fields at 255 characters so the log entry can be
created. the untruncated contents are still available in the body
column.

test code:

Mail::send([], [], function($message) {
    $message->to('[email protected].' . str_repeat('x', 255))->subject('Test')->setBody('E-Mail'); 
});

flexponsive and others added 5 commits February 24, 2021 16:06
in the email_log table, some fields (addresses and subject) have type
'string', which means laravel creates them with a default length of 255
characters.

however, in case of many e-mails - e.g. in cc - the total length of a
header can exceed this character limit. theoretically, a single e-mail
address could be [up to 320 characters
long](https://stackoverflow.com/a/49645137/3096626)

before this patch, the length limit was not checked and e-mails would
not be logged. error message:

```
[previous exception] [object] (PDOException(code: 22001): SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'bcc' at row 1 at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:115)
[stacktrace]
```

this patch truncates fields at 255 characters so the log entry can be
created. the untruncated contents are still available in the body
column.
this makes it easier to search by message id when needed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant