/usr/share/perl5/Mail/SpamAssassin/Plugin/SpamCop.pm is in spamassassin 3.4.1-8build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | # <@LICENSE>
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# </@LICENSE>
=head1 NAME
Mail::SpamAssassin::Plugin::SpamCop - perform SpamCop reporting of messages
=head1 SYNOPSIS
loadplugin Mail::SpamAssassin::Plugin::SpamCop
=head1 DESCRIPTION
SpamCop is a service for reporting spam. SpamCop determines the origin
of unwanted email and reports it to the relevant Internet service
providers. By reporting spam, you have a positive impact on the
problem. Reporting unsolicited email also helps feed spam filtering
systems, including, but not limited to, the SpamCop blacklist used in
SpamAssassin as a DNSBL.
Note that spam reports sent by this plugin to SpamCop each include the
entire spam message.
See http://www.spamcop.net/ for more information about SpamCop.
=cut
package Mail::SpamAssassin::Plugin::SpamCop;
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Logger;
use IO::Socket;
use strict;
use warnings;
use bytes;
use re 'taint';
use constant HAS_NET_DNS => eval { require Net::DNS; };
use constant HAS_NET_SMTP => eval { require Net::SMTP; };
use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);
sub new {
my $class = shift;
my $mailsaobject = shift;
$class = ref($class) || $class;
my $self = $class->SUPER::new($mailsaobject);
bless ($self, $class);
# are network tests enabled?
if (!$mailsaobject->{local_tests_only} && HAS_NET_DNS && HAS_NET_SMTP) {
$self->{spamcop_available} = 1;
dbg("reporter: network tests on, attempting SpamCop");
}
else {
$self->{spamcop_available} = 0;
dbg("reporter: local tests only, disabling SpamCop");
}
$self->set_config($mailsaobject->{conf});
return $self;
}
sub set_config {
my($self, $conf) = @_;
my @cmds;
=head1 USER OPTIONS
=over 4
=item spamcop_from_address user@example.com (default: none)
This address is used during manual reports to SpamCop as the From:
address. You can use your normal email address. If this is not set, a
guess will be used as the From: address in SpamCop reports.
=cut
push (@cmds, {
setting => 'spamcop_from_address',
default => '',
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
code => sub {
my ($self, $key, $value, $line) = @_;
if ($value =~ /([^<\s]+\@[^>\s]+)/) {
$self->{spamcop_from_address} = $1;
}
elsif ($value =~ /^$/) {
return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
}
else {
return $Mail::SpamAssassin::Conf::INVALID_VALUE;
}
},
});
=item spamcop_to_address user@example.com (default: generic reporting address)
Your customized SpamCop report submission address. You need to obtain
this address by registering at C<http://www.spamcop.net/>. If this is
not set, SpamCop reports will go to a generic reporting address for
SpamAssassin users and your reports will probably have less weight in
the SpamCop system.
=cut
push (@cmds, {
setting => 'spamcop_to_address',
default => 'spamassassin-submit@spam.spamcop.net',
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
code => sub {
my ($self, $key, $value, $line) = @_;
if ($value =~ /([^<\s]+\@[^>\s]+)/) {
$self->{spamcop_to_address} = $1;
}
elsif ($value =~ /^$/) {
return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
}
else {
return $Mail::SpamAssassin::Conf::INVALID_VALUE;
}
},
});
=item spamcop_max_report_size (default: 50)
Messages larger than this size (in kilobytes) will be truncated in
report messages sent to SpamCop. The default setting is the maximum
size that SpamCop will accept at the time of release.
=cut
push (@cmds, {
setting => 'spamcop_max_report_size',
default => 50,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
$conf->{parser}->register_commands(\@cmds);
}
sub plugin_report {
my ($self, $options) = @_;
return unless $self->{spamcop_available};
if (!$options->{report}->{options}->{dont_report_to_spamcop}) {
if ($self->spamcop_report($options)) {
$options->{report}->{report_available} = 1;
info("reporter: spam reported to SpamCop");
$options->{report}->{report_return} = 1;
}
else {
info("reporter: could not report spam to SpamCop");
}
}
}
sub smtp_dbg {
my ($command, $smtp) = @_;
dbg("reporter: SpamCop sent $command");
my $code = $smtp->code();
my $message = $smtp->message();
my $debug;
$debug .= $code if $code;
$debug .= ($code ? " " : "") . $message if $message;
chomp $debug;
dbg("reporter: SpamCop received $debug");
return 1;
}
sub spamcop_report {
my ($self, $options) = @_;
# original text
my $original = ${$options->{text}};
# check date
my $header = $original;
$header =~ s/\r?\n\r?\n.*//s;
my $date = Mail::SpamAssassin::Util::receive_date($header);
if ($date && $date < time - 2*86400) {
warn("reporter: SpamCop message older than 2 days, not reporting\n");
return 0;
}
# message variables
my $boundary = "----------=_" . sprintf("%08X.%08X",time,int(rand(2**32)));
while ($original =~ /^\Q${boundary}\E$/m) {
$boundary .= "/".sprintf("%08X",int(rand(2**32)));
}
my $description = "spam report via " . Mail::SpamAssassin::Version();
my $trusted = $options->{msg}->{metadata}->{relays_trusted_str};
my $untrusted = $options->{msg}->{metadata}->{relays_untrusted_str};
my $user = $options->{report}->{main}->{'username'} || 'unknown';
my $host = Mail::SpamAssassin::Util::fq_hostname() || 'unknown';
my $from = $options->{report}->{conf}->{spamcop_from_address} || "$user\@$host";
# message data
my %head = (
'To' => $options->{report}->{conf}->{spamcop_to_address},
'From' => $from,
'Subject' => 'report spam',
'Date' => Mail::SpamAssassin::Util::time_to_rfc822_date(),
'Message-Id' =>
sprintf("<%08X.%08X@%s>",time,int(rand(2**32)),$host),
'MIME-Version' => '1.0',
'Content-Type' => "multipart/mixed; boundary=\"$boundary\"",
);
# truncate message
if (length($original) > $self->{main}->{conf}->{spamcop_max_report_size} * 1024) {
substr($original, ($self->{main}->{conf}->{spamcop_max_report_size} * 1024)) =
"\n[truncated by SpamAssassin]\n";
}
my $body = <<"EOM";
This is a multi-part message in MIME format.
--$boundary
Content-Type: message/rfc822; x-spam-type=report
Content-Description: $description
Content-Disposition: attachment
Content-Transfer-Encoding: 8bit
X-Spam-Relays-Trusted: $trusted
X-Spam-Relays-Untrusted: $untrusted
$original
--$boundary--
EOM
# compose message
my $message;
while (my ($k, $v) = each %head) {
$message .= "$k: $v\n";
}
$message .= "\n" . $body;
# send message
my $failure;
my $mx = $head{To};
my $hello = Mail::SpamAssassin::Util::fq_hostname() || $from;
$mx =~ s/.*\@//;
$hello =~ s/.*\@//;
for my $rr (Net::DNS::mx($mx)) {
my $exchange = Mail::SpamAssassin::Util::untaint_hostname($rr->exchange);
next unless $exchange;
my $smtp;
if ($smtp = Net::SMTP->new($exchange,
Hello => $hello,
Port => 587,
Timeout => 10))
{
if ($smtp->mail($from) && smtp_dbg("FROM $from", $smtp) &&
$smtp->recipient($head{To}) && smtp_dbg("TO $head{To}", $smtp) &&
$smtp->data($message) && smtp_dbg("DATA", $smtp) &&
$smtp->quit() && smtp_dbg("QUIT", $smtp))
{
# tell user we succeeded after first attempt if we previously failed
warn("reporter: SpamCop report to $exchange succeeded\n") if defined $failure;
return 1;
}
my $code = $smtp->code();
my $text = $smtp->message();
$failure = "$code $text" if ($code && $text);
}
$failure ||= "Net::SMTP error";
chomp $failure;
warn("reporter: SpamCop report to $exchange failed: $failure\n");
}
return 0;
}
1;
=back
=cut
|