<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Mail extends Model
{
    protected $table = 'mails';

    protected $guarded = [];

    public function getMailBoxClient($account = [])
    {
        $config = config('imap');
        $config['accounts']['default']['host'] = isset($account['host']) ? $account['host'] : $this->imap_host;
        $config['accounts']['default']['port'] = isset($account['port']) ? $account['port'] : $this->imap_port;
        $config['accounts']['default']['username'] = isset($account['username']) ? $account['username'] : $this->email;
        $config['accounts']['default']['password'] = isset($account['password']) ? $account['password'] : $this->password;

        $cm = new \Webklex\PHPIMAP\ClientManager($config);

        return $cm->account();
    }
}
