| 1 | # | ||||||||||||||||||||
| 2 | # Mail/Salsa.pm | ||||||||||||||||||||
| 3 | # Last Modification: Fri May 28 19:22:47 WEST 2010 | ||||||||||||||||||||
| 4 | # | ||||||||||||||||||||
| 5 | # Copyright (c) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>. | ||||||||||||||||||||
| 6 | # All rights reserved. | ||||||||||||||||||||
| 7 | # This module is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 8 | # it under the same terms as Perl itself. | ||||||||||||||||||||
| 9 | # | ||||||||||||||||||||
| 10 | package Mail::Salsa; | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use 5.008000; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | require Exporter; | |||||||||||||||||||
| 17 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 1 | ▶ | use Mail::Salsa::Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use Mail::Salsa::Utils; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 1 | ▶ | use Mail::Salsa::Logs qw(logs); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 1 | ▶ | use MIME::Explode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||
| 26 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 27 | 1 | our @EXPORT = qw(); | |||||||||||||||||||
| 28 | 1 | our $VERSION = '0.15'; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 31 | 0 | my $proto = shift; | |||||||||||||||||||
| 32 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 33 | 0 | my $self = { | |||||||||||||||||||
| 34 | headers => {}, | ||||||||||||||||||||
| 35 | message => undef, | ||||||||||||||||||||
| 36 | action => "", | ||||||||||||||||||||
| 37 | list => "", | ||||||||||||||||||||
| 38 | list_dir => "", | ||||||||||||||||||||
| 39 | logs_dir => "", | ||||||||||||||||||||
| 40 | tmp_dir => "/tmp", | ||||||||||||||||||||
| 41 | archive_dir => "", | ||||||||||||||||||||
| 42 | queue_dir => "", | ||||||||||||||||||||
| 43 | smtp_server => [], | ||||||||||||||||||||
| 44 | from => "", | ||||||||||||||||||||
| 45 | config => {}, | ||||||||||||||||||||
| 46 | @_ | ||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||
| 48 | 0 | bless ($self, $class); | |||||||||||||||||||
| 49 | 0 | my $action = ucfirst(lc($self->{'action'})); | |||||||||||||||||||
| 50 | 0 | ▶ | $action or return(undef); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | delete($self->{'action'}); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $fh = $self->{'filehandle'}; | |||||||||||||||||||
| 54 | 0 | my $line_from = <$fh>; | |||||||||||||||||||
| 55 | 0 | my ($from) = ($line_from =~ /^From +([^ ]+) +/); | |||||||||||||||||||
| 56 | 0 | ▶ | $from or return(undef); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | $self->{'from'} = lc($from); | |||||||||||||||||||
| 58 | 0 | $self->parse_stream(); | |||||||||||||||||||
| 59 | 0 | delete($self->{'filehandle'}); | |||||||||||||||||||
| 60 | TEST: { | ||||||||||||||||||||
| 61 | 0 | ▶ | unless($action eq "Admin") { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | ▶ | if(-e (my $cf = Mail::Salsa::Utils::file_path($self->{'list'}, $self->{'list_dir'}, "configuration.txt"))) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | $self->{'config'} = Mail::Salsa::Config::get_config( | |||||||||||||||||||
| 64 | file => $cf, | ||||||||||||||||||||
| 65 | defaults => { | ||||||||||||||||||||
| 66 | 'title' => "", | ||||||||||||||||||||
| 67 | 'prefix' => "", | ||||||||||||||||||||
| 68 | 'subscribe' => "y", | ||||||||||||||||||||
| 69 | 'unsubscribe' => "y", | ||||||||||||||||||||
| 70 | 'max_message_size' => 0, | ||||||||||||||||||||
| 71 | 'stamp_life' => "1m", | ||||||||||||||||||||
| 72 | 'archive' => "n", | ||||||||||||||||||||
| 73 | 'header' => "n", | ||||||||||||||||||||
| 74 | 'footer' => "n", | ||||||||||||||||||||
| 75 | 'language' => "en", | ||||||||||||||||||||
| 76 | 'localnet' => [], | ||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||
| 80 | 0 | my ($name, $domain) = split(/\@/, $self->{'list'}); | |||||||||||||||||||
| 81 | Mail::Salsa::Utils::tplsendmail( | ||||||||||||||||||||
| 82 | smtp_server => $self->{'smtp_server'}, | ||||||||||||||||||||
| 83 | label => "LIST_NOT_ACTIVE", | ||||||||||||||||||||
| 84 | lang => $self->{'config'}->{'language'}, | ||||||||||||||||||||
| 85 | vars => { | ||||||||||||||||||||
| 86 | master => "salsa-master\@$domain", | ||||||||||||||||||||
| 87 | from => "$name\-owner\@$domain", | ||||||||||||||||||||
| 88 | to => $self->{'from'}, | ||||||||||||||||||||
| 89 | 0 | list => $self->{'list'}, | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||
| 92 | 0 | last TEST; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 0 | eval("use Mail::Salsa::Action::$action;\nMail::Salsa::Action::$action\-\>new(\%\{\$self\});\n"); | |||||||||||||||||||
| 96 | 0 | ▶ | $self->logs("[eval] $@", "errors") if($@); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 0 | Mail::Salsa::Utils::clean_dir($self->{'tmp_dir'}); | |||||||||||||||||||
| 99 | 0 | return($self); | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | ▶ | sub parse_stream { | ||||||||||||||||||
|
Subroutine
parse_stream: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 103 | 0 | my $self = shift; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | my $id = (my $tmp_dir = ""); | |||||||||||||||||||
| 106 | 0 | ▶ | do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 0 | $id = Mail::Salsa::Utils::generate_id(); | |||||||||||||||||||
| 108 | 0 | $tmp_dir = join("/", $self->{'tmp_dir'}, $id); | |||||||||||||||||||
| 109 | } until(!(-d $tmp_dir)); | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | $self->{'tmp_dir'} = $tmp_dir; | |||||||||||||||||||
| 112 | 0 | my $filename = ($self->{'message'} = join("/", $tmp_dir, "$id\.msg")); | |||||||||||||||||||
| 113 | 0 | my $explode = MIME::Explode->new( | |||||||||||||||||||
| 114 | output_dir => $tmp_dir, | ||||||||||||||||||||
| 115 | mkdir => 0700, | ||||||||||||||||||||
| 116 | decode_subject => 1, | ||||||||||||||||||||
| 117 | content_types => ["text/plain"], | ||||||||||||||||||||
| 118 | types_action => "include" | ||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||
| 120 | 0 | ▶ | open(OUTPUT, ">", $filename) or die("Couldn't open $filename for writing: $!\n"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 0 | eval { | |||||||||||||||||||
| 122 | 0 | $self->{'headers'} = $explode->parse($self->{'filehandle'}, \*OUTPUT); | |||||||||||||||||||
| 123 | }; | ||||||||||||||||||||
| 124 | 0 | ▶ | $self->logs("[eval] $@", "errors") if($@); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 0 | close(OUTPUT); | |||||||||||||||||||
| 126 | 0 | return(); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||