Debian Codegraph @

cassandane/Cassandane/Cyrus/UIDonly.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::UIDonly;
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
52 use lib '.';
53 use base qw(Cassandane::Cyrus::TestCase);
54 use Cassandane::Util::Log;
55
56 use charnames ':full';
57
58 sub new
59 {
60 my ($class, @args) = @_;
61
62 my $config = Cassandane::Config->default()->clone();
63
64 $config->set(conversations => 'yes');
65
66 my $self = $class->SUPER::new({
67 config => $config,
68 deliver => 1,
69 adminstore => 1,
70 services => [ 'imap', 'sieve' ]
71 }, @args);
72
73 $self->needs('component', 'sieve');
74 return $self;
75 }
76
77 sub set_up
78 {
79 my ($self) = @_;
80 $self->SUPER::set_up();
81 }
82
83 sub tear_down
84 {
85 my ($self) = @_;
86 $self->SUPER::tear_down();
87 }
88
89 sub uidonly_cmd
90 {
91 my $self = shift;
92 my $imaptalk = shift;
93 my $cmd = shift;
94
95 my %fetched;
96 my %handlers =
97 (
98 uidfetch => sub
99 {
100 my (undef, $items, $uid) = @_;
101
102 if (ref($items) ne 'HASH') {
103 # IMAPTalk < 4.06. Convert the key/value list into a hash
104 my %hash;
105 my $kvlist = $imaptalk->_next_atom();
106 while (@$kvlist) {
107 my ($key, $val) = (shift @$kvlist, shift @$kvlist);
108 $hash{lc($key)} = $val;
109 }
110 $items = \%hash;
111 }
112
113 $fetched{$uid} = $items;
114 },
115 );
116
117 $imaptalk->_imap_cmd($cmd, 0, \%handlers, @_);
118 $self->assert_str_equals('ok', $imaptalk->get_last_completion_response());
119
120 return %fetched;
121 }
122
123 use Cassandane::Tiny::Loader 'tiny-tests/UIDonly';
124
125 1;