blib/lib/Email/LocalDelivery/Ezmlm.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 50.0% 5 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 82.9% 39 / 47 CC 7 SCAR 17.6
CC
7
Cov
81%
deliver
7.8
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Email::LocalDelivery::Ezmlm;
3 1 our $VERSION = '0.10';
4 1 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Basename qw( dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Email::LocalDelivery::Ezmlm - deliver mail into ezmlm archives
10  
11 =head1 SYNOPSIS
12  
13 use Email::LocalDelivery;
14 Email::LocalDelivery->deliver($mail, "/some/box//") or die "couldn't deliver";
15  
16 =head1 DESCRIPTION
17  
18 This module delivers RFC822 messages into ezmlm-style archive folders.
19  
20 This module was created to allow easy interoperability between
21 L<Siesta> and L<colobus>. Colobus is an nntp server which uses ezmlm
22 archives as its message store.
23  
24 =head1 METHODS
25  
26 =head2 ->deliver( $message, @folders )
27  
28 used as a class method. returns the names of the files ultimately
29 delivered to
30  
31 =cut
32  
33 1 ▶sub deliver {
Subroutine deliver: called CC=7 SCAR=20.6
Pod documented
34 1 my ($class, $mail, @folders) = @_;
35  
36 1 my @delivered;
37 1 for my $folder (@folders) {
38 # trim the identifier off, as mkpath doesn't get on with it
39 1 $folder =~ s{//?$}{};
40 # XXX should lock the folder - figure out how ezmlm does that
41  
42 1 my $num;
43 1 ▶ if (open my $fh, "$folder/num") {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "$folder/num") 0 1 1
44 0 ($num) = (<$fh> =~ m/^(\d+)/);
45 }
46 1 ++$num;
47  
48 1 my $filename = sprintf('%s/archive/%d/%02d',
49 $folder, int $num / 100, $num % 100);
50 1 eval { mkpath( dirname $filename ) };
51 1 ▶ open my $fh, ">$filename" or next;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$filename" or next 1 0 1
52 1 print $fh $mail;
53 1 ▶ close $fh or next;
Branch: 1 branch
BranchTrueFalseTotal
close $fh or next 1 0 1
54  
55 0 ▶ open $fh, ">$folder/num" or do { unlink $filename; next };
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$folder/num" or do { unlink $filename; next } 1 0 1
56 1 print $fh "$num\n";
57 1 ▶ close $fh or die "couldn't rewrite '$folder/num' $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "couldn't rewrite '$folder/num' $!" 1 0 1
58 1 push @delivered, $filename;
59 }
60 1 return @delivered;
61 }
62  
63 1 1;
64 __END__
↑ Summary