Debian Codegraph @

cassandane/Cassandane/Cyrus/JMAPSieve.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2019 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::JMAPSieve;
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, @args) = @_;
62
63 my $config = Cassandane::Config->default()->clone();
64
65 my ($maj, $min) = Cassandane::Instance->get_version();
66 if ($maj == 3 && $min == 0) {
67 # need to explicitly add 'body' to sieve_extensions for 3.0
68 $config->set(sieve_extensions =>
69 "fileinto reject vacation vacation-seconds imap4flags notify " .
70 "envelope relational regex subaddress copy date index " .
71 "imap4flags mailbox mboxmetadata servermetadata variables " .
72 "body");
73 }
74 elsif ($maj < 3) {
75 # also for 2.5 (the earliest Cyrus that Cassandane can test)
76 $config->set(sieve_extensions =>
77 "fileinto reject vacation vacation-seconds imap4flags notify " .
78 "envelope relational regex subaddress copy date index " .
79 "imap4flags body");
80 }
81
82 $config->set(caldav_realm => 'Cassandane',
83 conversations => 'yes',
84 httpmodules => 'carddav caldav jmap',
85 httpallowcompress => 'no',
86 jmap_nonstandard_extensions => 'yes');
87
88 my $self = $class->SUPER::new({
89 config => $config,
90 jmap => 1,
91 deliver => 1,
92 adminstore => 1,
93 services => [ 'imap', 'sieve', 'http' ]
94 }, @args);
95
96 $self->needs('component', 'jmap');
97 $self->needs('component', 'sieve');
98 return $self;
99 }
100
101 sub set_up
102 {
103 my ($self) = @_;
104 $self->SUPER::set_up();
105 $self->{jmap}->DefaultUsing([
106 'urn:ietf:params:jmap:core',
107 'urn:ietf:params:jmap:mail',
108 'urn:ietf:params:jmap:sieve',
109 'https://cyrusimap.org/ns/jmap/sieve', # for SieveScript/test
110 'https://cyrusimap.org/ns/jmap/blob',
111 ]);
112 }
113
114 sub tear_down
115 {
116 my ($self) = @_;
117 $self->SUPER::tear_down();
118 }
119
120 sub download
121 {
122 my ($self, $accountid, $blobid) = @_;
123 my $jmap = $self->{jmap};
124
125 my $uri = $jmap->downloaduri($accountid, $blobid);
126 my %Headers;
127 $Headers{'Authorization'} = $jmap->auth_header();
128 my %getopts = (headers => \%Headers);
129 my $res = $jmap->ua->get($uri, \%getopts);
130 xlog $self, "JMAP DOWNLOAD @_ " . Dumper($res);
131 return $res;
132 }
133
134 use Cassandane::Tiny::Loader 'tiny-tests/JMAPSieve';
135
136 1;