Skip to content

Commit

Permalink
Merge pull request #7 from bernardo-campos/compress-body
Browse files Browse the repository at this point in the history
feat: store body emails as compressed strings
  • Loading branch information
dcblogdev authored Jun 27, 2022
2 parents cf336db + b96212b commit 0fab638
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions config/sentemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
// emails per page
'perPage' => 10,

'noEmailsMessage' => 'No emails found.'
];
'noEmailsMessage' => 'No emails found.',

// body emails are stored as compressed strings to save db disk
/* Do not change after first mail is stored */
'compressBody' => false,
];
13 changes: 13 additions & 0 deletions src/Models/SentEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,17 @@
class SentEmail extends Model
{
protected $guarded = [];

public function getBodyAttribute($compressed) {
return config('sentemails.compressBody')
? gzinflate(base64_decode($compressed))
: $compressed;
}

public function setBodyAttribute($raw) {
$body = config('sentemails.compressBody')
? base64_encode(gzdeflate($raw, 9))
: $raw;
$this->attributes['body'] = $body;
}
}

0 comments on commit 0fab638

Please sign in to comment.