| 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::Fetch; |
| 41 |
use strict; |
| 42 |
use warnings; |
| 43 |
use Data::Dumper; |
| 44 |
use DateTime; |
| 45 |
use IO::Scalar; |
| 46 |
|
| 47 |
use lib '.'; |
| 48 |
use base qw(Cassandane::Cyrus::TestCase); |
| 49 |
use Cassandane::Address; |
| 50 |
use Cassandane::Util::DateTime qw(to_rfc822); |
| 51 |
use Cassandane::Util::Log; |
| 52 |
|
| 53 |
$Data::Dumper::Sortkeys = 1; |
| 54 |
|
| 55 |
sub new |
| 56 |
{ |
| 57 |
my $class = shift; |
| 58 |
return $class->SUPER::new({ adminstore => 1 }, @_); |
| 59 |
} |
| 60 |
|
| 61 |
sub set_up |
| 62 |
{ |
| 63 |
my ($self) = @_; |
| 64 |
$self->SUPER::set_up(); |
| 65 |
} |
| 66 |
|
| 67 |
sub tear_down |
| 68 |
{ |
| 69 |
my ($self) = @_; |
| 70 |
$self->SUPER::tear_down(); |
| 71 |
} |
| 72 |
|
| 73 |
# |
| 74 |
# Test COPY behaviour with a very long sequence set |
| 75 |
# |
| 76 |
sub test_fetch_header |
| 77 |
{ |
| 78 |
my ($self) = @_; |
| 79 |
|
| 80 |
my $imaptalk = $self->{store}->get_client(); |
| 81 |
|
| 82 |
$imaptalk->create("INBOX.dest"); |
| 83 |
$self->make_message("Test Message"); |
| 84 |
|
| 85 |
# unfortunately, you can't see the data that went over the wire very easily |
| 86 |
# in IMAPTalk - but we know the headers will be in a literal, so.. |
| 87 |
my $body = ""; |
| 88 |
$imaptalk->literal_handle_control(new IO::Scalar \$body); |
| 89 |
my $res = $imaptalk->fetch('1', '(UID FLAGS BODY.PEEK[HEADER.FIELDS (MESSAGE-ID)])'); |
| 90 |
$imaptalk->literal_handle_control(0); |
| 91 |
|
| 92 |
$self->assert(defined $res, "Fetch feturned a response"); |
| 93 |
$self->assert_matches(qr/^Message-ID: <[^>]+>\s+$/, $body); |
| 94 |
} |
| 95 |
|
| 96 |
# https://github.com/cyrusimap/cyrus-imapd/issues/21 |
| 97 |
sub test_duplicate_headers |
| 98 |
:min_version_3_0 |
| 99 |
{ |
| 100 |
my ($self) = @_; |
| 101 |
|
| 102 |
my $from1 = Cassandane::Address->new(localpart => 'firstsender', |
| 103 |
domain => 'example.com'); |
| 104 |
my $from2 = Cassandane::Address->new(localpart => 'secondsender', |
| 105 |
domain => 'example.com'); |
| 106 |
|
| 107 |
my $rcpt1 = Cassandane::Address->new(localpart => 'firstrecipient', |
| 108 |
domain => 'example.com'); |
| 109 |
my $rcpt2 = Cassandane::Address->new(localpart => 'secondrecipient', |
| 110 |
domain => 'example.com'); |
| 111 |
|
| 112 |
my $cc1 = Cassandane::Address->new(localpart => 'firstcc', |
| 113 |
domain => 'example.com'); |
| 114 |
my $cc2 = Cassandane::Address->new(localpart => 'secondcc', |
| 115 |
domain => 'example.com'); |
| 116 |
|
| 117 |
my $bcc1 = Cassandane::Address->new(localpart => 'firstbcc', |
| 118 |
domain => 'example.com'); |
| 119 |
my $bcc2 = Cassandane::Address->new(localpart => 'secondbcc', |
| 120 |
domain => 'example.com'); |
| 121 |
|
| 122 |
my $date1 = DateTime->from_epoch(epoch => time()); |
| 123 |
my $date2 = DateTime->from_epoch(epoch => time() - 2); |
| 124 |
|
| 125 |
my $msg = $self->make_message( |
| 126 |
'subject1', |
| 127 |
from => $from1, |
| 128 |
to => $rcpt1, |
| 129 |
cc => $cc1, |
| 130 |
bcc => $bcc1, |
| 131 |
messageid => '[email protected]', |
| 132 |
date => $date1, |
| 133 |
extra_headers => [ |
| 134 |
[subject => 'subject2'], |
| 135 |
[from => $from2->as_string() ], |
| 136 |
[to => $rcpt2->as_string() ], |
| 137 |
[cc => $cc2->as_string() ], |
| 138 |
[bcc => $bcc2->as_string() ], |
| 139 |
['message-id' => '<[email protected]>' ], |
| 140 |
[date => to_rfc822($date2) ], |
| 141 |
], |
| 142 |
); |
| 143 |
|
| 144 |
# Verify that it created duplicate headers, and didn't collate the values. |
| 145 |
# If it collated the values, this test proves nothing. |
| 146 |
$self->assert_equals(scalar(grep { $_->{name} eq 'subject' } @{$msg->{headers}}), 2); |
| 147 |
$self->assert_equals(scalar(grep { $_->{name} eq 'from' } @{$msg->{headers}}), 2); |
| 148 |
$self->assert_equals(scalar(grep { $_->{name} eq 'to' } @{$msg->{headers}}), 2); |
| 149 |
$self->assert_equals(scalar(grep { $_->{name} eq 'cc' } @{$msg->{headers}}), 2); |
| 150 |
$self->assert_equals(scalar(grep { $_->{name} eq 'bcc' } @{$msg->{headers}}), 2); |
| 151 |
|
| 152 |
# XXX Cassandane::Message's add_header() appends rather than prepends. |
| 153 |
# So we currently expect all the "second" values, when we would prefer |
| 154 |
# to expect the "first" ones. |
| 155 |
my %exp = ( |
| 156 |
Subject => 'subject2', |
| 157 |
From => $from2->address(), |
| 158 |
To => $rcpt2->address(), |
| 159 |
Cc => $cc2->address(), |
| 160 |
Bcc => $bcc2->address(), |
| 161 |
Date => to_rfc822($date2), |
| 162 |
'Message-ID' => '<[email protected]>', |
| 163 |
'In-Reply-To' => undef, |
| 164 |
); |
| 165 |
|
| 166 |
my $imaptalk = $self->{store}->get_client(); |
| 167 |
my $res = $imaptalk->fetch('1', 'ENVELOPE'); |
| 168 |
|
| 169 |
# XXX what behaviour do we expect from Sender and Reply-To headers? |
| 170 |
delete $res->{1}->{envelope}->{Sender}; |
| 171 |
delete $res->{1}->{envelope}->{'Reply-To'}; |
| 172 |
|
| 173 |
$self->assert_deep_equals(\%exp, $res->{1}->{envelope}); |
| 174 |
} |
| 175 |
|
| 176 |
sub test_header_multiple |
| 177 |
{ |
| 178 |
my ($self) = @_; |
| 179 |
|
| 180 |
my $talk = $self->{store}->get_client(); |
| 181 |
|
| 182 |
my $extra_headers = [ |
| 183 |
['x-nice-day-for', 'start again (come on)' ], |
| 184 |
['x-awkward', 'interjection' ], |
| 185 |
['x-nice-day-for', 'white wedding' ], |
| 186 |
['x-nice-day-for', 'start agaaain' ], |
| 187 |
]; |
| 188 |
|
| 189 |
my %exp; |
| 190 |
$exp{1} = $self->make_message('message 1', |
| 191 |
'extra_headers' => $extra_headers); |
| 192 |
$exp{2} = $self->make_message('nice day'); |
| 193 |
$self->check_messages(\%exp); |
| 194 |
|
| 195 |
my $res = $talk->fetch('1:*', |
| 196 |
'(BODY.PEEK[HEADER.FIELDS (x-nice-day-for)])'); |
| 197 |
$self->assert_num_equals(2, scalar keys %{$res}); |
| 198 |
|
| 199 |
my $expected = { |
| 200 |
'x-nice-day-for' => [ |
| 201 |
'start again (come on)', |
| 202 |
'white wedding', |
| 203 |
'start agaaain', |
| 204 |
], |
| 205 |
}; |
| 206 |
$self->assert_deep_equals($expected, $res->{1}->{headers}); |
| 207 |
$self->assert_deep_equals({}, $res->{2}->{headers}); |
| 208 |
} |
| 209 |
|
| 210 |
sub test_fetch_section |
| 211 |
{ |
| 212 |
my ($self) = @_; |
| 213 |
|
| 214 |
my $imaptalk = $self->{store}->get_client(); |
| 215 |
|
| 216 |
# Start body |
| 217 |
my $body = "--047d7b33dd729737fe04d3bde348\r\n"; |
| 218 |
|
| 219 |
# Subpart 1 |
| 220 |
$body .= "" |
| 221 |
. "Content-Type: text/plain; charset=UTF-8\r\n" |
| 222 |
. "\r\n" |
| 223 |
. "body1" |
| 224 |
. "\r\n"; |
| 225 |
|
| 226 |
# Subpart 2 |
| 227 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 228 |
. "Content-Type: text/html;charset=\"ISO-8859-1\"\r\n" |
| 229 |
. "\r\n" |
| 230 |
. "<html><body><p>body2</p></body></html>" |
| 231 |
. "\r\n"; |
| 232 |
|
| 233 |
# Subpart 3 |
| 234 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 235 |
. "Content-Type: multipart/mixed;boundary=frontier\r\n" |
| 236 |
. "\r\n"; |
| 237 |
|
| 238 |
# Subpart 3.1 |
| 239 |
$body .= "--frontier\r\n" |
| 240 |
. "Content-Type: text/plain\r\n" |
| 241 |
. "\r\n" |
| 242 |
. "body31" |
| 243 |
. "\r\n"; |
| 244 |
|
| 245 |
# Subpart 3.2 |
| 246 |
$body .= "--frontier\r\n" |
| 247 |
. "Content-Type: multipart/mixed;boundary=border\r\n" |
| 248 |
. "\r\n" |
| 249 |
. "body32" |
| 250 |
. "\r\n"; |
| 251 |
|
| 252 |
# Subpart 3.2.1 |
| 253 |
$body .= "--border\r\n" |
| 254 |
. "Content-Type: text/plain\r\n" |
| 255 |
. "\r\n" |
| 256 |
. "body321" |
| 257 |
. "\r\n"; |
| 258 |
|
| 259 |
# Subpart 3.2.2 |
| 260 |
$body .= "--border\r\n" |
| 261 |
. "Content-Type: application/octet-stream\r\n" |
| 262 |
. "Content-Transfer-Encoding: base64\r\n" |
| 263 |
. "\r\n" |
| 264 |
. "PGh0bWw+CiAgPGhlYWQ+CiAg==" |
| 265 |
. "\r\n"; |
| 266 |
|
| 267 |
# End subpart 3.2 |
| 268 |
$body .= "--border--\r\n"; |
| 269 |
|
| 270 |
# End subpart 3 |
| 271 |
$body .= "--frontier--\r\n"; |
| 272 |
|
| 273 |
# Subpart 4 |
| 274 |
my $msg4 = "" |
| 275 |
. "Return-Path: <Ava.Nguyen\@local>\r\n" |
| 276 |
. "Mime-Version: 1.0\r\n" |
| 277 |
. "Content-Type: text/plain\r\n" |
| 278 |
. "Content-Transfer-Encoding: 7bit\r\n" |
| 279 |
. "Subject: bar\r\n" |
| 280 |
. "From: Ava T. Nguyen <Ava.Nguyen\@local>\r\n" |
| 281 |
. "Message-ID: <fake.1475639947.6507\@local>\r\n" |
| 282 |
. "Date: Wed, 05 Oct 2016 14:59:07 +1100\r\n" |
| 283 |
. "To: Test User <test\@local>\r\n" |
| 284 |
. "\r\n" |
| 285 |
. "body4"; |
| 286 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 287 |
. "Content-Type: message/rfc822\r\n" |
| 288 |
. "\r\n" |
| 289 |
. $msg4 |
| 290 |
. "\r\n"; |
| 291 |
|
| 292 |
# Subpart 5 |
| 293 |
my $msg5 = "" |
| 294 |
. "Return-Path: <bla\@local>\r\n" |
| 295 |
. "Mime-Version: 1.0\r\n" |
| 296 |
. "Content-Type: multipart/mixed;boundary=subpart5\r\n" |
| 297 |
. "Content-Transfer-Encoding: 7bit\r\n" |
| 298 |
. "Subject: baz\r\n" |
| 299 |
. "From: blu\@local\r\n" |
| 300 |
. "Message-ID: <fake.12123239947.6507\@local>\r\n" |
| 301 |
. "Date: Wed, 06 Oct 2016 14:59:07 +1100\r\n" |
| 302 |
. "To: Test User <test\@local>\r\n" |
| 303 |
. "\r\n" |
| 304 |
. "--subpart5\r\n" |
| 305 |
. "Content-Type: text/plain\r\n" |
| 306 |
. "\r\n" |
| 307 |
. "body51" |
| 308 |
. "\r\n" |
| 309 |
. "--subpart5\r\n" |
| 310 |
. "Content-Type: text/plain\r\n" |
| 311 |
. "\r\n" |
| 312 |
. "body52" |
| 313 |
. "\r\n" |
| 314 |
. "--subpart5--\r\n"; |
| 315 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 316 |
. "Content-Type: message/rfc822\r\n" |
| 317 |
. "\r\n" |
| 318 |
. $msg5 |
| 319 |
. "\r\n"; |
| 320 |
|
| 321 |
# End body |
| 322 |
$body .= "--047d7b33dd729737fe04d3bde348--"; |
| 323 |
|
| 324 |
$self->make_message("foo", |
| 325 |
mime_type => "multipart/mixed", |
| 326 |
mime_boundary => "047d7b33dd729737fe04d3bde348", |
| 327 |
body => $body |
| 328 |
); |
| 329 |
|
| 330 |
my $res; |
| 331 |
|
| 332 |
$res = $imaptalk->fetch('1', '(BODY[1])'); |
| 333 |
$self->assert_str_equals($res->{'1'}->{body}, "body1"); |
| 334 |
|
| 335 |
$res = $imaptalk->fetch('1', '(BODY[2])'); |
| 336 |
$self->assert_str_equals($res->{'1'}->{body}, "<html><body><p>body2</p></body></html>"); |
| 337 |
|
| 338 |
$res = $imaptalk->fetch('1', '(BODY[3.1])'); |
| 339 |
$self->assert_str_equals($res->{'1'}->{body}, "body31"); |
| 340 |
|
| 341 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1])'); |
| 342 |
$self->assert_str_equals($res->{'1'}->{body}, "body321"); |
| 343 |
|
| 344 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1.MIME])'); |
| 345 |
$self->assert($res->{'1'}->{body} =~ m/Content-Type/); |
| 346 |
$self->assert(not $res->{'1'}->{body} =~ m/body321/); |
| 347 |
|
| 348 |
$res = $imaptalk->fetch('1', '(BODY[3.2.2])'); |
| 349 |
$self->assert_str_equals($res->{'1'}->{body}, "PGh0bWw+CiAgPGhlYWQ+CiAg=="); |
| 350 |
|
| 351 |
$res = $imaptalk->fetch('1', '(BODY[3.2.2]<4.3>)'); |
| 352 |
$self->assert_str_equals($res->{'1'}->{body}, substr("PGh0bWw+CiAgPGhlYWQ+CiAg==", 4, 3)); |
| 353 |
|
| 354 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[4.HEADER.FIELDS (CONTENT-TYPE)])'); |
| 355 |
$self->assert_str_equals($res->{'1'}->{headers}->{"content-type"}[0], "text/plain"); |
| 356 |
|
| 357 |
$res = $imaptalk->fetch('1', '(BODY[4.1.MIME])'); |
| 358 |
$self->assert($res->{'1'}->{body} =~ m/Content-Type/); |
| 359 |
|
| 360 |
$res = $imaptalk->fetch('1', '(BODY[4])'); |
| 361 |
$self->assert_str_equals($res->{'1'}->{body}, $msg4); |
| 362 |
|
| 363 |
$res = $imaptalk->fetch('1', '(BODY[5.2])'); |
| 364 |
$self->assert_str_equals($res->{'1'}->{body}, "body52"); |
| 365 |
|
| 366 |
# Check for some bogus subparts |
| 367 |
$res = $imaptalk->fetch('1', '(BODY[3.2.3])'); |
| 368 |
$self->assert_null($res->{'1'}->{body}); |
| 369 |
|
| 370 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1.2])'); |
| 371 |
$self->assert_null($res->{'1'}->{body}); |
| 372 |
|
| 373 |
$res = $imaptalk->fetch('1', '(BODY[4.2])'); |
| 374 |
$self->assert_null($res->{'1'}->{body}); |
| 375 |
|
| 376 |
$res = $imaptalk->fetch('1', '(BODY[-1])'); |
| 377 |
$self->assert_null($res->{'1'}->{body}); |
| 378 |
} |
| 379 |
|
| 380 |
sub test_fetch_section_multipart |
| 381 |
{ |
| 382 |
my ($self) = @_; |
| 383 |
|
| 384 |
my $imaptalk = $self->{store}->get_client(); |
| 385 |
|
| 386 |
# Start body |
| 387 |
my $body = "--047d7b33dd729737fe04d3bde348\r\n"; |
| 388 |
|
| 389 |
# Subpart 1 |
| 390 |
$body .= "" |
| 391 |
. "Content-Type: text/plain; charset=UTF-8\r\n" |
| 392 |
. "\r\n" |
| 393 |
. "body1" |
| 394 |
. "\r\n"; |
| 395 |
|
| 396 |
# Subpart 2 |
| 397 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 398 |
. "Content-Type: text/html;charset=\"ISO-8859-1\"\r\n" |
| 399 |
. "\r\n" |
| 400 |
. "<html><body><p>body2</p></body></html>" |
| 401 |
. "\r\n"; |
| 402 |
|
| 403 |
# Subpart 3 |
| 404 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 405 |
. "Content-Type: multipart/mixed;boundary=frontier\r\n" |
| 406 |
. "\r\n"; |
| 407 |
|
| 408 |
# Subpart 3.1 |
| 409 |
$body .= "--frontier\r\n" |
| 410 |
. "Content-Type: text/plain\r\n" |
| 411 |
. "\r\n" |
| 412 |
. "body31" |
| 413 |
. "\r\n"; |
| 414 |
|
| 415 |
# Subpart 3.2 |
| 416 |
$body .= "--frontier\r\n" |
| 417 |
. "Content-Type: multipart/mixed;boundary=border\r\n" |
| 418 |
. "\r\n" |
| 419 |
. "body32" |
| 420 |
. "\r\n"; |
| 421 |
|
| 422 |
# Subpart 3.2.1 |
| 423 |
$body .= "--border\r\n" |
| 424 |
. "Content-Type: text/plain\r\n" |
| 425 |
. "\r\n" |
| 426 |
. "body321" |
| 427 |
. "\r\n"; |
| 428 |
|
| 429 |
# Subpart 3.2.2 |
| 430 |
$body .= "--border\r\n" |
| 431 |
. "Content-Type: application/octet-stream\r\n" |
| 432 |
. "Content-Transfer-Encoding: base64\r\n" |
| 433 |
. "\r\n" |
| 434 |
. "PGh0bWw+CiAgPGhlYWQ+CiAg==" |
| 435 |
. "\r\n"; |
| 436 |
|
| 437 |
# End subpart 3.2 |
| 438 |
$body .= "--border--\r\n"; |
| 439 |
|
| 440 |
# End subpart 3 |
| 441 |
$body .= "--frontier--\r\n"; |
| 442 |
|
| 443 |
# End body |
| 444 |
$body .= "--047d7b33dd729737fe04d3bde348--"; |
| 445 |
|
| 446 |
$self->make_message("foo", |
| 447 |
mime_type => "multipart/mixed", |
| 448 |
mime_boundary => "047d7b33dd729737fe04d3bde348", |
| 449 |
body => $body |
| 450 |
); |
| 451 |
|
| 452 |
my $res; |
| 453 |
|
| 454 |
$res = $imaptalk->fetch('1', '(BODY[1])'); |
| 455 |
$self->assert_str_equals($res->{'1'}->{body}, "body1"); |
| 456 |
|
| 457 |
$res = $imaptalk->fetch('1', '(BODY[2])'); |
| 458 |
$self->assert_str_equals($res->{'1'}->{body}, "<html><body><p>body2</p></body></html>"); |
| 459 |
|
| 460 |
$res = $imaptalk->fetch('1', '(BODY[3.1])'); |
| 461 |
$self->assert_str_equals($res->{'1'}->{body}, "body31"); |
| 462 |
|
| 463 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1])'); |
| 464 |
$self->assert_str_equals($res->{'1'}->{body}, "body321"); |
| 465 |
|
| 466 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1.MIME])'); |
| 467 |
$self->assert($res->{'1'}->{body} =~ m/Content-Type/); |
| 468 |
$self->assert(not $res->{'1'}->{body} =~ m/body321/); |
| 469 |
|
| 470 |
$res = $imaptalk->fetch('1', '(BODY[3.2.2])'); |
| 471 |
$self->assert_str_equals($res->{'1'}->{body}, "PGh0bWw+CiAgPGhlYWQ+CiAg=="); |
| 472 |
|
| 473 |
$res = $imaptalk->fetch('1', '(BODY[3.2.2]<4.3>)'); |
| 474 |
$self->assert_str_equals($res->{'1'}->{body}, substr("PGh0bWw+CiAgPGhlYWQ+CiAg==", 4, 3)); |
| 475 |
|
| 476 |
# Check for some bogus subparts |
| 477 |
$res = $imaptalk->fetch('1', '(BODY[3.2.3])'); |
| 478 |
$self->assert_null($res->{'1'}->{body}); |
| 479 |
|
| 480 |
$res = $imaptalk->fetch('1', '(BODY[3.2.1.2])'); |
| 481 |
$self->assert_null($res->{'1'}->{body}); |
| 482 |
|
| 483 |
$res = $imaptalk->fetch('1', '(BODY[4.2])'); |
| 484 |
$self->assert_null($res->{'1'}->{body}); |
| 485 |
|
| 486 |
$res = $imaptalk->fetch('1', '(BODY[-1])'); |
| 487 |
$self->assert_null($res->{'1'}->{body}); |
| 488 |
} |
| 489 |
|
| 490 |
sub test_fetch_section_rfc822digest |
| 491 |
{ |
| 492 |
my ($self) = @_; |
| 493 |
|
| 494 |
my $imaptalk = $self->{store}->get_client(); |
| 495 |
|
| 496 |
my $ct = "multipart/digest; boundary=\"foo\""; |
| 497 |
my $from = "sub\@domain.org"; |
| 498 |
my $date = "Sun, 12 Aug 2012 12:34:56 +0300"; |
| 499 |
my $subj = "submsg"; |
| 500 |
|
| 501 |
my $body = "" |
| 502 |
. "From: $from\r\n" |
| 503 |
. "Date: $date\r\n" |
| 504 |
. "Subject: $subj\r\n" |
| 505 |
. "Content-Type: $ct\r\n" |
| 506 |
. "\r\n" |
| 507 |
. "prologue\r\n" |
| 508 |
. "\r\n" |
| 509 |
. "--foo\r\n" |
| 510 |
. "\r\n" |
| 511 |
. "From: m1\@example.com\r\n" |
| 512 |
. "Subject: m1\r\n" |
| 513 |
. "\r\n" |
| 514 |
. "m1 body\r\n" |
| 515 |
. "\r\n" |
| 516 |
. "--foo\r\n" |
| 517 |
. "X-Mime: m2 header\r\n" |
| 518 |
. "\r\n" |
| 519 |
. "From: m2\@example.com\r\n" |
| 520 |
. "Subject: m2\r\n" |
| 521 |
. "\r\n" |
| 522 |
. "m2 body\r\n" |
| 523 |
. "\r\n" |
| 524 |
. "--foo--\r\n" |
| 525 |
. "\r\n" |
| 526 |
. "epilogue\r\n" |
| 527 |
. "\r\n"; |
| 528 |
|
| 529 |
$self->make_message("foo", |
| 530 |
mime_type => "message/rfc822", |
| 531 |
body => $body, |
| 532 |
); |
| 533 |
|
| 534 |
my $res; |
| 535 |
|
| 536 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[TEXT])'); |
| 537 |
$self->assert_str_equals($res->{'1'}->{body}, $body); |
| 538 |
|
| 539 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[1])'); |
| 540 |
$self->assert_str_equals($res->{'1'}->{body}, $body); |
| 541 |
|
| 542 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[1.HEADER])'); |
| 543 |
$self->assert_str_equals($res->{'1'}->{headers}->{"content-type"}[0], $ct); |
| 544 |
$self->assert_str_equals($res->{'1'}->{headers}->{"date"}[0], $date); |
| 545 |
$self->assert_str_equals($res->{'1'}->{headers}->{"from"}[0], $from); |
| 546 |
$self->assert_str_equals($res->{'1'}->{headers}->{"subject"}[0], $subj); |
| 547 |
} |
| 548 |
|
| 549 |
sub test_fetch_section_rfc822 |
| 550 |
{ |
| 551 |
my ($self) = @_; |
| 552 |
|
| 553 |
my $imaptalk = $self->{store}->get_client(); |
| 554 |
|
| 555 |
my $body = "" |
| 556 |
. "From: sub\@domain.org\r\n" |
| 557 |
. "Date: Sun, 12 Aug 2012 12:34:56 +0300\r\n" |
| 558 |
. "Subject: submsg\r\n" |
| 559 |
. "\r\n" |
| 560 |
. "foo"; |
| 561 |
|
| 562 |
$self->make_message("foo", |
| 563 |
mime_type => "message/rfc822", |
| 564 |
body => $body, |
| 565 |
); |
| 566 |
|
| 567 |
my $res; |
| 568 |
|
| 569 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[TEXT])'); |
| 570 |
$self->assert_str_equals($res->{'1'}->{body}, $body); |
| 571 |
|
| 572 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[1])'); |
| 573 |
$self->assert_str_equals($res->{'1'}->{body}, $body); |
| 574 |
|
| 575 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[1.TEXT])'); |
| 576 |
$self->assert_str_equals($res->{'1'}->{body}, "foo"); |
| 577 |
|
| 578 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[1.1])'); |
| 579 |
$self->assert_str_equals($res->{'1'}->{body}, "foo"); |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
sub test_fetch_section_nomultipart |
| 584 |
{ |
| 585 |
my ($self) = @_; |
| 586 |
|
| 587 |
my $imaptalk = $self->{store}->get_client(); |
| 588 |
|
| 589 |
$self->make_message( |
| 590 |
"foo", |
| 591 |
from => Cassandane::Address->new( |
| 592 |
localpart => 'foo', |
| 593 |
domain => 'example.com', |
| 594 |
), |
| 595 |
mime_type => "text/plain", |
| 596 |
body => "body1", |
| 597 |
); |
| 598 |
|
| 599 |
my $res; |
| 600 |
|
| 601 |
$res = $imaptalk->fetch('1', '(BODY[1])'); |
| 602 |
$self->assert_str_equals($res->{'1'}->{body}, "body1"); |
| 603 |
|
| 604 |
# RFC 3501: "Every message has at least one part number." |
| 605 |
$res = $imaptalk->fetch('1', '(BODY[1.MIME])'); |
| 606 |
$self->assert($res->{'1'}->{body} =~ m/Content-Type/); |
| 607 |
$self->assert(not $res->{'1'}->{body} =~ m/body1/); |
| 608 |
|
| 609 |
$res = $imaptalk->fetch('1', '(BODY[HEADER])'); |
| 610 |
$self->assert($res->{'1'}->{body} =~ m/Content-Type/); |
| 611 |
|
| 612 |
$res = $imaptalk->fetch('1', '(BODY.PEEK[HEADER.FIELDS (FROM)])'); |
| 613 |
$self->assert_str_equals($res->{'1'}->{headers}->{from}[0], "<foo\@example.com>"); |
| 614 |
|
| 615 |
$res = $imaptalk->fetch('1', '(BODY[1.HEADER])'); |
| 616 |
$self->assert_null($res->{'1'}->{body}); |
| 617 |
|
| 618 |
# invalid |
| 619 |
$res = $imaptalk->fetch('1', '(BODY[0])'); |
| 620 |
$self->assert_null($res->{'1'}->{body}); |
| 621 |
|
| 622 |
# invalid |
| 623 |
$res = $imaptalk->fetch('1', '(BODY[1.1])'); |
| 624 |
$self->assert_null($res->{'1'}->{body}); |
| 625 |
|
| 626 |
# invalid |
| 627 |
$res = $imaptalk->fetch('1', '(BODY[0.1])'); |
| 628 |
$self->assert_null($res->{'1'}->{body}); |
| 629 |
|
| 630 |
# invalid |
| 631 |
$res = $imaptalk->fetch('1', '(BODY[1.0])'); |
| 632 |
$self->assert_null($res->{'1'}->{body}); |
| 633 |
|
| 634 |
$res = $imaptalk->fetch('1', '(BINARY[1]<0.2>)'); |
| 635 |
$self->assert_str_equals($res->{'1'}->{binary}, "bo"); |
| 636 |
|
| 637 |
$res = $imaptalk->fetch('1', '(BINARY[1]<2.10>)'); |
| 638 |
$self->assert_str_equals($res->{'1'}->{binary}, "dy1"); |
| 639 |
|
| 640 |
$res = $imaptalk->fetch('1', '(BINARY[1]<10.12>)'); |
| 641 |
$self->assert_str_equals($res->{'1'}->{binary}, ""); |
| 642 |
} |
| 643 |
|
| 644 |
sub test_fetch_urlfetch |
| 645 |
{ |
| 646 |
my ($self) = @_; |
| 647 |
|
| 648 |
my %exp_sub; |
| 649 |
my $store = $self->{store}; |
| 650 |
my $talk = $store->get_client(); |
| 651 |
|
| 652 |
$store->set_folder("INBOX"); |
| 653 |
$store->_select(); |
| 654 |
$self->{gen}->set_next_uid(1); |
| 655 |
|
| 656 |
my $body; |
| 657 |
|
| 658 |
# Subpart 1 |
| 659 |
$body = "--047d7b33dd729737fe04d3bde348\r\n" |
| 660 |
. "Content-Type: text/plain; charset=UTF-8\r\n" |
| 661 |
. "\r\n" |
| 662 |
. "body1" |
| 663 |
. "\r\n"; |
| 664 |
|
| 665 |
# Subpart 2 |
| 666 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 667 |
. "Content-Type: multipart/mixed;boundary=frontier\r\n" |
| 668 |
. "\r\n"; |
| 669 |
|
| 670 |
# Subpart 2.1 |
| 671 |
$body .= "--frontier\r\n" |
| 672 |
. "Content-Type: text/plain\r\n" |
| 673 |
. "\r\n" |
| 674 |
. "body21" |
| 675 |
. "\r\n"; |
| 676 |
|
| 677 |
# End subpart 2 |
| 678 |
$body .= "--frontier--\r\n"; |
| 679 |
|
| 680 |
# Subpart 3 |
| 681 |
my $msg3 = "" |
| 682 |
. "Return-Path: <Ava.Nguyen\@local>\r\n" |
| 683 |
. "Mime-Version: 1.0\r\n" |
| 684 |
. "Content-Type: text/plain\r\n" |
| 685 |
. "Content-Transfer-Encoding: 7bit\r\n" |
| 686 |
. "Subject: bar\r\n" |
| 687 |
. "From: Ava T. Nguyen <Ava.Nguyen\@local>\r\n" |
| 688 |
. "Message-ID: <fake.1475639947.6507\@local>\r\n" |
| 689 |
. "Date: Wed, 05 Oct 2016 14:59:07 +1100\r\n" |
| 690 |
. "To: Test User <test\@local>\r\n" |
| 691 |
. "\r\n" |
| 692 |
. "body3"; |
| 693 |
|
| 694 |
$body .= "--047d7b33dd729737fe04d3bde348\r\n" |
| 695 |
. "Content-Type: message/rfc822\r\n" |
| 696 |
. "\r\n" |
| 697 |
. $msg3 |
| 698 |
. "\r\n"; |
| 699 |
|
| 700 |
# End body |
| 701 |
$body .= "--047d7b33dd729737fe04d3bde348--"; |
| 702 |
|
| 703 |
$self->make_message("foo", |
| 704 |
mime_type => "multipart/mixed", |
| 705 |
mime_boundary => "047d7b33dd729737fe04d3bde348", |
| 706 |
body => $body |
| 707 |
); |
| 708 |
|
| 709 |
my $uid; |
| 710 |
my %handlers = |
| 711 |
( |
| 712 |
appenduid => sub |
| 713 |
{ |
| 714 |
my ($cmd, $ids) = @_; |
| 715 |
$uid = ${$ids}[1]; |
| 716 |
}, |
| 717 |
); |
| 718 |
|
| 719 |
my $res; |
| 720 |
|
| 721 |
# Copy the whole message |
| 722 |
$res = $talk->_imap_cmd('append', 0, \%handlers, |
| 723 |
'INBOX', [], "14-Jul-2013 17:01:02 +0000", |
| 724 |
"CATENATE", [ |
| 725 |
"URL", "/INBOX/;uid=1/;section=HEADER", |
| 726 |
"URL", "/INBOX/;uid=1/;section=TEXT", |
| 727 |
], |
| 728 |
); |
| 729 |
$self->assert_not_null($uid); |
| 730 |
$res = $talk->fetch($uid, '(BODY.PEEK[TEXT])'); |
| 731 |
$self->assert_str_equals($res->{$uid}->{body}, $body); |
| 732 |
|
| 733 |
# Merge the headers of an embedded RFC822 message with a plaintext subpart |
| 734 |
$res = $talk->_imap_cmd('append', 0, \%handlers, |
| 735 |
'INBOX', [], "14-Jul-2013 17:01:02 +0000", |
| 736 |
"CATENATE", [ |
| 737 |
"URL", "/INBOX/;uid=1/;section=3.HEADER", |
| 738 |
"URL", "/INBOX/;uid=1/;section=2.1", |
| 739 |
], |
| 740 |
); |
| 741 |
$self->assert_not_null($uid); |
| 742 |
$res = $talk->fetch($uid, '(BODY.PEEK[TEXT] BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])'); |
| 743 |
$self->assert_str_equals($res->{$uid}->{headers}->{'content-type'}[0], "text/plain"); |
| 744 |
$self->assert_str_equals($res->{$uid}->{body}, "body21"); |
| 745 |
|
| 746 |
# Extract an embedded RFC822 message into a new standalone message |
| 747 |
$res = $talk->_imap_cmd('append', 0, \%handlers, |
| 748 |
'INBOX', [], "14-Jul-2013 17:01:02 +0000", |
| 749 |
"CATENATE", [ |
| 750 |
"URL", "/INBOX/;uid=1/;section=3", |
| 751 |
], |
| 752 |
); |
| 753 |
$self->assert_not_null($uid); |
| 754 |
$res = $talk->fetch($uid, '(BODY.PEEK[TEXT] BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])'); |
| 755 |
$self->assert_str_equals($res->{$uid}->{headers}->{'content-type'}[0], "text/plain"); |
| 756 |
$self->assert_str_equals($res->{$uid}->{body}, "body3"); |
| 757 |
|
| 758 |
# Extract part of an embedded RFC822 message into a new standalone message |
| 759 |
$res = $talk->_imap_cmd('append', 0, \%handlers, |
| 760 |
'INBOX', [], "14-Jul-2013 17:01:02 +0000", |
| 761 |
"CATENATE", [ |
| 762 |
"URL", "/INBOX/;uid=1/;section=3.HEADER", |
| 763 |
"URL", "/INBOX/;uid=1/;section=3.TEXT;partial=1.3", |
| 764 |
], |
| 765 |
); |
| 766 |
$self->assert_not_null($uid); |
| 767 |
$res = $talk->fetch($uid, '(BODY.PEEK[TEXT] BODY.PEEK[HEADER.FIELDS (CONTENT-TYPE)])'); |
| 768 |
$self->assert_str_equals($res->{$uid}->{headers}->{'content-type'}[0], "text/plain"); |
| 769 |
$self->assert_str_equals($res->{$uid}->{body}, "ody"); |
| 770 |
} |
| 771 |
|
| 772 |
sub test_fetch_flags_before_exists |
| 773 |
{ |
| 774 |
my ($self) = @_; |
| 775 |
|
| 776 |
my $imaptalk = $self->{store}->get_client(); |
| 777 |
my $admintalk = $self->{adminstore}->get_client(); |
| 778 |
|
| 779 |
$admintalk->select('user.cassandane'); |
| 780 |
$self->make_message("Test Message"); |
| 781 |
# this sets the state with EXISTS = 1 |
| 782 |
$admintalk->fetch('1:*', '(flags)'); |
| 783 |
|
| 784 |
$self->make_message("Test Message"); |
| 785 |
# $res = $admintalk->fetch('1:*', '(flags)'); |
| 786 |
|
| 787 |
# need to make our own handlers |
| 788 |
my %handlers; |
| 789 |
{ |
| 790 |
my $sawfetch = -1; |
| 791 |
use Data::Dumper; |
| 792 |
$handlers{fetch} = sub { $sawfetch = $_[2] if $sawfetch < $_[2] }; |
| 793 |
$handlers{exists} = sub { die "Got exists count too late for $_[2]" if $_[2] <= $sawfetch }; |
| 794 |
} |
| 795 |
|
| 796 |
# expecting to see EXISTS 2 before FETCH 2 |
| 797 |
$admintalk->_imap_cmd("fetch", 1, \%handlers, \'1:*', '(flags)'); |
| 798 |
} |
| 799 |
|
| 800 |
sub test_tell_exists_count_earlier |
| 801 |
:min_version_3_0 |
| 802 |
{ |
| 803 |
my ($self) = @_; |
| 804 |
|
| 805 |
my $imaptalk = $self->{store}->get_client(); |
| 806 |
my $admintalk = $self->{adminstore}->get_client(); |
| 807 |
|
| 808 |
$admintalk->select('user.cassandane'); |
| 809 |
|
| 810 |
$self->make_message("Test Message 1"); |
| 811 |
$admintalk->fetch('1:*', '(flags)'); |
| 812 |
|
| 813 |
$self->make_message("Test Message 2"); |
| 814 |
$admintalk->fetch('2:*', '(flags)'); |
| 815 |
|
| 816 |
$self->make_message("Test Message 3"); |
| 817 |
$admintalk->fetch('3:*', '(uid flags)'); |
| 818 |
|
| 819 |
$admintalk->unselect(); |
| 820 |
$admintalk->select('user.cassandane'); |
| 821 |
|
| 822 |
$imaptalk->store('2', '+flags', '(\\Flagged)'); |
| 823 |
$self->make_message("Test Message 4"); |
| 824 |
|
| 825 |
my %handlers; |
| 826 |
{ |
| 827 |
my $sawfetch = -1; |
| 828 |
my $sawmsg2fetch = -1; |
| 829 |
my $sawmsg3fetch = -1; |
| 830 |
my $sawmsg4fetch = -1; |
| 831 |
use Data::Dumper; |
| 832 |
$handlers{fetch} = sub { |
| 833 |
$sawfetch = 1 if $sawfetch < 0; |
| 834 |
|
| 835 |
if ($_[2] == 2) { $sawmsg2fetch = $_[2] } |
| 836 |
elsif ($_[2] == 3) { |
| 837 |
$sawmsg3fetch = $_[2]; |
| 838 |
die "Got FETCH for 3 before 2" if $sawmsg2fetch < 0; |
| 839 |
} |
| 840 |
elsif ($_[2] == 3) { |
| 841 |
$sawmsg4fetch = $_[2]; |
| 842 |
die "Got FETCH for 4 before 2" if $sawmsg2fetch < 0; |
| 843 |
die "Got FETCH for 4 before 3" if $sawmsg3fetch < 0; |
| 844 |
} |
| 845 |
else { } |
| 846 |
}; |
| 847 |
$handlers{exists} = sub { die "Got EXISTS after FETCH for $_[2]" if $sawfetch > 0; }; |
| 848 |
} |
| 849 |
|
| 850 |
$admintalk->_imap_cmd("fetch", 1, \%handlers, \'3:*', '(uid flags)'); |
| 851 |
} |
| 852 |
|
| 853 |
sub test_mailboxids |
| 854 |
:min_version_3_1 :Conversations |
| 855 |
{ |
| 856 |
my ($self) = @_; |
| 857 |
|
| 858 |
my $imaptalk = $self->{store}->get_client(); |
| 859 |
|
| 860 |
my $res = $imaptalk->status('INBOX', ['mailboxid']); |
| 861 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 862 |
my $inbox_id = $res->{'mailboxid'}->[0]; |
| 863 |
$self->assert_not_null($inbox_id); |
| 864 |
|
| 865 |
$imaptalk->create("INBOX.target"); |
| 866 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 867 |
$res = $imaptalk->status('INBOX.target', ['mailboxid']); |
| 868 |
my $target_id = $res->{'mailboxid'}->[0]; |
| 869 |
$self->assert_not_null($target_id); |
| 870 |
|
| 871 |
# make a message |
| 872 |
my $msg = $self->make_message("test message"); |
| 873 |
my $uid = $msg->{attrs}->{uid}; |
| 874 |
|
| 875 |
# expect to find it in INBOX only |
| 876 |
$res = $imaptalk->fetch('1', '(MAILBOXES MAILBOXIDS)'); |
| 877 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 878 |
$self->assert_deep_equals([$inbox_id], $res->{1}->{'mailboxids'}); |
| 879 |
$self->assert_deep_equals(['INBOX'], $res->{1}->{'mailboxes'}); |
| 880 |
|
| 881 |
# copy it to INBOX.target |
| 882 |
$imaptalk->copy($uid, "INBOX.target"); |
| 883 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 884 |
|
| 885 |
# expect to find it in INBOX and INBOX.target |
| 886 |
$res = $imaptalk->fetch('1', '(MAILBOXES MAILBOXIDS)'); |
| 887 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 888 |
$self->assert_deep_equals([$inbox_id, $target_id], |
| 889 |
$res->{1}->{'mailboxids'}); |
| 890 |
$self->assert_deep_equals(['INBOX', 'INBOX.target'], |
| 891 |
$res->{1}->{'mailboxes'}); |
| 892 |
|
| 893 |
# delete it from INBOX |
| 894 |
$imaptalk->store('1', '+FLAGS', '(\\Deleted)'); |
| 895 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 896 |
|
| 897 |
# expect to find it in INBOX.target only |
| 898 |
$res = $imaptalk->fetch('1', '(MAILBOXES MAILBOXIDS)'); |
| 899 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 900 |
$self->assert_deep_equals([$target_id], |
| 901 |
$res->{1}->{'mailboxids'}); |
| 902 |
$self->assert_deep_equals(['INBOX.target'], |
| 903 |
$res->{1}->{'mailboxes'}); |
| 904 |
|
| 905 |
# expunge INBOX |
| 906 |
$imaptalk->expunge(); |
| 907 |
|
| 908 |
# expect to find it in INBOX.target only |
| 909 |
$res = $imaptalk->fetch('1', '(MAILBOXES MAILBOXIDS)'); |
| 910 |
$self->assert_str_equals('no', $imaptalk->get_last_completion_response()); |
| 911 |
$imaptalk->select('INBOX.target'); |
| 912 |
$res = $imaptalk->fetch('1', '(MAILBOXES MAILBOXIDS)'); |
| 913 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 914 |
$self->assert_deep_equals([$target_id], |
| 915 |
$res->{1}->{'mailboxids'}); |
| 916 |
$self->assert_deep_equals(['INBOX.target'], |
| 917 |
$res->{1}->{'mailboxes'}); |
| 918 |
} |
| 919 |
|
| 920 |
sub test_mailboxids_noconversations |
| 921 |
:min_version_3_1 |
| 922 |
{ |
| 923 |
my ($self) = @_; |
| 924 |
|
| 925 |
my $imaptalk = $self->{store}->get_client(); |
| 926 |
|
| 927 |
# make a message |
| 928 |
my $msg = $self->make_message("test message"); |
| 929 |
my $uid = $msg->{attrs}->{uid}; |
| 930 |
|
| 931 |
# expect FETCH MAILBOXES to be rejected |
| 932 |
my $res = $imaptalk->fetch('1', '(MAILBOXES)'); |
| 933 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 934 |
|
| 935 |
# expect FETCH MAILBOXIDS to be rejected |
| 936 |
$res = $imaptalk->fetch('1', '(MAILBOXIDS)'); |
| 937 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 938 |
} |
| 939 |
|
| 940 |
# test for older draft preview behaviour, obsoleted by publication of |
| 941 |
# RFC 8970 |
| 942 |
sub test_preview_args_legacy |
| 943 |
:min_version_3_1 :max_version_3_4 :Conversations |
| 944 |
{ |
| 945 |
my ($self) = @_; |
| 946 |
|
| 947 |
my $imaptalk = $self->{store}->get_client(); |
| 948 |
|
| 949 |
# make a message |
| 950 |
my $msg = $self->make_message("test message"); |
| 951 |
my $uid = $msg->{attrs}->{uid}; |
| 952 |
|
| 953 |
my $res; |
| 954 |
|
| 955 |
# expect no name to be accepted |
| 956 |
$res = $imaptalk->fetch('1', '(PREVIEW)'); |
| 957 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 958 |
|
| 959 |
# expect no name to be accepted |
| 960 |
$res = $imaptalk->fetch('1', '(PREVIEW ())'); |
| 961 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 962 |
|
| 963 |
# expect bad name to be rejected |
| 964 |
$res = $imaptalk->fetch('1', '(PREVIEW (FUZZY=BUZZY))'); |
| 965 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 966 |
|
| 967 |
# expect fuzzy name to be accepted |
| 968 |
$res = $imaptalk->fetch('1', '(PREVIEW (FUZZY))'); |
| 969 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 970 |
|
| 971 |
# expect lazy fuzzy name to be accepted |
| 972 |
$res = $imaptalk->fetch('1', '(PREVIEW (LAZY=FUZZY))'); |
| 973 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 974 |
} |
| 975 |
|
| 976 |
sub test_preview_args |
| 977 |
:min_version_3_5 :Conversations |
| 978 |
{ |
| 979 |
my ($self) = @_; |
| 980 |
|
| 981 |
my $imaptalk = $self->{store}->get_client(); |
| 982 |
|
| 983 |
# make a message |
| 984 |
my $msg = $self->make_message("test message"); |
| 985 |
my $uid = $msg->{attrs}->{uid}; |
| 986 |
|
| 987 |
my $res; |
| 988 |
|
| 989 |
# expect no modifier to be accepted |
| 990 |
$res = $imaptalk->fetch('1', '(PREVIEW)'); |
| 991 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 992 |
|
| 993 |
# expect empty modifier list to be rejected |
| 994 |
$res = $imaptalk->fetch('1', '(PREVIEW ())'); |
| 995 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 996 |
|
| 997 |
# expect bad modifier name to be rejected |
| 998 |
$res = $imaptalk->fetch('1', '(PREVIEW (FOO))'); |
| 999 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 1000 |
|
| 1001 |
# expect lazy modifier to be accepted |
| 1002 |
$res = $imaptalk->fetch('1', '(PREVIEW (LAZY))'); |
| 1003 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1004 |
|
| 1005 |
# expect lazy + bad modifier to be rejected |
| 1006 |
$res = $imaptalk->fetch('1', '(PREVIEW (LAZY FOO))'); |
| 1007 |
$self->assert_str_equals('bad', $imaptalk->get_last_completion_response()); |
| 1008 |
} |
| 1009 |
|
| 1010 |
sub test_unknown_cte |
| 1011 |
{ |
| 1012 |
my ($self) = @_; |
| 1013 |
|
| 1014 |
my $imaptalk = $self->{store}->get_client(); |
| 1015 |
|
| 1016 |
my $ct = "multipart/mixed"; |
| 1017 |
my $boundary = "mitomycin"; |
| 1018 |
|
| 1019 |
# Subpart 1 |
| 1020 |
my $body = "" |
| 1021 |
. "--$boundary\r\n" |
| 1022 |
. "Content-Type: text/plain; charset=\"utf8\"\r\n" |
| 1023 |
. "\r\n" |
| 1024 |
. "The attachment to this email is meaningless gibberish\r\n"; |
| 1025 |
|
| 1026 |
# Subpart 2 |
| 1027 |
$body .= "" |
| 1028 |
. "--$boundary\r\n" |
| 1029 |
. "Content-Disposition: attachment; filename=\"gibberish.dat\"\r\n" |
| 1030 |
. "Content-Type: application/octet-stream; name=\"gibberish.dat\"\r\n" |
| 1031 |
. "Content-Transfer-Encoding: x-no-such-encoding\r\n" |
| 1032 |
. "\r\n" |
| 1033 |
. "There'll never be a decoder for this encoding, so this\r\n" |
| 1034 |
. "text can't possibly ever decode to something coherent.\r\n" |
| 1035 |
. "--$boundary--\r\n"; |
| 1036 |
|
| 1037 |
my $msg = $self->make_message("foo", |
| 1038 |
mime_type => $ct, |
| 1039 |
mime_boundary => $boundary, |
| 1040 |
body => $body |
| 1041 |
); |
| 1042 |
my $uid = $msg->{attrs}->{uid}; |
| 1043 |
my $res; |
| 1044 |
|
| 1045 |
# fetch BINARY.PEEK should fail |
| 1046 |
$res = $imaptalk->fetch('1', '(BINARY.PEEK[2])'); |
| 1047 |
$self->assert_str_equals('no', $imaptalk->get_last_completion_response()); |
| 1048 |
$self->assert_matches(qr{UNKNOWN-CTE}, $imaptalk->get_last_error()); |
| 1049 |
|
| 1050 |
# fetch BINARY.SIZE should fail |
| 1051 |
$res = $imaptalk->fetch('1', '(BINARY.SIZE[2])'); |
| 1052 |
$self->assert_str_equals('no', $imaptalk->get_last_completion_response()); |
| 1053 |
$self->assert_matches(qr{UNKNOWN-CTE}, $imaptalk->get_last_error()); |
| 1054 |
|
| 1055 |
# enable UID mode... |
| 1056 |
$imaptalk->uid(1); |
| 1057 |
|
| 1058 |
# UID fetch BINARY.PEEK should fail |
| 1059 |
$res = $imaptalk->fetch($uid, '(BINARY.PEEK[2])'); |
| 1060 |
$self->assert_str_equals('no', $imaptalk->get_last_completion_response()); |
| 1061 |
$self->assert_matches(qr{UNKNOWN-CTE}, $imaptalk->get_last_error()); |
| 1062 |
|
| 1063 |
# UID fetch BINARY.SIZE should fail |
| 1064 |
$res = $imaptalk->fetch($uid, '(BINARY.SIZE[2])'); |
| 1065 |
$self->assert_str_equals('no', $imaptalk->get_last_completion_response()); |
| 1066 |
$self->assert_matches(qr{UNKNOWN-CTE}, $imaptalk->get_last_error()); |
| 1067 |
} |
| 1068 |
|
| 1069 |
sub test_partial |
| 1070 |
{ |
| 1071 |
my ($self) = @_; |
| 1072 |
|
| 1073 |
my $imaptalk = $self->{store}->get_client(); |
| 1074 |
|
| 1075 |
xlog $self, "append some messages"; |
| 1076 |
my %exp; |
| 1077 |
my $N = 10; |
| 1078 |
for (1..$N) |
| 1079 |
{ |
| 1080 |
my $msg = $self->make_message("Message $_"); |
| 1081 |
$exp{$_} = $msg; |
| 1082 |
} |
| 1083 |
xlog $self, "check the messages got there"; |
| 1084 |
$self->check_messages(\%exp); |
| 1085 |
|
| 1086 |
# expunge the 1st and 6th |
| 1087 |
$imaptalk->store('1,6', '+FLAGS', '(\\Deleted)'); |
| 1088 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1089 |
$imaptalk->expunge(); |
| 1090 |
|
| 1091 |
# fetch all |
| 1092 |
my $res = $imaptalk->fetch('1:*', '(UID)'); |
| 1093 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1094 |
$self->assert_str_equals($res->{'1'}->{uid}, "2"); |
| 1095 |
$self->assert_str_equals($res->{'2'}->{uid}, "3"); |
| 1096 |
$self->assert_str_equals($res->{'3'}->{uid}, "4"); |
| 1097 |
$self->assert_str_equals($res->{'4'}->{uid}, "5"); |
| 1098 |
$self->assert_str_equals($res->{'5'}->{uid}, "7"); |
| 1099 |
$self->assert_str_equals($res->{'6'}->{uid}, "8"); |
| 1100 |
$self->assert_str_equals($res->{'7'}->{uid}, "9"); |
| 1101 |
$self->assert_str_equals($res->{'8'}->{uid}, "10"); |
| 1102 |
|
| 1103 |
# fetch first 2 |
| 1104 |
$res = $imaptalk->fetch('1:*', '(UID) (PARTIAL 1:2)'); |
| 1105 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1106 |
$self->assert_str_equals($res->{'1'}->{uid}, "2"); |
| 1107 |
$self->assert_str_equals($res->{'2'}->{uid}, "3"); |
| 1108 |
|
| 1109 |
# fetch next 2 |
| 1110 |
$res = $imaptalk->fetch('1:*', '(UID) (PARTIAL 3:4)'); |
| 1111 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1112 |
$self->assert_str_equals($res->{'3'}->{uid}, "4"); |
| 1113 |
$self->assert_str_equals($res->{'4'}->{uid}, "5"); |
| 1114 |
|
| 1115 |
# fetch last 2 |
| 1116 |
$res = $imaptalk->fetch('1:*', '(UID) (PARTIAL -1:-2)'); |
| 1117 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1118 |
$self->assert_str_equals($res->{'8'}->{uid}, "10"); |
| 1119 |
$self->assert_str_equals($res->{'7'}->{uid}, "9"); |
| 1120 |
|
| 1121 |
# fetch the previous 2 |
| 1122 |
$res = $imaptalk->fetch('1:*', '(UID) (PARTIAL -3:-4)'); |
| 1123 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1124 |
$self->assert_str_equals($res->{'6'}->{uid}, "8"); |
| 1125 |
$self->assert_str_equals($res->{'5'}->{uid}, "7"); |
| 1126 |
|
| 1127 |
# enable UID mode... |
| 1128 |
$imaptalk->uid(1); |
| 1129 |
|
| 1130 |
# fetch the middle 2 by UID |
| 1131 |
$res = $imaptalk->fetch('4:8', '(UID) (PARTIAL 2:3)'); |
| 1132 |
$self->assert_str_equals('ok', $imaptalk->get_last_completion_response()); |
| 1133 |
$self->assert_str_equals($res->{'5'}->{uid}, "5"); |
| 1134 |
$self->assert_str_equals($res->{'7'}->{uid}, "7"); |
| 1135 |
} |
| 1136 |
|
| 1137 |
1; |