|
14 | 14 | use Dot\Mail\Event\MailEventListenerAwareTrait; |
15 | 15 | use Dot\Mail\Exception\InvalidArgumentException; |
16 | 16 | use Dot\Mail\Exception\MailException; |
| 17 | +use Dot\Mail\Options\MailOptions; |
17 | 18 | use Dot\Mail\Result\MailResult; |
18 | 19 | use Dot\Mail\Result\ResultInterface; |
19 | 20 | use Laminas\Mail\Message; |
| 21 | +use Laminas\Mail\Storage\Imap; |
20 | 22 | use Laminas\Mail\Transport\TransportInterface; |
21 | 23 | use Laminas\Mime\Message as MimeMessage; |
22 | 24 | use Laminas\Mime\Mime; |
@@ -49,11 +51,15 @@ class MailService implements |
49 | 51 | public function __construct( |
50 | 52 | LogServiceInterface $logService, |
51 | 53 | Message $message, |
52 | | - TransportInterface $transport |
| 54 | + TransportInterface $transport, |
| 55 | + Imap $storage, |
| 56 | + MailOptions $mailOptions |
53 | 57 | ) { |
54 | 58 | $this->logService = $logService; |
55 | 59 | $this->message = $message; |
56 | 60 | $this->transport = $transport; |
| 61 | + $this->storage = $storage; |
| 62 | + $this->mailOptions = $mailOptions; |
57 | 63 | } |
58 | 64 |
|
59 | 65 | /** |
@@ -87,6 +93,13 @@ public function send(): ResultInterface |
87 | 93 | $this->logService->sent($this->message); |
88 | 94 | } |
89 | 95 |
|
| 96 | + //save copy of sent message to folders |
| 97 | + if ($this->mailOptions->getSaveSentMessageFolder()) { |
| 98 | + foreach ($this->mailOptions->getSaveSentMessageFolder() as $folder) { |
| 99 | + $this->storage->appendMessage($this->message->toString(), $folder); |
| 100 | + } |
| 101 | + } |
| 102 | + |
90 | 103 | return $result; |
91 | 104 | } |
92 | 105 |
|
@@ -268,4 +281,19 @@ public function setTransport(TransportInterface $transport) |
268 | 281 | { |
269 | 282 | $this->transport = $transport; |
270 | 283 | } |
| 284 | + |
| 285 | + /** |
| 286 | + * @return array |
| 287 | + */ |
| 288 | + public function getFolderGlobalNames() |
| 289 | + { |
| 290 | + $folderGlobalNames = []; |
| 291 | + foreach ($this->storage->getFolders() as $folder) { |
| 292 | + $folderGlobalNames[] = $folder->getGlobalName(); |
| 293 | + } |
| 294 | + foreach ($this->storage->getFolders()->getChildren() as $folder) { |
| 295 | + $folderGlobalNames[] = $folder->getGlobalName(); |
| 296 | + } |
| 297 | + return $folderGlobalNames; |
| 298 | + } |
271 | 299 | } |
0 commit comments