From b96212bda60d20bd30bc22b519c145873bbf2a44 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Sun, 29 May 2022 16:41:41 -0300 Subject: [PATCH] feat: store body emails as compressed strings This feature allows to save space in db. Use it before storing the first email --- config/sentemails.php | 8 ++++++-- src/Models/SentEmail.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/sentemails.php b/config/sentemails.php index 1c9e823..8085be8 100644 --- a/config/sentemails.php +++ b/config/sentemails.php @@ -13,5 +13,9 @@ // emails per page 'perPage' => 10, - 'noEmailsMessage' => 'No emails found.' -]; \ No newline at end of file + '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, +]; diff --git a/src/Models/SentEmail.php b/src/Models/SentEmail.php index 88d01a9..a764b75 100644 --- a/src/Models/SentEmail.php +++ b/src/Models/SentEmail.php @@ -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; + } }