VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
152 lines
3.5 KiB
PHP
152 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Mailbox extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public static function defaultQuotaMb(): int
|
|
{
|
|
return (int) config('mailinfra.default_mailbox_quota_mb', 10240);
|
|
}
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'website_id',
|
|
'hosting_account_id',
|
|
'domain_id',
|
|
'email_domain_id',
|
|
'display_name',
|
|
'local_part',
|
|
'address',
|
|
'password_hash',
|
|
'quota_mb',
|
|
'disk_used_bytes',
|
|
'last_usage_sync_at',
|
|
'status',
|
|
'is_paid',
|
|
'payment_reference',
|
|
'paid_at',
|
|
'billing_type',
|
|
'monthly_price',
|
|
'subscription_started_at',
|
|
'subscription_expires_at',
|
|
'subscription_status',
|
|
'maildir_path',
|
|
'credentials_issued_at',
|
|
'incoming_token',
|
|
'inbound_enabled',
|
|
'outbound_enabled',
|
|
'outbound_provider',
|
|
'smtp_host',
|
|
'smtp_port',
|
|
'smtp_encryption',
|
|
'smtp_username',
|
|
'smtp_password',
|
|
'from_name',
|
|
'from_address',
|
|
'metadata',
|
|
'webmail_secret',
|
|
];
|
|
|
|
protected $casts = [
|
|
'inbound_enabled' => 'boolean',
|
|
'outbound_enabled' => 'boolean',
|
|
'is_paid' => 'boolean',
|
|
'paid_at' => 'datetime',
|
|
'monthly_price' => 'decimal:2',
|
|
'subscription_started_at' => 'datetime',
|
|
'subscription_expires_at' => 'datetime',
|
|
'smtp_password' => 'encrypted',
|
|
'quota_mb' => 'integer',
|
|
'disk_used_bytes' => 'integer',
|
|
'last_usage_sync_at' => 'datetime',
|
|
'credentials_issued_at' => 'datetime',
|
|
'metadata' => 'array',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password_hash',
|
|
'webmail_secret',
|
|
'incoming_token',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function website(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Website::class);
|
|
}
|
|
|
|
public function domain(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Domain::class);
|
|
}
|
|
|
|
public function hostingAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(HostingAccount::class);
|
|
}
|
|
|
|
public function emailDomain(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EmailDomain::class);
|
|
}
|
|
|
|
public function threads(): HasMany
|
|
{
|
|
return $this->hasMany(MailThread::class);
|
|
}
|
|
|
|
public function messages(): HasMany
|
|
{
|
|
return $this->hasMany(MailMessage::class);
|
|
}
|
|
|
|
public function isStandalone(): bool
|
|
{
|
|
return $this->website_id === null && $this->email_domain_id !== null;
|
|
}
|
|
|
|
public function isWebsiteLinked(): bool
|
|
{
|
|
return $this->website_id !== null;
|
|
}
|
|
|
|
public function getDomainHostAttribute(): ?string
|
|
{
|
|
if ($this->emailDomain) {
|
|
return $this->emailDomain->domain;
|
|
}
|
|
|
|
if ($this->domain) {
|
|
return $this->domain->host;
|
|
}
|
|
|
|
$parts = explode('@', $this->address ?? '', 2);
|
|
return $parts[1] ?? null;
|
|
}
|
|
|
|
public function getOwnerIdAttribute(): ?int
|
|
{
|
|
if ($this->user_id) {
|
|
return $this->user_id;
|
|
}
|
|
|
|
if ($this->website) {
|
|
return $this->website->owner_user_id;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|