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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ShvetsGroup/LaravelEmailDatabaseLog/EmailLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function handle(MessageSending $event): void
'body' => $message->getBody()->bodyToString(),
'headers' => $message->getHeaders()->toString(),
'attachments' => $this->saveAttachments($message),
'message_id' => substr($this->getMessageId($message), 0, 255)
]);
}

Expand All @@ -44,7 +45,8 @@ function formatAddressField(Email $message, string $field): ?string
{
$headers = $message->getHeaders();

return $headers->get($field)?->getBodyAsString();
$field = $headers->get($field)?->getBodyAsString();
return $field ? substr($field, 0, 255) : null;
}

/**
Expand All @@ -63,4 +65,9 @@ protected function saveAttachments(Email $message): ?string
->map(fn(DataPart $part) => $part->toString())
->implode("\n\n");
}

function getMessageId($message) {
$header = $message->getHeaders()->get('Message-ID');
return $header ? $header->getId() : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddMessageIdEmailLog extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('email_log', function (Blueprint $table) {
$table->string('message_id')->nullable();
$table->index(['message_id']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('email_log', function (Blueprint $table) {
$table->dropColumn('message_id');
});
}
}
31 changes: 31 additions & 0 deletions src/database/migrations/2021_07_12_120000_change_body_longtext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class ChangeBodyLongtext extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('email_log', function (Blueprint $table) {
$table->longtext('body')->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('email_log', function (Blueprint $table) {
$table->dropColumn('message_id');
});
}
}