You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2021/04/12 13:32:05 UTC
svn commit: r1888675 -
/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm
Author: hege
Date: Mon Apr 12 13:32:05 2021
New Revision: 1888675
URL: http://svn.apache.org/viewvc?rev=1888675&view=rev
Log:
Add spamcop_relayhost option (Bug 5402)
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm?rev=1888675&r1=1888674&r2=1888675&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SpamCop.pm Mon Apr 12 13:32:05 2021
@@ -43,6 +43,7 @@ package Mail::SpamAssassin::Plugin::Spam
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Logger;
+use Mail::SpamAssassin::Util qw(untaint_var);
use IO::Socket;
use strict;
use warnings;
@@ -152,6 +153,35 @@ size that SpamCop will accept at the tim
type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
});
+=item spamcop_relayhost server:port (default: direct connection to SpamCop)
+
+Direct connection to SpamCop servers (port 587) is used for report
+submission by default. If this is undesirable or blocked by local firewall
+policies, you can specify a local SMTP relayhost to forward reports.
+Relayhost should be configured to not scan the report, for example by using
+a separate submission port. SSL or authentication is not supported.
+
+=cut
+
+ push (@cmds, {
+ setting => 'spamcop_relayhost',
+ default => undef,
+ type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
+ code => sub {
+ my ($self, $key, $value, $line) = @_;
+ if ($value =~ /^(\S+):(\d{2,5})$/) {
+ $self->{spamcop_relayhost} = untaint_var($1);
+ $self->{spamcop_relayport} = untaint_var($2);
+ }
+ elsif ($value =~ /^$/) {
+ return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
+ }
+ else {
+ return $Mail::SpamAssassin::Conf::INVALID_VALUE;
+ }
+ }
+ });
+
$conf->{parser}->register_commands(\@cmds);
}
@@ -256,17 +286,31 @@ EOM
# 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,
+
+ my @mxs;
+ if ($options->{report}->{conf}->{spamcop_relayhost}) {
+ push @mxs, $options->{report}->{conf}->{spamcop_relayhost};
+ } else {
+ my $mx = $head{To};
+ $mx =~ s/.*\@//;
+ foreach my $rr (Net::DNS::mx($mx)) {
+ if (defined $rr->exchange) {
+ push @mxs, Mail::SpamAssassin::Util::untaint_hostname($rr->exchange);
+ }
+ }
+ if (!@mxs) {
+ warn("reporter: failed to resolve SpamCop MX servers\n");
+ return 0;
+ }
+ }
+ my $port = $options->{report}->{conf}->{spamcop_relayport} || 587;
+
+ for my $exchange (@mxs) {
+ if (my $smtp = Net::SMTP->new($exchange,
Hello => $hello,
- Port => 587,
+ Port => $port,
Timeout => 10))
{
if ($smtp->mail($from) && smtp_dbg("FROM $from", $smtp) &&