File Coverage

blib/lib/Mail/Salsa/Action/Return.pm
Criterion Covered Total %
statement 21 48 43.7
branch 0 12 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 0 3 0.0
total 28 76 36.8


line stmt bran cond sub pod time code
1             #
2             # Mail/Salsa/Action/Return.pm
3             # Last Modification: Wed Apr 20 17:09:05 WEST 2005
4             #
5             # Copyright (c) 2005 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::Return;
10              
11 1     1   28359 use 5.008000;
  1         5  
  1         44  
12 1     1   7 use strict;
  1         2  
  1         38  
13 1     1   5 use warnings;
  1         2  
  1         50  
14              
15             require Exporter;
16 1     1   597 use Mail::Salsa::Logs qw(logs);
  1         3  
  1         75  
17 1     1   754 use Mail::Salsa::Action::Unsubscribe qw(remove_from_list);
  1         3  
  1         76  
18 1     1   6 use Mail::Salsa::Utils qw(file_path);
  1         1  
  1         42  
19 1     1   933 use SelfLoader;
  1         2097  
  1         561  
20              
21             our @ISA = qw(Exporter);
22              
23             # Items to export into callers namespace by default. Note: do not export
24             # names by default without a very good reason. Use EXPORT_OK instead.
25             # Do not simply export all your public functions/methods/constants.
26              
27             # This allows declaration use Mail::Salsa ':all';
28             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
29             # will save memory.
30             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
31              
32             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
33             our @EXPORT = qw();
34             our $VERSION = '0.01';
35              
36             SelfLoader->load_stubs();
37              
38             sub new {
39 0     0 0   my $proto = shift;
40 0   0       my $class = ref($proto) || $proto;
41 0           my $self = {@_};
42 0           bless ($self, $class);
43 0           $self->process_msg();
44 0           return($self);
45             }
46              
47             sub process_msg {
48 0     0 0   my $self = shift;
49              
50 0           my ($name, $domain) = split(/\@/, $self->{'list'});
51 0           my $returnedfile = join("/", $self->{'tmp_dir'}, 'file');
52 0 0         (-e $returnedfile) or return();
53 0           my $addrs = &find_wrong_email($returnedfile);
54 0 0         scalar(keys(%{$addrs})) or return();
  0            
55 0           my $file = file_path($self->{'list'}, $self->{'list_dir'}, "list\.txt");
56 0           my $res = remove_from_list($file, $addrs);
57 0           for my $email (keys(%{$addrs})) {
  0            
58 0 0         $self->logs(join("", "[user unknown unsubscribed] user: ", $email), "list") if($email);
59             }
60             #exit();
61 0           return();
62             }
63              
64             sub find_wrong_email {
65 0     0 0   my $file = shift;
66              
67 0           my %addresses = ();
68 0 0         open(FILE, "<", $file) or return({});
69 0           while() {
70 0 0         if(my $email = &look4email($_)) { exists($addresses{$email}) or $addresses{$email} = 0; }
  0 0          
71             }
72 0           close(FILE);
73 0           return(\%addresses);
74             }
75              
76             # Autoload methods go after =cut, and are processed by the autosplit program.
77              
78             1;
79              
80             __DATA__