~ubuntu-branches/ubuntu/utopic/spamassassin/utopic-updates

« back to all changes in this revision

Viewing changes to lib/Mail/SpamAssassin/Message/Metadata/Received.pm

  • Committer: Package Import Robot
  • Author(s): Noah Meyerhans
  • Date: 2014-02-14 22:45:15 UTC
  • mfrom: (0.8.1) (0.6.2) (5.1.22 sid)
  • Revision ID: package-import@ubuntu.com-20140214224515-z1es2twos8xh7n2y
Tags: 3.4.0-1
* New upstream version! (Closes: 738963, 738872, 738867)
* Scrub the environment when switching to the debian-spamd user in
  postinst and cron.daily. (Closes: 738951)
* Enhancements to postinst to better manage ownership of
  /var/lib/spamassassin, via Iain Lane <iain.lane@canonical.com>
  (Closes: 738974)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
# ---------------------------------------------------------------------------
39
39
 
40
 
package Mail::SpamAssassin::Message::Metadata::Received;
41
 
1;
 
40
use strict;  # make Test::Perl::Critic happy
 
41
package Mail::SpamAssassin::Message::Metadata::Received; 1;
42
42
 
43
43
package Mail::SpamAssassin::Message::Metadata;
44
44
use strict;
48
48
 
49
49
use Mail::SpamAssassin::Dns;
50
50
use Mail::SpamAssassin::PerMsgStatus;
51
 
use Mail::SpamAssassin::Util::RegistrarBoundaries;
52
51
use Mail::SpamAssassin::Constants qw(:ip);
53
52
 
54
53
# ---------------------------------------------------------------------------
56
55
sub parse_received_headers {
57
56
  my ($self, $permsgstatus, $msg) = @_;
58
57
 
 
58
  my $suppl_attrib = $msg->{suppl_attrib};  # out-of-band info from a caller
 
59
 
 
60
  # a caller may assert that a message is coming from inside or from an
 
61
  # authenticated roaming users; this info may not be available in mail
 
62
  # header section, e.g. in case of nonstandard authentication mechanisms
 
63
  my $originating;  # boolean
 
64
  $originating = $suppl_attrib->{originating}  if ref $suppl_attrib;
 
65
 
59
66
  $self->{relays_trusted} = [ ];
60
67
  $self->{num_relays_trusted} = 0;
61
68
  $self->{relays_trusted_str} = '';
190
197
      } else {
191
198
        # trusted_networks matches?
192
199
        if (!$relay->{auth} && !$trusted->contains_ip($relay->{ip})) {
193
 
          $in_trusted = 0;
 
200
          if (!$originating) {
 
201
            $in_trusted = 0;    # break the trust chain
 
202
          } else {  # caller asserts a msg was submitted from inside or auth'd
 
203
            $found_msa = 1;     # let's assume the previous hop was actually
 
204
                                # an MSA, and propagate trust from here on
 
205
            dbg('received-header: originating, '.
 
206
                '%s and remaining relays will be considered trusted%s',
 
207
                $relay->{ip}, !$in_internal ? '' : ', but no longer internal');
 
208
          }
194
209
          $in_internal = 0;     # if it's not trusted it's not internal
195
210
        } else {
196
211
          # internal_networks matches?
384
399
 
385
400
  # try to catch authenticated message identifier
386
401
  #
387
 
  # with ESMTPA, ESMTPSA, LMTPA, LMTPSA should cover RFC 3848 compliant MTAs
 
402
  # with ESMTPA, ESMTPSA, LMTPA, LMTPSA should cover RFC 3848 compliant MTAs,
 
403
  # UTF8SMTPA and UTF8LMTPA are covered by RFC 4954 and RFC 6531,
388
404
  # with ASMTP (Authenticated SMTP) is used by Earthlink, Exim 4.34, and others
389
405
  # with HTTP should only be authenticated webmail sessions
390
406
  # with HTTPU is used by Communigate Pro with Pronto! webmail interface
391
 
  if (/ by / && / with (ESMTPA|ESMTPSA|LMTPA|LMTPSA|ASMTP|HTTPU?)(?: |$)/i) {
 
407
  if (/ by / && / with ((?:ES|L|UTF8S|UTF8L)MTPS?A|ASMTP|HTTPU?)(?: |;|$)/i) {
392
408
    $auth = $1;
393
409
  }
394
410
  # GMail should use ESMTPSA to indicate that it is in fact authenticated,
404
420
  elsif (/authenticated/ && /^from .*?(?:\](?: \([^)]*\))?\)|\)\]) .*?\(.*?authenticated.*?\).*? by/) {
405
421
    $auth = 'Sendmail';
406
422
  }
 
423
  # workaround for GMX, which authenticates users but does not indicate it properly - # SMTP version
 
424
  elsif (/from \S* \((?:HELO|EHLO) (\S*)\) \[(${IP_ADDRESS})\] by (mail\.gmx\.(?:net|com)) \([^\)]+\) with ((?:ESMTP|SMTP))/) {
 
425
    $auth = "GMX ($4 / $3)";
 
426
  }
