| 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::FastMail; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
use DateTime; |
| 44 |
use JSON::XS; |
| 45 |
use Net::CalDAVTalk 0.09; |
| 46 |
use Net::CardDAVTalk 0.05; |
| 47 |
use Net::CardDAVTalk::VCard; |
| 48 |
use Mail::JMAPTalk 0.12; |
| 49 |
use Data::Dumper; |
| 50 |
use Storable 'dclone'; |
| 51 |
|
| 52 |
use lib '.'; |
| 53 |
use base qw(Cassandane::Cyrus::TestCase); |
| 54 |
use Cassandane::Util::Log; |
| 55 |
|
| 56 |
use charnames ':full'; |
| 57 |
|
| 58 |
our $RNUM = 1; |
| 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 |
httpmodules => 'carddav caldav jmap', |
| 68 |
httpallowcompress => 'no', |
| 69 |
allowusermoves => 'yes', |
| 70 |
altnamespace => 'no', |
| 71 |
anyoneuseracl => 'no', |
| 72 |
archive_enabled => 'yes', |
| 73 |
autoexpunge => 'yes', |
| 74 |
caldav_allowattach => 'yes', |
| 75 |
caldav_allowscheduling => 'yes', |
| 76 |
caldav_create_attach => 'yes', |
| 77 |
caldav_create_default => 'no', |
| 78 |
caldav_create_sched => 'yes', |
| 79 |
caldav_realm => 'FastMail', |
| 80 |
calendar_component_set => 'VEVENT', |
| 81 |
crossdomains => 'yes', |
| 82 |
crossdomains_onlyother => 'yes', |
| 83 |
annotation_allow_undefined => 'yes', |
| 84 |
conversations => 'yes', |
| 85 |
conversations_counted_flags => '\\Draft \\Flagged $IsMailingList $IsNotification $HasAttachment $HasTD', |
| 86 |
conversations_max_thread => '100', |
| 87 |
mailbox_initial_flags => '$X-ME-Annot-2 $IsMailingList $IsNotification $HasAttachment $HasTD', |
| 88 |
defaultacl => 'admin lrswipkxtecdan', |
| 89 |
defaultdomain => 'internal', |
| 90 |
delete_unsubscribe => 'yes', |
| 91 |
expunge_mode => 'delayed', |
| 92 |
hashimapspool => 'on', |
| 93 |
httpallowcompress => 'no', |
| 94 |
httpkeepalive => '0', |
| 95 |
httpmodules => 'caldav carddav jmap', |
| 96 |
httpprettytelemetry => 'yes', |
| 97 |
imapidresponse => 'no', |
| 98 |
imapmagicplus => 'yes', |
| 99 |
implicit_owner_rights => 'lkn', |
| 100 |
internaldate_heuristic => 'receivedheader', |
| 101 |
jmap_preview_annot => '/shared/vendor/messagingengine.com/preview', |
| 102 |
jmap_nonstandard_extensions => 'yes', |
| 103 |
jmapauth_allowsasl => 'yes', |
| 104 |
lmtp_fuzzy_mailbox_match => 'yes', |
| 105 |
lmtp_exclude_specialuse => '\XChats \XTemplates \XNotes \Drafts \Snoozed', |
| 106 |
lmtp_over_quota_perm_failure => 'yes', |
| 107 |
maxheaderlines => '4096', |
| 108 |
maxword => '8388608', |
| 109 |
maxquoted => '8388608', |
| 110 |
munge8bit => 'no', |
| 111 |
notesmailbox => 'Notes', |
| 112 |
popsubfolders => 'yes', |
| 113 |
popuseacl => 'yes', |
| 114 |
postmaster => '[email protected]', |
| 115 |
quota_db => 'quotalegacy', |
| 116 |
quota_use_conversations => 'yes', |
| 117 |
quotawarnpercent => '98', |
| 118 |
reverseacls => 'yes', |
| 119 |
rfc3028_strict => 'no', |
| 120 |
savedate => 'yes', |
| 121 |
sieve_extensions => 'fileinto reject vacation imapflags notify envelope body relational regex subaddress copy mailbox mboxmetadata servermetadata date index variables imap4flags editheader duplicate vacation-seconds fcc x-cyrus-jmapquery x-cyrus-snooze x-cyrus-log mailboxid special-use', |
| 122 |
sieve_utf8fileinto => 'yes', |
| 123 |
sieve_use_lmtp_reject => 'no', |
| 124 |
sievenotifier => 'mailto', |
| 125 |
sieve_maxscriptsize => '1024K', |
| 126 |
sieve_vacation_min_response => '60', |
| 127 |
specialusealways => 'yes', |
| 128 |
specialuse_extra => '\\XChats \\XTemplates \\XNotes', |
| 129 |
statuscache => 'on', |
| 130 |
subscription_db => 'flat', |
| 131 |
suppress_capabilities => 'URLAUTH URLAUTH=BINARY', |
| 132 |
tcp_keepalive => 'yes', |
| 133 |
timeout => '60', |
| 134 |
unix_group_enable => 'no', |
| 135 |
unixhierarchysep => 'no', |
| 136 |
virtdomains => 'userid', |
| 137 |
search_engine => 'xapian', |
| 138 |
search_index_headers => 'no', |
| 139 |
search_batchsize => '8192', |
| 140 |
search_maxtime => '30', |
| 141 |
search_snippet_length => '160', |
| 142 |
search_query_language => 'yes', |
| 143 |
search_index_language => 'yes', |
| 144 |
telemetry_bysessionid => 'yes', |
| 145 |
delete_mode => 'delayed', |
| 146 |
pop3alt_uidl_format => 'dovecot', |
| 147 |
event_content_inclusion_mode => 'standard', |
| 148 |
event_content_size => '1', |
| 149 |
event_exclude_specialuse => '\\Junk', |
| 150 |
event_extra_params => 'modseq vnd.fastmail.clientId service uidnext vnd.fastmail.sessionId vnd.cmu.envelope vnd.fastmail.convUnseen vnd.fastmail.convExists vnd.fastmail.cid vnd.cmu.mbtype vnd.cmu.davFilename vnd.cmu.davUid vnd.cmu.mailboxACL vnd.fastmail.counters messages vnd.cmu.unseenMessages flagNames vnd.cmu.emailid vnd.cmu.threadid vnd.cmu.visibleUsers', |
| 151 |
event_groups => 'mailbox message flags calendar applepushservice', |
| 152 |
event_notifier => 'pusher', |
| 153 |
sync_log => 'yes', |
| 154 |
); |
| 155 |
|
| 156 |
my $self = $class->SUPER::new({ |
| 157 |
config => $config, |
| 158 |
jmap => 1, |
| 159 |
deliver => 1, |
| 160 |
adminstore => 1, |
| 161 |
services => [ 'imap', 'http', 'sieve' ] |
| 162 |
}, @args); |
| 163 |
|
| 164 |
$self->needs('component', 'jmap'); |
| 165 |
$self->needs('component', 'sieve'); |
| 166 |
$self->needs('dependency', 'cld2'); |
| 167 |
return $self; |
| 168 |
} |
| 169 |
|
| 170 |
sub set_up |
| 171 |
{ |
| 172 |
my ($self) = @_; |
| 173 |
$self->SUPER::set_up(); |
| 174 |
$self->{jmap}->DefaultUsing([ |
| 175 |
'urn:ietf:params:jmap:core', |
| 176 |
'urn:ietf:params:jmap:mail', |
| 177 |
'urn:ietf:params:jmap:submission', |
| 178 |
]); |
| 179 |
} |
| 180 |
|
| 181 |
# XXX Cheating and just passing in all the using strings that cyrus |
| 182 |
# XXX recognises -- these were ripped from http_jmap.h, try to keep |
| 183 |
# XXX them up to date! :) |
| 184 |
sub default_using { |
| 185 |
return qw( |
| 186 |
urn:ietf:params:jmap:core |
| 187 |
urn:ietf:params:jmap:mail |
| 188 |
urn:ietf:params:jmap:submission |
| 189 |
https://cyrusimap.org/ns/jmap/blob |
| 190 |
urn:ietf:params:jmap:calendars |
| 191 |
https://cyrusimap.org/ns/jmap/contacts |
| 192 |
https://cyrusimap.org/ns/jmap/calendars |
| 193 |
https://cyrusimap.org/ns/jmap/mail |
| 194 |
https://cyrusimap.org/ns/jmap/performance |
| 195 |
https://cyrusimap.org/ns/jmap/debug |
| 196 |
https://cyrusimap.org/ns/jmap/quota |
| 197 |
); |
| 198 |
} |
| 199 |
|
| 200 |
# XXX This is here as documentation -- these ones are supported by |
| 201 |
# XXX cyrus in some, but not all, configurations |
| 202 |
# my @non_default_using = qw( |
| 203 |
# urn:ietf:params:jmap:vacationresponse |
| 204 |
# urn:ietf:params:jmap:websocket |
| 205 |
# ); |
| 206 |
|
| 207 |
sub _fmjmap_req |
| 208 |
{ |
| 209 |
my ($self, $cmd, %args) = @_; |
| 210 |
my $jmap = delete $args{jmap} || $self->{jmap}; |
| 211 |
|
| 212 |
my $rnum = "R" . $RNUM++; |
| 213 |
my $res = $jmap->Request({methodCalls => [[$cmd, \%args, $rnum]], |
| 214 |
using => [ $self->default_using ] }); |
| 215 |
my $res1 = $res->{methodResponses}[0]; |
| 216 |
$self->assert_not_null($res1); |
| 217 |
$self->assert_str_equals($rnum, $res1->[2]); |
| 218 |
return $res1; |
| 219 |
} |
| 220 |
|
| 221 |
sub _fmjmap_ok |
| 222 |
{ |
| 223 |
my ($self, $cmd, %args) = @_; |
| 224 |
my $res = $self->_fmjmap_req($cmd, %args); |
| 225 |
$self->assert_str_equals($cmd, $res->[0]); |
| 226 |
return $res->[1]; |
| 227 |
} |
| 228 |
|
| 229 |
sub _fmjmap_err |
| 230 |
{ |
| 231 |
my ($self, $cmd, %args) = @_; |
| 232 |
my $res = $self->_fmjmap_req($cmd, %args); |
| 233 |
$self->assert_str_equals("error", $res->[0]); |
| 234 |
return $res->[1]; |
| 235 |
} |
| 236 |
|
| 237 |
sub _set_quotaroot |
| 238 |
{ |
| 239 |
my ($self, $quotaroot) = @_; |
| 240 |
$self->{quotaroot} = $quotaroot; |
| 241 |
} |
| 242 |
|
| 243 |
sub _set_quotalimits |
| 244 |
{ |
| 245 |
my ($self, %resources) = @_; |
| 246 |
my $admintalk = $self->{adminstore}->get_client(); |
| 247 |
|
| 248 |
my $quotaroot = delete $resources{quotaroot} || $self->{quotaroot}; |
| 249 |
my @quotalist; |
| 250 |
foreach my $resource (keys %resources) |
| 251 |
{ |
| 252 |
my $limit = $resources{$resource} |
| 253 |
or die "No limit specified for $resource"; |
| 254 |
push(@quotalist, uc($resource), $limit); |
| 255 |
} |
| 256 |
$self->{limits}->{$quotaroot} = { @quotalist }; |
| 257 |
$admintalk->setquota($quotaroot, \@quotalist); |
| 258 |
$self->assert_str_equals('ok', $admintalk->get_last_completion_response()); |
| 259 |
} |
| 260 |
|
| 261 |
use Cassandane::Tiny::Loader 'tiny-tests/FastMail'; |
| 262 |
|
| 263 |
1; |