Debian Codegraph @

cassandane/Cassandane/Cyrus/JMAPEmailSubmission.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 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
32 # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
33 # AND FITNESS, IN NO EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE
34 # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
36 # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
37 # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
38 #
39
40 package Cassandane::Cyrus::JMAPEmailSubmission;
41 use strict;
42 use warnings;
43 use DateTime;
44 use JSON::XS;
45 use Net::CalDAVTalk 0.09;
46 use Net::CardDAVTalk 0.03;
47 use Mail::JMAPTalk 0.13;
48 use Data::Dumper;
49 use Storable 'dclone';
50 use MIME::Base64 qw(encode_base64);
51 use Cwd qw(abs_path getcwd);
52 use URI;
53
54 use lib '.';
55 use base qw(Cassandane::Cyrus::TestCase);
56 use Cassandane::Util::Log;
57
58 use charnames ':full';
59
60 sub new
61 {
62 my ($class, @args) = @_;
63
64 my $config = Cassandane::Config->default()->clone();
65 $config->set(caldav_realm => 'Cassandane',
66 conversations => 'yes',
67 conversations_counted_flags => "\\Draft \\Flagged \$IsMailingList \$IsNotification \$HasAttachment",
68 event_groups => 'mailbox message flags calendar applepushservice jmap',
69 jmapsubmission_deleteonsend => 'no',
70 httpmodules => 'carddav caldav jmap',
71 httpallowcompress => 'no');
72
73 my $self = $class->SUPER::new({
74 config => $config,
75 jmap => 1,
76 adminstore => 1,
77 services => [ 'imap', 'http' ],
78 smtpdaemon => 1,
79 }, @args);
80
81 $self->needs('component', 'jmap');
82 return $self;
83 }
84
85 sub set_up
86 {
87 my ($self) = @_;
88 $self->SUPER::set_up();
89 $self->{jmap}->DefaultUsing([
90 'urn:ietf:params:jmap:core',
91 'urn:ietf:params:jmap:mail',
92 'urn:ietf:params:jmap:submission',
93 ]);
94 }
95
96 sub getinbox
97 {
98 my ($self, $args) = @_;
99
100 $args = {} unless $args;
101
102 my $jmap = $self->{jmap};
103
104 xlog $self, "get existing mailboxes";
105 my $res = $jmap->CallMethods([['Mailbox/get', $args, "R1"]]);
106 $self->assert_not_null($res);
107
108 my %m = map { $_->{name} => $_ } @{$res->[0][1]{list}};
109 return $m{"Inbox"};
110 }
111
112 use Cassandane::Tiny::Loader 'tiny-tests/JMAPEmailSubmission';
113
114 1;