File Coverage

blib/lib/Mail/Salsa/Archive.pm
Criterion Covered Total %
statement 18 41 43.9
branch 0 8 0.0
condition n/a
subroutine 6 8 75.0
pod 0 2 0.0
total 24 59 40.6


line stmt bran cond sub pod time code
1             #
2             # Mail/Salsa/Archive.pm
3             # Last Modification: Mon May 31 15:05:16 WEST 2004
4             #
5             # Copyright (c) 2004 Henrique Dias . All rights reserved.
6             # This module is free software; you can redistribute it and/or modify
7             # it under the same terms as Perl itself.
8             #
9             package Mail::Salsa::Archive;
10              
11 3     3   30980 use 5.008000;
  3         11  
  3         107  
12 3     3   14 use strict;
  3         5  
  3         101  
13 3     3   22 use warnings;
  3         10  
  3         142  
14              
15             require Exporter;
16 3     3   826 use AutoLoader qw(AUTOLOAD);
  3         1422  
  3         15  
17 3     3   104 use Fcntl qw(:DEFAULT :flock);
  3         6  
  3         1757  
18 3     3   3692 use POSIX qw(strftime);
  3         26041  
  3         26  
19              
20             our @ISA = qw(Exporter);
21              
22             # Items to export into callers namespace by default. Note: do not export
23             # names by default without a very good reason. Use EXPORT_OK instead.
24             # Do not simply export all your public functions/methods/constants.
25              
26             # This allows declaration use Mail::Salsa::Archive ':all';
27             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
28             # will save memory.
29             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
30             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
31             our @EXPORT = qw(&archive_msg);
32             our $VERSION = '0.01';
33              
34             sub archive_msg {
35 0     0 0   my $self = shift;
36              
37 0           my ($name, $domain) = split(/\@/, $self->{'list'});
38 0           my $dir = join("/", $self->{'archive_dir'}, $domain, $name);
39 0 0         unless(-d $dir) {
40 0           Mail::Salsa::Utils::make_dir_rec($dir, 0755);
41 0 0         (-d $dir) or die("$!");
42             }
43 0           my $date = strftime("%a %b %e %H:%M:%S %Y", localtime);
44 0           my $mailbox = &mailbox_name();
45 0 0         open(MSG, "<", $self->{'message'}) or die("$!");
46 0 0         open(ARCHIVE, ">>", join("/", $dir, $mailbox)) or die("$!");
47 0           flock(ARCHIVE, LOCK_EX);
48 0           print ARCHIVE join(" ", "From", $self->{'from'}, "$date\n");
49 0           while() { print ARCHIVE $_; }
  0            
50 0           flock(ARCHIVE, LOCK_UN);
51 0           close(ARCHIVE);
52 0           close(MSG);
53 0           return();
54             }
55              
56             sub mailbox_name {
57 0     0 0   my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
58 0           my ($mon, $year) = (localtime(time))[4,5];
59 0           my $month = $months[$mon];
60 0           $year += 1900;
61 0           return("$year-$month");
62             }
63              
64             # Preloaded methods go here.
65              
66             # Autoload methods go after =cut, and are processed by the autosplit program.
67              
68             1;
69             __END__