"Fossies" - the Fresh Open Source Software Archive

Member "Mail-Box-3.007/t/121maildir-write.t" (15 Feb 2019, 3008 Bytes) of package /linux/privat/Mail-Box-3.007.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env perl
    2 
    3 #
    4 # Test writing of maildir folders.
    5 #
    6 
    7 use strict;
    8 use warnings;
    9 
   10 use Mail::Box::Test;
   11 use Mail::Box::Maildir;
   12 
   13 use Test::More;
   14 use File::Compare;
   15 use File::Copy;
   16 
   17 BEGIN {
   18    if($windows)
   19    {   plan skip_all => 'Filenames not compatible with Windows';
   20        exit 1;
   21    }
   22    plan tests => 45;
   23 }
   24 
   25 my $mdsrc = File::Spec->catfile($folderdir, 'maildir.src');
   26 
   27 clean_dir $mdsrc;
   28 unpack_mbox2maildir($src, $mdsrc);
   29 
   30 my $folder = Mail::Box::Maildir->new
   31   ( folder       => $mdsrc
   32   , extract      => 'LAZY'
   33   , access       => 'rw'
   34   );
   35 
   36 ok(defined $folder);
   37 
   38 ok($folder->message(40)->label('accepted'),        "40 accepted");
   39 ok(!$folder->message(41)->label('accepted'),       "41 not accepted");
   40 
   41 #
   42 # Count files flagged for deletion  (T flag)
   43 #
   44 
   45 my $to_be_deleted =0;
   46 $_->deleted && $to_be_deleted++  foreach $folder->messages;
   47 cmp_ok($to_be_deleted, "==", 7);
   48 
   49 $folder->close;
   50 
   51 #
   52 # Reopen the folder and see whether the messages flagged for deletion
   53 # are away.
   54 #
   55 
   56 $folder = new Mail::Box::Maildir
   57   ( folder       => $mdsrc
   58   , extract      => 'LAZY'
   59   , access       => 'rw'
   60   );
   61 
   62 cmp_ok($folder->messages, "==", 38);
   63 
   64 my $msg6 = $folder->message(6);
   65 like($msg6->filename , qr/:2,$/);
   66 ok(!$msg6->label('draft'));
   67 ok(!$msg6->label('flagged'));
   68 ok(!$msg6->label('replied'));
   69 ok(!$msg6->label('seen'));
   70 ok(!$msg6->modified);
   71 
   72 my $msg12 = $folder->message(12);
   73 like($msg12->filename , qr/:2,DFRS$/);
   74 ok($msg12->label('draft'));
   75 ok($msg12->label('flagged'));
   76 ok($msg12->label('replied'));
   77 ok($msg12->label('seen'));
   78 
   79 ok(!$msg12->label(flagged => 0));
   80 ok(!$msg12->label('flagged'));
   81 like($msg12->filename , qr/:2,DRS$/);
   82 
   83 ok(!$msg12->label(draft => 0));
   84 ok(!$msg12->label('draft'));
   85 like($msg12->filename , qr/:2,RS$/);
   86 
   87 ok(!$msg12->label(seen => 0));
   88 ok(!$msg12->label('seen'));
   89 like($msg12->filename , qr/:2,R$/);
   90 
   91 ok($msg12->label(flagged => 1));
   92 ok($msg12->label('flagged'));
   93 like($msg12->filename , qr/:2,FR$/);
   94 
   95 ok(!$msg12->label(flagged => 0, replied => 0));
   96 ok(!$msg12->label('flagged'));
   97 ok(!$msg12->label('replied'));
   98 like($msg12->filename , qr/:2,$/);
   99 
  100 ok(!$msg12->modified);
  101 
  102 #
  103 # Test accepting and unaccepting
  104 #
  105 
  106 # test are only run on unix, so we can simply use '/'s
  107 is($msg12->filename, 't/folders/maildir.src/cur/110000010.l.43:2,');
  108 ok($msg12->label('accepted'),                      "12 accepted");
  109 cmp_ok($msg12->label(accepted => 0), '==', 0,      'un-accept a message');
  110 ok(! $msg12->label('accepted'));
  111 is($msg12->filename, 't/folders/maildir.src/new/110000010.l.43:2,');
  112 ok(!$msg12->modified);   # message is not modified
  113 ok($folder->modified);   # ... but the folder is modified
  114                          #     (which implies nothing)
  115 cmp_ok($msg12->label(accepted => 1), '==', 1,      'accept the message');
  116 ok($msg12->label('accepted'));
  117 is($msg12->filename, 't/folders/maildir.src/cur/110000010.l.43:2,');
  118 
  119 ok(! $folder->message(-1)->label('accepted'));
  120 $folder->message(-1)->accept;
  121 ok($folder->message(-1)->label('accepted'));
  122 
  123 $folder->close;
  124 clean_dir $mdsrc;