Debian Codegraph @

plugins/parse_addr_withhelo

raw
1 #!perl -w
2
3 =head1 NAME
4
5 parse_addr_withhelo
6
7 =head1 SYNOPSIS
8
9 strict RFC 821 forbids parameters after the
10
11 MAIL FROM:<[email protected]>
12 and
13 RCPT TO:<[email protected]>
14
15 load this plugin to enforce, else the default EHLO parsing with
16 parameters is done.
17
18 =cut
19
20 use strict;
21 use warnings;
22
23 use Qpsmtpd::Constants;
24
25 sub hook_mail_parse {
26 my $self = shift;
27 return (OK, \&_parse) if ($self->qp->connection->hello eq 'helo');
28 return (DECLINED);
29 }
30
31 sub hook_rcpt_parse {
32 my $self = shift;
33 return (OK, \&_parse) if ($self->qp->connection->hello eq 'helo');
34 return (DECLINED);
35 }
36
37 sub _parse {
38 my ($self, $cmd, $line) = @_;
39 $self->log(LOGDEBUG, "_parse() cmd=[$cmd], line=[$line]");
40 if ($cmd eq 'mail') {
41 return (DENY, "Syntax error in command")
42 unless ($line =~ s/^from:\s*//i);
43 }
44 else { # cmd eq 'rcpt'
45 return (DENY, "Syntax error in command")
46 unless ($line =~ s/^to:\s*//i);
47 }
48
49 if ($line =~ s/^(<.*>)\s*//) {
50 my $addr = $1;
51 return (DENY, "No parameters allowed in " . uc($cmd))
52 if ($line =~ /^\S/);
53 return (OK, $addr, ());
54 }
55
56 ## now, no <> are given
57 $line =~ s/\s*$//;
58 if ($line =~ /\@/) {
59 return (DENY, "No parameters allowed in " . uc($cmd))
60 if ($line =~ /\@\S+\s+\S/);
61 return (OK, $line, ());
62 }
63
64 if ($cmd eq "mail") {
65 return (OK, "<>") unless $line; # 'MAIL FROM:' -> 'MAIL FROM:<>'
66 return (DENY, "Could not parse your MAIL FROM command");
67 }
68 else {
69 return (DENY, "Could not parse your RCPT TO command")
70 unless $line =~ /^(postmaster|abuse)$/i;
71 }
72 }
73