Debian Codegraph @

cassandane/Cassandane/Cyrus/InProgress.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2023 FastMail Pty Ltd. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
15 # distribution.
16 #
17 # 3. The name "Fastmail Pty Ltd" must not be used to
18 # endorse or promote products derived from this software without
19 # prior written permission. For permission or any legal
20 # details, please contact
21 # FastMail Pty Ltd
22 # PO Box 234
23 # Collins St West 8007
24 # Victoria
25 # Australia
26 #
27 # 4. Redistributions of any form whatsoever must retain the following
28 # acknowledgment:
29 # "This product includes software developed by Fastmail Pty. Ltd."
30 #
31 # FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
32 # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
33 # EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT
34 # OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
35 # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
36 # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
37 # OF THIS SOFTWARE.
38 #
39
40 package Cassandane::Cyrus::InProgress;
41 use strict;
42 use warnings;
43 use DateTime;
44 use JSON;
45 use JSON::XS;
46 use Mail::JMAPTalk 0.13;
47 use Data::Dumper;
48 use Storable 'dclone';
49 use File::Basename;
50 use IO::File;
51 use Cwd qw(abs_path getcwd);
52
53 use lib '.';
54 use base qw(Cassandane::Cyrus::TestCase);
55 use Cassandane::Util::Log;
56
57 use charnames ':full';
58
59 sub new
60 {
61 my $class = shift;
62
63 my $config = Cassandane::Config->default()->clone();
64 $config->set(mailbox_legacy_dirs => 'yes');
65 $config->set(singleinstancestore => 'no');
66 $config->set(imap_inprogress_interval => '1s');
67
68 my $self = $class->SUPER::new({
69 adminstore => 1,
70 config => $config,
71 services => ['imap'],
72 }, @_);
73
74 $self->needs('component', 'slowio');
75 return $self;
76 }
77
78 sub set_up
79 {
80 my ($self) = @_;
81 $self->SUPER::set_up();
82 }
83
84 sub tear_down
85 {
86 my ($self) = @_;
87 $self->SUPER::tear_down();
88 }
89
90 sub test_xrename
91 :SlowIO :NoAltNameSpace
92 {
93 my ($self) = @_;
94
95 my @resp;
96 my %handlers =
97 (
98 ok => sub
99 {
100 my (undef, $ok) = @_;
101 push(@resp, $ok);
102 },
103 );
104
105 xlog $self, "Create some personal folders";
106 my $talk = $self->{store}->get_client();
107 $self->setup_mailbox_structure($talk, [
108 [ 'create' => [qw( INBOX.src INBOX.src.child INBOX.src.child.grand)] ],
109 ]);
110
111 xlog $self, "rename mailbox tree";
112 @resp = ();
113 $talk->_imap_cmd('XRENAME', 0, \%handlers, "INBOX.src", "INBOX.dst");
114 $self->assert_str_equals('ok', $talk->get_last_completion_response());
115 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
116 # we shouldn't have a count or total
117 $self->assert_null($resp[0][1][1]);
118 $self->assert_null($resp[0][1][2]);
119 $self->assert_str_equals('rename', $resp[0][3]);
120 $self->assert_str_equals('INBOX.src', $resp[0][4]);
121 $self->assert_str_equals('INBOX.dst', $resp[0][5]);
122 $self->assert_str_equals('INBOX.src.child', $resp[1][4]);
123 $self->assert_str_equals('INBOX.dst.child', $resp[1][5]);
124 $self->assert_str_equals('INBOX.src.child.grand', $resp[2][4]);
125 $self->assert_str_equals('INBOX.dst.child.grand', $resp[2][5]);
126 }
127
128 sub test_copy
129 :SlowIO :NoAltNameSpace
130 {
131 my ($self) = @_;
132
133 my @resp;
134 my %handlers =
135 (
136 ok => sub
137 {
138 my (undef, $ok) = @_;
139 push(@resp, $ok);
140 },
141 );
142
143 xlog "generate some test messages";
144 foreach (1..100) {
145 $self->make_message("Message $_", size => 128_000);
146 }
147
148 xlog $self, "Create another folder";
149 my $talk = $self->{store}->get_client();
150 $talk->create("INBOX.dst");
151 $self->assert_str_equals('ok', $talk->get_last_completion_response());
152
153 xlog $self, "copy messages";
154 @resp = ();
155 $talk->select("INBOX");
156 $talk->_imap_cmd('COPY', 0, \%handlers, '1:100', 'INBOX.dst');
157 $self->assert_str_equals('ok', $talk->get_last_completion_response());
158 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
159 # we don't know what the exact count will be, be we know the total
160 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
161 $self->assert_str_equals('100', $resp[0][1][2]);
162 }
163
164 sub test_search
165 :SlowIO :NoAltNameSpace
166 {
167 my ($self) = @_;
168
169 my @resp;
170 my %handlers =
171 (
172 ok => sub
173 {
174 my (undef, $ok) = @_;
175 push(@resp, $ok);
176 },
177 );
178
179 xlog "generate some test messages";
180 foreach (1..100) {
181 $self->make_message("Message $_", size => 128_000);
182 }
183
184 xlog $self, "search messages";
185 my $talk = $self->{store}->get_client();
186 @resp = ();
187 $talk->_imap_cmd('SEARCH', 0, \%handlers, 'RETURN', '(PARTIAL -1:-500)', '1:100', 'BODY', 'needle');
188 $self->assert_str_equals('ok', $talk->get_last_completion_response());
189 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
190 # we don't know what the exact count will be, be we know the total
191 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
192 $self->assert_str_equals('100', $resp[0][1][2]);
193 }
194
195 sub test_esearch_selected
196 :SlowIO :NoAltNameSpace
197 {
198 my ($self) = @_;
199
200 my @resp;
201 my %handlers =
202 (
203 ok => sub
204 {
205 my (undef, $ok) = @_;
206 push(@resp, $ok);
207 },
208 );
209
210 xlog "generate some test messages";
211 foreach (1..100) {
212 $self->make_message("Message $_", size => 128_000);
213 }
214
215 xlog $self, "esearch selected mailbox";
216 my $talk = $self->{store}->get_client();
217 @resp = ();
218 $talk->_imap_cmd('ESEARCH', 0, \%handlers,
219 'IN', '(SELECTED)', '1:100', 'BODY', 'needle');
220 $self->assert_str_equals('ok', $talk->get_last_completion_response());
221 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
222 # we don't know what the exact count will be, be we know the total
223 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
224 $self->assert_str_equals('100', $resp[0][1][2]);
225 }
226
227 sub test_esearch_multiple
228 :SlowIO :NoAltNameSpace
229 {
230 my ($self) = @_;
231
232 my @resp;
233 my %handlers =
234 (
235 ok => sub
236 {
237 my (undef, $ok) = @_;
238 push(@resp, $ok);
239 },
240 );
241
242 xlog "generate some test messages";
243 foreach (1..100) {
244 $self->make_message("Message $_", size => 128_000);
245 }
246
247 xlog $self, "Create another folder";
248 my $talk = $self->{store}->get_client();
249 $talk->create("INBOX.dst");
250 $self->assert_str_equals('ok', $talk->get_last_completion_response());
251
252 xlog $self, "copy messages";
253 @resp = ();
254 $talk->select("INBOX");
255 $talk->_imap_cmd('COPY', 0, \%handlers, '1:100', 'INBOX.dst');
256 $self->assert_str_equals('ok', $talk->get_last_completion_response());
257 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
258 # we don't know what the exact count will be, be we know the total
259 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
260 $self->assert_str_equals('100', $resp[0][1][2]);
261
262 xlog $self, "esearch multiple mailboxes";
263 @resp = ();
264 $talk->_imap_cmd('ESEARCH', 0, \%handlers,
265 'IN', '(PERSONAL)', '1:100', 'BODY', 'needle');
266 $self->assert_str_equals('ok', $talk->get_last_completion_response());
267 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
268 # we shouldn't have a count or total
269 $self->assert_null($resp[0][1][1]);
270 $self->assert_null($resp[0][1][2]);
271 }
272
273 sub test_sort
274 :SlowIO :NoAltNameSpace
275 {
276 my ($self) = @_;
277
278 my @resp;
279 my %handlers =
280 (
281 ok => sub
282 {
283 my (undef, $ok) = @_;
284 push(@resp, $ok);
285 },
286 );
287
288 xlog "generate some test messages";
289 foreach (1..100) {
290 $self->make_message("Message $_", size => 128_000);
291 }
292
293 xlog $self, "sort messages";
294 my $talk = $self->{store}->get_client();
295 @resp = ();
296 $talk->_imap_cmd('SORT', 0, \%handlers,
297 '(ARRIVAL)', 'US-ASCII', '1:100', 'BODY', 'needle');
298 $self->assert_str_equals('ok', $talk->get_last_completion_response());
299 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
300 # we don't know what the exact count will be, be we know the total
301 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
302 $self->assert_str_equals('100', $resp[0][1][2]);
303 }
304
305 sub test_thread
306 :SlowIO :NoAltNameSpace
307 {
308 my ($self) = @_;
309
310 my @resp;
311 my %handlers =
312 (
313 ok => sub
314 {
315 my (undef, $ok) = @_;
316 push(@resp, $ok);
317 },
318 );
319
320 xlog "generate some test messages";
321 foreach (1..100) {
322 $self->make_message("Message $_", size => 128_000);
323 }
324
325 xlog $self, "thread messages";
326 my $talk = $self->{store}->get_client();
327 @resp = ();
328 $talk->_imap_cmd('THREAD', 0, \%handlers,
329 'REFERENCES', 'US-ASCII', '1:100', 'BODY', 'needle');
330 $self->assert_str_equals('ok', $talk->get_last_completion_response());
331 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
332 # we don't know what the exact count will be, be we know the total
333 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
334 $self->assert_str_equals('100', $resp[0][1][2]);
335 }
336
337 sub test_rename
338 :SlowIO :NoAltNameSpace
339 {
340 my ($self) = @_;
341
342 my @resp;
343 my %handlers =
344 (
345 ok => sub
346 {
347 my (undef, $ok) = @_;
348 push(@resp, $ok);
349 },
350 );
351
352 xlog "generate some test messages";
353 foreach (1..100) {
354 $self->make_message("Message $_", size => 128_000);
355 }
356
357 xlog $self, "rename INBOX";
358 my $talk = $self->{store}->get_client();
359 @resp = ();
360 $talk->_imap_cmd('RENAME', 0, \%handlers, 'INBOX', 'INBOX.Archive');
361 $self->assert_str_equals('ok', $talk->get_last_completion_response());
362 $self->assert_str_equals('[INPROGRESS', $resp[0][0]);
363 # we don't know what the exact count will be, be we know the total
364 $self->assert_matches(qr/^[0-9]+$/, $resp[0][1][1]);
365 $self->assert_str_equals('100', $resp[0][1][2]);
366 }
367
368 1;