Debian Codegraph @

lib/3rdParty/composer/webklex/php-imap/tests/live/MessageTest.php

raw symbols SCIP
1 <?php
2 /*
3 * File: MessageTest.php
4 * Category: -
5 * Author: M.Goldenbaum
6 * Created: 07.03.23 20:21
7 * Updated: -
8 *
9 * Description:
10 * -
11 */
12
13
14 namespace Tests\live;
15
16 use Carbon\Carbon;
17 use Webklex\PHPIMAP\Client;
18 use Webklex\PHPIMAP\Exceptions\AuthFailedException;
19 use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
20 use Webklex\PHPIMAP\Exceptions\EventNotFoundException;
21 use Webklex\PHPIMAP\Exceptions\FolderFetchingException;
22 use Webklex\PHPIMAP\Exceptions\GetMessagesFailedException;
23 use Webklex\PHPIMAP\Exceptions\ImapBadRequestException;
24 use Webklex\PHPIMAP\Exceptions\ImapServerErrorException;
25 use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException;
26 use Webklex\PHPIMAP\Exceptions\MaskNotFoundException;
27 use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException;
28 use Webklex\PHPIMAP\Exceptions\MessageFlagException;
29 use Webklex\PHPIMAP\Exceptions\MessageHeaderFetchingException;
30 use Webklex\PHPIMAP\Exceptions\MessageNotFoundException;
31 use Webklex\PHPIMAP\Exceptions\MessageSizeFetchingException;
32 use Webklex\PHPIMAP\Exceptions\ResponseException;
33 use Webklex\PHPIMAP\Exceptions\RuntimeException;
34 use Webklex\PHPIMAP\Folder;
35 use Webklex\PHPIMAP\Header;
36 use Webklex\PHPIMAP\IMAP;
37 use Webklex\PHPIMAP\Message;
38 use Webklex\PHPIMAP\Structure;
39 use Webklex\PHPIMAP\Support\AttachmentCollection;
40 use Webklex\PHPIMAP\Support\FlagCollection;
41 use Webklex\PHPIMAP\Support\Masks\AttachmentMask;
42 use Webklex\PHPIMAP\Support\Masks\MessageMask;
43 use \ReflectionException;
44
45 /**
46 * Class MessageTest
47 *
48 * @package Tests\live
49 */
50 class MessageTest extends LiveMailboxTestCase {
51
52 /**
53 * Get the default message
54 *
55 * @return Message
56 * @throws AuthFailedException
57 * @throws ConnectionFailedException
58 * @throws EventNotFoundException
59 * @throws FolderFetchingException
60 * @throws ImapBadRequestException
61 * @throws ImapServerErrorException
62 * @throws InvalidMessageDateException
63 * @throws MaskNotFoundException
64 * @throws MessageContentFetchingException
65 * @throws MessageFlagException
66 * @throws MessageHeaderFetchingException
67 * @throws ResponseException
68 * @throws RuntimeException
69 */
70 protected function getDefaultMessage() : Message {
71 $folder = $this->getFolder('INBOX');
72
73 $message = $this->appendMessageTemplate($folder, "plain.eml");
74 self::assertInstanceOf(Message::class, $message);
75
76 return $message;
77 }
78
79 /**
80 * Test Message::convertEncoding()
81 *
82 * @return void
83 * @throws AuthFailedException
84 * @throws ConnectionFailedException
85 * @throws EventNotFoundException
86 * @throws FolderFetchingException
87 * @throws ImapBadRequestException
88 * @throws ImapServerErrorException
89 * @throws InvalidMessageDateException
90 * @throws MaskNotFoundException
91 * @throws MessageContentFetchingException
92 * @throws MessageFlagException
93 * @throws MessageHeaderFetchingException
94 * @throws ResponseException
95 * @throws RuntimeException
96 * @throws MessageNotFoundException
97 */
98 public function testConvertEncoding(): void {
99 $message = $this->getDefaultMessage();
100 self::assertEquals("Entwürfe+", $message->getDecoder()->convertEncoding("Entw&APw-rfe+", "UTF7-IMAP", "UTF-8"));
101
102 // Cleanup
103 self::assertTrue($message->delete());
104 }
105
106 /**
107 * Test Message::thread()
108 *
109 * @return void
110 * @throws AuthFailedException
111 * @throws ConnectionFailedException
112 * @throws EventNotFoundException
113 * @throws FolderFetchingException
114 * @throws ImapBadRequestException
115 * @throws ImapServerErrorException
116 * @throws InvalidMessageDateException
117 * @throws MaskNotFoundException
118 * @throws MessageContentFetchingException
119 * @throws MessageFlagException
120 * @throws MessageHeaderFetchingException
121 * @throws MessageNotFoundException
122 * @throws ResponseException
123 * @throws RuntimeException
124 * @throws GetMessagesFailedException
125 */
126 public function testThread(): void {
127 $client = $this->getClient();
128
129 $delimiter = $this->getManager()->getConfig()->get("options.delimiter");
130 $folder_path = implode($delimiter, ['INBOX', 'thread']);
131
132 $folder = $client->getFolder($folder_path);
133 if ($folder !== null) {
134 self::assertTrue($this->deleteFolder($folder));
135 }
136 $folder = $client->createFolder($folder_path, false);
137
138 $message1 = $this->appendMessageTemplate($folder, "thread_my_topic.eml");
139 $message2 = $this->appendMessageTemplate($folder, "thread_re_my_topic.eml");
140 $message3 = $this->appendMessageTemplate($folder, "thread_unrelated.eml");
141
142 $thread = $message1->thread($folder);
143 self::assertCount(2, $thread);
144
145 $thread = $message2->thread($folder);
146 self::assertCount(2, $thread);
147
148 $thread = $message3->thread($folder);
149 self::assertCount(1, $thread);
150
151 // Cleanup
152 self::assertTrue($message1->delete());
153 self::assertTrue($message2->delete());
154 self::assertTrue($message3->delete());
155 $client->expunge();
156
157 self::assertTrue($this->deleteFolder($folder));
158 }
159
160 /**
161 * Test Message::hasAttachments()
162 *
163 * @return void
164 * @throws AuthFailedException
165 * @throws ConnectionFailedException
166 * @throws EventNotFoundException
167 * @throws FolderFetchingException
168 * @throws ImapBadRequestException
169 * @throws ImapServerErrorException
170 * @throws InvalidMessageDateException
171 * @throws MaskNotFoundException
172 * @throws MessageContentFetchingException
173 * @throws MessageFlagException
174 * @throws MessageHeaderFetchingException
175 * @throws MessageNotFoundException
176 * @throws ResponseException
177 * @throws RuntimeException
178 */
179 public function testHasAttachments(): void {
180 $message = $this->getDefaultMessage();
181 self::assertFalse($message->hasAttachments());
182
183 $folder = $message->getFolder();
184 self::assertInstanceOf(Folder::class, $folder);
185 self::assertTrue($message->delete());
186
187 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
188 self::assertInstanceOf(Message::class, $message);
189 self::assertTrue($message->hasAttachments());
190
191 // Cleanup
192 self::assertTrue($message->delete());
193 }
194
195 /**
196 * Test Message::getFetchOptions()
197 *
198 * @return void
199 * @throws AuthFailedException
200 * @throws ConnectionFailedException
201 * @throws EventNotFoundException
202 * @throws FolderFetchingException
203 * @throws ImapBadRequestException
204 * @throws ImapServerErrorException
205 * @throws InvalidMessageDateException
206 * @throws MaskNotFoundException
207 * @throws MessageContentFetchingException
208 * @throws MessageFlagException
209 * @throws MessageHeaderFetchingException
210 * @throws MessageNotFoundException
211 * @throws ResponseException
212 * @throws RuntimeException
213 */
214 public function testGetFetchOptions(): void {
215 $message = $this->getDefaultMessage();
216 self::assertEquals(IMAP::FT_PEEK, $message->getFetchOptions());
217
218 // Cleanup
219 self::assertTrue($message->delete());
220 }
221
222 /**
223 * Test Message::getMessageId()
224 *
225 * @return void
226 * @throws AuthFailedException
227 * @throws ConnectionFailedException
228 * @throws EventNotFoundException
229 * @throws FolderFetchingException
230 * @throws ImapBadRequestException
231 * @throws ImapServerErrorException
232 * @throws InvalidMessageDateException
233 * @throws MaskNotFoundException
234 * @throws MessageContentFetchingException
235 * @throws MessageFlagException
236 * @throws MessageHeaderFetchingException
237 * @throws MessageNotFoundException
238 * @throws ResponseException
239 * @throws RuntimeException
240 */
241 public function testGetMessageId(): void {
242 $folder = $this->getFolder('INBOX');
243 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
244 self::assertInstanceOf(Message::class, $message);
245
246 self::assertEquals("[email protected]", $message->getMessageId());
247
248 // Cleanup
249 self::assertTrue($message->delete());
250 }
251
252 /**
253 * Test Message::getReplyTo()
254 *
255 * @return void
256 * @throws AuthFailedException
257 * @throws ConnectionFailedException
258 * @throws EventNotFoundException
259 * @throws FolderFetchingException
260 * @throws ImapBadRequestException
261 * @throws ImapServerErrorException
262 * @throws InvalidMessageDateException
263 * @throws MaskNotFoundException
264 * @throws MessageContentFetchingException
265 * @throws MessageFlagException
266 * @throws MessageHeaderFetchingException
267 * @throws MessageNotFoundException
268 * @throws ResponseException
269 * @throws RuntimeException
270 */
271 public function testGetReplyTo(): void {
272 $folder = $this->getFolder('INBOX');
273 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
274 self::assertInstanceOf(Message::class, $message);
275
276 self::assertEquals("testreply_to <[email protected]>", $message->getReplyTo());
277 self::assertEquals("[email protected]", $message->getReplyTo()->first()->mail);
278 self::assertEquals("testreply_to", $message->getReplyTo()->first()->personal);
279
280 // Cleanup
281 self::assertTrue($message->delete());
282 }
283
284 /**
285 * Test Message::setSequence()
286 *
287 * @return void
288 * @throws AuthFailedException
289 * @throws ConnectionFailedException
290 * @throws EventNotFoundException
291 * @throws FolderFetchingException
292 * @throws ImapBadRequestException
293 * @throws ImapServerErrorException
294 * @throws InvalidMessageDateException
295 * @throws MaskNotFoundException
296 * @throws MessageContentFetchingException
297 * @throws MessageFlagException
298 * @throws MessageHeaderFetchingException
299 * @throws MessageNotFoundException
300 * @throws ResponseException
301 * @throws RuntimeException
302 */
303 public function testSetSequence(): void {
304 $message = $this->getDefaultMessage();
305 self::assertEquals($message->uid, $message->getSequenceId());
306
307 $message->setSequence(IMAP::ST_MSGN);
308 self::assertEquals($message->msgn, $message->getSequenceId());
309
310 $message->setSequence(null);
311 self::assertEquals($message->uid, $message->getSequenceId());
312
313 // Cleanup
314 self::assertTrue($message->delete());
315 }
316
317 /**
318 * Test Message::getEvent()
319 *
320 * @return void
321 * @throws AuthFailedException
322 * @throws ConnectionFailedException
323 * @throws EventNotFoundException
324 * @throws FolderFetchingException
325 * @throws ImapBadRequestException
326 * @throws ImapServerErrorException
327 * @throws InvalidMessageDateException
328 * @throws MaskNotFoundException
329 * @throws MessageContentFetchingException
330 * @throws MessageFlagException
331 * @throws MessageHeaderFetchingException
332 * @throws MessageNotFoundException
333 * @throws ResponseException
334 * @throws RuntimeException
335 */
336 public function testGetEvent(): void {
337 $message = $this->getDefaultMessage();
338
339 $message->setEvent("message", "test", "test");
340 self::assertEquals("test", $message->getEvent("message", "test"));
341
342 // Cleanup
343 self::assertTrue($message->delete());
344 }
345
346 /**
347 * Test Message::__construct()
348 *
349 * @return void
350 * @throws AuthFailedException
351 * @throws ConnectionFailedException
352 * @throws EventNotFoundException
353 * @throws FolderFetchingException
354 * @throws ImapBadRequestException
355 * @throws ImapServerErrorException
356 * @throws InvalidMessageDateException
357 * @throws MaskNotFoundException
358 * @throws MessageContentFetchingException
359 * @throws MessageFlagException
360 * @throws MessageHeaderFetchingException
361 * @throws MessageNotFoundException
362 * @throws ResponseException
363 * @throws RuntimeException
364 */
365 public function test__construct(): void {
366 $message = $this->getDefaultMessage();
367
368 // Cleanup
369 self::assertTrue($message->delete());
370 }
371
372 /**
373 * Test Message::setFlag()
374 *
375 * @return void
376 * @throws AuthFailedException
377 * @throws ConnectionFailedException
378 * @throws EventNotFoundException
379 * @throws FolderFetchingException
380 * @throws ImapBadRequestException
381 * @throws ImapServerErrorException
382 * @throws InvalidMessageDateException
383 * @throws MaskNotFoundException
384 * @throws MessageContentFetchingException
385 * @throws MessageFlagException
386 * @throws MessageHeaderFetchingException
387 * @throws MessageNotFoundException
388 * @throws ResponseException
389 * @throws RuntimeException
390 */
391 public function testSetFlag(): void {
392 $message = $this->getDefaultMessage();
393
394 self::assertTrue($message->setFlag("seen"));
395 self::assertTrue($message->getFlags()->has("seen"));
396
397 // Cleanup
398 self::assertTrue($message->delete());
399 }
400
401 /**
402 * Test Message::getMsgn()
403 *
404 * @return void
405 * @throws AuthFailedException
406 * @throws ConnectionFailedException
407 * @throws EventNotFoundException
408 * @throws FolderFetchingException
409 * @throws ImapBadRequestException
410 * @throws ImapServerErrorException
411 * @throws InvalidMessageDateException
412 * @throws MaskNotFoundException
413 * @throws MessageContentFetchingException
414 * @throws MessageFlagException
415 * @throws MessageHeaderFetchingException
416 * @throws MessageNotFoundException
417 * @throws ResponseException
418 * @throws RuntimeException
419 */
420 public function testGetMsgn(): void {
421 $client = $this->getClient();
422
423 $delimiter = $this->getManager()->getConfig()->get("options.delimiter");
424 $folder_path = implode($delimiter, ['INBOX', 'test']);
425
426 $folder = $client->getFolder($folder_path);
427 if ($folder !== null) {
428 self::assertTrue($this->deleteFolder($folder));
429 }
430 $folder = $client->createFolder($folder_path, false);
431
432 $message = $this->appendMessageTemplate($folder, "plain.eml");
433 self::assertInstanceOf(Message::class, $message);
434
435 self::assertEquals(1, $message->getMsgn());
436
437 // Cleanup
438 self::assertTrue($message->delete());
439 self::assertTrue($this->deleteFolder($folder));
440 }
441
442 /**
443 * Test Message::peek()
444 *
445 * @return void
446 * @throws AuthFailedException
447 * @throws ConnectionFailedException
448 * @throws EventNotFoundException
449 * @throws FolderFetchingException
450 * @throws ImapBadRequestException
451 * @throws ImapServerErrorException
452 * @throws InvalidMessageDateException
453 * @throws MaskNotFoundException
454 * @throws MessageContentFetchingException
455 * @throws MessageFlagException
456 * @throws MessageHeaderFetchingException
457 * @throws MessageNotFoundException
458 * @throws ResponseException
459 * @throws RuntimeException
460 */
461 public function testPeek(): void {
462 $message = $this->getDefaultMessage();
463 self::assertFalse($message->getFlags()->has("seen"));
464 self::assertEquals(IMAP::FT_PEEK, $message->getFetchOptions());
465 $message->peek();
466 self::assertFalse($message->getFlags()->has("seen"));
467
468 $message->setFetchOption(IMAP::FT_UID);
469 self::assertEquals(IMAP::FT_UID, $message->getFetchOptions());
470 $message->peek();
471 self::assertTrue($message->getFlags()->has("seen"));
472
473 // Cleanup
474 self::assertTrue($message->delete());
475
476 }
477
478 /**
479 * Test Message::unsetFlag()
480 *
481 * @return void
482 * @throws AuthFailedException
483 * @throws ConnectionFailedException
484 * @throws EventNotFoundException
485 * @throws FolderFetchingException
486 * @throws ImapBadRequestException
487 * @throws ImapServerErrorException
488 * @throws InvalidMessageDateException
489 * @throws MaskNotFoundException
490 * @throws MessageContentFetchingException
491 * @throws MessageFlagException
492 * @throws MessageHeaderFetchingException
493 * @throws MessageNotFoundException
494 * @throws ResponseException
495 * @throws RuntimeException
496 */
497 public function testUnsetFlag(): void {
498 $message = $this->getDefaultMessage();
499
500 self::assertFalse($message->getFlags()->has("seen"));
501
502 self::assertTrue($message->setFlag("seen"));
503 self::assertTrue($message->getFlags()->has("seen"));
504
505 self::assertTrue($message->unsetFlag("seen"));
506 self::assertFalse($message->getFlags()->has("seen"));
507
508 // Cleanup
509 self::assertTrue($message->delete());
510 }
511
512 /**
513 * Test Message::setSequenceId()
514 *
515 * @return void
516 * @throws AuthFailedException
517 * @throws ConnectionFailedException
518 * @throws EventNotFoundException
519 * @throws FolderFetchingException
520 * @throws ImapBadRequestException
521 * @throws ImapServerErrorException
522 * @throws InvalidMessageDateException
523 * @throws MaskNotFoundException
524 * @throws MessageContentFetchingException
525 * @throws MessageFlagException
526 * @throws MessageHeaderFetchingException
527 * @throws MessageNotFoundException
528 * @throws ResponseException
529 * @throws RuntimeException
530 */
531 public function testSetSequenceId(): void {
532 $message = $this->getDefaultMessage();
533 self::assertEquals($message->uid, $message->getSequenceId());
534
535 $original_sequence = $message->getSequenceId();
536
537 $message->setSequenceId(1, IMAP::ST_MSGN);
538 self::assertEquals(1, $message->getSequenceId());
539
540 $message->setSequenceId(1);
541 self::assertEquals(1, $message->getSequenceId());
542
543 $message->setSequenceId($original_sequence);
544
545 // Cleanup
546 self::assertTrue($message->delete());
547
548 }
549
550 /**
551 * Test Message::getTo()
552 *
553 * @return void
554 * @throws AuthFailedException
555 * @throws ConnectionFailedException
556 * @throws EventNotFoundException
557 * @throws FolderFetchingException
558 * @throws ImapBadRequestException
559 * @throws ImapServerErrorException
560 * @throws InvalidMessageDateException
561 * @throws MaskNotFoundException
562 * @throws MessageContentFetchingException
563 * @throws MessageFlagException
564 * @throws MessageHeaderFetchingException
565 * @throws MessageNotFoundException
566 * @throws ResponseException
567 * @throws RuntimeException
568 */
569 public function testGetTo(): void {
570 $message = $this->getDefaultMessage();
571 $folder = $message->getFolder();
572 self::assertInstanceOf(Folder::class, $folder);
573
574 self::assertEquals("[email protected]", $message->getTo());
575 self::assertTrue($message->delete());
576
577 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
578 self::assertInstanceOf(Message::class, $message);
579
580 self::assertEquals("testnameto <[email protected]>", $message->getTo());
581 self::assertEquals("testnameto", $message->getTo()->first()->personal);
582 self::assertEquals("[email protected]", $message->getTo()->first()->mail);
583
584 // Cleanup
585 self::assertTrue($message->delete());
586 }
587
588 /**
589 * Test Message::setUid()
590 *
591 * @return void
592 * @throws AuthFailedException
593 * @throws ConnectionFailedException
594 * @throws EventNotFoundException
595 * @throws FolderFetchingException
596 * @throws ImapBadRequestException
597 * @throws ImapServerErrorException
598 * @throws InvalidMessageDateException
599 * @throws MaskNotFoundException
600 * @throws MessageContentFetchingException
601 * @throws MessageFlagException
602 * @throws MessageHeaderFetchingException
603 * @throws MessageNotFoundException
604 * @throws ResponseException
605 * @throws RuntimeException
606 */
607 public function testSetUid(): void {
608 $message = $this->getDefaultMessage();
609 self::assertEquals($message->uid, $message->getSequenceId());
610
611 $original_sequence = $message->getSequenceId();
612
613 $message->setUid(789);
614 self::assertEquals(789, $message->uid);
615
616 $message->setUid($original_sequence);
617
618 // Cleanup
619 self::assertTrue($message->delete());
620
621 }
622
623 /**
624 * Test Message::getUid()
625 *
626 * @return void
627 * @throws AuthFailedException
628 * @throws ConnectionFailedException
629 * @throws EventNotFoundException
630 * @throws FolderFetchingException
631 * @throws ImapBadRequestException
632 * @throws ImapServerErrorException
633 * @throws InvalidMessageDateException
634 * @throws MaskNotFoundException
635 * @throws MessageContentFetchingException
636 * @throws MessageFlagException
637 * @throws MessageHeaderFetchingException
638 * @throws MessageNotFoundException
639 * @throws ResponseException
640 * @throws RuntimeException
641 */
642 public function testGetUid(): void {
643 $message = $this->getDefaultMessage();
644 self::assertEquals($message->uid, $message->getSequenceId());
645
646 $original_sequence = $message->uid;
647
648 $message->setUid(789);
649 self::assertEquals(789, $message->uid);
650 self::assertEquals(789, $message->getUid());
651
652 $message->setUid($original_sequence);
653
654 // Cleanup
655 self::assertTrue($message->delete());
656 }
657
658 /**
659 * Test Message::hasTextBody()
660 *
661 * @return void
662 * @throws AuthFailedException
663 * @throws ConnectionFailedException
664 * @throws EventNotFoundException
665 * @throws FolderFetchingException
666 * @throws ImapBadRequestException
667 * @throws ImapServerErrorException
668 * @throws InvalidMessageDateException
669 * @throws MaskNotFoundException
670 * @throws MessageContentFetchingException
671 * @throws MessageFlagException
672 * @throws MessageHeaderFetchingException
673 * @throws MessageNotFoundException
674 * @throws ResponseException
675 * @throws RuntimeException
676 */
677 public function testHasTextBody(): void {
678 $message = $this->getDefaultMessage();
679 self::assertTrue($message->hasTextBody());
680
681 // Cleanup
682 self::assertTrue($message->delete());
683 }
684
685 /**
686 * Test Message::__get()
687 *
688 * @return void
689 * @throws AuthFailedException
690 * @throws ConnectionFailedException
691 * @throws EventNotFoundException
692 * @throws FolderFetchingException
693 * @throws ImapBadRequestException
694 * @throws ImapServerErrorException
695 * @throws InvalidMessageDateException
696 * @throws MaskNotFoundException
697 * @throws MessageContentFetchingException
698 * @throws MessageFlagException
699 * @throws MessageHeaderFetchingException
700 * @throws MessageNotFoundException
701 * @throws ResponseException
702 * @throws RuntimeException
703 */
704 public function test__get(): void {
705 $message = $this->getDefaultMessage();
706 self::assertEquals($message->uid, $message->getSequenceId());
707 self::assertEquals("Example", $message->subject);
708 self::assertEquals("[email protected]", $message->to);
709
710 // Cleanup
711 self::assertTrue($message->delete());
712 }
713
714 /**
715 * Test Message::getDate()
716 *
717 * @return void
718 * @throws AuthFailedException
719 * @throws ConnectionFailedException
720 * @throws EventNotFoundException
721 * @throws FolderFetchingException
722 * @throws ImapBadRequestException
723 * @throws ImapServerErrorException
724 * @throws InvalidMessageDateException
725 * @throws MaskNotFoundException
726 * @throws MessageContentFetchingException
727 * @throws MessageFlagException
728 * @throws MessageHeaderFetchingException
729 * @throws MessageNotFoundException
730 * @throws ResponseException
731 * @throws RuntimeException
732 */
733 public function testGetDate(): void {
734 $message = $this->getDefaultMessage();
735 self::assertInstanceOf(Carbon::class, $message->getDate()->toDate());
736
737 // Cleanup
738 self::assertTrue($message->delete());
739 }
740
741 /**
742 * Test Message::setMask()
743 *
744 * @return void
745 * @throws AuthFailedException
746 * @throws ConnectionFailedException
747 * @throws EventNotFoundException
748 * @throws FolderFetchingException
749 * @throws ImapBadRequestException
750 * @throws ImapServerErrorException
751 * @throws InvalidMessageDateException
752 * @throws MaskNotFoundException
753 * @throws MessageContentFetchingException
754 * @throws MessageFlagException
755 * @throws MessageHeaderFetchingException
756 * @throws MessageNotFoundException
757 * @throws ResponseException
758 * @throws RuntimeException
759 */
760 public function testSetMask(): void {
761 $message = $this->getDefaultMessage();
762 self::assertEquals(MessageMask::class, $message->getMask());
763
764 $message->setMask(AttachmentMask::class);
765 self::assertEquals(AttachmentMask::class, $message->getMask());
766
767 $message->setMask(MessageMask::class);
768 self::assertEquals(MessageMask::class, $message->getMask());
769
770 // Cleanup
771 self::assertTrue($message->delete());
772 }
773
774 /**
775 * Test Message::getSequenceId()
776 *
777 * @return void
778 * @throws AuthFailedException
779 * @throws ConnectionFailedException
780 * @throws EventNotFoundException
781 * @throws FolderFetchingException
782 * @throws ImapBadRequestException
783 * @throws ImapServerErrorException
784 * @throws InvalidMessageDateException
785 * @throws MaskNotFoundException
786 * @throws MessageContentFetchingException
787 * @throws MessageFlagException
788 * @throws MessageHeaderFetchingException
789 * @throws MessageNotFoundException
790 * @throws ResponseException
791 * @throws RuntimeException
792 */
793 public function testGetSequenceId(): void {
794 $message = $this->getDefaultMessage();
795 self::assertEquals($message->uid, $message->getSequenceId());
796
797 $original_sequence = $message->getSequenceId();
798
799 $message->setSequenceId(789, IMAP::ST_MSGN);
800 self::assertEquals(789, $message->getSequenceId());
801
802 $message->setSequenceId(789);
803 self::assertEquals(789, $message->getSequenceId());
804
805 $message->setSequenceId($original_sequence);
806
807 // Cleanup
808 self::assertTrue($message->delete());
809 }
810
811 /**
812 * Test Message::setConfig()
813 *
814 * @return void
815 * @throws AuthFailedException
816 * @throws ConnectionFailedException
817 * @throws EventNotFoundException
818 * @throws FolderFetchingException
819 * @throws ImapBadRequestException
820 * @throws ImapServerErrorException
821 * @throws InvalidMessageDateException
822 * @throws MaskNotFoundException
823 * @throws MessageContentFetchingException
824 * @throws MessageFlagException
825 * @throws MessageHeaderFetchingException
826 * @throws MessageNotFoundException
827 * @throws ResponseException
828 * @throws RuntimeException
829 */
830 public function testSetConfig(): void {
831 $message = $this->getDefaultMessage();
832
833 $options = $message->getOptions();
834 self::assertIsArray($options);
835
836 $message->setOptions(["foo" => "bar"]);
837 self::assertArrayHasKey("foo", $message->getOptions());
838
839 $message->setOptions($options);
840
841 // Cleanup
842 self::assertTrue($message->delete());
843 }
844
845 /**
846 * Test Message::getEvents()
847 *
848 * @return void
849 * @throws AuthFailedException
850 * @throws ConnectionFailedException
851 * @throws EventNotFoundException
852 * @throws FolderFetchingException
853 * @throws ImapBadRequestException
854 * @throws ImapServerErrorException
855 * @throws InvalidMessageDateException
856 * @throws MaskNotFoundException
857 * @throws MessageContentFetchingException
858 * @throws MessageFlagException
859 * @throws MessageHeaderFetchingException
860 * @throws MessageNotFoundException
861 * @throws ResponseException
862 * @throws RuntimeException
863 */
864 public function testGetEvents(): void {
865 $message = $this->getDefaultMessage();
866
867 $events = $message->getEvents();
868 self::assertIsArray($events);
869
870 // Cleanup
871 self::assertTrue($message->delete());
872 }
873
874 /**
875 * Test Message::setFetchOption()
876 *
877 * @return void
878 * @throws AuthFailedException
879 * @throws ConnectionFailedException
880 * @throws EventNotFoundException
881 * @throws FolderFetchingException
882 * @throws ImapBadRequestException
883 * @throws ImapServerErrorException
884 * @throws InvalidMessageDateException
885 * @throws MaskNotFoundException
886 * @throws MessageContentFetchingException
887 * @throws MessageFlagException
888 * @throws MessageHeaderFetchingException
889 * @throws MessageNotFoundException
890 * @throws ResponseException
891 * @throws RuntimeException
892 */
893 public function testSetFetchOption(): void {
894 $message = $this->getDefaultMessage();
895
896 $fetch_option = $message->fetch_options;
897
898 $message->setFetchOption(IMAP::FT_UID);
899 self::assertEquals(IMAP::FT_UID, $message->fetch_options);
900
901 $message->setFetchOption(IMAP::FT_PEEK);
902 self::assertEquals(IMAP::FT_PEEK, $message->fetch_options);
903
904 $message->setFetchOption(IMAP::FT_UID | IMAP::FT_PEEK);
905 self::assertEquals(IMAP::FT_UID | IMAP::FT_PEEK, $message->fetch_options);
906
907 $message->setFetchOption($fetch_option);
908
909 // Cleanup
910 self::assertTrue($message->delete());
911 }
912
913 /**
914 * Test Message::getMsglist()
915 *
916 * @return void
917 * @throws AuthFailedException
918 * @throws ConnectionFailedException
919 * @throws EventNotFoundException
920 * @throws FolderFetchingException
921 * @throws ImapBadRequestException
922 * @throws ImapServerErrorException
923 * @throws InvalidMessageDateException
924 * @throws MaskNotFoundException
925 * @throws MessageContentFetchingException
926 * @throws MessageFlagException
927 * @throws MessageHeaderFetchingException
928 * @throws MessageNotFoundException
929 * @throws ResponseException
930 * @throws RuntimeException
931 */
932 public function testGetMsglist(): void {
933 $message = $this->getDefaultMessage();
934
935 self::assertEquals(0, (int)$message->getMsglist()->toString());
936
937 // Cleanup
938 self::assertTrue($message->delete());
939 }
940
941 /**
942 * Test Message::decodeString()
943 *
944 * @return void
945 * @throws AuthFailedException
946 * @throws ConnectionFailedException
947 * @throws EventNotFoundException
948 * @throws FolderFetchingException
949 * @throws ImapBadRequestException
950 * @throws ImapServerErrorException
951 * @throws InvalidMessageDateException
952 * @throws MaskNotFoundException
953 * @throws MessageContentFetchingException
954 * @throws MessageFlagException
955 * @throws MessageHeaderFetchingException
956 * @throws MessageNotFoundException
957 * @throws ResponseException
958 * @throws RuntimeException
959 */
960 public function testDecodeString(): void {
961 $message = $this->getDefaultMessage();
962
963 $string = '<p class=3D"MsoNormal">Test<o:p></o:p></p>';
964 self::assertEquals('<p class="MsoNormal">Test<o:p></o:p></p>', $message->getDecoder()->decode($string, IMAP::MESSAGE_ENC_QUOTED_PRINTABLE));
965
966 // Cleanup
967 self::assertTrue($message->delete());
968 }
969
970 /**
971 * Test Message::attachments()
972 *
973 * @return void
974 * @throws AuthFailedException
975 * @throws ConnectionFailedException
976 * @throws EventNotFoundException
977 * @throws FolderFetchingException
978 * @throws ImapBadRequestException
979 * @throws ImapServerErrorException
980 * @throws InvalidMessageDateException
981 * @throws MaskNotFoundException
982 * @throws MessageContentFetchingException
983 * @throws MessageFlagException
984 * @throws MessageHeaderFetchingException
985 * @throws MessageNotFoundException
986 * @throws ResponseException
987 * @throws RuntimeException
988 */
989 public function testAttachments(): void {
990 $folder = $this->getFolder('INBOX');
991
992 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
993 self::assertTrue($message->hasAttachments());
994 self::assertSameSize([1], $message->attachments());
995
996 // Cleanup
997 self::assertTrue($message->delete());
998 }
999
1000 /**
1001 * Test Message::getMask()
1002 *
1003 * @return void
1004 * @throws AuthFailedException
1005 * @throws ConnectionFailedException
1006 * @throws EventNotFoundException
1007 * @throws FolderFetchingException
1008 * @throws ImapBadRequestException
1009 * @throws ImapServerErrorException
1010 * @throws InvalidMessageDateException
1011 * @throws MaskNotFoundException
1012 * @throws MessageContentFetchingException
1013 * @throws MessageFlagException
1014 * @throws MessageHeaderFetchingException
1015 * @throws MessageNotFoundException
1016 * @throws ResponseException
1017 * @throws RuntimeException
1018 */
1019 public function testGetMask(): void {
1020 $message = $this->getDefaultMessage();
1021 self::assertEquals(MessageMask::class, $message->getMask());
1022
1023 $message->setMask(AttachmentMask::class);
1024 self::assertEquals(AttachmentMask::class, $message->getMask());
1025
1026 $message->setMask(MessageMask::class);
1027 self::assertEquals(MessageMask::class, $message->getMask());
1028
1029 // Cleanup
1030 self::assertTrue($message->delete());
1031 }
1032
1033 /**
1034 * Test Message::hasHTMLBody()
1035 *
1036 * @return void
1037 * @throws AuthFailedException
1038 * @throws ConnectionFailedException
1039 * @throws EventNotFoundException
1040 * @throws FolderFetchingException
1041 * @throws ImapBadRequestException
1042 * @throws ImapServerErrorException
1043 * @throws InvalidMessageDateException
1044 * @throws MaskNotFoundException
1045 * @throws MessageContentFetchingException
1046 * @throws MessageFlagException
1047 * @throws MessageHeaderFetchingException
1048 * @throws MessageNotFoundException
1049 * @throws ResponseException
1050 * @throws RuntimeException
1051 */
1052 public function testHasHTMLBody(): void {
1053 $folder = $this->getFolder('INBOX');
1054
1055 $message = $this->appendMessageTemplate($folder, "[email protected]");
1056 self::assertTrue($message->hasHTMLBody());
1057
1058 // Cleanup
1059 self::assertTrue($message->delete());
1060
1061 $message = $this->getDefaultMessage();
1062 self::assertFalse($message->hasHTMLBody());
1063
1064 // Cleanup
1065 self::assertTrue($message->delete());
1066 }
1067
1068 /**
1069 * Test Message::setEvents()
1070 *
1071 * @return void
1072 * @throws AuthFailedException
1073 * @throws ConnectionFailedException
1074 * @throws EventNotFoundException
1075 * @throws FolderFetchingException
1076 * @throws ImapBadRequestException
1077 * @throws ImapServerErrorException
1078 * @throws InvalidMessageDateException
1079 * @throws MaskNotFoundException
1080 * @throws MessageContentFetchingException
1081 * @throws MessageFlagException
1082 * @throws MessageHeaderFetchingException
1083 * @throws MessageNotFoundException
1084 * @throws ResponseException
1085 * @throws RuntimeException
1086 */
1087 public function testSetEvents(): void {
1088 $message = $this->getDefaultMessage();
1089
1090 $events = $message->getEvents();
1091 self::assertIsArray($events);
1092
1093 $message->setEvents(["foo" => "bar"]);
1094 self::assertArrayHasKey("foo", $message->getEvents());
1095
1096 $message->setEvents($events);
1097
1098 // Cleanup
1099 self::assertTrue($message->delete());
1100 }
1101
1102 /**
1103 * Test Message::__set()
1104 *
1105 * @return void
1106 * @throws AuthFailedException
1107 * @throws ConnectionFailedException
1108 * @throws EventNotFoundException
1109 * @throws FolderFetchingException
1110 * @throws ImapBadRequestException
1111 * @throws ImapServerErrorException
1112 * @throws InvalidMessageDateException
1113 * @throws MaskNotFoundException
1114 * @throws MessageContentFetchingException
1115 * @throws MessageFlagException
1116 * @throws MessageHeaderFetchingException
1117 * @throws MessageNotFoundException
1118 * @throws ResponseException
1119 * @throws RuntimeException
1120 */
1121 public function test__set(): void {
1122 $message = $this->getDefaultMessage();
1123
1124 $message->foo = "bar";
1125 self::assertEquals("bar", $message->getFoo());
1126
1127 // Cleanup
1128 self::assertTrue($message->delete());
1129 }
1130
1131 /**
1132 * Test Message::getHTMLBody()
1133 *
1134 * @return void
1135 * @throws AuthFailedException
1136 * @throws ConnectionFailedException
1137 * @throws EventNotFoundException
1138 * @throws FolderFetchingException
1139 * @throws ImapBadRequestException
1140 * @throws ImapServerErrorException
1141 * @throws InvalidMessageDateException
1142 * @throws MaskNotFoundException
1143 * @throws MessageContentFetchingException
1144 * @throws MessageFlagException
1145 * @throws MessageHeaderFetchingException
1146 * @throws MessageNotFoundException
1147 * @throws ResponseException
1148 * @throws RuntimeException
1149 */
1150 public function testGetHTMLBody(): void {
1151 $folder = $this->getFolder('INBOX');
1152
1153 $message = $this->appendMessageTemplate($folder, "[email protected]");
1154 self::assertTrue($message->hasHTMLBody());
1155 self::assertIsString($message->getHTMLBody());
1156
1157 // Cleanup
1158 self::assertTrue($message->delete());
1159
1160 $message = $this->getDefaultMessage();
1161 self::assertFalse($message->hasHTMLBody());
1162 self::assertEmpty($message->getHTMLBody());
1163
1164 // Cleanup
1165 self::assertTrue($message->delete());
1166 }
1167
1168 /**
1169 * Test Message::getSequence()
1170 *
1171 * @return void
1172 * @throws AuthFailedException
1173 * @throws ConnectionFailedException
1174 * @throws EventNotFoundException
1175 * @throws FolderFetchingException
1176 * @throws ImapBadRequestException
1177 * @throws ImapServerErrorException
1178 * @throws InvalidMessageDateException
1179 * @throws MaskNotFoundException
1180 * @throws MessageContentFetchingException
1181 * @throws MessageFlagException
1182 * @throws MessageHeaderFetchingException
1183 * @throws MessageNotFoundException
1184 * @throws ResponseException
1185 * @throws RuntimeException
1186 */
1187 public function testGetSequence(): void {
1188 $message = $this->getDefaultMessage();
1189 self::assertEquals(IMAP::ST_UID, $message->getSequence());
1190
1191 $original_sequence = $message->getSequence();
1192
1193 $message->setSequence(IMAP::ST_MSGN);
1194 self::assertEquals(IMAP::ST_MSGN, $message->getSequence());
1195
1196 $message->setSequence($original_sequence);
1197 self::assertEquals(IMAP::ST_UID, $message->getSequence());
1198
1199 // Cleanup
1200 self::assertTrue($message->delete());
1201 }
1202
1203 /**
1204 * Test Message::restore()
1205 *
1206 * @return void
1207 * @throws AuthFailedException
1208 * @throws ConnectionFailedException
1209 * @throws EventNotFoundException
1210 * @throws FolderFetchingException
1211 * @throws ImapBadRequestException
1212 * @throws ImapServerErrorException
1213 * @throws InvalidMessageDateException
1214 * @throws MaskNotFoundException
1215 * @throws MessageContentFetchingException
1216 * @throws MessageFlagException
1217 * @throws MessageHeaderFetchingException
1218 * @throws MessageNotFoundException
1219 * @throws ResponseException
1220 * @throws RuntimeException
1221 */
1222 public function testRestore(): void {
1223 $message = $this->getDefaultMessage();
1224
1225 $message->setFlag("deleted");
1226 self::assertTrue($message->hasFlag("deleted"));
1227
1228 $message->restore();
1229 self::assertFalse($message->hasFlag("deleted"));
1230
1231 // Cleanup
1232 self::assertTrue($message->delete());
1233 }
1234
1235 /**
1236 * Test Message::getPriority()
1237 *
1238 * @return void
1239 * @throws AuthFailedException
1240 * @throws ConnectionFailedException
1241 * @throws EventNotFoundException
1242 * @throws FolderFetchingException
1243 * @throws ImapBadRequestException
1244 * @throws ImapServerErrorException
1245 * @throws InvalidMessageDateException
1246 * @throws MaskNotFoundException
1247 * @throws MessageContentFetchingException
1248 * @throws MessageFlagException
1249 * @throws MessageHeaderFetchingException
1250 * @throws MessageNotFoundException
1251 * @throws ResponseException
1252 * @throws RuntimeException
1253 */
1254 public function testGetPriority(): void {
1255 $folder = $this->getFolder('INBOX');
1256
1257 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
1258 self::assertEquals(1, $message->getPriority()->first());
1259
1260 // Cleanup
1261 self::assertTrue($message->delete());
1262 }
1263
1264 /**
1265 * Test Message::setAttachments()
1266 *
1267 * @return void
1268 * @throws AuthFailedException
1269 * @throws ConnectionFailedException
1270 * @throws EventNotFoundException
1271 * @throws FolderFetchingException
1272 * @throws ImapBadRequestException
1273 * @throws ImapServerErrorException
1274 * @throws InvalidMessageDateException
1275 * @throws MaskNotFoundException
1276 * @throws MessageContentFetchingException
1277 * @throws MessageFlagException
1278 * @throws MessageHeaderFetchingException
1279 * @throws MessageNotFoundException
1280 * @throws ResponseException
1281 * @throws RuntimeException
1282 */
1283 public function testSetAttachments(): void {
1284 $message = $this->getDefaultMessage();
1285
1286 $message->setAttachments(new AttachmentCollection(["foo" => "bar"]));
1287 self::assertIsArray($message->attachments()->toArray());
1288 self::assertTrue($message->attachments()->has("foo"));
1289
1290 // Cleanup
1291 self::assertTrue($message->delete());
1292 }
1293
1294 /**
1295 * Test Message::getFrom()
1296 *
1297 * @return void
1298 * @throws AuthFailedException
1299 * @throws ConnectionFailedException
1300 * @throws EventNotFoundException
1301 * @throws FolderFetchingException
1302 * @throws ImapBadRequestException
1303 * @throws ImapServerErrorException
1304 * @throws InvalidMessageDateException
1305 * @throws MaskNotFoundException
1306 * @throws MessageContentFetchingException
1307 * @throws MessageFlagException
1308 * @throws MessageHeaderFetchingException
1309 * @throws MessageNotFoundException
1310 * @throws ResponseException
1311 * @throws RuntimeException
1312 */
1313 public function testGetFrom(): void {
1314 $message = $this->getDefaultMessage();
1315 self::assertEquals("[email protected]", $message->getFrom()->first()->mail);
1316
1317 // Cleanup
1318 self::assertTrue($message->delete());
1319 }
1320
1321 /**
1322 * Test Message::setEvent()
1323 *
1324 * @return void
1325 * @throws AuthFailedException
1326 * @throws ConnectionFailedException
1327 * @throws EventNotFoundException
1328 * @throws FolderFetchingException
1329 * @throws ImapBadRequestException
1330 * @throws ImapServerErrorException
1331 * @throws InvalidMessageDateException
1332 * @throws MaskNotFoundException
1333 * @throws MessageContentFetchingException
1334 * @throws MessageFlagException
1335 * @throws MessageHeaderFetchingException
1336 * @throws MessageNotFoundException
1337 * @throws ResponseException
1338 * @throws RuntimeException
1339 */
1340 public function testSetEvent(): void {
1341 $message = $this->getDefaultMessage();
1342
1343 $message->setEvent("message", "bar", "foo");
1344 self::assertArrayHasKey("bar", $message->getEvents()["message"]);
1345
1346 // Cleanup
1347 self::assertTrue($message->delete());
1348 }
1349
1350 /**
1351 * Test Message::getInReplyTo()
1352 *
1353 * @return void
1354 * @throws AuthFailedException
1355 * @throws ConnectionFailedException
1356 * @throws EventNotFoundException
1357 * @throws FolderFetchingException
1358 * @throws ImapBadRequestException
1359 * @throws ImapServerErrorException
1360 * @throws InvalidMessageDateException
1361 * @throws MaskNotFoundException
1362 * @throws MessageContentFetchingException
1363 * @throws MessageFlagException
1364 * @throws MessageHeaderFetchingException
1365 * @throws MessageNotFoundException
1366 * @throws ResponseException
1367 * @throws RuntimeException
1368 */
1369 public function testGetInReplyTo(): void {
1370 $message = $this->getDefaultMessage();
1371 self::assertEquals("", $message->getInReplyTo());
1372
1373 // Cleanup
1374 self::assertTrue($message->delete());
1375
1376 $folder = $this->getFolder('INBOX');
1377
1378 $message = $this->appendMessageTemplate($folder, "[email protected]");
1379 self::assertEquals("Webklex/php-imap/issues/[email protected]", $message->getInReplyTo());
1380
1381 // Cleanup
1382 self::assertTrue($message->delete());
1383 }
1384
1385 /**
1386 * Test Message::copy()
1387 *
1388 * @return void
1389 * @throws AuthFailedException
1390 * @throws ConnectionFailedException
1391 * @throws EventNotFoundException
1392 * @throws FolderFetchingException
1393 * @throws ImapBadRequestException
1394 * @throws ImapServerErrorException
1395 * @throws InvalidMessageDateException
1396 * @throws MaskNotFoundException
1397 * @throws MessageContentFetchingException
1398 * @throws MessageFlagException
1399 * @throws MessageHeaderFetchingException
1400 * @throws MessageNotFoundException
1401 * @throws ResponseException
1402 * @throws RuntimeException
1403 */
1404 public function testCopy(): void {
1405 $message = $this->getDefaultMessage();
1406 $client = $message->getClient();
1407 self::assertInstanceOf(Client::class, $client);
1408
1409 $delimiter = $this->getManager()->getConfig()->get("options.delimiter");
1410 $folder_path = implode($delimiter, ['INBOX', 'test']);
1411
1412 $folder = $client->getFolder($folder_path);
1413 if ($folder !== null) {
1414 self::assertTrue($this->deleteFolder($folder));
1415 }
1416 $folder = $client->createFolder($folder_path, false);
1417 self::assertInstanceOf(Folder::class, $folder);
1418
1419 $new_message = $message->copy($folder->path, true);
1420 self::assertInstanceOf(Message::class, $new_message);
1421 self::assertEquals($folder->path, $new_message->getFolder()->path);
1422
1423 // Cleanup
1424 self::assertTrue($message->delete());
1425 self::assertTrue($new_message->delete());
1426
1427 }
1428
1429 /**
1430 * Test Message::getBodies()
1431 *
1432 * @return void
1433 * @throws AuthFailedException
1434 * @throws ConnectionFailedException
1435 * @throws EventNotFoundException
1436 * @throws FolderFetchingException
1437 * @throws ImapBadRequestException
1438 * @throws ImapServerErrorException
1439 * @throws InvalidMessageDateException
1440 * @throws MaskNotFoundException
1441 * @throws MessageContentFetchingException
1442 * @throws MessageFlagException
1443 * @throws MessageHeaderFetchingException
1444 * @throws MessageNotFoundException
1445 * @throws ResponseException
1446 * @throws RuntimeException
1447 */
1448 public function testGetBodies(): void {
1449 $message = $this->getDefaultMessage();
1450 self::assertIsArray($message->getBodies());
1451 self::assertCount(1, $message->getBodies());
1452
1453 // Cleanup
1454 self::assertTrue($message->delete());
1455
1456 }
1457
1458 /**
1459 * Test Message::getFlags()
1460 *
1461 * @return void
1462 * @throws AuthFailedException
1463 * @throws ConnectionFailedException
1464 * @throws EventNotFoundException
1465 * @throws FolderFetchingException
1466 * @throws ImapBadRequestException
1467 * @throws ImapServerErrorException
1468 * @throws InvalidMessageDateException
1469 * @throws MaskNotFoundException
1470 * @throws MessageContentFetchingException
1471 * @throws MessageFlagException
1472 * @throws MessageHeaderFetchingException
1473 * @throws MessageNotFoundException
1474 * @throws ResponseException
1475 * @throws RuntimeException
1476 */
1477 public function testGetFlags(): void {
1478 $message = $this->getDefaultMessage();
1479 self::assertIsArray($message->getFlags()->all());
1480
1481 self::assertFalse($message->hasFlag("seen"));
1482
1483 self::assertTrue($message->setFlag("seen"));
1484 self::assertTrue($message->getFlags()->has("seen"));
1485 self::assertTrue($message->hasFlag("seen"));
1486
1487 // Cleanup
1488 self::assertTrue($message->delete());
1489 }
1490
1491 /**
1492 * Test Message::addFlag()
1493 *
1494 * @return void
1495 * @throws AuthFailedException
1496 * @throws ConnectionFailedException
1497 * @throws EventNotFoundException
1498 * @throws FolderFetchingException
1499 * @throws ImapBadRequestException
1500 * @throws ImapServerErrorException
1501 * @throws InvalidMessageDateException
1502 * @throws MaskNotFoundException
1503 * @throws MessageContentFetchingException
1504 * @throws MessageFlagException
1505 * @throws MessageHeaderFetchingException
1506 * @throws MessageNotFoundException
1507 * @throws ResponseException
1508 * @throws RuntimeException
1509 */
1510 public function testAddFlag(): void {
1511 $message = $this->getDefaultMessage();
1512 self::assertFalse($message->hasFlag("seen"));
1513
1514 self::assertTrue($message->addFlag("seen"));
1515 self::assertTrue($message->hasFlag("seen"));
1516
1517 // Cleanup
1518 self::assertTrue($message->delete());
1519 }
1520
1521 /**
1522 * Test Message::getSubject()
1523 *
1524 * @return void
1525 * @throws AuthFailedException
1526 * @throws ConnectionFailedException
1527 * @throws EventNotFoundException
1528 * @throws FolderFetchingException
1529 * @throws ImapBadRequestException
1530 * @throws ImapServerErrorException
1531 * @throws InvalidMessageDateException
1532 * @throws MaskNotFoundException
1533 * @throws MessageContentFetchingException
1534 * @throws MessageFlagException
1535 * @throws MessageHeaderFetchingException
1536 * @throws MessageNotFoundException
1537 * @throws ResponseException
1538 * @throws RuntimeException
1539 */
1540 public function testGetSubject(): void {
1541 $message = $this->getDefaultMessage();
1542 self::assertEquals("Example", $message->getSubject());
1543
1544 // Cleanup
1545 self::assertTrue($message->delete());
1546 }
1547
1548 /**
1549 * Test Message::getClient()
1550 *
1551 * @return void
1552 * @throws AuthFailedException
1553 * @throws ConnectionFailedException
1554 * @throws EventNotFoundException
1555 * @throws FolderFetchingException
1556 * @throws ImapBadRequestException
1557 * @throws ImapServerErrorException
1558 * @throws InvalidMessageDateException
1559 * @throws MaskNotFoundException
1560 * @throws MessageContentFetchingException
1561 * @throws MessageFlagException
1562 * @throws MessageHeaderFetchingException
1563 * @throws MessageNotFoundException
1564 * @throws ResponseException
1565 * @throws RuntimeException
1566 */
1567 public function testGetClient(): void {
1568 $message = $this->getDefaultMessage();
1569 self::assertInstanceOf(Client::class, $message->getClient());
1570
1571 // Cleanup
1572 self::assertTrue($message->delete());
1573 }
1574
1575 /**
1576 * Test Message::setFetchFlagsOption()
1577 *
1578 * @return void
1579 * @throws AuthFailedException
1580 * @throws ConnectionFailedException
1581 * @throws EventNotFoundException
1582 * @throws FolderFetchingException
1583 * @throws ImapBadRequestException
1584 * @throws ImapServerErrorException
1585 * @throws InvalidMessageDateException
1586 * @throws MaskNotFoundException
1587 * @throws MessageContentFetchingException
1588 * @throws MessageFlagException
1589 * @throws MessageHeaderFetchingException
1590 * @throws MessageNotFoundException
1591 * @throws ResponseException
1592 * @throws RuntimeException
1593 */
1594 public function testSetFetchFlagsOption(): void {
1595 $message = $this->getDefaultMessage();
1596
1597 self::assertTrue($message->getFetchFlagsOption());
1598 $message->setFetchFlagsOption(false);
1599 self::assertFalse($message->getFetchFlagsOption());
1600
1601 // Cleanup
1602 self::assertTrue($message->delete());
1603 }
1604
1605 /**
1606 * Test Message::mask()
1607 *
1608 * @return void
1609 * @throws AuthFailedException
1610 * @throws ConnectionFailedException
1611 * @throws EventNotFoundException
1612 * @throws FolderFetchingException
1613 * @throws ImapBadRequestException
1614 * @throws ImapServerErrorException
1615 * @throws InvalidMessageDateException
1616 * @throws MaskNotFoundException
1617 * @throws MessageContentFetchingException
1618 * @throws MessageFlagException
1619 * @throws MessageHeaderFetchingException
1620 * @throws MessageNotFoundException
1621 * @throws ResponseException
1622 * @throws RuntimeException
1623 */
1624 public function testMask(): void {
1625 $message = $this->getDefaultMessage();
1626 self::assertInstanceOf(MessageMask::class, $message->mask());
1627
1628 // Cleanup
1629 self::assertTrue($message->delete());
1630 }
1631
1632 /**
1633 * Test Message::setMsglist()
1634 *
1635 * @return void
1636 * @throws AuthFailedException
1637 * @throws ConnectionFailedException
1638 * @throws EventNotFoundException
1639 * @throws FolderFetchingException
1640 * @throws ImapBadRequestException
1641 * @throws ImapServerErrorException
1642 * @throws InvalidMessageDateException
1643 * @throws MaskNotFoundException
1644 * @throws MessageContentFetchingException
1645 * @throws MessageFlagException
1646 * @throws MessageHeaderFetchingException
1647 * @throws MessageNotFoundException
1648 * @throws ResponseException
1649 * @throws RuntimeException
1650 */
1651 public function testSetMsglist(): void {
1652 $message = $this->getDefaultMessage();
1653 $message->setMsglist("foo");
1654 self::assertEquals("foo", $message->getMsglist());
1655
1656 // Cleanup
1657 self::assertTrue($message->delete());
1658 }
1659
1660 /**
1661 * Test Message::flags()
1662 *
1663 * @return void
1664 * @throws AuthFailedException
1665 * @throws ConnectionFailedException
1666 * @throws EventNotFoundException
1667 * @throws FolderFetchingException
1668 * @throws ImapBadRequestException
1669 * @throws ImapServerErrorException
1670 * @throws InvalidMessageDateException
1671 * @throws MaskNotFoundException
1672 * @throws MessageContentFetchingException
1673 * @throws MessageFlagException
1674 * @throws MessageHeaderFetchingException
1675 * @throws MessageNotFoundException
1676 * @throws ResponseException
1677 * @throws RuntimeException
1678 */
1679 public function testFlags(): void {
1680 $message = $this->getDefaultMessage();
1681 self::assertInstanceOf(FlagCollection::class, $message->flags());
1682
1683 // Cleanup
1684 self::assertTrue($message->delete());
1685 }
1686
1687 /**
1688 * Test Message::getAttributes()
1689 *
1690 * @return void
1691 * @throws AuthFailedException
1692 * @throws ConnectionFailedException
1693 * @throws EventNotFoundException
1694 * @throws FolderFetchingException
1695 * @throws ImapBadRequestException
1696 * @throws ImapServerErrorException
1697 * @throws InvalidMessageDateException
1698 * @throws MaskNotFoundException
1699 * @throws MessageContentFetchingException
1700 * @throws MessageFlagException
1701 * @throws MessageHeaderFetchingException
1702 * @throws MessageNotFoundException
1703 * @throws ResponseException
1704 * @throws RuntimeException
1705 */
1706 public function testGetAttributes(): void {
1707 $message = $this->getDefaultMessage();
1708 self::assertIsArray($message->getAttributes());
1709 self::assertArrayHasKey("subject", $message->getAttributes());
1710
1711 // Cleanup
1712 self::assertTrue($message->delete());
1713 }
1714
1715 /**
1716 * Test Message::getAttachments()
1717 *
1718 * @return void
1719 * @throws AuthFailedException
1720 * @throws ConnectionFailedException
1721 * @throws EventNotFoundException
1722 * @throws FolderFetchingException
1723 * @throws ImapBadRequestException
1724 * @throws ImapServerErrorException
1725 * @throws InvalidMessageDateException
1726 * @throws MaskNotFoundException
1727 * @throws MessageContentFetchingException
1728 * @throws MessageFlagException
1729 * @throws MessageHeaderFetchingException
1730 * @throws MessageNotFoundException
1731 * @throws ResponseException
1732 * @throws RuntimeException
1733 */
1734 public function testGetAttachments(): void {
1735 $message = $this->getDefaultMessage();
1736 self::assertInstanceOf(AttachmentCollection::class, $message->getAttachments());
1737
1738 // Cleanup
1739 self::assertTrue($message->delete());
1740 }
1741
1742 /**
1743 * Test Message::getRawBody()
1744 *
1745 * @return void
1746 * @throws AuthFailedException
1747 * @throws ConnectionFailedException
1748 * @throws EventNotFoundException
1749 * @throws FolderFetchingException
1750 * @throws ImapBadRequestException
1751 * @throws ImapServerErrorException
1752 * @throws InvalidMessageDateException
1753 * @throws MaskNotFoundException
1754 * @throws MessageContentFetchingException
1755 * @throws MessageFlagException
1756 * @throws MessageHeaderFetchingException
1757 * @throws MessageNotFoundException
1758 * @throws ResponseException
1759 * @throws RuntimeException
1760 */
1761 public function testGetRawBody(): void {
1762 $message = $this->getDefaultMessage();
1763 self::assertIsString($message->getRawBody());
1764
1765 // Cleanup
1766 self::assertTrue($message->delete());
1767 }
1768
1769 /**
1770 * Test Message::is()
1771 *
1772 * @return void
1773 * @throws AuthFailedException
1774 * @throws ConnectionFailedException
1775 * @throws EventNotFoundException
1776 * @throws FolderFetchingException
1777 * @throws ImapBadRequestException
1778 * @throws ImapServerErrorException
1779 * @throws InvalidMessageDateException
1780 * @throws MaskNotFoundException
1781 * @throws MessageContentFetchingException
1782 * @throws MessageFlagException
1783 * @throws MessageHeaderFetchingException
1784 * @throws MessageNotFoundException
1785 * @throws ResponseException
1786 * @throws RuntimeException
1787 */
1788 public function testIs(): void {
1789 $message = $this->getDefaultMessage();
1790 self::assertTrue($message->is($message));
1791
1792 // Cleanup
1793 self::assertTrue($message->delete());
1794 }
1795
1796 /**
1797 * Test Message::setFlags()
1798 *
1799 * @return void
1800 * @throws AuthFailedException
1801 * @throws ConnectionFailedException
1802 * @throws EventNotFoundException
1803 * @throws FolderFetchingException
1804 * @throws ImapBadRequestException
1805 * @throws ImapServerErrorException
1806 * @throws InvalidMessageDateException
1807 * @throws MaskNotFoundException
1808 * @throws MessageContentFetchingException
1809 * @throws MessageFlagException
1810 * @throws MessageHeaderFetchingException
1811 * @throws MessageNotFoundException
1812 * @throws ResponseException
1813 * @throws RuntimeException
1814 */
1815 public function testSetFlags(): void {
1816 $message = $this->getDefaultMessage();
1817 $message->setFlags(new FlagCollection());
1818 self::assertFalse($message->hasFlag("recent"));
1819
1820 // Cleanup
1821 self::assertTrue($message->delete());
1822 }
1823
1824 /**
1825 * Test Message::make()
1826 *
1827 * @return void
1828 * @throws AuthFailedException
1829 * @throws ConnectionFailedException
1830 * @throws EventNotFoundException
1831 * @throws FolderFetchingException
1832 * @throws ImapBadRequestException
1833 * @throws ImapServerErrorException
1834 * @throws InvalidMessageDateException
1835 * @throws MaskNotFoundException
1836 * @throws MessageContentFetchingException
1837 * @throws MessageFlagException
1838 * @throws ResponseException
1839 * @throws RuntimeException
1840 * @throws ReflectionException
1841 */
1842 public function testMake(): void {
1843 $folder = $this->getFolder('INBOX');
1844 $folder->getClient()->openFolder($folder->path);
1845
1846 $email = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", "[email protected]"]));
1847 if(!str_contains($email, "\r\n")){
1848 $email = str_replace("\n", "\r\n", $email);
1849 }
1850
1851 $raw_header = substr($email, 0, strpos($email, "\r\n\r\n"));
1852 $raw_body = substr($email, strlen($raw_header)+8);
1853
1854 $message = Message::make(0, null, $folder->getClient(), $raw_header, $raw_body, [0 => "\\Seen"], IMAP::ST_UID);
1855 self::assertInstanceOf(Message::class, $message);
1856 }
1857
1858 /**
1859 * Test Message::setAvailableFlags()
1860 *
1861 * @return void
1862 * @throws AuthFailedException
1863 * @throws ConnectionFailedException
1864 * @throws EventNotFoundException
1865 * @throws FolderFetchingException
1866 * @throws ImapBadRequestException
1867 * @throws ImapServerErrorException
1868 * @throws InvalidMessageDateException
1869 * @throws MaskNotFoundException
1870 * @throws MessageContentFetchingException
1871 * @throws MessageFlagException
1872 * @throws MessageHeaderFetchingException
1873 * @throws MessageNotFoundException
1874 * @throws ResponseException
1875 * @throws RuntimeException
1876 */
1877 public function testSetAvailableFlags(): void {
1878 $message = $this->getDefaultMessage();
1879
1880 $message->setAvailableFlags(["foo"]);
1881 self::assertSameSize(["foo"], $message->getAvailableFlags());
1882 self::assertEquals("foo", $message->getAvailableFlags()[0]);
1883
1884 // Cleanup
1885 self::assertTrue($message->delete());
1886 }
1887
1888 /**
1889 * Test Message::getSender()
1890 *
1891 * @return void
1892 * @throws AuthFailedException
1893 * @throws ConnectionFailedException
1894 * @throws EventNotFoundException
1895 * @throws FolderFetchingException
1896 * @throws ImapBadRequestException
1897 * @throws ImapServerErrorException
1898 * @throws InvalidMessageDateException
1899 * @throws MaskNotFoundException
1900 * @throws MessageContentFetchingException
1901 * @throws MessageFlagException
1902 * @throws MessageHeaderFetchingException
1903 * @throws MessageNotFoundException
1904 * @throws ResponseException
1905 * @throws RuntimeException
1906 */
1907 public function testGetSender(): void {
1908 $folder = $this->getFolder('INBOX');
1909
1910 $message = $this->appendMessageTemplate($folder, "example_attachment.eml");
1911 self::assertEquals("testsender <[email protected]>", $message->getSender());
1912 self::assertEquals("testsender", $message->getSender()->first()->personal);
1913 self::assertEquals("[email protected]", $message->getSender()->first()->mail);
1914
1915 // Cleanup
1916 self::assertTrue($message->delete());
1917 }
1918
1919 /**
1920 * Test Message::fromFile()
1921 *
1922 * @return void
1923 * @throws AuthFailedException
1924 * @throws ConnectionFailedException
1925 * @throws ImapBadRequestException
1926 * @throws ImapServerErrorException
1927 * @throws InvalidMessageDateException
1928 * @throws MaskNotFoundException
1929 * @throws MessageContentFetchingException
1930 * @throws ReflectionException
1931 * @throws ResponseException
1932 * @throws RuntimeException
1933 */
1934 public function testFromFile(): void {
1935 $this->getManager();
1936 $filename = implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", "[email protected]"]);
1937 $message = Message::fromFile($filename);
1938 self::assertInstanceOf(Message::class, $message);
1939 }
1940
1941 /**
1942 * Test Message::getStructure()
1943 *
1944 * @return void
1945 * @throws AuthFailedException
1946 * @throws ConnectionFailedException
1947 * @throws EventNotFoundException
1948 * @throws FolderFetchingException
1949 * @throws ImapBadRequestException
1950 * @throws ImapServerErrorException
1951 * @throws InvalidMessageDateException
1952 * @throws MaskNotFoundException
1953 * @throws MessageContentFetchingException
1954 * @throws MessageFlagException
1955 * @throws MessageHeaderFetchingException
1956 * @throws MessageNotFoundException
1957 * @throws ResponseException
1958 * @throws RuntimeException
1959 */
1960 public function testGetStructure(): void {
1961 $message = $this->getDefaultMessage();
1962 self::assertInstanceOf(Structure::class, $message->getStructure());
1963
1964 // Cleanup
1965 self::assertTrue($message->delete());
1966 }
1967
1968 /**
1969 * Test Message::get()
1970 *
1971 * @return void
1972 * @throws AuthFailedException
1973 * @throws ConnectionFailedException
1974 * @throws EventNotFoundException
1975 * @throws FolderFetchingException
1976 * @throws ImapBadRequestException
1977 * @throws ImapServerErrorException
1978 * @throws InvalidMessageDateException
1979 * @throws MaskNotFoundException
1980 * @throws MessageContentFetchingException
1981 * @throws MessageFlagException
1982 * @throws MessageHeaderFetchingException
1983 * @throws MessageNotFoundException
1984 * @throws ResponseException
1985 * @throws RuntimeException
1986 * @throws MessageSizeFetchingException
1987 */
1988 public function testGet(): void {
1989 $message = $this->getDefaultMessage();
1990 self::assertEquals("Example", $message->get("subject"));
1991
1992 // Cleanup
1993 self::assertTrue($message->delete());
1994 }
1995
1996 /**
1997 * Test Message::getSize()
1998 *
1999 * @return void
2000 * @throws AuthFailedException
2001 * @throws ConnectionFailedException
2002 * @throws EventNotFoundException
2003 * @throws FolderFetchingException
2004 * @throws ImapBadRequestException
2005 * @throws ImapServerErrorException
2006 * @throws InvalidMessageDateException
2007 * @throws MaskNotFoundException
2008 * @throws MessageContentFetchingException
2009 * @throws MessageFlagException
2010 * @throws MessageHeaderFetchingException
2011 * @throws MessageNotFoundException
2012 * @throws ResponseException
2013 * @throws RuntimeException
2014 */
2015 public function testGetSize(): void {
2016 $message = $this->getDefaultMessage();
2017 self::assertEquals(214, $message->getSize());
2018
2019 // Cleanup
2020 self::assertTrue($message->delete());
2021 }
2022
2023 /**
2024 * Test Message::getHeader()
2025 *
2026 * @return void
2027 * @throws AuthFailedException
2028 * @throws ConnectionFailedException
2029 * @throws EventNotFoundException
2030 * @throws FolderFetchingException
2031 * @throws ImapBadRequestException
2032 * @throws ImapServerErrorException
2033 * @throws InvalidMessageDateException
2034 * @throws MaskNotFoundException
2035 * @throws MessageContentFetchingException
2036 * @throws MessageFlagException
2037 * @throws MessageHeaderFetchingException
2038 * @throws MessageNotFoundException
2039 * @throws ResponseException
2040 * @throws RuntimeException
2041 */
2042 public function testGetHeader(): void {
2043 $message = $this->getDefaultMessage();
2044 self::assertInstanceOf(Header::class, $message->getHeader());
2045
2046 // Cleanup
2047 self::assertTrue($message->delete());
2048 }
2049
2050 /**
2051 * Test Message::getReferences()
2052 *
2053 * @return void
2054 * @throws AuthFailedException
2055 * @throws ConnectionFailedException
2056 * @throws EventNotFoundException
2057 * @throws FolderFetchingException
2058 * @throws ImapBadRequestException
2059 * @throws ImapServerErrorException
2060 * @throws InvalidMessageDateException
2061 * @throws MaskNotFoundException
2062 * @throws MessageContentFetchingException
2063 * @throws MessageFlagException
2064 * @throws MessageHeaderFetchingException
2065 * @throws MessageNotFoundException
2066 * @throws ResponseException
2067 * @throws RuntimeException
2068 */
2069 public function testGetReferences(): void {
2070 $folder = $this->getFolder('INBOX');
2071
2072 $message = $this->appendMessageTemplate($folder, "[email protected]");
2073 self::assertIsArray($message->getReferences()->all());
2074 self::assertEquals("Webklex/php-imap/issues/[email protected]", $message->getReferences()->first());
2075
2076 // Cleanup
2077 self::assertTrue($message->delete());
2078 }
2079
2080 /**
2081 * Test Message::setFolderPath()
2082 *
2083 * @return void
2084 * @throws AuthFailedException
2085 * @throws ConnectionFailedException
2086 * @throws EventNotFoundException
2087 * @throws FolderFetchingException
2088 * @throws ImapBadRequestException
2089 * @throws ImapServerErrorException
2090 * @throws InvalidMessageDateException
2091 * @throws MaskNotFoundException
2092 * @throws MessageContentFetchingException
2093 * @throws MessageFlagException
2094 * @throws MessageHeaderFetchingException
2095 * @throws MessageNotFoundException
2096 * @throws ResponseException
2097 * @throws RuntimeException
2098 */
2099 public function testSetFolderPath(): void {
2100 $message = $this->getDefaultMessage();
2101
2102 $folder_path = $message->getFolderPath();
2103
2104 $message->setFolderPath("foo");
2105 self::assertEquals("foo", $message->getFolderPath());
2106
2107 $message->setFolderPath($folder_path);
2108
2109 // Cleanup
2110 self::assertTrue($message->delete());
2111 }
2112
2113 /**
2114 * Test Message::getTextBody()
2115 *
2116 * @return void
2117 * @throws AuthFailedException
2118 * @throws ConnectionFailedException
2119 * @throws EventNotFoundException
2120 * @throws FolderFetchingException
2121 * @throws ImapBadRequestException
2122 * @throws ImapServerErrorException
2123 * @throws InvalidMessageDateException
2124 * @throws MaskNotFoundException
2125 * @throws MessageContentFetchingException
2126 * @throws MessageFlagException
2127 * @throws MessageHeaderFetchingException
2128 * @throws MessageNotFoundException
2129 * @throws ResponseException
2130 * @throws RuntimeException
2131 */
2132 public function testGetTextBody(): void {
2133 $message = $this->getDefaultMessage();
2134 self::assertIsString($message->getTextBody());
2135
2136 // Cleanup
2137 self::assertTrue($message->delete());
2138 }
2139
2140 /**
2141 * Test Message::move()
2142 *
2143 * @return void
2144 * @throws AuthFailedException
2145 * @throws ConnectionFailedException
2146 * @throws EventNotFoundException
2147 * @throws FolderFetchingException
2148 * @throws ImapBadRequestException
2149 * @throws ImapServerErrorException
2150 * @throws InvalidMessageDateException
2151 * @throws MaskNotFoundException
2152 * @throws MessageContentFetchingException
2153 * @throws MessageFlagException
2154 * @throws MessageHeaderFetchingException
2155 * @throws MessageNotFoundException
2156 * @throws ResponseException
2157 * @throws RuntimeException
2158 */
2159 public function testMove(): void {
2160 $message = $this->getDefaultMessage();
2161 $client = $message->getClient();
2162 self::assertInstanceOf(Client::class, $client);
2163
2164 $delimiter = $this->getManager()->getConfig()->get("options.delimiter");
2165 $folder_path = implode($delimiter, ['INBOX', 'test']);
2166
2167 $folder = $client->getFolder($folder_path);
2168 if ($folder !== null) {
2169 self::assertTrue($this->deleteFolder($folder));
2170 }
2171 $folder = $client->createFolder($folder_path, false);
2172 self::assertInstanceOf(Folder::class, $folder);
2173
2174 $message = $message->move($folder->path, true);
2175 self::assertInstanceOf(Message::class, $message);
2176 self::assertEquals($folder->path, $message->getFolder()->path);
2177
2178 // Cleanup
2179 self::assertTrue($message->delete());
2180 }
2181
2182 /**
2183 * Test Message::getFolderPath()
2184 *
2185 * @return void
2186 * @throws AuthFailedException
2187 * @throws ConnectionFailedException
2188 * @throws EventNotFoundException
2189 * @throws FolderFetchingException
2190 * @throws ImapBadRequestException
2191 * @throws ImapServerErrorException
2192 * @throws InvalidMessageDateException
2193 * @throws MaskNotFoundException
2194 * @throws MessageContentFetchingException
2195 * @throws MessageFlagException
2196 * @throws MessageHeaderFetchingException
2197 * @throws MessageNotFoundException
2198 * @throws ResponseException
2199 * @throws RuntimeException
2200 */
2201 public function testGetFolderPath(): void {
2202 $message = $this->getDefaultMessage();
2203 self::assertEquals("INBOX", $message->getFolderPath());
2204
2205 // Cleanup
2206 self::assertTrue($message->delete());
2207 }
2208
2209 /**
2210 * Test Message::getFolder()
2211 *
2212 * @return void
2213 * @throws AuthFailedException
2214 * @throws ConnectionFailedException
2215 * @throws EventNotFoundException
2216 * @throws FolderFetchingException
2217 * @throws ImapBadRequestException
2218 * @throws ImapServerErrorException
2219 * @throws InvalidMessageDateException
2220 * @throws MaskNotFoundException
2221 * @throws MessageContentFetchingException
2222 * @throws MessageFlagException
2223 * @throws MessageHeaderFetchingException
2224 * @throws MessageNotFoundException
2225 * @throws ResponseException
2226 * @throws RuntimeException
2227 */
2228 public function testGetFolder(): void {
2229 $message = $this->getDefaultMessage();
2230 self::assertInstanceOf(Folder::class, $message->getFolder());
2231
2232 // Cleanup
2233 self::assertTrue($message->delete());
2234 }
2235
2236 /**
2237 * Test Message::getFetchBodyOption()
2238 *
2239 * @return void
2240 * @throws AuthFailedException
2241 * @throws ConnectionFailedException
2242 * @throws EventNotFoundException
2243 * @throws FolderFetchingException
2244 * @throws ImapBadRequestException
2245 * @throws ImapServerErrorException
2246 * @throws InvalidMessageDateException
2247 * @throws MaskNotFoundException
2248 * @throws MessageContentFetchingException
2249 * @throws MessageFlagException
2250 * @throws MessageHeaderFetchingException
2251 * @throws MessageNotFoundException
2252 * @throws ResponseException
2253 * @throws RuntimeException
2254 */
2255 public function testGetFetchBodyOption(): void {
2256 $message = $this->getDefaultMessage();
2257 self::assertTrue($message->getFetchBodyOption());
2258
2259 // Cleanup
2260 self::assertTrue($message->delete());
2261 }
2262
2263 /**
2264 * Test Message::setFetchBodyOption()
2265 *
2266 * @return void
2267 * @throws AuthFailedException
2268 * @throws ConnectionFailedException
2269 * @throws EventNotFoundException
2270 * @throws FolderFetchingException
2271 * @throws ImapBadRequestException
2272 * @throws ImapServerErrorException
2273 * @throws InvalidMessageDateException
2274 * @throws MaskNotFoundException
2275 * @throws MessageContentFetchingException
2276 * @throws MessageFlagException
2277 * @throws MessageHeaderFetchingException
2278 * @throws MessageNotFoundException
2279 * @throws ResponseException
2280 * @throws RuntimeException
2281 */
2282 public function testSetFetchBodyOption(): void {
2283 $message = $this->getDefaultMessage();
2284
2285 $message->setFetchBodyOption(false);
2286 self::assertFalse($message->getFetchBodyOption());
2287
2288 // Cleanup
2289 self::assertTrue($message->delete());
2290 }
2291
2292 /**
2293 * Test Message::getFetchFlagsOption()
2294 *
2295 * @return void
2296 * @throws AuthFailedException
2297 * @throws ConnectionFailedException
2298 * @throws EventNotFoundException
2299 * @throws FolderFetchingException
2300 * @throws ImapBadRequestException
2301 * @throws ImapServerErrorException
2302 * @throws InvalidMessageDateException
2303 * @throws MaskNotFoundException
2304 * @throws MessageContentFetchingException
2305 * @throws MessageFlagException
2306 * @throws MessageHeaderFetchingException
2307 * @throws MessageNotFoundException
2308 * @throws ResponseException
2309 * @throws RuntimeException
2310 */
2311 public function testGetFetchFlagsOption(): void {
2312 $message = $this->getDefaultMessage();
2313 self::assertTrue($message->getFetchFlagsOption());
2314
2315 // Cleanup
2316 self::assertTrue($message->delete());
2317 }
2318
2319 /**
2320 * Test Message::__call()
2321 *
2322 * @return void
2323 * @throws AuthFailedException
2324 * @throws ConnectionFailedException
2325 * @throws EventNotFoundException
2326 * @throws FolderFetchingException
2327 * @throws ImapBadRequestException
2328 * @throws ImapServerErrorException
2329 * @throws InvalidMessageDateException
2330 * @throws MaskNotFoundException
2331 * @throws MessageContentFetchingException
2332 * @throws MessageFlagException
2333 * @throws MessageHeaderFetchingException
2334 * @throws MessageNotFoundException
2335 * @throws ResponseException
2336 * @throws RuntimeException
2337 */
2338 public function test__call(): void {
2339 $message = $this->getDefaultMessage();
2340 self::assertEquals("Example", $message->getSubject());
2341
2342 // Cleanup
2343 self::assertTrue($message->delete());
2344 }
2345
2346 /**
2347 * Test Message::setClient()
2348 *
2349 * @return void
2350 * @throws AuthFailedException
2351 * @throws ConnectionFailedException
2352 * @throws EventNotFoundException
2353 * @throws FolderFetchingException
2354 * @throws ImapBadRequestException
2355 * @throws ImapServerErrorException
2356 * @throws InvalidMessageDateException
2357 * @throws MaskNotFoundException
2358 * @throws MessageContentFetchingException
2359 * @throws MessageFlagException
2360 * @throws MessageHeaderFetchingException
2361 * @throws MessageNotFoundException
2362 * @throws ResponseException
2363 * @throws RuntimeException
2364 */
2365 public function testSetClient(): void {
2366 $message = $this->getDefaultMessage();
2367 $client = $message->getClient();
2368 self::assertInstanceOf(Client::class, $client);
2369
2370 $message->setClient(null);
2371 self::assertNull($message->getClient());
2372
2373 $message->setClient($client);
2374 self::assertInstanceOf(Client::class, $message->getClient());
2375
2376 // Cleanup
2377 self::assertTrue($message->delete());
2378 }
2379
2380 /**
2381 * Test Message::setMsgn()
2382 *
2383 * @return void
2384 * @throws AuthFailedException
2385 * @throws ConnectionFailedException
2386 * @throws EventNotFoundException
2387 * @throws FolderFetchingException
2388 * @throws ImapBadRequestException
2389 * @throws ImapServerErrorException
2390 * @throws InvalidMessageDateException
2391 * @throws MaskNotFoundException
2392 * @throws MessageContentFetchingException
2393 * @throws MessageFlagException
2394 * @throws MessageHeaderFetchingException
2395 * @throws MessageNotFoundException
2396 * @throws ResponseException
2397 * @throws RuntimeException
2398 */
2399 public function testSetMsgn(): void {
2400 $message = $this->getDefaultMessage();
2401
2402 $uid = $message->getUid();
2403 $message->setMsgn(789);
2404 self::assertEquals(789, $message->getMsgn());
2405 $message->setUid($uid);
2406
2407 // Cleanup
2408 self::assertTrue($message->delete());
2409 }
2410 }