File: maildir.t

package info (click to toggle)
libemail-sender-perl 2.601-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: perl: 2,276; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,326 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!perl
use strict;
use warnings;

use lib 't/lib';
use Test::Email::Sender::Util;
use File::Spec ();
use File::Temp ();

use Test::More tests => 10;

use Email::Sender::Transport::Maildir;

my $message = readfile('t/messages/simple.msg');

my $maildir   = File::Temp::tempdir(CLEANUP => 1);

my (undef, $failfile) = File::Temp::tempfile(UNLINK => 1);
my $faildir = File::Spec->catdir($failfile, 'Maildir');

my $sender = Email::Sender::Transport::Maildir->new({
  dir => $maildir,
});

for (1..2) {
  my $result = $sender->send(
    join('', @$message),
    {
      to   => [ 'rjbs@example.com' ],
      from => 'rjbs@example.biz',
    },
  );

  isa_ok($result, 'Email::Sender::Success', "delivery result");
  is(
    index($result->filename, $maildir),
    0,
    "the result filename begins with the maildir",
  );

  ok(
    -f $result->filename,
    "...and exists",
  );
}

my $new = File::Spec->catdir($maildir, 'new');

ok(-d $new, "maildir ./new directory exists now");

my @files = grep { $_ !~ /^\./ } <$new/*>;

is(@files, 2, "there are now two delivered messages in the Maildir");

my $lines = readfile($files[0]);

my $simple = Email::Simple->new(join '', @$lines);

is($simple->header('X-Email-Sender-To'), 'rjbs@example.com', 'env info in hdr');
is($simple->header('Lines'), 4, 'we counted lines correctly');