"Fossies" - the Fresh Open Source Software Archive

Member "Mail-Box-3.007/t/102mbox-delay.t" (15 Feb 2019, 4129 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 delay-loading on mbox folders.
    5 #
    6 
    7 use strict;
    8 use warnings;
    9 
   10 use Mail::Box::Test;
   11 use Mail::Box::Mbox;
   12 
   13 use Test::More tests => 288;
   14 use File::Compare;
   15 use File::Copy;
   16 
   17 #
   18 # We will work with a copy of the original to avoid that we write
   19 # over our test file.
   20 #
   21 
   22 copy $src, $cpy
   23     or die "Cannot create test folder $cpy: $!\n";
   24 
   25 my $folder = Mail::Box::Mbox->new
   26   ( folder       => "=$cpyfn"
   27   , folderdir    => $folderdir
   28   , lock_type    => 'NONE'
   29   , extract      => 'LAZY'
   30   , access       => 'rw'
   31   );
   32 
   33 die "Couldn't read $cpy: $!\n"
   34     unless $folder;
   35 
   36 #
   37 # Check that the whole folder is continuous
   38 #
   39 
   40 my $blank = $crlf_platform ? 2 : 1;
   41 my ($end, $msgnr) = (-$blank, 0);
   42 
   43 foreach my $message ($folder->messages)
   44 {   my ($msgbegin, $msgend)   = $message->fileLocation;
   45     my ($headbegin, $headend) = $message->head->fileLocation;
   46     my ($bodybegin, $bodyend) = $message->body->fileLocation;
   47 
   48     cmp_ok($msgbegin, "==", $end+$blank, "begin $msgnr");
   49     cmp_ok($headbegin, ">", $msgbegin,   "end $msgnr");
   50     cmp_ok($bodybegin, "==", $headend,   "glue $msgnr");
   51     $end = $bodyend;
   52     $msgnr++;
   53 }
   54 
   55 cmp_ok($end+$blank , "==",  -s $folder->filename, "full folder read");
   56 
   57 #
   58 # None of the messages should be modified.
   59 #
   60 
   61 my $modified = 0;
   62 $modified ||= $_->modified foreach $folder->messages;
   63 ok(! $modified,                                   "folder not modified");
   64 
   65 #
   66 # Write unmodified folder to different file.
   67 # Because file-to-file copy of unmodified messages, the result must be
   68 # the same.
   69 #
   70 
   71 my $oldsize = -s $folder->filename;
   72 
   73 $folder->modified(1);    # force write
   74 ok($folder->write,                                 "writing folder");
   75 cmp_ok($oldsize, "==",  -s $folder->filename,      "expected size");
   76 
   77 # Try to read it back
   78 
   79 my $copy = new Mail::Box::Mbox
   80   ( folder       => "=$cpyfn"
   81   , folderdir    => $folderdir
   82   , lock_type    => 'NONE'
   83   , extract      => 'LAZY'
   84   );
   85 
   86 ok(defined $copy,                                   "re-reading folder");
   87 cmp_ok($folder->messages, "==", $copy->messages,    "all messages found");
   88 
   89 # Check also if the subjects are the same.
   90 
   91 my @f_subjects = map {$_->head->get('subject') ||''} $folder->messages;
   92 my @c_subjects = map {$_->head->get('subject') ||''} $copy->messages;
   93 
   94 while(@f_subjects)
   95 {   my $f = shift @f_subjects;
   96     my $c = shift @c_subjects;
   97     last unless $f eq $c;
   98 }
   99 ok(!@f_subjects,                                     "all msg-subjects found");
  100 
  101 #
  102 # None of the messages should be parsed yet.
  103 #
  104 
  105 my $parsed = 0;
  106 $_->isParsed && $parsed++ foreach $folder->messages;
  107 cmp_ok($parsed, "==", 0,                             "none of the msgs parsed");
  108 
  109 #
  110 # Check that the whole folder is continuous
  111 #
  112 
  113 ($end, $msgnr) = (-$blank, 0);
  114 foreach my $message ($copy->messages)
  115 {   my ($msgbegin, $msgend)   = $message->fileLocation;
  116     my ($headbegin, $headend) = $message->head->fileLocation;
  117     my ($bodybegin, $bodyend) = $message->body->fileLocation;
  118 
  119 #warn "($msgbegin, $msgend) ($headbegin, $headend) ($bodybegin, $bodyend)\n";
  120     cmp_ok($msgbegin, "==", $end+$blank, "begin $msgnr");
  121     cmp_ok($headbegin, ">", $msgbegin,   "end $msgnr");
  122     cmp_ok($bodybegin, "==", $headend,   "glue $msgnr");
  123     $end = $bodyend;
  124     $msgnr++;
  125 }
  126 cmp_ok($end+$blank, "==",  -s $copy->filename,      "written file size ok");
  127 
  128 #
  129 # None of the messages should be parsed still.
  130 #
  131 
  132 $parsed = 0;
  133 $_->isParsed && $parsed++ foreach $copy->messages;
  134 cmp_ok($parsed, "==", 0,                            "none of the msgs parsed");
  135 
  136 #
  137 # Force one message to be loaded.
  138 #
  139 
  140 my $message = $copy->message(3)->forceLoad;
  141 ok(ref $message,                                    "force load of one msg");
  142 my $body = $message->body;
  143 ok($message->isParsed);
  144 
  145 isa_ok($message, 'Mail::Message');
  146 
  147 #
  148 # Ask for a new field from the header, which is not taken by
  149 # default.  The message should get parsed.
  150 #
  151 
  152 ok(!defined $message->head->get('xyz'));
  153 
  154 ok(not $copy->message(2)->isParsed);
  155 ok(defined $copy->message(2)->head->get('x-mailer'));
  156 isa_ok($copy->message(2)->head, 'Mail::Message::Head::Complete');
  157 ok(not $copy->message(2)->isParsed);
  158 
  159 unlink $cpy;