| 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::Replace; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
use DateTime; |
| 44 |
use Data::Dumper; |
| 45 |
|
| 46 |
use lib '.'; |
| 47 |
use base qw(Cassandane::Cyrus::TestCase); |
| 48 |
use Cassandane::Util::Log; |
| 49 |
use Cassandane::Generator; |
| 50 |
use Cassandane::MessageStoreFactory; |
| 51 |
use Cassandane::Instance; |
| 52 |
|
| 53 |
sub new |
| 54 |
{ |
| 55 |
my $class = shift; |
| 56 |
return $class->SUPER::new({adminstore => 1}, @_); |
| 57 |
} |
| 58 |
|
| 59 |
sub set_up |
| 60 |
{ |
| 61 |
my ($self) = @_; |
| 62 |
$self->SUPER::set_up(); |
| 63 |
} |
| 64 |
|
| 65 |
sub tear_down |
| 66 |
{ |
| 67 |
my ($self) = @_; |
| 68 |
$self->SUPER::tear_down(); |
| 69 |
} |
| 70 |
|
| 71 |
sub test_replace_same_mailbox |
| 72 |
:min_version_3_9 |
| 73 |
{ |
| 74 |
my ($self) = @_; |
| 75 |
|
| 76 |
my $talk = $self->{store}->get_client(); |
| 77 |
|
| 78 |
my %exp; |
| 79 |
$exp{A} = $self->make_message("Message A", store => $self->{store}); |
| 80 |
$self->check_messages(\%exp); |
| 81 |
|
| 82 |
$talk->select('INBOX'); |
| 83 |
|
| 84 |
%exp = (); |
| 85 |
$exp{B} = $self->{gen}->generate(subject => "Message B"); |
| 86 |
|
| 87 |
# REPLACE |
| 88 |
$talk->_imap_cmd('REPLACE', 0, '', "1", "INBOX", |
| 89 |
{ Literal => $exp{B}->as_string() }); |
| 90 |
$self->check_messages(\%exp); |
| 91 |
|
| 92 |
%exp = (); |
| 93 |
$exp{C} = $self->{gen}->generate(subject => "Message C"); |
| 94 |
|
| 95 |
# UID REPLACE |
| 96 |
$talk->_imap_cmd('UID', 0, '', 'REPLACE', "2", "INBOX", |
| 97 |
"(\\flagged)", " 7-Feb-1994 22:43:04 -0800", |
| 98 |
{ Literal => $exp{C}->as_string() }); |
| 99 |
$self->check_messages(\%exp); |
| 100 |
} |
| 101 |
|
| 102 |
sub test_replace_different_mailbox |
| 103 |
:min_version_3_9 |
| 104 |
{ |
| 105 |
my ($self) = @_; |
| 106 |
|
| 107 |
my $talk = $self->{store}->get_client(); |
| 108 |
|
| 109 |
my %exp; |
| 110 |
$exp{A} = $self->make_message("Message A", store => $self->{store}); |
| 111 |
$self->check_messages(\%exp); |
| 112 |
|
| 113 |
$talk->create("INBOX.foo"); |
| 114 |
$talk->select('INBOX'); |
| 115 |
|
| 116 |
%exp = (); |
| 117 |
$exp{B} = $self->{gen}->generate(subject => "Message B", uid => 1); |
| 118 |
|
| 119 |
$talk->_imap_cmd('REPLACE', 0, '', "1", "INBOX.foo", |
| 120 |
{ Literal => $exp{B}->as_string() }); |
| 121 |
$self->check_messages({}); |
| 122 |
|
| 123 |
$self->{store}->set_folder("INBOX.foo"); |
| 124 |
$self->check_messages(\%exp); |
| 125 |
} |
| 126 |
|
| 127 |
1; |