File Coverage

blib/lib/Email/LocalDelivery/Ezmlm.pm
Criterion Covered Total %
statement 28 30 93.3
branch 5 10 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 38 45 84.4


line stmt bran cond sub pod time code
1 1     1   8975 use strict;
  1         4  
  1         68  
2             package Email::LocalDelivery::Ezmlm;
3             our $VERSION = '0.10';
4 1     1   6 use File::Path qw(mkpath);
  1         3  
  1         103  
5 1     1   16 use File::Basename qw( dirname );
  1         2  
  1         568  
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 and L. 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             sub deliver {
34 1     1 1 18 my ($class, $mail, @folders) = @_;
35              
36 1         1 my @delivered;
37 1         3 for my $folder (@folders) {
38             # trim the identifier off, as mkpath doesn't get on with it
39 1         7 $folder =~ s{//?$}{};
40             # XXX should lock the folder - figure out how ezmlm does that
41              
42 1         2 my $num;
43 1 50       51 if (open my $fh, "$folder/num") {
44 1         16 ($num) = (<$fh> =~ m/^(\d+)/);
45             }
46 1         4 ++$num;
47              
48 1         12 my $filename = sprintf('%s/archive/%d/%02d',
49             $folder, int $num / 100, $num % 100);
50 1         2 eval { mkpath( dirname $filename ) };
  1         111  
51 1 50       137 open my $fh, ">$filename" or next;
52 1         20 print $fh $mail;
53 1 50       67 close $fh or next;
54              
55 1 50       101 open $fh, ">$folder/num" or do { unlink $filename; next };
  0         0  
  0         0  
56 1         5 print $fh "$num\n";
57 1 50       37 close $fh or die "couldn't rewrite '$folder/num' $!";
58 1         17 push @delivered, $filename;
59             }
60 1         6 return @delivered;
61             }
62              
63             1;
64             __END__