Completed
Pull Request — master (#42)
by Frederik
02:56
created

ImapTransport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 44
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A send() 0 15 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Transport;
5
6
use Genkgo\Mail\MessageInterface;
7
use Genkgo\Mail\Protocol\Imap\Client;
8
use Genkgo\Mail\Protocol\Imap\ParenthesizedList;
9
use Genkgo\Mail\Protocol\Imap\Request\AppendCommand;
10
use Genkgo\Mail\Protocol\Imap\Request\AppendDataRequest;
11
use Genkgo\Mail\Protocol\Imap\Response\CompletionResult;
12
use Genkgo\Mail\TransportInterface;
13
14
final class ImapTransport implements TransportInterface
15
{
16
    /**
17
     * @var Client
18
     */
19
    private $client;
20
    /**
21
     * @var string
22
     */
23
    private $mailbox;
24
25
    /**
26
     * SmtpTransport constructor.
27
     * @param Client $client
28
     * @param string $inbox
29
     */
30
    public function __construct(
31
        Client $client,
32
        string $inbox
33
    ) {
34
        $this->client = $client;
35
        $this->mailbox = $inbox;
36
    }
37
38
    /**
39
     * @param MessageInterface $message
40
     * @return void
41
     */
42
    public function send(MessageInterface $message): void
43
    {
44
        $tag = $this->client->newTag();
45
46
        $this->client
47
            ->emit(new AppendCommand($tag, $this->mailbox, strlen((string)$message), new ParenthesizedList()))
48
            ->last()
49
            ->assertContinuation();
50
51
        $this->client
52
            ->emit(new AppendDataRequest($tag, $message))
53
            ->last()
54
            ->assertCompletion(CompletionResult::ok())
55
            ->assertTagged();
56
    }
57
}