407
427
  # Critical Path Messaging Server
408
428
  elsif (/ \(authenticated as /&&/\) by .+ \(\d{1,2}\.\d\.\d{3}(?:\.\d{1,3})?\) \(authenticated as .+\) id /) {
409
429
    $auth = 'CriticalPath';
412
432
  elsif (/\) \(Authenticated sender: \S+\) by \S+ \(Postfix\) with /) {
413
433
    $auth = 'Postfix';
414
434
  }
415
 
  # Communigate Pro
416
 
  elsif (/CommuniGate Pro SMTP/ && / \(account /) {
 
435
  # Communigate Pro - Bug 6495 adds HTTP as possible transmission method
 
436
  elsif (/CommuniGate Pro (HTTP|SMTP)/ && / \(account /) {
417
437
    $auth = 'Communigate';
418
438
  }
419
439
  # Microsoft Exchange (complete with syntax error)
429
449
      $envfrom = $1;
430
450
    }
431
451
 
432
 
    # bug 3236: ignore Squirrelmail injection steps.
433
452
    # from 142.169.110.122 (SquirrelMail authenticated user synapse) by
434
453
    # mail.nomis80.org with HTTP; Sat, 3 Apr 2004 10:33:43 -0500 (EST)
435
 
    if (/ \(SquirrelMail authenticated user /) {
436
 
      dbg("received-header: ignored SquirrelMail injection: $_");
437
 
      return 0;
 
454
    # Expanded to NaSMail Bug 6783
 
455
    if (/ \((?:SquirrelMail|NaSMail) authenticated user /) {
 
456
      #REVERTING bug 3236 and implementing re: bug 6549
 
457
      if (/(${IP_ADDRESS})\b(?![.-]).{10,80}by (\S+) with HTTP/) {
 
458
        $ip = $1; $by = $2; goto enough;
 
459
      }
438
460
    }
439
461
 
440
462
    # AOL WebMail headers
855
877
    if (/^(\S+) \((?:HELO|EHLO) ([^\)]*)\) \((\S*@)?\[?(${IP_ADDRESS})\]?\).* by (\S+) /)
856
878
    {
857
879
      $mta_looked_up_dns = 1;
858
 
      $rdns = $1; $helo = $2; $ident = (defined $3) ? $3 : '';
859
 
      $ip = $4; $by = $5;
860
 
      if ($ident) { $ident =~ s/\@$//; }
 
880
      $rdns = $1; 
 
881
      $helo = $2; 
 
882
      $ident = (defined $3) ? $3 : '';
 
883
      $ip = $4; 
 
884
      $by = $5;
 
885
      if ($ident) { 
 
886
        $ident =~ s/\@$//; 
 
887
      }
861
888
      goto enough;
862
889
    }
863
890
 
1071
1098
      goto enough;
1072
1099
    }
1073
1100
 
 
1101
    # Yahoo Authenticated SMTP; Bug #6535
 
1102
    # from itrqtnlnq (lucilleskinner@93.124.107.183 with login) by smtp111.mail.ne1.yahoo.com with SMTP; 17 Jan 2011 08:23:27 -0800 PST
 
1103
    if (/^(\S+) \((\S+)@(${IP_ADDRESS}) with login\) by (\S+\.yahoo\.com) with SMTP/) {
 
1104
      $helo = $1; $ip = $3; $by = $4; goto enough;
 
1105
    }
 
1106
 
1074
1107
    # a synthetic header, generated internally:
1075
1108
    # Received: X-Originating-IP: 1.2.3.4
1076
1109
    if (/^X-Originating-IP: (\S+)$/) {
1255
1288
    $rdns = '';         # some MTAs seem to do this
1256
1289
  }
1257
1290
  
1258
 
  $ip =~ s/^\[//; $ip =~ s/\]$//;
 
1291
  $ip =~ s/^ipv6://i;   # remove "IPv6:" prefix
 
1292
  $ip =~ s/^\[//; $ip =~ s/\]\z//;
1259
1293
 
1260
 
  $ip =~ s/^ipv6://i;   # remove optional "IPv6:" prefix
 
1294
  # IPv6 Scoped Address (RFC 4007, RFC 6874, RFC 3986 "unreserved" charset)
 
1295
  $ip =~ s/%[A-Z0-9._~-]*\z//si;  # scoped address? remove <zone_id>
1261
1296
 
1262
1297
  # remove "::ffff:" prefix from IPv4-mapped-in-IPv6 addresses,
1263
 
  # so we can treat them as simply IPv4 addresses
 
1298
  # so we can treat them simply as IPv4 addresses
 
1299
  # (only handles 'alternative form', not 'preferred form' - to be improved)
1264
1300
  $ip =~ s/^0*:0*:(?:0*:)*ffff:(\d+\.\d+\.\d+\.\d+)$/$1/i;
1265
1301
 
1266
1302
  $envfrom =~ s/^\s*<*//gs; $envfrom =~ s/>*\s*$//gs;