Skip to content

message.date property should be internaldate #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/JMAP/TestSuite/Account.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ package JMAP::TestSuite::AccountContext {
To => '[email protected]',
Subject => 'This is a test',
'Message-Id' => $arg->{message_id} // "<default.$$.$^T\@$$.example.com>",
( $arg->{date} ? ( Date => $arg->{date} ) : () ),
],
body => "This is a very simple message.",
);
Expand Down
95 changes: 95 additions & 0 deletions t/getMessageList-sort-on-date.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use strict;
use warnings;

use JMAP::TestSuite;
use JMAP::TestSuite::Util qw(batch_ok);

use Test::Deep::JType;
use Test::More;

use DateTime;
use Email::MessageID;

my $server = JMAP::TestSuite->get_server;

$server->simple_test(sub {
my ($context) = @_;

my $tester = $context->tester;

# Get us a mailbox to play with
my $batch = $context->create_batch(mailbox => {
x => { name => "Folder X at $^T.$$" },
});

batch_ok($batch);

ok( $batch->is_entirely_successful, "created a mailbox");
my $x = $batch->result_for('x');

my %message = (
2016 => {
header => "Sun, 25 Dec 2016 12:00:01 −0300",
date => '2016-12-25T12:00:01Z',
},
2005 => {
header => "Sun, 25 Dec 2005 12:00:01 −0300",
date => '2005-12-25T12:00:01Z',
},
);

# Import messages with specific dates, expect
# the highest to come back when sorting by date desc
for my $year (sort { $b <=> $a } keys %message) {
my ($hdr_date, $date) = $message{$year}->@{ qw(header date) };
subtest "message with date header $hdr_date" => sub {
my $blob = $context->email_blob(generic => {
message_id => Email::MessageID->new->in_brackets,
date => $hdr_date,
});

ok($blob->is_success, "our upload succeeded (" . $blob->blobId . ")");

$batch = $context->import_messages({
msg => { blobId => $blob, mailboxIds => [ $x->id ] },
});

batch_ok($batch);

ok($batch->is_entirely_successful, "we uploaded and imported messages");

my $message_id = $batch->result_for('msg')->id;
$message{$year}{id} = $message_id;
};
}

my $res = $tester->request([
[
getMessageList => {
filter => { inMailbox => $x->id },
sort => [ 'date desc' ],
limit => 1,
fetchMessages => jtrue(),
fetchMessageProperties => [ 'date', ] ,
}
],
]);

my $first = $res->sentence(1)->arguments->{list}[0];
my ($which) = grep { $message{$_}{id} eq $first->{id} } keys %message;

is($which, 2005, "the more recently imported message is newer");

isnt(
$first->{date},
$message{$which}{date},
"the message.date is not from the ancient header value"
);

cmp_ok(
$first->{date}, 'gt', '2017-01-01',
"...and we return an internaldate in the plausible present"
);
});

done_testing;