mailwolt/app/Models/SandboxMail.php

34 lines
856 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SandboxMail extends Model
{
protected $fillable = [
'message_id', 'from_address', 'from_name', 'to_addresses',
'subject', 'body_text', 'body_html', 'raw_headers',
'is_read', 'received_at',
];
protected $casts = [
'to_addresses' => 'array',
'is_read' => 'boolean',
'received_at' => 'datetime',
];
public function getToPreviewAttribute(): string
{
$addrs = $this->to_addresses ?? [];
return implode(', ', array_slice($addrs, 0, 2)) . (count($addrs) > 2 ? ' +' . (count($addrs) - 2) : '');
}
public function getSenderAttribute(): string
{
return $this->from_name
? "{$this->from_name} <{$this->from_address}>"
: $this->from_address;
}
}