| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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 . 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
|
|
|
2
|
|
21836
|
use 5.008000; |
|
|
2
|
|
|
|
|
9
|
|
|
|
2
|
|
|
|
|
98
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
84
|
|
|
13
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
261
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
|
16
|
2
|
|
|
2
|
|
1012
|
use AutoLoader qw(AUTOLOAD); |
|
|
2
|
|
|
|
|
1657
|
|
|
|
2
|
|
|
|
|
11
|
|
|
17
|
2
|
|
|
2
|
|
733
|
use Mail::Salsa::Logs qw(logs); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
128
|
|
|
18
|
2
|
|
|
2
|
|
10
|
use Mail::Salsa::Utils qw(file_path); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
126
|
|
|
19
|
2
|
|
|
2
|
|
10
|
use Fcntl qw(:flock); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2785
|
|
|
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
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
|
32
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
33
|
|
|
|
|
|
|
our @EXPORT = qw(&remove_from_list); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
|
38
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
|
39
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
40
|
0
|
|
|
|
|
|
my $self = {@_}; |
|
41
|
0
|
|
|
|
|
|
bless ($self, $class); |
|
42
|
0
|
|
|
|
|
|
$self->process_msg(); |
|
43
|
0
|
|
|
|
|
|
return($self); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub process_msg { |
|
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my ($name, $domain) = split(/\@/, $self->{'list'}); |
|
50
|
0
|
0
|
|
|
|
|
if($self->{'config'}->{'unsubscribe'} eq "n") { |
|
51
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if(exists($self->{'headers'}->{'0.0'}->{'cc'})) { |
|
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
|
0
|
|
|
|
|
if(scalar(@{$exist}) < scalar(@emails)) { |
|
|
0
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @notexist = (); |
|
73
|
0
|
|
|
|
|
|
my %seen = (); |
|
74
|
0
|
|
|
|
|
|
@seen{@{$exist}} = (0 .. $#{$exist}); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
for my $e (@emails) { exists($seen{$e}) or push(@notexist, $e); } |
|
|
0
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Mail::Salsa::Utils::tplsendmail( |
|
77
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
list => $self->{'list'}, |
|
85
|
|
|
|
|
|
|
emails => join("\n", @notexist), |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
); |
|
88
|
0
|
0
|
|
|
|
|
(scalar(@notexist) < scalar(@emails)) or return(); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
|
|
|
my $kfile = file_path($self->{'list'}, $self->{'list_dir'}, 'stamp.txt'); |
|
91
|
0
|
0
|
|
|
|
|
if(my $stamp = Mail::Salsa::Utils::get_key($kfile)) { |
|
92
|
0
|
0
|
|
|
|
|
if(my $human = Mail::Salsa::Utils::lookup4key($self->{'message'}, $stamp)) { |
|
93
|
0
|
0
|
|
|
|
|
if(&remove_from_list($file, { $self->{'from'} => 0 })) { |
|
94
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
list => $self->{'list'}, |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
0
|
|
|
|
|
|
for my $email (@{$exist}) { |
|
|
0
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
origin => $self->{'from'}, |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
0
|
|
|
|
|
|
return(); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub remove_from_list { |
|
128
|
0
|
|
|
0
|
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})); |
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
open(LIST, "<", $file) or die("$!"); |
|
134
|
0
|
|
|
|
|
|
flock(LIST, LOCK_EX); |
|
135
|
0
|
0
|
|
|
|
|
open(TMPLIST, ">", "$file\.tmp") or die("$!"); |
|
136
|
0
|
|
|
|
|
|
select(TMPLIST); |
|
137
|
0
|
|
|
|
|
|
while() { |
|
138
|
0
|
0
|
0
|
|
|
|
if($exist && |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
if($exist < $n) { rename("$file\.tmp", $file); } |
|
|
0
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; |
|
159
|
|
|
|
|
|
|
__END__ |