-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMessageTest.php
More file actions
147 lines (111 loc) · 4.52 KB
/
MessageTest.php
File metadata and controls
147 lines (111 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
use DirectoryTree\ImapEngine\Connection\ImapConnection;
use DirectoryTree\ImapEngine\Enums\ImapFlag;
use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException;
use DirectoryTree\ImapEngine\Folder;
use DirectoryTree\ImapEngine\Mailbox;
use DirectoryTree\ImapEngine\Message;
test('it moves message using MOVE when capable and returns the new UID', function () {
$mailbox = Mailbox::make([
'username' => 'foo',
'password' => 'bar',
]);
$mailbox->connect(ImapConnection::fake([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'* CAPABILITY IMAP4rev1 STARTTLS MOVE AUTH=PLAIN',
'TAG2 OK CAPABILITY completed',
'TAG3 OK [COPYUID 1234567890 1 42] MOVE completed',
]));
$folder = new Folder($mailbox, 'INBOX', [], '/');
$message = new Message($folder, 1, [], 'header', 'body');
$newUid = $message->move('INBOX.Sent');
expect($newUid)->toBe(42);
});
test('it copies and then deletes message using UIDPLUS when incapable of MOVE and returns the new UID', function () {
$mailbox = Mailbox::make([
'username' => 'foo',
'password' => 'bar',
]);
$mailbox->connect(ImapConnection::fake([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'* CAPABILITY IMAP4rev1 STARTTLS UIDPLUS AUTH=PLAIN',
'TAG2 OK CAPABILITY completed',
'TAG3 OK [COPYUID 1234567890 1 123] COPY completed',
'TAG4 OK STORE completed',
]));
$folder = new Folder($mailbox, 'INBOX', [], '/');
$message = new Message($folder, 1, [], 'header', 'body');
$newUid = $message->move('INBOX.Sent');
expect($newUid)->toBe(123);
});
test('it throws exception when server does not support MOVE or UIDPLUS capabilities', function () {
$mailbox = Mailbox::make([
'username' => 'foo',
'password' => 'bar',
]);
$mailbox->connect(ImapConnection::fake([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN',
'TAG2 OK CAPABILITY completed',
]));
$folder = new Folder($mailbox, 'INBOX', [], '/');
$message = new Message($folder, 1, [], 'header', 'body');
$message->move('INBOX.Sent');
})->throws(ImapCapabilityException::class);
test('it can mark and unmark a message as flagged', function () {
$mailbox = Mailbox::make([
'username' => 'foo',
'password' => 'bar',
]);
$mailbox->connect(ImapConnection::fake([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
'* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN',
'TAG2 OK CAPABILITY completed',
'TAG3 OK STORE completed',
]));
$folder = new Folder($mailbox, 'INBOX', [], '/');
$message = new Message($folder, 1, [], 'header', 'body');
expect($message->isFlagged())->toBeFalse();
expect($message->flags())->not->toContain('\\Flagged');
$message->markFlagged();
expect($message->isFlagged())->toBeTrue();
expect($message->flags())->toContain('\\Flagged');
expect($message->hasFlag(ImapFlag::Flagged))->toBeTrue();
$message->unmarkFlagged();
expect($message->isFlagged())->toBeFalse();
expect($message->flags())->not->toContain('\\Flagged');
expect($message->hasFlag(ImapFlag::Flagged))->toBeFalse();
});
test('it can determine if two messages are the same', function () {
$mailbox = Mailbox::make([
'username' => 'foo',
'password' => 'bar',
]);
$mailbox->connect(ImapConnection::fake([
'* OK Welcome to IMAP',
'TAG1 OK Logged in',
]));
$folder1 = new Folder($mailbox, 'INBOX', [], '/');
$folder2 = new Folder($mailbox, 'INBOX.Sent', [], '/');
// Create messages with different properties
$message1 = new Message($folder1, 1, [], 'header1', 'body1');
$message2 = new Message($folder1, 1, [], 'header1', 'body1'); // Same as message1
$message3 = new Message($folder1, 2, [], 'header1', 'body1'); // Different UID
$message4 = new Message($folder2, 1, [], 'header1', 'body1'); // Different folder
$message5 = new Message($folder1, 1, [], 'header2', 'body1'); // Different header
$message6 = new Message($folder1, 1, [], 'header1', 'body2'); // Different body
// Same message
expect($message1->is($message2))->toBeTrue();
// Different UID
expect($message1->is($message3))->toBeFalse();
// Different folder
expect($message1->is($message4))->toBeFalse();
// Different header
expect($message1->is($message5))->toBeFalse();
// Different body
expect($message1->is($message6))->toBeFalse();
});