| 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
| |||||||||||
| 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
| |||||||||||
| 52 | 1 | print $fh $mail; | |||||||||
| 53 | 1 | ▶ | close $fh or next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | open $fh, ">$folder/num" or do { unlink $filename; next }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | print $fh "$num\n"; | |||||||||
| 57 | 1 | ▶ | close $fh or die "couldn't rewrite '$folder/num' $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 1 | push @delivered, $filename; | |||||||||
| 59 | } | ||||||||||
| 60 | 1 | return @delivered; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 1 | 1; | |||||||||
| 64 | __END__ | ||||||||||