File Coverage

blib/lib/Mail/Salsa/Action/Subscribe.pm
Criterion Covered Total %
statement 18 55 32.7
branch 0 14 0.0
condition 0 3 0.0
subroutine 6 9 66.6
pod 0 3 0.0
total 24 84 28.5


line stmt bran cond sub pod time code
1             #
2             # Mail/Salsa/Action/Subscribe.pm
3             # Last Modification: Thu Jul 1 12:02:05 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::Action::Subscribe;
10              
11 1     1   26483 use 5.008000;
  1         4  
  1         36  
12 1     1   5 use strict;
  1         1  
  1         103  
13 1     1   4 use warnings;
  1         2  
  1         48  
14              
15             require Exporter;
16 1     1   823 use AutoLoader qw(AUTOLOAD);
  1         2003  
  1         6  
17 1     1   501 use Mail::Salsa::Logs qw(logs);
  1         3  
  1         73  
18 1     1   4 use Mail::Salsa::Utils qw(file_path);
  1         2  
  1         855  
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 ':all';
27             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
28             # will save memory.
29              
30             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
31             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
32             our @EXPORT = qw();
33              
34             our $VERSION = '0.01';
35              
36             sub new {
37 0     0 0   my $proto = shift;
38 0   0       my $class = ref($proto) || $proto;
39 0           my $self = {@_};
40 0           bless ($self, $class);
41 0           $self->process_msg();
42 0           return($self);
43             }
44              
45             sub process_msg {
46 0     0 0   my $self = shift;
47              
48 0           my ($name, $domain) = split(/\@/, $self->{'list'});
49 0 0         if($self->{'config'}->{'subscribe'} eq "n") {
50 0           Mail::Salsa::Utils::tplsendmail(
51             smtp_server => $self->{'smtp_server'},
52             timeout => $self->{'timeout'},
53             label => "SUBSCRIBE",
54             lang => $self->{'config'}->{'language'},
55             vars => {
56             from => "$name\-owner\@$domain",
57             to => $self->{'from'},
58             list => $self->{'list'},
59             }
60             );
61 0           return();
62             }
63 0           my $file = file_path($self->{'list'}, $self->{'list_dir'}, "list\.txt");
64 0           my @emails = ();
65 0 0         if(exists($self->{'headers'}->{'0.0'}->{'cc'})) {
66 0           @emails = split(/ *[\,\;] */, $self->{'headers'}->{'0.0'}->{'cc'});
67 0           Mail::Salsa::Utils::only_addresses(\@emails);
68 0           } else { $emails[0] = $self->{'from'}; }
69 0           my $exist = Mail::Salsa::Utils::check4email(\@emails, $file);
70 0 0         if(my $n = scalar(@{$exist})) {
  0            
71 0           Mail::Salsa::Utils::tplsendmail(
72             smtp_server => $self->{'smtp_server'},
73             timeout => $self->{'timeout'},
74             label => "EMAIL_EXISTS",
75             lang => $self->{'config'}->{'language'},
76             vars => {
77             from => "$name\-owner\@$domain",
78             to => $self->{'from'},
79             list => $self->{'list'},
80 0           emails => join("\n", @{$exist}),
81             }
82             );
83 0 0         ($n < scalar(@emails)) or return();
84             }
85 0           my $kfile = file_path($self->{'list'}, $self->{'list_dir'}, 'stamp.txt');
86 0 0         if(my $stamp = Mail::Salsa::Utils::get_key($kfile)) {
87 0 0         if(my $human = Mail::Salsa::Utils::lookup4key($self->{'message'}, $stamp)) {
88 0           $self->add2list();
89 0           Mail::Salsa::Utils::tplsendmail(
90             smtp_server => $self->{'smtp_server'},
91             timeout => $self->{'timeout'},
92             label => "EMAIL_ADDED",
93             lang => $self->{'config'}->{'language'},
94             vars => {
95             from => "$name\-owner\@$domain",
96             to => $self->{'from'},
97             list => $self->{'list'},
98             }
99             );
100             } else {
101 0           for my $email (@emails) {
102 0           Mail::Salsa::Utils::tplsendmail(
103             smtp_server => $self->{'smtp_server'},
104             timeout => $self->{'timeout'},
105             label => "CONFIRM_SUB",
106             lang => $self->{'config'}->{'language'},
107             vars => {
108             from => "$name\-subscribe\@$domain",
109             to => $email,
110             list => $self->{'list'},
111             stamp => $stamp,
112             origin => $self->{'from'},
113             }
114             );
115             }
116             }
117             }
118 0           return();
119             }
120              
121             sub add2list {
122 0     0 0   my $self = shift;
123              
124 0           my $file = file_path($self->{'list'}, $self->{'list_dir'}, "list\.txt");
125 0 0         open(LIST, ">>", $file) or die("$!");
126 0           print LIST $self->{'from'}, "\n";
127 0           close(LIST);
128 0           return();
129             }
130              
131             # Autoload methods go after =cut, and are processed by the autosplit program.
132              
133             1;
134             __END__