| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Mail/Salsa/Action/Unsubscribe.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Last Modification: Fri Sep 23 15:24:08 WEST 2005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2005 Henrique Dias <hdias@aesbuc.pt>. 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::Unsubscribe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use 5.008000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Mail::Salsa::Logs qw(logs); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Mail::Salsa::Utils qw(file_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Fcntl qw(:flock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | our @EXPORT = qw(&remove_from_list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->process_msg(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub process_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_msg: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ($name, $domain) = split(/\@/, $self->{'list'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if($self->{'config'}->{'unsubscribe'} eq "n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | Mail::Salsa::Utils::tplsendmail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | smtp_server => $self->{'smtp_server'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | timeout => $self->{'timeout'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | label => "UNSUBSCRIBE", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | lang => $self->{'config'}->{'language'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | vars => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | from => "$name-owner\@$domain", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | to => $self->{'from'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | list => $self->{'list'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $file = file_path($self->{'list'}, $self->{'list_dir'}, "list\.txt"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my @emails = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if(exists($self->{'headers'}->{'0.0'}->{'cc'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | @emails = split(/ *[\,\;] */, $self->{'headers'}->{'0.0'}->{'cc'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | Mail::Salsa::Utils::only_addresses(\@emails); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | } else { $emails[0] = $self->{'from'}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $exist = Mail::Salsa::Utils::check4email(\@emails, $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if(scalar(@{$exist}) < scalar(@emails)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my @notexist = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my %seen = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | @seen{@{$exist}} = (0 .. $#{$exist}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | for my $e (@emails) { exists($seen{$e}) or push(@notexist, $e); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | Mail::Salsa::Utils::tplsendmail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | smtp_server => $self->{'smtp_server'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | timeout => $self->{'timeout'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | label => "EMAILNOTEXIST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | lang => $self->{'config'}->{'language'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | vars => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | from => "$name\-owner\@$domain", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | to => $self->{'from'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | list => $self->{'list'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | emails => join("\n", @notexist), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | (scalar(@notexist) < scalar(@emails)) or return(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $kfile = file_path($self->{'list'}, $self->{'list_dir'}, 'stamp.txt'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if(my $stamp = Mail::Salsa::Utils::get_key($kfile)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if(my $human = Mail::Salsa::Utils::lookup4key($self->{'message'}, $stamp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if(&remove_from_list($file, { $self->{'from'} => 0 })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Mail::Salsa::Utils::tplsendmail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | smtp_server => $self->{'smtp_server'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | timeout => $self->{'timeout'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | label => "EMAIL_REMOVED", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | lang => $self->{'config'}->{'language'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | vars => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | from => "$name\-owner\@$domain", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | to => $self->{'from'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | list => $self->{'list'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | for my $email (@{$exist}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Mail::Salsa::Utils::tplsendmail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | smtp_server => $self->{'smtp_server'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | timeout => $self->{'timeout'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | label => "CONFIRM_UNSUB", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | lang => $self->{'config'}->{'language'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | vars => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | from => "$name\-unsubscribe\@$domain", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | to => $email, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | list => $self->{'list'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | stamp => $stamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | origin => $self->{'from'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub remove_from_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_from_list: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $addrs = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $pattern = '[^\@<>(),;:\s]+\@([\w\-]+\.)+[a-zA-Z]{2,4}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $n = (my $exist) = scalar(keys(%{$addrs})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | open(LIST, "<", $file) or die("$!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | flock(LIST, LOCK_EX); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | open(TMPLIST, ">", "$file\.tmp") or die("$!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | select(TMPLIST); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | while(<LIST>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if($exist && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$exist and /^[^\#]/ and /<?($pattern)>?/ and exists $addrs->{$1}
$exist and /^[^\#]/ and /<?($pattern)>?/
$exist and /^[^\#]/
MC/DC0%0/4
$exist and /^[^\#]/ and /<?($pattern)>?/ and exists $addrs->{$1}
$exist
/^[^\#]/
/<?($pattern)>?/
exists $addrs->{$1}
Truth table0%0/5
A and B and C and D
A= $existB= /^[^\#]/C= /<?($pattern)>?/D= exists $addrs->{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | /^[^\#]/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | /<?($pattern)>?/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | exists($addrs->{$1})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $addrs->{$1} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $exist--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | print TMPLIST $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | close(TMPLIST); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | flock(LIST, LOCK_UN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | close(LIST); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if($exist < $n) { rename("$file\.tmp", $file); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | else { unlink("$file\.tmp"); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return($n - $exist); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||