EmailClient.php 733 Bytes
Newer Older
Korko's avatar
Korko committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

namespace App\Services;

use Webklex\IMAP\Facades\Client;

class EmailClient
{
	protected $delegate;

	public function __construct($connexion = 'default')
	{
        $this->delegate = Client::account($connexion);
        $this->delegate->connect();
	}

    public function getUnseenMails(): Iterable
    {
19
        $oFolder = $this->delegate->getFolder(config('imap.folders.inbox'));
Korko's avatar
Korko committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

        return $oFolder->query()->whereUnseen()->get();
    }

    /**
     * Proxies all methods to the delegate.
     *
     * @param string $method
     * @param array  $args
     *
     * @return mixed
     */
    public function __call($method, $args)
    {
        return call_user_func_array([$this->delegate, $method], $args);
    }
}