File: parse_addr_withhelo

package info (click to toggle)
qpsmtpd 0.94-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,340 kB
  • sloc: perl: 17,176; sh: 543; makefile: 186; sql: 100
file content (73 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (4)
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
#!perl -w

=head1 NAME

parse_addr_withhelo

=head1 SYNOPSIS

strict RFC 821 forbids parameters after the

   MAIL FROM:<user@example.net>
 and
   RCPT TO:<someone@example.com>

load this plugin to enforce, else the default EHLO parsing with
parameters is done.

=cut

use strict;
use warnings;

use Qpsmtpd::Constants;

sub hook_mail_parse {
    my $self = shift;
    return (OK, \&_parse) if ($self->qp->connection->hello eq 'helo');
    return (DECLINED);
}

sub hook_rcpt_parse {
    my $self = shift;
    return (OK, \&_parse) if ($self->qp->connection->hello eq 'helo');
    return (DECLINED);
}

sub _parse {
    my ($self, $cmd, $line) = @_;
    $self->log(LOGDEBUG, "_parse() cmd=[$cmd], line=[$line]");
    if ($cmd eq 'mail') {
        return (DENY, "Syntax error in command")
          unless ($line =~ s/^from:\s*//i);
    }
    else {    # cmd eq 'rcpt'
        return (DENY, "Syntax error in command")
          unless ($line =~ s/^to:\s*//i);
    }

    if ($line =~ s/^(<.*>)\s*//) {
        my $addr = $1;
        return (DENY, "No parameters allowed in " . uc($cmd))
          if ($line =~ /^\S/);
        return (OK, $addr, ());
    }

    ## now, no <> are given
    $line =~ s/\s*$//;
    if ($line =~ /\@/) {
        return (DENY, "No parameters allowed in " . uc($cmd))
          if ($line =~ /\@\S+\s+\S/);
        return (OK, $line, ());
    }

    if ($cmd eq "mail") {
        return (OK, "<>") unless $line;    # 'MAIL FROM:' -> 'MAIL FROM:<>'
        return (DENY, "Could not parse your MAIL FROM command");
    }
    else {
        return (DENY, "Could not parse your RCPT TO command")
          unless $line =~ /^(postmaster|abuse)$/i;
    }
}