'boolean', 'is_starred' => 'boolean', 'is_important' => 'boolean', 'is_sent' => 'boolean', 'is_draft' => 'boolean', 'is_trash' => 'boolean', 'received_at' => 'datetime', 'sent_at' => 'datetime', ]; public function folder(): BelongsTo { return $this->belongsTo(EmailFolder::class, 'email_folder_id'); } public function attachments(): HasMany { return $this->hasMany(EmailAttachment::class, 'email_message_id'); } public function getExcerptAttribute(): string { $body = strip_tags($this->body_text ?? $this->body_html ?? ''); return mb_strimwidth($body, 0, 100, '...'); } public function getBodyForDisplayAttribute(): string { if ($this->body_html) { return $this->body_html; } return nl2br(e($this->body_text ?? '')); } public function scopeUnread($query) { return $query->where('is_read', false); } public function scopeInbox($query) { return $query->whereHas('folder', fn($q) => $q->where('type', 'inbox')); } public function scopeSent($query) { return $query->where('is_sent', true); } }