| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Copyright (c) 2011-2017 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::Conversations; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
use DateTime; |
| 44 |
use URI::Escape; |
| 45 |
|
| 46 |
use lib '.'; |
| 47 |
use base qw(Cassandane::Cyrus::TestCase); |
| 48 |
use Cassandane::ThreadedGenerator; |
| 49 |
use Cassandane::Util::Log; |
| 50 |
use Cassandane::Util::DateTime qw(to_iso8601 from_iso8601 |
| 51 |
from_rfc822 |
| 52 |
to_rfc3501 from_rfc3501); |
| 53 |
|
| 54 |
use lib '../perl/imap'; |
| 55 |
use Cyrus::IndexFile; |
| 56 |
|
| 57 |
sub new |
| 58 |
{ |
| 59 |
my ($class, @args) = @_; |
| 60 |
my $config = Cassandane::Config->default()->clone(); |
| 61 |
|
| 62 |
my $buildinfo = Cassandane::BuildInfo->new(); |
| 63 |
|
| 64 |
# if we're gonna try and run jmap tests, set up config for it |
| 65 |
if ($buildinfo->get('component', 'jmap')) { |
| 66 |
$config->set(caldav_realm => 'Cassandane', |
| 67 |
conversations => 'yes', |
| 68 |
conversations_counted_flags => "\\Draft \\Flagged \$IsMailingList \$IsNotification \$HasAttachment", |
| 69 |
jmapsubmission_deleteonsend => 'no', |
| 70 |
ctl_conversationsdb_conversations_max_thread => 5, |
| 71 |
httpmodules => 'carddav caldav jmap', |
| 72 |
httpallowcompress => 'no'); |
| 73 |
|
| 74 |
return $class->SUPER::new({ |
| 75 |
config => $config, |
| 76 |
jmap => 1, |
| 77 |
adminstore => 1, |
| 78 |
services => [ 'imap', 'http' ] |
| 79 |
}, @args); |
| 80 |
} |
| 81 |
else { |
| 82 |
$config->set(conversations => 'yes', |
| 83 |
conversations_counted_flags => "\\Draft \\Flagged \$IsMailingList \$IsNotification \$HasAttachment", |
| 84 |
ctl_conversationsdb_conversations_max_thread => 5); |
| 85 |
|
| 86 |
return $class->SUPER::new({ |
| 87 |
config => $config, |
| 88 |
adminstore => 1, |
| 89 |
}, @args); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
sub set_up |
| 94 |
{ |
| 95 |
my ($self) = @_; |
| 96 |
$self->SUPER::set_up(); |
| 97 |
my ($maj, $min) = Cassandane::Instance->get_version(); |
| 98 |
|
| 99 |
# basecid was added after 3.0 |
| 100 |
if ($maj > 3 or ($maj == 3 and $min > 0)) { |
| 101 |
$self->{store}->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 102 |
} |
| 103 |
else { |
| 104 |
$self->{store}->set_fetch_attributes('uid', 'cid'); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
sub tear_down |
| 109 |
{ |
| 110 |
my ($self) = @_; |
| 111 |
$self->SUPER::tear_down(); |
| 112 |
} |
| 113 |
|
| 114 |
# The resulting CID when a clash happens is supposed to be |
| 115 |
# the MAXIMUM of all the CIDs. Here we use the fact that |
| 116 |
# CIDs are expressed in a form where lexical order is the |
| 117 |
# same as numeric order. |
| 118 |
sub choose_cid |
| 119 |
{ |
| 120 |
my (@cids) = @_; |
| 121 |
@cids = sort { $b cmp $a } @cids; |
| 122 |
return $cids[0]; |
| 123 |
} |
| 124 |
|
| 125 |
# |
| 126 |
# Test APPEND of messages to IMAP |
| 127 |
# |
| 128 |
sub test_append |
| 129 |
:min_version_3_0 |
| 130 |
{ |
| 131 |
my ($self) = @_; |
| 132 |
my %exp; |
| 133 |
|
| 134 |
# check IMAP server has the XCONVERSATIONS capability |
| 135 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 136 |
|
| 137 |
xlog $self, "generating message A"; |
| 138 |
$exp{A} = $self->make_message("Message A"); |
| 139 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 140 |
$self->check_messages(\%exp); |
| 141 |
|
| 142 |
xlog $self, "generating message B"; |
| 143 |
$exp{B} = $self->make_message("Message B"); |
| 144 |
$exp{B}->set_attributes(uid => 2, cid => $exp{B}->make_cid()); |
| 145 |
$self->check_messages(\%exp); |
| 146 |
|
| 147 |
xlog $self, "generating message C"; |
| 148 |
$exp{C} = $self->make_message("Message C"); |
| 149 |
$exp{C}->set_attributes(uid => 3, cid => $exp{C}->make_cid()); |
| 150 |
my $actual = $self->check_messages(\%exp); |
| 151 |
|
| 152 |
xlog $self, "generating message D"; |
| 153 |
$exp{D} = $self->make_message("Message D"); |
| 154 |
$exp{D}->set_attributes(uid => 4, cid => $exp{D}->make_cid()); |
| 155 |
$self->check_messages(\%exp); |
| 156 |
} |
| 157 |
|
| 158 |
# |
| 159 |
# Test APPEND of messages to IMAP |
| 160 |
# |
| 161 |
sub test_append_reply |
| 162 |
:min_version_3_0 |
| 163 |
{ |
| 164 |
my ($self) = @_; |
| 165 |
my %exp; |
| 166 |
|
| 167 |
# check IMAP server has the XCONVERSATIONS capability |
| 168 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 169 |
|
| 170 |
xlog $self, "generating message A"; |
| 171 |
$exp{A} = $self->make_message("Message A"); |
| 172 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 173 |
$self->check_messages(\%exp); |
| 174 |
|
| 175 |
xlog $self, "generating message B"; |
| 176 |
$exp{B} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 177 |
$exp{B}->set_attributes(uid => 2, cid => $exp{A}->make_cid()); |
| 178 |
$self->check_messages(\%exp); |
| 179 |
} |
| 180 |
|
| 181 |
# |
| 182 |
# Test APPEND of messages to IMAP |
| 183 |
# |
| 184 |
sub test_append_reply_200 |
| 185 |
:min_version_3_1 |
| 186 |
{ |
| 187 |
my ($self) = @_; |
| 188 |
my %exp; |
| 189 |
|
| 190 |
# check IMAP server has the XCONVERSATIONS capability |
| 191 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 192 |
|
| 193 |
xlog $self, "generating message A"; |
| 194 |
$exp{A} = $self->make_message("Message A"); |
| 195 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 196 |
$self->check_messages(\%exp); |
| 197 |
|
| 198 |
xlog $self, "generating replies"; |
| 199 |
for (1..99) { |
| 200 |
$exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 201 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 202 |
} |
| 203 |
$exp{"B"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 204 |
$exp{"B"}->set_attributes(uid => 101, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 205 |
for (1..99) { |
| 206 |
$exp{"B$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 207 |
$exp{"B$_"}->set_attributes(uid => 101+$_, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 208 |
} |
| 209 |
$exp{"C"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 210 |
$exp{"C"}->set_attributes(uid => 201, cid => $exp{C}->make_cid(), basecid => $exp{A}->make_cid()); |
| 211 |
|
| 212 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 213 |
} |
| 214 |
|
| 215 |
# |
| 216 |
# Test MOVE of messages after conversation split |
| 217 |
# |
| 218 |
sub test_move_200 |
| 219 |
:min_version_3_1 |
| 220 |
{ |
| 221 |
my ($self) = @_; |
| 222 |
my %exp; |
| 223 |
|
| 224 |
# check IMAP server has the XCONVERSATIONS capability |
| 225 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 226 |
|
| 227 |
xlog $self, "generating message A"; |
| 228 |
$exp{A} = $self->make_message("Message A"); |
| 229 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 230 |
$self->check_messages(\%exp); |
| 231 |
|
| 232 |
xlog $self, "generating replies"; |
| 233 |
for (1..99) { |
| 234 |
$exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 235 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 236 |
} |
| 237 |
$exp{"B"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 238 |
$exp{"B"}->set_attributes(uid => 101, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 239 |
for (1..99) { |
| 240 |
$exp{"B$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 241 |
$exp{"B$_"}->set_attributes(uid => 101+$_, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 242 |
} |
| 243 |
$exp{"C"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 244 |
$exp{"C"}->set_attributes(uid => 201, cid => $exp{C}->make_cid(), basecid => $exp{A}->make_cid()); |
| 245 |
|
| 246 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 247 |
|
| 248 |
my $talk = $self->{store}->get_client(); |
| 249 |
|
| 250 |
$talk->create("INBOX.foo"); |
| 251 |
$talk->select("INBOX"); |
| 252 |
# NOTE: 110 here becomes 109 after '9' is already moved |
| 253 |
$talk->fetch('9,110', '(emailid threadid)'); |
| 254 |
$talk->move('9', "INBOX.foo"); |
| 255 |
$talk->move('109', "INBOX.foo"); |
| 256 |
$talk->select("INBOX.foo"); |
| 257 |
my $res = $talk->fetch('1:2', '(emailid threadid)'); |
| 258 |
my $emailid1 = $res->{1}{emailid}[0]; |
| 259 |
my $threadid1 = $res->{1}{threadid}[0]; |
| 260 |
my $emailid2 = $res->{2}{emailid}[0]; |
| 261 |
my $threadid2 = $res->{2}{threadid}[0]; |
| 262 |
$self->assert_str_equals($threadid1, 'T' . $exp{A}->make_cid()); |
| 263 |
$self->assert_str_equals($threadid2, 'T' . $exp{B}->make_cid()); |
| 264 |
|
| 265 |
# XXX probably should split the jmap stuff below into a separate |
| 266 |
# XXX test, so we can just mark it :needs_component_jmap instead |
| 267 |
# XXX of hacking it up like this... :) |
| 268 |
my $buildinfo = Cassandane::BuildInfo->new(); |
| 269 |
if (not $buildinfo->get('component', 'jmap')) { |
| 270 |
return; |
| 271 |
} |
| 272 |
|
| 273 |
my $jmap = $self->{jmap}; |
| 274 |
xlog $self, "create bar mailbox"; |
| 275 |
$res = $jmap->CallMethods([ |
| 276 |
['Mailbox/set', { create => { "1" => { |
| 277 |
name => "bar", |
| 278 |
}}}, "R1"] |
| 279 |
]); |
| 280 |
$self->assert_str_equals('Mailbox/set', $res->[0][0]); |
| 281 |
$self->assert_str_equals('R1', $res->[0][2]); |
| 282 |
$self->assert_not_null($res->[0][1]{created}); |
| 283 |
my $bar = $res->[0][1]{created}{"1"}{id}; |
| 284 |
|
| 285 |
$res = $jmap->CallMethods([ |
| 286 |
['Email/set', { update => { |
| 287 |
$emailid1 => { mailboxIds => { $bar => $JSON::true } }, |
| 288 |
$emailid2 => { mailboxIds => { $bar => $JSON::true } }, |
| 289 |
}}, "R1"] |
| 290 |
]); |
| 291 |
|
| 292 |
$self->assert_str_equals('Email/set', $res->[0][0]); |
| 293 |
$self->assert(exists $res->[0][1]{updated}{$emailid1}); |
| 294 |
$self->assert(exists $res->[0][1]{updated}{$emailid2}); |
| 295 |
$self->assert_str_equals('R1', $res->[0][2]); |
| 296 |
|
| 297 |
$res = $jmap->CallMethods([ |
| 298 |
['Email/get', { ids => [$emailid1,$emailid2], properties => ['threadId'] |
| 299 |
}, "R1"] |
| 300 |
]); |
| 301 |
|
| 302 |
$self->assert_str_equals('Email/get', $res->[0][0]); |
| 303 |
$self->assert_str_equals('R1', $res->[0][2]); |
| 304 |
my %map = map { $_->{id} => $_->{threadId} } @{$res->[0][1]{list}}; |
| 305 |
$self->assert_str_equals($map{$emailid1}, $threadid1); |
| 306 |
$self->assert_str_equals($map{$emailid2}, $threadid2); |
| 307 |
} |
| 308 |
|
| 309 |
# |
| 310 |
# Test normalisation of Subjects containing nonascii whitespace |
| 311 |
# |
| 312 |
# At present, non-breaking space is the only nonascii whitespace |
| 313 |
# our normalisation supports |
| 314 |
# |
| 315 |
# The normalisation function is properly tested in the cunit tests, |
| 316 |
# but we need a test out here too to verify that it works when |
| 317 |
# decoded from the real world! |
| 318 |
# |
| 319 |
sub test_normalise_nonascii_whitespace |
| 320 |
:min_version_3_0 |
| 321 |
{ |
| 322 |
my ($self) = @_; |
| 323 |
my %exp; |
| 324 |
|
| 325 |
# check IMAP server has the XCONVERSATIONS capability |
| 326 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 327 |
|
| 328 |
xlog $self, "generating message A"; |
| 329 |
# we saw in the wild a message with an encoded nbsp in the subject... |
| 330 |
$exp{A} = $self->make_message("=?UTF-8?Q?hello=C2=A0there?="); |
| 331 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 332 |
$self->check_messages(\%exp); |
| 333 |
|
| 334 |
xlog $self, "generating message B"; |
| 335 |
# ... but the reply had replaced this with a normal space |
| 336 |
$exp{B} = $self->make_message("Re: hello there", references => [ $exp{A} ]); |
| 337 |
$exp{B}->set_attributes(uid => 2, cid => $exp{A}->make_cid()); |
| 338 |
$self->check_messages(\%exp); |
| 339 |
} |
| 340 |
|
| 341 |
# |
| 342 |
# test reconstruct of larger conversation |
| 343 |
# |
| 344 |
sub test_reconstruct_splitconv |
| 345 |
:min_version_3_1 |
| 346 |
{ |
| 347 |
my ($self) = @_; |
| 348 |
my %exp; |
| 349 |
|
| 350 |
my $talk = $self->{store}->get_client(); |
| 351 |
|
| 352 |
# check IMAP server has the XCONVERSATIONS capability |
| 353 |
$self->assert($talk->capability()->{xconversations}); |
| 354 |
|
| 355 |
xlog $self, "generating message A"; |
| 356 |
$exp{A} = $self->make_message("Message A"); |
| 357 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 358 |
$self->check_messages(\%exp); |
| 359 |
|
| 360 |
xlog $self, "generating replies"; |
| 361 |
for (1..20) { |
| 362 |
$exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ]); |
| 363 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 364 |
} |
| 365 |
|
| 366 |
$talk->create('foo'); |
| 367 |
$talk->copy('1:*', 'foo'); |
| 368 |
|
| 369 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 370 |
|
| 371 |
# first run WITHOUT splitting |
| 372 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-R', '-r'); |
| 373 |
|
| 374 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 375 |
$talk->select("foo"); |
| 376 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 377 |
$talk->select("INBOX"); |
| 378 |
|
| 379 |
# then run WITH splitting, and see the changed CIDs |
| 380 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-R', '-r', '-S'); |
| 381 |
|
| 382 |
for (5..9) { |
| 383 |
$exp{"A$_"}->set_attributes(cid => $exp{"A5"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 384 |
} |
| 385 |
for (10..14) { |
| 386 |
$exp{"A$_"}->set_attributes(cid => $exp{"A10"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 387 |
} |
| 388 |
for (15..19) { |
| 389 |
$exp{"A$_"}->set_attributes(cid => $exp{"A15"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 390 |
} |
| 391 |
$exp{"A20"}->set_attributes(cid => $exp{"A20"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 392 |
|
| 393 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 394 |
$talk->select("foo"); |
| 395 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 396 |
$talk->select("INBOX"); |
| 397 |
|
| 398 |
# zero everything out |
| 399 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-z', 'cassandane'); |
| 400 |
|
| 401 |
# rebuild |
| 402 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-b', 'cassandane'); |
| 403 |
|
| 404 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 405 |
$talk->select("foo"); |
| 406 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 407 |
$talk->select("INBOX"); |
| 408 |
|
| 409 |
# support for -Z was added after 3.8 |
| 410 |
my ($maj, $min) = Cassandane::Instance->get_version(); |
| 411 |
return if ($maj < 3 or ($maj == 3 and $min < 8)); |
| 412 |
|
| 413 |
# zero out ONLY two CIDs |
| 414 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', |
| 415 |
'-Z' => $exp{"A15"}->make_cid(), |
| 416 |
'-Z' => $exp{"A10"}->make_cid(), |
| 417 |
'cassandane'); |
| 418 |
for (10..19) { |
| 419 |
$exp{"A$_"}->set_attributes(cid => undef, basecid => undef); |
| 420 |
} |
| 421 |
|
| 422 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 423 |
$talk->select("foo"); |
| 424 |
$self->check_messages(\%exp, keyed_on => 'uid'); |
| 425 |
$talk->select("INBOX"); |
| 426 |
} |
| 427 |
|
| 428 |
# |
| 429 |
# test clearing the modseq |
| 430 |
# |
| 431 |
sub test_clearmodseq |
| 432 |
:min_version_3_1 |
| 433 |
{ |
| 434 |
my ($self) = @_; |
| 435 |
|
| 436 |
my $talk = $self->{store}->get_client(); |
| 437 |
|
| 438 |
# check IMAP server has the XCONVERSATIONS capability |
| 439 |
$self->assert($talk->capability()->{xconversations}); |
| 440 |
|
| 441 |
my $admintalk = $self->{adminstore}->get_client(); |
| 442 |
$admintalk->setquota('user.cassandane', ['STORAGE', 500000]); |
| 443 |
|
| 444 |
for (1..20) { |
| 445 |
$self->make_message("Message A$_"); |
| 446 |
} |
| 447 |
|
| 448 |
my $precounters = $self->{store}->get_counters(); |
| 449 |
# we've made a bunch of changes, this should be more than 10! |
| 450 |
$self->assert($precounters->{highestmodseq} > 10, "$precounters->{highestmodseq} > 10"); |
| 451 |
|
| 452 |
# zero out the modseqs |
| 453 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-M', 'cassandane'); |
| 454 |
|
| 455 |
my $midcounters = $self->{store}->get_counters(); |
| 456 |
# we haven't made any changes, should actually be zero! |
| 457 |
$self->assert($midcounters->{highestmodseq} < 10, "$midcounters->{highestmodseq} < 10"); |
| 458 |
|
| 459 |
$self->make_message("Message B1"); |
| 460 |
$self->make_message("Message B2"); |
| 461 |
|
| 462 |
my $postcounters = $self->{store}->get_counters(); |
| 463 |
# we've only created two more emails, it shouldn't have bounced higher |
| 464 |
$self->assert($postcounters->{highestmodseq} < 10, "$postcounters->{highestmodseq} < 10"); |
| 465 |
|
| 466 |
} |
| 467 |
|
| 468 |
# |
| 469 |
# Test APPEND of messages to IMAP |
| 470 |
# |
| 471 |
sub _munge_annot_crc |
| 472 |
{ |
| 473 |
my ($instance, $file, $value) = @_; |
| 474 |
|
| 475 |
# this needs a bit of magic to know where to write... so |
| 476 |
# we do some hard-coded cyrus.index handling |
| 477 |
my $fh = IO::File->new($file, "+<"); |
| 478 |
die "NO SUCH FILE $file" unless $fh; |
| 479 |
my $index = Cyrus::IndexFile->new($fh); |
| 480 |
|
| 481 |
my $header = $index->header(); |
| 482 |
$header->{SyncCRCsAnnot} = $value; |
| 483 |
$index->rewrite_header($header); |
| 484 |
|
| 485 |
$fh->close(); |
| 486 |
} |
| 487 |
sub test_replication_reply_200 |
| 488 |
:min_version_3_1 :needs_component_replication |
| 489 |
{ |
| 490 |
my ($self) = @_; |
| 491 |
my %exp; |
| 492 |
|
| 493 |
# check IMAP server has the XCONVERSATIONS capability |
| 494 |
my $master_store = $self->{master_store}; |
| 495 |
my $replica_store = $self->{replica_store}; |
| 496 |
$master_store->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 497 |
$replica_store->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 498 |
|
| 499 |
$self->assert($master_store->get_client()->capability()->{xconversations}); |
| 500 |
|
| 501 |
xlog $self, "generating message A"; |
| 502 |
$exp{A} = $self->make_message("Message A", store => $master_store); |
| 503 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 504 |
xlog $self, "checking message A on master"; |
| 505 |
$self->check_messages(\%exp, store => $master_store); |
| 506 |
xlog $self, "running replication"; |
| 507 |
$self->run_replication(); |
| 508 |
$self->check_replication('cassandane'); |
| 509 |
xlog $self, "checking message A on replica"; |
| 510 |
$self->check_messages(\%exp, store => $replica_store); |
| 511 |
|
| 512 |
xlog $self, "generating replies"; |
| 513 |
for (1..99) { |
| 514 |
$exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $master_store); |
| 515 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 516 |
} |
| 517 |
$exp{"B"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $master_store); |
| 518 |
$exp{"B"}->set_attributes(uid => 101, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 519 |
for (1..99) { |
| 520 |
$exp{"B$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $master_store); |
| 521 |
$exp{"B$_"}->set_attributes(uid => 101+$_, cid => $exp{B}->make_cid(), basecid => $exp{A}->make_cid()); |
| 522 |
} |
| 523 |
$exp{"C"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $master_store); |
| 524 |
$exp{"C"}->set_attributes(uid => 201, cid => $exp{C}->make_cid(), basecid => $exp{A}->make_cid()); |
| 525 |
|
| 526 |
# this shouldn't make any difference, but it doesn when you're not logging annotation |
| 527 |
# usage for split conversations properly, so just leaving it here to break this unrelated-ish test and gain |
| 528 |
# the benefits of check_replication's annotsize check |
| 529 |
$self->{instance}->run_command({ cyrus => 1 }, 'reconstruct', '-u' => 'cassandane'); |
| 530 |
|
| 531 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $master_store); |
| 532 |
$self->run_replication(); |
| 533 |
$self->check_replication('cassandane'); |
| 534 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 535 |
|
| 536 |
# corrupt the sync_annot_crc at both ends and check that we can fix it without syncback |
| 537 |
xlog $self, "Damaging annotations CRCs"; |
| 538 |
my $mpath = $self->{instance}->folder_to_directory('user.cassandane'); |
| 539 |
my $rpath = $self->{replica}->folder_to_directory('user.cassandane'); |
| 540 |
_munge_annot_crc($self->{instance}, "$mpath/cyrus.index", 1); |
| 541 |
_munge_annot_crc($self->{replica}, "$rpath/cyrus.index", 2); |
| 542 |
|
| 543 |
$self->run_replication(nosyncback => 1); |
| 544 |
$self->check_replication('cassandane'); |
| 545 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 546 |
|
| 547 |
xlog $self, "Creating a message on the replica now to make sure it gets the right CID"; |
| 548 |
$exp{"D"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $replica_store); |
| 549 |
$exp{"D"}->set_attributes(uid => 202, cid => $exp{C}->make_cid(), basecid => $exp{A}->make_cid()); |
| 550 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 551 |
} |
| 552 |
|
| 553 |
# |
| 554 |
# Test APPEND of messages to IMAP |
| 555 |
# |
| 556 |
sub test_replication_reconstruct |
| 557 |
:min_version_3_1 :needs_component_replication |
| 558 |
{ |
| 559 |
my ($self) = @_; |
| 560 |
my %exp; |
| 561 |
|
| 562 |
# check IMAP server has the XCONVERSATIONS capability |
| 563 |
my $master_store = $self->{master_store}; |
| 564 |
my $replica_store = $self->{replica_store}; |
| 565 |
$master_store->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 566 |
$replica_store->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 567 |
|
| 568 |
$self->assert($master_store->get_client()->capability()->{xconversations}); |
| 569 |
|
| 570 |
xlog $self, "generating message A"; |
| 571 |
$exp{A} = $self->make_message("Message A", store => $master_store); |
| 572 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 573 |
xlog $self, "checking message A on master"; |
| 574 |
$self->check_messages(\%exp, store => $master_store); |
| 575 |
xlog $self, "running replication"; |
| 576 |
$self->run_replication(); |
| 577 |
$self->check_replication('cassandane'); |
| 578 |
xlog $self, "checking message A on replica"; |
| 579 |
$self->check_messages(\%exp, store => $replica_store); |
| 580 |
|
| 581 |
xlog $self, "generating replies"; |
| 582 |
for (1..20) { |
| 583 |
$exp{"A$_"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $master_store); |
| 584 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 585 |
} |
| 586 |
|
| 587 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $master_store); |
| 588 |
$self->run_replication(); |
| 589 |
$self->check_replication('cassandane'); |
| 590 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 591 |
|
| 592 |
$self->{instance}->run_command({ cyrus => 1 }, 'ctl_conversationsdb', '-R', '-r', '-S'); |
| 593 |
|
| 594 |
for (5..9) { |
| 595 |
$exp{"A$_"}->set_attributes(cid => $exp{"A5"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 596 |
} |
| 597 |
for (10..14) { |
| 598 |
$exp{"A$_"}->set_attributes(cid => $exp{"A10"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 599 |
} |
| 600 |
for (15..19) { |
| 601 |
$exp{"A$_"}->set_attributes(cid => $exp{"A15"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 602 |
} |
| 603 |
$exp{"A20"}->set_attributes(cid => $exp{"A20"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 604 |
|
| 605 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $master_store); |
| 606 |
$self->run_replication(); |
| 607 |
$self->check_replication('cassandane'); |
| 608 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 609 |
|
| 610 |
xlog $self, "Creating a message on the replica now to make sure it gets the right CID"; |
| 611 |
$exp{"D"} = $self->make_message("Re: Message A", references => [ $exp{A} ], store => $replica_store); |
| 612 |
$exp{"D"}->set_attributes(uid => 22, cid => $exp{"A20"}->make_cid(), basecid => $exp{A}->make_cid()); |
| 613 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $replica_store); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
# |
| 618 |
# Test APPEND of messages to IMAP which results in a CID clash. |
| 619 |
# |
| 620 |
sub bogus_test_append_clash |
| 621 |
:min_version_3_0 |
| 622 |
{ |
| 623 |
my ($self) = @_; |
| 624 |
my %exp; |
| 625 |
|
| 626 |
# check IMAP server has the XCONVERSATIONS capability |
| 627 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 628 |
|
| 629 |
xlog $self, "generating message A"; |
| 630 |
$exp{A} = $self->make_message("Message A"); |
| 631 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 632 |
$self->check_messages(\%exp); |
| 633 |
|
| 634 |
xlog $self, "generating message B"; |
| 635 |
$exp{B} = $self->make_message("Message B"); |
| 636 |
$exp{B}->set_attributes(uid => 2, cid => $exp{B}->make_cid()); |
| 637 |
my $actual = $self->check_messages(\%exp); |
| 638 |
|
| 639 |
xlog $self, "generating message C"; |
| 640 |
my $ElCid = choose_cid($exp{A}->get_attribute('cid'), |
| 641 |
$exp{B}->get_attribute('cid')); |
| 642 |
$exp{C} = $self->make_message("Message C", |
| 643 |
references => [ $exp{A}, $exp{B} ], |
| 644 |
); |
| 645 |
$exp{C}->set_attributes(uid => 3, cid => $ElCid); |
| 646 |
|
| 647 |
# Since IRIS-293, inserting this message will have the side effect |
| 648 |
# of renumbering some of the existing messages. Predict and test |
| 649 |
# which messages get renumbered. |
| 650 |
my $nextuid = 4; |
| 651 |
foreach my $s (qw(A B)) |
| 652 |
{ |
| 653 |
if ($actual->{"Message $s"}->make_cid() ne $ElCid) |
| 654 |
{ |
| 655 |
$exp{$s}->set_attributes(uid => $nextuid, cid => $ElCid); |
| 656 |
$nextuid++; |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
$self->check_messages(\%exp); |
| 661 |
} |
| 662 |
|
| 663 |
# |
| 664 |
# Test APPEND of messages to IMAP which results in multiple CID clashes. |
| 665 |
# |
| 666 |
sub bogus_test_double_clash |
| 667 |
:min_version_3_0 |
| 668 |
{ |
| 669 |
my ($self) = @_; |
| 670 |
my %exp; |
| 671 |
|
| 672 |
# check IMAP server has the XCONVERSATIONS capability |
| 673 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 674 |
|
| 675 |
xlog $self, "generating message A"; |
| 676 |
$exp{A} = $self->make_message("Message A"); |
| 677 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 678 |
$self->check_messages(\%exp); |
| 679 |
|
| 680 |
xlog $self, "generating message B"; |
| 681 |
$exp{B} = $self->make_message("Message B"); |
| 682 |
$exp{B}->set_attributes(uid => 2, cid => $exp{B}->make_cid()); |
| 683 |
$self->check_messages(\%exp); |
| 684 |
|
| 685 |
xlog $self, "generating message C"; |
| 686 |
$exp{C} = $self->make_message("Message C"); |
| 687 |
$exp{C}->set_attributes(uid => 3, cid => $exp{C}->make_cid()); |
| 688 |
my $actual = $self->check_messages(\%exp); |
| 689 |
|
| 690 |
xlog $self, "generating message D"; |
| 691 |
my $ElCid = choose_cid($exp{A}->get_attribute('cid'), |
| 692 |
$exp{B}->get_attribute('cid'), |
| 693 |
$exp{C}->get_attribute('cid')); |
| 694 |
$exp{D} = $self->make_message("Message D", |
| 695 |
references => [ $exp{A}, $exp{B}, $exp{C} ], |
| 696 |
); |
| 697 |
$exp{D}->set_attributes(uid => 4, cid => $ElCid); |
| 698 |
|
| 699 |
# Since IRIS-293, inserting this message will have the side effect |
| 700 |
# of renumbering some of the existing messages. Predict and test |
| 701 |
# which messages get renumbered. |
| 702 |
my $nextuid = 5; |
| 703 |
foreach my $s (qw(A B C)) |
| 704 |
{ |
| 705 |
if ($actual->{"Message $s"}->make_cid() ne $ElCid) |
| 706 |
{ |
| 707 |
$exp{$s}->set_attributes(uid => $nextuid, cid => $ElCid); |
| 708 |
$nextuid++; |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
$self->check_messages(\%exp); |
| 713 |
} |
| 714 |
|
| 715 |
# |
| 716 |
# Test that a CID clash resolved on the master is replicated |
| 717 |
# |
| 718 |
sub bogus_test_replication_clash |
| 719 |
:min_version_3_0 :needs_component_replication |
| 720 |
{ |
| 721 |
my ($self) = @_; |
| 722 |
my %exp; |
| 723 |
|
| 724 |
xlog $self, "need a master and replica pair"; |
| 725 |
$self->assert_not_null($self->{replica}); |
| 726 |
my $master_store = $self->{master_store}; |
| 727 |
my $replica_store = $self->{replica_store}; |
| 728 |
|
| 729 |
$master_store->set_fetch_attributes('uid', 'cid'); |
| 730 |
$replica_store->set_fetch_attributes('uid', 'cid'); |
| 731 |
|
| 732 |
# Double check that we're connected to the servers |
| 733 |
# we wanted to be connected to. |
| 734 |
$self->assert($master_store->{host} eq $replica_store->{host}); |
| 735 |
$self->assert($master_store->{port} != $replica_store->{port}); |
| 736 |
|
| 737 |
# check IMAP server has the XCONVERSATIONS capability |
| 738 |
$self->assert($master_store->get_client()->capability()->{xconversations}); |
| 739 |
$self->assert($replica_store->get_client()->capability()->{xconversations}); |
| 740 |
|
| 741 |
xlog $self, "generating message A"; |
| 742 |
$exp{A} = $self->make_message("Message A", store => $master_store); |
| 743 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 744 |
$self->run_replication(); |
| 745 |
$self->check_replication('cassandane'); |
| 746 |
$self->check_messages(\%exp, store => $master_store); |
| 747 |
$self->check_messages(\%exp, store => $replica_store); |
| 748 |
|
| 749 |
xlog $self, "generating message B"; |
| 750 |
$exp{B} = $self->make_message("Message B", store => $master_store); |
| 751 |
$exp{B}->set_attributes(uid => 2, cid => $exp{B}->make_cid()); |
| 752 |
$self->run_replication(); |
| 753 |
$self->check_replication('cassandane'); |
| 754 |
$self->check_messages(\%exp, store => $master_store); |
| 755 |
$self->check_messages(\%exp, store => $replica_store); |
| 756 |
|
| 757 |
xlog $self, "generating message C"; |
| 758 |
$exp{C} = $self->make_message("Message C", store => $master_store); |
| 759 |
$exp{C}->set_attributes(uid => 3, cid => $exp{C}->make_cid()); |
| 760 |
$self->run_replication(); |
| 761 |
$self->check_replication('cassandane'); |
| 762 |
my $actual = $self->check_messages(\%exp, store => $master_store); |
| 763 |
$self->check_messages(\%exp, store => $replica_store); |
| 764 |
|
| 765 |
xlog $self, "generating message D"; |
| 766 |
my $ElCid = choose_cid($exp{A}->get_attribute('cid'), |
| 767 |
$exp{B}->get_attribute('cid'), |
| 768 |
$exp{C}->get_attribute('cid')); |
| 769 |
$exp{D} = $self->make_message("Message D", |
| 770 |
store => $master_store, |
| 771 |
references => [ $exp{A}, $exp{B}, $exp{C} ], |
| 772 |
); |
| 773 |
$exp{D}->set_attributes(uid => 4, cid => $ElCid); |
| 774 |
|
| 775 |
# Since IRIS-293, inserting this message will have the side effect |
| 776 |
# of renumbering some of the existing messages. Predict and test |
| 777 |
# which messages get renumbered. |
| 778 |
my $nextuid = 5; |
| 779 |
foreach my $s (qw(A B C)) |
| 780 |
{ |
| 781 |
if ($actual->{"Message $s"}->make_cid() ne $ElCid) |
| 782 |
{ |
| 783 |
$exp{$s}->set_attributes(uid => $nextuid, cid => $ElCid); |
| 784 |
$nextuid++; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
$self->run_replication(); |
| 789 |
$self->check_replication('cassandane'); |
| 790 |
$self->check_messages(\%exp, store => $master_store); |
| 791 |
$self->check_messages(\%exp, store => $replica_store); |
| 792 |
} |
| 793 |
|
| 794 |
# |
| 795 |
# Test APPEND of a new composed draft message to the Drafts folder by |
| 796 |
# the Fastmail webui, which sets the X-ME-Message-ID header to thread |
| 797 |
# conversations but not any of Message-ID, References, or In-Reply-To. |
| 798 |
# |
| 799 |
sub bogus_test_fm_webui_draft |
| 800 |
:min_version_3_0 |
| 801 |
{ |
| 802 |
my ($self) = @_; |
| 803 |
my %exp; |
| 804 |
|
| 805 |
# check IMAP server has the XCONVERSATIONS capability |
| 806 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 807 |
|
| 808 |
xlog $self, "generating message A"; |
| 809 |
$exp{A} = $self->{gen}->generate(subject => 'Draft message A'); |
| 810 |
$exp{A}->remove_headers('Message-ID'); |
| 811 |
# $exp{A}->add_header('X-ME-Message-ID', '<[email protected]>'); |
| 812 |
$exp{A}->add_header('X-ME-Message-ID', '<[email protected]>'); |
| 813 |
$exp{A}->set_attribute(cid => $exp{A}->make_cid()); |
| 814 |
|
| 815 |
$self->{store}->write_begin(); |
| 816 |
$self->{store}->write_message($exp{A}); |
| 817 |
$self->{store}->write_end(); |
| 818 |
$self->check_messages(\%exp); |
| 819 |
|
| 820 |
xlog $self, "generating message B"; |
| 821 |
$exp{B} = $exp{A}->clone(); |
| 822 |
$exp{B}->set_headers('Subject', 'Draft message B'); |
| 823 |
$exp{B}->set_body("Completely different text here\r\n"); |
| 824 |
|
| 825 |
$self->{store}->write_begin(); |
| 826 |
$self->{store}->write_message($exp{B}); |
| 827 |
$self->{store}->write_end(); |
| 828 |
$self->check_messages(\%exp); |
| 829 |
} |
| 830 |
|
| 831 |
# |
| 832 |
# Test a COPY between folders owned by different users |
| 833 |
# |
| 834 |
sub bogus_test_cross_user_copy |
| 835 |
:min_version_3_0 |
| 836 |
{ |
| 837 |
my ($self) = @_; |
| 838 |
my $bobuser = "bob"; |
| 839 |
my $bobfolder = "user.$bobuser"; |
| 840 |
|
| 841 |
xlog $self, "Testing COPY between folders owned by different users [IRIS-893]"; |
| 842 |
|
| 843 |
# check IMAP server has the XCONVERSATIONS capability |
| 844 |
$self->assert($self->{store}->get_client()->capability()->{xconversations}); |
| 845 |
|
| 846 |
my $srv = $self->{instance}->get_service('imap'); |
| 847 |
|
| 848 |
$self->{instance}->create_user($bobuser); |
| 849 |
|
| 850 |
my $adminstore = $srv->create_store(username => 'admin'); |
| 851 |
my $adminclient = $adminstore->get_client(); |
| 852 |
$adminclient->setacl('user.cassandane', $bobuser => 'lrswipkxtecda') |
| 853 |
or die "Cannot setacl on user.cassandane: $@"; |
| 854 |
|
| 855 |
xlog $self, "generating two messages"; |
| 856 |
my %exp; |
| 857 |
$exp{A} = $self->{gen}->generate(subject => 'Message A'); |
| 858 |
my $cid = $exp{A}->make_cid(); |
| 859 |
$exp{A}->set_attribute(cid => $cid); |
| 860 |
$exp{B} = $self->{gen}->generate(subject => 'Message B', |
| 861 |
references => [ $exp{A} ]); |
| 862 |
$exp{B}->set_attribute(cid => $cid); |
| 863 |
|
| 864 |
xlog $self, "Writing messaged to user.cassandane"; |
| 865 |
$self->{store}->write_begin(); |
| 866 |
$self->{store}->write_message($exp{A}); |
| 867 |
$self->{store}->write_message($exp{B}); |
| 868 |
$self->{store}->write_end(); |
| 869 |
xlog $self, "Check that the messages made it"; |
| 870 |
$self->check_messages(\%exp); |
| 871 |
|
| 872 |
my $bobstore = $srv->create_store(username => $bobuser); |
| 873 |
$bobstore->set_fetch_attributes('uid', 'cid'); |
| 874 |
my $bobclient = $bobstore->get_client(); |
| 875 |
$bobstore->set_folder('user.cassandane'); |
| 876 |
$bobstore->_select(); |
| 877 |
$bobclient->copy(2, $bobfolder) |
| 878 |
or die "Cannot COPY message to $bobfolder"; |
| 879 |
|
| 880 |
xlog $self, "Check that the message made it to $bobfolder"; |
| 881 |
my %bobexp; |
| 882 |
$bobexp{B} = $exp{B}->clone(); |
| 883 |
$bobexp{B}->set_attributes(uid => 1, cid => $exp{B}->make_cid()); |
| 884 |
$bobstore->set_folder($bobfolder); |
| 885 |
$self->check_messages(\%bobexp, store => $bobstore); |
| 886 |
} |
| 887 |
|
| 888 |
# |
| 889 |
# Test APPEND of messages to IMAP |
| 890 |
# |
| 891 |
sub test_replication_trashseen |
| 892 |
:min_version_3_1 :needs_component_replication |
| 893 |
{ |
| 894 |
my ($self) = @_; |
| 895 |
my %exp; |
| 896 |
|
| 897 |
# check IMAP server has the XCONVERSATIONS capability |
| 898 |
my $master_store = $self->{master_store}; |
| 899 |
my $replica_store = $self->{replica_store}; |
| 900 |
$master_store->set_fetch_attributes('uid', 'cid'); |
| 901 |
$replica_store->set_fetch_attributes('uid', 'cid'); |
| 902 |
|
| 903 |
my $mtalk = $master_store->get_client(); |
| 904 |
|
| 905 |
$self->assert($mtalk->capability()->{xconversations}); |
| 906 |
|
| 907 |
xlog $self, "generating message A"; |
| 908 |
$exp{A} = $self->make_message("Message A", store => $master_store); |
| 909 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 910 |
xlog $self, "checking message A on master"; |
| 911 |
$self->check_messages(\%exp, store => $master_store); |
| 912 |
|
| 913 |
$mtalk->create("INBOX.Trash"); |
| 914 |
$mtalk->select("INBOX"); |
| 915 |
$mtalk->store('1', '+flags', '\\Seen'); |
| 916 |
$mtalk->move('1', 'INBOX.Trash'); |
| 917 |
$mtalk->select('INBOX.Trash'); |
| 918 |
$mtalk->store('1', '-flags', '\\Seen'); |
| 919 |
|
| 920 |
xlog $self, "running replication"; |
| 921 |
$self->run_replication(); |
| 922 |
$self->check_replication('cassandane'); |
| 923 |
} |
| 924 |
|
| 925 |
# |
| 926 |
# Test limits on GUID duplicates |
| 927 |
# |
| 928 |
sub test_guid_duplicate_same_folder |
| 929 |
:min_version_3_3 :LowEmailLimits |
| 930 |
{ |
| 931 |
my ($self) = @_; |
| 932 |
my %exp; |
| 933 |
|
| 934 |
xlog $self, "generating message A"; |
| 935 |
$exp{A} = $self->make_message("Message A"); |
| 936 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 937 |
$self->check_messages(\%exp); |
| 938 |
|
| 939 |
my $talk = $self->{store}->get_client(); |
| 940 |
|
| 941 |
$talk->create("INBOX.dest"); |
| 942 |
|
| 943 |
$talk->select("INBOX"); |
| 944 |
my $r1 = $talk->copy("1", "INBOX.dest"); |
| 945 |
my $r2 = $talk->copy("1", "INBOX.dest"); |
| 946 |
my $r3 = $talk->copy("1", "INBOX.dest"); |
| 947 |
$self->assert_not_null($r1); |
| 948 |
$self->assert_not_null($r2); |
| 949 |
$self->assert_null($r3); |
| 950 |
$self->assert_matches(qr/Too many identical emails/, $talk->get_last_error()); |
| 951 |
|
| 952 |
$self->assert_syslog_matches($self->{instance}, |
| 953 |
qr{IOERROR: conversations GUID limit}); |
| 954 |
|
| 955 |
$talk->select("INBOX.dest"); |
| 956 |
my $data = $talk->fetch("1:*", "(emailid threadid uid)"); |
| 957 |
$self->assert_not_null($data->{1}); |
| 958 |
$self->assert_not_null($data->{2}); |
| 959 |
$self->assert_null($data->{3}); |
| 960 |
} |
| 961 |
|
| 962 |
sub test_guid_duplicate_total_count |
| 963 |
:min_version_3_3 :LowEmailLimits |
| 964 |
{ |
| 965 |
my ($self) = @_; |
| 966 |
my %exp; |
| 967 |
|
| 968 |
xlog $self, "generating message A"; |
| 969 |
$exp{A} = $self->make_message("Message A"); |
| 970 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 971 |
$self->check_messages(\%exp); |
| 972 |
|
| 973 |
my $talk = $self->{store}->get_client(); |
| 974 |
|
| 975 |
$talk->create("INBOX.M1"); |
| 976 |
$talk->create("INBOX.M2"); |
| 977 |
$talk->create("INBOX.M3"); |
| 978 |
$talk->create("INBOX.M4"); |
| 979 |
$talk->create("INBOX.M5"); |
| 980 |
|
| 981 |
$talk->select("INBOX"); |
| 982 |
|
| 983 |
my $r1 = $talk->copy("1", "INBOX.M1"); |
| 984 |
my $r2 = $talk->copy("1", "INBOX.M2"); |
| 985 |
my $r3 = $talk->copy("1", "INBOX.M3"); |
| 986 |
my $r4 = $talk->copy("1", "INBOX.M4"); |
| 987 |
my $r5 = $talk->copy("1", "INBOX.M5"); |
| 988 |
|
| 989 |
$self->assert_not_null($r1); |
| 990 |
$self->assert_not_null($r2); |
| 991 |
$self->assert_not_null($r3); |
| 992 |
$self->assert_not_null($r4); |
| 993 |
$self->assert_null($r5); |
| 994 |
$self->assert_matches(qr/Too many identical emails/, $talk->get_last_error()); |
| 995 |
$self->assert_syslog_matches($self->{instance}, |
| 996 |
qr{IOERROR: conversations GUID limit}); |
| 997 |
} |
| 998 |
|
| 999 |
# |
| 1000 |
# Test limits on GUID duplicates |
| 1001 |
# |
| 1002 |
sub test_guid_duplicate_expunges |
| 1003 |
:min_version_3_3 :LowEmailLimits :DelayedExpunge |
| 1004 |
{ |
| 1005 |
my ($self) = @_; |
| 1006 |
my %exp; |
| 1007 |
|
| 1008 |
xlog $self, "generating message A"; |
| 1009 |
$exp{A} = $self->make_message("Message A"); |
| 1010 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 1011 |
$self->check_messages(\%exp); |
| 1012 |
|
| 1013 |
my $talk = $self->{store}->get_client(); |
| 1014 |
|
| 1015 |
$talk->create("INBOX.dest"); |
| 1016 |
|
| 1017 |
for (1..9) { |
| 1018 |
$talk->select("INBOX"); |
| 1019 |
my $r = $talk->copy("1", "INBOX.dest"); |
| 1020 |
$self->assert_not_null($r); |
| 1021 |
$talk->select("INBOX.dest"); |
| 1022 |
$talk->store('1:*', '+flags', '(\\Deleted)'); |
| 1023 |
$talk->expunge(); |
| 1024 |
} |
| 1025 |
|
| 1026 |
$talk->select("INBOX"); |
| 1027 |
my $r = $talk->copy("1", "INBOX.dest"); |
| 1028 |
$self->assert_null($r); |
| 1029 |
$self->assert_matches(qr/Too many identical emails/, $talk->get_last_error()); |
| 1030 |
|
| 1031 |
$self->assert_syslog_matches($self->{instance}, |
| 1032 |
qr{IOERROR: conversations GUID limit}); |
| 1033 |
} |
| 1034 |
|
| 1035 |
# Test APPEND of two messages, the second of which has a different subject, |
| 1036 |
# and would otherwise have threaded, but also has an X-ME-Message-ID header |
| 1037 |
# and make sure they don't thread |
| 1038 |
# |
| 1039 |
sub test_x_me_message_id_nomatch_threading |
| 1040 |
:min_version_3_0 |
| 1041 |
{ |
| 1042 |
my ($self) = @_; |
| 1043 |
my %exp; |
| 1044 |
|
| 1045 |
xlog $self, "generating message A"; |
| 1046 |
$exp{A} = $self->{gen}->generate(subject => 'Message A'); |
| 1047 |
$exp{A}->set_headers('Message-ID', '<[email protected]>'); |
| 1048 |
$exp{A}->set_attribute(cid => $exp{A}->make_cid()); |
| 1049 |
|
| 1050 |
$self->{store}->write_begin(); |
| 1051 |
$self->{store}->write_message($exp{A}); |
| 1052 |
$self->{store}->write_end(); |
| 1053 |
$self->check_messages(\%exp); |
| 1054 |
|
| 1055 |
xlog $self, "generating message B"; |
| 1056 |
$exp{B} = $exp{A}->clone(); |
| 1057 |
$exp{B}->set_headers('Message-ID', '<[email protected]>'); |
| 1058 |
$exp{B}->set_headers('In-Reply-To', '<[email protected]>'); |
| 1059 |
$exp{B}->set_headers('X-ME-Message-ID', '<[email protected]>'); |
| 1060 |
$exp{B}->set_headers('Subject', 'Message B'); |
| 1061 |
$exp{B}->set_body("Completely different text here\r\n"); |
| 1062 |
$exp{B}->set_attribute(cid => $exp{B}->make_cid()); |
| 1063 |
|
| 1064 |
$self->{store}->write_begin(); |
| 1065 |
$self->{store}->write_message($exp{B}); |
| 1066 |
$self->{store}->write_end(); |
| 1067 |
$self->check_messages(\%exp); |
| 1068 |
} |
| 1069 |
|
| 1070 |
sub test_rename_between_users |
| 1071 |
:NoAltNameSpace |
| 1072 |
{ |
| 1073 |
my ($self) = @_; |
| 1074 |
my $admintalk = $self->{adminstore}->get_client(); |
| 1075 |
|
| 1076 |
xlog $self, "create shared account"; |
| 1077 |
$admintalk->create("user.manifold"); |
| 1078 |
|
| 1079 |
$admintalk->setacl("user.manifold", admin => 'lrswipkxtecdan'); |
| 1080 |
$admintalk->setacl("user.manifold", manifold => 'lrswipkxtecdan'); |
| 1081 |
$admintalk->setacl("user.manifold", cassandane => 'lrswipkxtecdn'); |
| 1082 |
|
| 1083 |
my $talk = $self->{store}->get_client(); |
| 1084 |
|
| 1085 |
$self->{store}->set_folder("INBOX"); |
| 1086 |
$self->make_message("Inbox Msg"); |
| 1087 |
|
| 1088 |
$talk->create("INBOX.foo"); |
| 1089 |
$self->{store}->set_folder("INBOX.foo"); |
| 1090 |
$self->make_message("Foo Msg"); |
| 1091 |
|
| 1092 |
$talk->create("INBOX.bar"); |
| 1093 |
$self->{store}->set_folder("INBOX.bar"); |
| 1094 |
$self->make_message("Bar Msg"); |
| 1095 |
|
| 1096 |
$self->{store}->set_folder("user.manifold"); |
| 1097 |
$self->make_message("Man Msg"); |
| 1098 |
|
| 1099 |
my $dirs = $self->{instance}->run_mbpath(-u => 'cassandane'); |
| 1100 |
my $mdirs = $self->{instance}->run_mbpath(-u => 'manifold'); |
| 1101 |
|
| 1102 |
# folder IDs should be "INBOX", "foo", "bar" |
| 1103 |
|
| 1104 |
my $res = $talk->status('INBOX.foo', ['mailboxid']); |
| 1105 |
my $fooid = $res->{'mailboxid'}->[0]; |
| 1106 |
|
| 1107 |
my %data = $self->{instance}->run_dbcommand($dirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1108 |
my %mdata = $self->{instance}->run_dbcommand($mdirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1109 |
|
| 1110 |
my $folders = Cyrus::DList->parse_string($data{'$FOLDER_IDS'})->as_perl; |
| 1111 |
my $mfolders = Cyrus::DList->parse_string($mdata{'$FOLDER_IDS'})->as_perl; |
| 1112 |
|
| 1113 |
$self->assert_num_equals(3, scalar @$folders); |
| 1114 |
$self->assert_num_equals(1, scalar @$mfolders); |
| 1115 |
$self->assert_str_equals($fooid, $folders->[1]); |
| 1116 |
|
| 1117 |
xlog $self, "Rename folder to other user"; |
| 1118 |
$talk->rename("INBOX.foo", "user.manifold.foo"); |
| 1119 |
|
| 1120 |
$admintalk->create('user.manifold.extra'); |
| 1121 |
$self->{store}->set_folder("user.manifold.extra"); |
| 1122 |
$self->make_message("Extra Msg"); |
| 1123 |
|
| 1124 |
%data = $self->{instance}->run_dbcommand($dirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1125 |
%mdata = $self->{instance}->run_dbcommand($mdirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1126 |
|
| 1127 |
$folders = Cyrus::DList->parse_string($data{'$FOLDER_IDS'})->as_perl; |
| 1128 |
$mfolders = Cyrus::DList->parse_string($mdata{'$FOLDER_IDS'})->as_perl; |
| 1129 |
$self->assert_num_equals(3, scalar @$folders); |
| 1130 |
$self->assert_num_equals(3, scalar @$mfolders); |
| 1131 |
$self->assert_str_equals('-', $folders->[1]); |
| 1132 |
$self->assert_str_equals($fooid, $mfolders->[1]); |
| 1133 |
|
| 1134 |
$talk->create("INBOX.again"); |
| 1135 |
$self->{store}->set_folder("INBOX.again"); |
| 1136 |
$self->make_message("Again Msg"); |
| 1137 |
|
| 1138 |
$res = $talk->status('INBOX.again', ['mailboxid']); |
| 1139 |
my $againid = $res->{'mailboxid'}->[0]; |
| 1140 |
|
| 1141 |
$talk->rename("user.manifold.foo", "INBOX.foo"); |
| 1142 |
|
| 1143 |
%data = $self->{instance}->run_dbcommand($dirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1144 |
%mdata = $self->{instance}->run_dbcommand($mdirs->{user}{conversations}, 'twoskip', ['SHOW']); |
| 1145 |
$folders = Cyrus::DList->parse_string($data{'$FOLDER_IDS'})->as_perl; |
| 1146 |
$mfolders = Cyrus::DList->parse_string($mdata{'$FOLDER_IDS'})->as_perl; |
| 1147 |
$self->assert_num_equals(4, scalar @$folders); |
| 1148 |
$self->assert_num_equals(3, scalar @$mfolders); |
| 1149 |
$self->assert_str_equals($againid, $folders->[1]); |
| 1150 |
$self->assert_str_equals($fooid, $folders->[3]); |
| 1151 |
$self->assert_str_equals('-', $mfolders->[1]); |
| 1152 |
} |
| 1153 |
|
| 1154 |
# |
| 1155 |
# Test user rename without splitting conversations |
| 1156 |
# |
| 1157 |
sub test_rename_user_nosplitconv |
| 1158 |
:AllowMoves :Replication :needs_component_replication |
| 1159 |
{ |
| 1160 |
my ($self) = @_; |
| 1161 |
|
| 1162 |
xlog $self, "Test user rename without splitting conversations"; |
| 1163 |
|
| 1164 |
my %exp; |
| 1165 |
|
| 1166 |
# check IMAP server has the XCONVERSATIONS capability |
| 1167 |
my $master_store = $self->{master_store}; |
| 1168 |
$self->assert($master_store->get_client()->capability()->{xconversations}); |
| 1169 |
|
| 1170 |
$master_store->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 1171 |
|
| 1172 |
xlog $self, "generating message A"; |
| 1173 |
$exp{A} = $self->make_message("Message A", store => $master_store); |
| 1174 |
$exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid()); |
| 1175 |
$self->check_messages(\%exp); |
| 1176 |
|
| 1177 |
xlog $self, "generating replies"; |
| 1178 |
for (1..20) { |
| 1179 |
$exp{"A$_"} = $self->make_message("Re: Message A", |
| 1180 |
references => [ $exp{A} ], |
| 1181 |
store => $master_store); |
| 1182 |
$exp{"A$_"}->set_attributes(uid => 1+$_, cid => $exp{A}->make_cid()); |
| 1183 |
} |
| 1184 |
|
| 1185 |
my $talk = $master_store->get_client(); |
| 1186 |
$talk->create('foo'); |
| 1187 |
$talk->copy('1:*', 'foo'); |
| 1188 |
|
| 1189 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $master_store); |
| 1190 |
$self->check_conversations(); |
| 1191 |
|
| 1192 |
$self->run_replication(); |
| 1193 |
$self->check_replication('cassandane'); |
| 1194 |
|
| 1195 |
# Reduce the conversation thread size |
| 1196 |
my $config = $self->{instance}->{config}; |
| 1197 |
$config->set(conversations_max_thread => 5); |
| 1198 |
$config->generate($self->{instance}->_imapd_conf()); |
| 1199 |
|
| 1200 |
$config = $self->{replica}->{config}; |
| 1201 |
$config->set(conversations_max_thread => 5); |
| 1202 |
$config->generate($self->{replica}->_imapd_conf()); |
| 1203 |
|
| 1204 |
# Rename the user |
| 1205 |
my $admintalk = $self->{adminstore}->get_client(); |
| 1206 |
my $res = $admintalk->rename('user.cassandane', 'user.newuser'); |
| 1207 |
$self->assert(not $admintalk->get_last_error()); |
| 1208 |
|
| 1209 |
$self->{adminstore}->set_folder("user.newuser"); |
| 1210 |
$self->{adminstore}->set_fetch_attributes('uid', 'cid', 'basecid'); |
| 1211 |
$self->check_messages(\%exp, keyed_on => 'uid', store => $self->{adminstore}); |
| 1212 |
$self->check_conversations(); |
| 1213 |
|
| 1214 |
$self->run_replication(user => 'newuser'); |
| 1215 |
$self->check_replication('newuser'); |
| 1216 |
} |
| 1217 |
|
| 1218 |
1; |