Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
61.90% covered (warning)
61.90%
13 / 21
55.56% covered (warning)
55.56%
10 / 18
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractMailProtocolDriver
60.00% covered (warning)
60.00%
12 / 20
55.56% covered (warning)
55.56%
10 / 18
42.10
0.00% covered (danger)
0.00%
0 / 1
 connect
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 ping
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 disconnect
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getFolderStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFolder
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 renameFolder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 deleteFolder
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fetchMessages
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMimePartStream
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRawMessageSource
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setFlags
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 moveMessages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 copyMessages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 deleteMessages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 saveDraft
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQuota
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 appendRawMessage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __clone
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Mail\Infrastructure\Protocol;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Mail\Domain\Contract\MailProtocolDriverInterface;
12use App\Modules\Mail\Domain\Model\ClientMailbox;
13use App\Modules\Mail\Domain\Model\MailFolderDto;
14use App\Modules\Mail\Domain\Model\MailFolderStatusDto;
15use App\Modules\Mail\Domain\Model\MailMimePartDto;
16use App\Modules\Mail\Domain\Model\MailOutgoingMessageDto;
17use App\Modules\Mail\Domain\Model\MailSearchCriteriaDto;
18use App\Modules\Mail\Domain\Model\MailServer;
19
20/**
21 * Base protocol driver providing shared connection state management and folder helpers.
22 *
23 * @package App\Modules\Mail\Infrastructure\Protocol
24 */
25abstract class AbstractMailProtocolDriver implements MailProtocolDriverInterface
26{
27    protected bool $connected = false;
28    protected ?ClientMailbox $mailbox = null;
29
30    /** {@inheritdoc} */
31    public function connect(ClientMailbox $mailbox, ?MailServer $server = null): void
32    {
33        $this->mailbox   = $mailbox;
34        $this->connected = true;
35    }
36
37    /** {@inheritdoc} */
38    public function ping(): bool
39    {
40        return $this->connected && $this->mailbox !== null;
41    }
42
43    /** {@inheritdoc} */
44    public function disconnect(): void
45    {
46        $this->connected = false;
47        $this->mailbox   = null;
48    }
49
50    /** {@inheritdoc} */
51    public function getFolderStatus(string $folderPath): MailFolderStatusDto
52    {
53        return new MailFolderStatusDto($folderPath);
54    }
55
56    /** {@inheritdoc} */
57    public function createFolder(string $folderName, ?string $parentFolder = null): MailFolderDto
58    {
59        return new MailFolderDto(id: strtolower($folderName), name: $folderName, path: $folderName);
60    }
61
62    /** {@inheritdoc} */
63    public function renameFolder(string $oldPath, string $newPath): void
64    {
65        // No-op by default for lightweight API drivers
66    }
67
68    /** {@inheritdoc} */
69    public function deleteFolder(string $folderPath): void
70    {
71        // No-op by default for lightweight API drivers
72    }
73
74    /** {@inheritdoc} */
75    public function fetchMessages(
76        string $folderPath,
77        MailSearchCriteriaDto $criteria,
78        int $page,
79        int $perPage
80    ): array {
81        return ['messages' => [], 'total' => 0];
82    }
83
84    /** {@inheritdoc} */
85    public function getMimePartStream(string $folderPath, string $messageUid, string $partId): MailMimePartDto
86    {
87        return new MailMimePartDto($partId, 'application/octet-stream', '', 0);
88    }
89
90    /** {@inheritdoc} */
91    public function getRawMessageSource(string $folderPath, string $messageUid): string
92    {
93        return '';
94    }
95
96    /** {@inheritdoc} */
97    public function setFlags(string $folderPath, array $messageUids, array $flags, bool $add = true): void
98    {
99        // No-op by default for lightweight API drivers
100    }
101
102    /** {@inheritdoc} */
103    public function moveMessages(string $sourceFolder, string $targetFolder, array $messageUids): void
104    {
105        // No-op by default for lightweight API drivers
106    }
107
108    /** {@inheritdoc} */
109    public function copyMessages(string $sourceFolder, string $targetFolder, array $messageUids): void
110    {
111        // No-op by default for lightweight API drivers
112    }
113
114    /** {@inheritdoc} */
115    public function deleteMessages(string $folderPath, array $messageUids, bool $expunge = true): void
116    {
117        // No-op by default for lightweight API drivers
118    }
119
120    /** {@inheritdoc} */
121    public function saveDraft(MailOutgoingMessageDto $message, ?string $existingDraftUid = null): string
122    {
123        return (string) time();
124    }
125
126    /** {@inheritdoc} */
127    public function getQuota(): ?array
128    {
129        return null;
130    }
131
132    /** {@inheritdoc} */
133    public function appendRawMessage(string $folderPath, string $rawPayload, array $flags = []): string
134    {
135        return (string) time();
136    }
137
138    /**
139     * Resets connection state on instance clone.
140     */
141    public function __clone(): void
142    {
143        $this->disconnect();
144    }
145}