~ubuntu-branches/ubuntu/lucid/spamassassin/lucid-proposed

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/Plugin/SPF.pm

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville, Ubuntu Merge-o-Matic, Laurent Bigonville
  • Date: 2006-07-31 15:40:08 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060731154008-j37ulp5pgfkddegw
Tags: 3.1.3-1ubuntu1
[ Ubuntu Merge-o-Matic ]
* Merge from debian unstable.

[ Laurent Bigonville ]
* fix debian/control.
* drop debian/patches/40_fix_dns_issue.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
use Mail::SpamAssassin::Plugin;
36
36
use Mail::SpamAssassin::Logger;
 
37
use Mail::SpamAssassin::Timeout;
37
38
use strict;
38
39
use warnings;
39
40
use bytes;
79
80
 
80
81
=over 4
81
82
 
 
83
=item spf_timeout n             (default: 5)
 
84
 
 
85
How many seconds to wait for an SPF query to complete, before scanning
 
86
continues without the SPF result.
 
87
 
 
88
=cut
 
89
 
 
90
  push (@cmds, {
 
91
    setting => 'spf_timeout',
 
92
    default => 5,
 
93
    type => $Mail::SpamAssassin::Conf::CONF_TYPE_NUMERIC
 
94
  });
 
95
 
82
96
=item whitelist_from_spf add@ress.com
83
97
 
84
98
Use this to supplement the whitelist_from addresses with a check against the
228
242
    $scanner->{spf_failure_comment} = undef;
229
243
  }
230
244
 
231
 
  my $lasthop = $scanner->{relays_untrusted}->[0];
 
245
  my $lasthop = $self->_get_relay($scanner);
232
246
  if (!defined $lasthop) {
233
 
    dbg("spf: message was delivered entirely via trusted relays, not required");
 
247
    dbg("spf: no suitable relay for spf use found, skipping SPF". ($ishelo ? '-helo' : '') ." check");
234
248
    return;
235
249
  }
236
250
 
286
300
  }
287
301
 
288
302
  my ($result, $comment);
289
 
  my $timeout = 5;
290
 
  my $oldalarm = 0;
291
 
 
292
 
  eval {
293
 
    local $SIG{ALRM} = sub { die "__alarm__ignore__\n" };
294
 
    $oldalarm = alarm($timeout);
 
303
  my $timeout = $scanner->{conf}->{spf_timeout};
 
304
 
 
305
  my $timer = Mail::SpamAssassin::Timeout->new({ secs => $timeout });
 
306
  my $err = $timer->run_and_catch(sub {
 
307
 
295
308
    ($result, $comment) = $query->result();
296
 
    if (defined $oldalarm) {
297
 
      alarm $oldalarm; $oldalarm = undef;
298
 
    }
299
 
  };
300
309
 
301
 
  my $err = $@;
302
 
  if (defined $oldalarm) {
303
 
    alarm $oldalarm; $oldalarm = undef;
304
 
  }
 
310
  });
305
311
 
306
312
  if ($err) {
307
313
    chomp $err;
308
 
    if ($err eq "__alarm__ignore__") {
309
 
      dbg("spf: lookup timed out after $timeout seconds");
310
 
    } else {
311
 
      warn("spf: lookup failed: $err\n");
312
 
    }
 
314
    warn("spf: lookup failed: $err\n");
313
315
    return 0;
314
316
  }
315
317
 
340
342
  dbg("spf: query for $scanner->{sender}/$ip/$helo: result: $result, comment: $comment");
341
343
}
342
344
 
 
345
sub _get_relay {
 
346
  my ($self, $scanner) = @_;
 
347
 
 
348
  # dos: first external relay, not first untrusted
 
349
  return $scanner->{relays_external}->[0];
 
350
}
 
351
 
343
352
sub _get_sender {
344
353
  my ($self, $scanner) = @_;
345
354
  my $sender;
347
356
  $scanner->{sender_got} = 1;
348
357
  $scanner->{sender} = '';
349
358
 
350
 
  if (exists($scanner->{relays_untrusted}->[0])) {
351
 
    $sender = $scanner->{relays_untrusted}->[0]->{envfrom};
 
359
  my $relay = $self->_get_relay($scanner);
 
360
  if (defined $relay) {
 
361
    $sender = $relay->{envfrom};
352
362
  }
353
363
 
354
364
  if ($sender) {
355
 
    dbg("spf: found Envelope-From in last untrusted Received header");
 
365
    dbg("spf: found Envelope-From in first external Received header");
356
366
  }
357
367
  else {
358
368
    # We cannot use the env-from data, since it went through 1 or more relays