1 |
diff -Nur -x '*.orig' -x '*.rej' smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/check_smtp_forward mezzanine_patched_smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/check_smtp_forward |
2 |
--- smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/check_smtp_forward 1970-01-01 10:00:00.000000000 +1000 |
3 |
+++ mezzanine_patched_smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/check_smtp_forward 2006-08-18 15:18:22.418632168 +1000 |
4 |
@@ -0,0 +1,96 @@ |
5 |
+=head1 NAME |
6 |
+ |
7 |
+check_smtp_forward |
8 |
+ |
9 |
+=head1 DESCRIPTION |
10 |
+ |
11 |
+This plugin checks whether SMTP forwarding would be allowed for this |
12 |
+recipient by connecting to the internal mail server. |
13 |
+ |
14 |
+If the internal mail server rejects the mail, we DENY it. |
15 |
+If the internal mail server would accept the mail, we DECLINE. |
16 |
+If the internal mail server cannot be contacted, we DENYSOFT. |
17 |
+ |
18 |
+=head1 CONFIG |
19 |
+ |
20 |
+Reads smtproutes to determine where to send mail for various domains. |
21 |
+Ignores any default smtproutes entries as they are for upstream mail |
22 |
+servers (e.g. ISP). |
23 |
+ |
24 |
+=head1 AUTHOR |
25 |
+ |
26 |
+Copyright 2006 Gordon Rowell <gordonr@gormand.com.au> |
27 |
+ |
28 |
+This software is free software and may be distributed under the same |
29 |
+terms as qpsmtpd itself. |
30 |
+ |
31 |
+Based in part on the smtp-forward plugin from the qpsmtpd distribution. |
32 |
+ |
33 |
+=cut |
34 |
+ |
35 |
+use Net::SMTP; |
36 |
+ |
37 |
+sub register { |
38 |
+ my ($self, $qp, @args) = @_; |
39 |
+ |
40 |
+ for my $smtp_route ($self->qp->config("smtproutes")) |
41 |
+ { |
42 |
+ $smtp_route =~ s/[ \[ \] ]//g; |
43 |
+ my ($host, $server) = $smtp_route =~ m/(\S+):(\S+)/; |
44 |
+ |
45 |
+ next unless ($host); |
46 |
+ |
47 |
+ $self->{_smtp_host}{$host} = $server; |
48 |
+ |
49 |
+ $self->log(LOGINFO, "$host: $server"); |
50 |
+ } |
51 |
+} |
52 |
+ |
53 |
+sub hook_rcpt { |
54 |
+ my ($self, $transaction, $recipient) = @_; |
55 |
+ my $host = lc $recipient->host; |
56 |
+ |
57 |
+ my $server = $self->{_smtp_host}{$host} or return (DECLINED); |
58 |
+ my $port; |
59 |
+ |
60 |
+ ($server, $port) = split(/:/, $server); |
61 |
+ $port ||= 25; |
62 |
+ |
63 |
+ $self->log(LOGINFO, "Checking $recipient on $server:$port"); |
64 |
+ |
65 |
+ my $smtp = Net::SMTP->new( |
66 |
+ $server, |
67 |
+ Port => $port, |
68 |
+ Timeout => 60, |
69 |
+ Hello => $self->qp->config("me"), |
70 |
+ ) || return (DENYSOFT, |
71 |
+ "Unable to connect to $server: $!"); |
72 |
+ |
73 |
+ $smtp->mail( $transaction->sender->address || "" ); |
74 |
+ my $rc = $smtp->code; |
75 |
+ my $message = $smtp->message; |
76 |
+ chomp($message); |
77 |
+ |
78 |
+ if ($rc =~ m/^4\d{2}$/ ) { |
79 |
+ return(DENYSOFT, "Unable to queue message ($message)"); |
80 |
+ } elsif ($rc =~ m/^5\d{2}$/ ) { |
81 |
+ return(DENY, "Unable to queue message ($message)"); |
82 |
+ } |
83 |
+ |
84 |
+ $smtp->to($recipient->address); |
85 |
+ $rc = $smtp->code; |
86 |
+ $message = $smtp->message; |
87 |
+ chomp($message); |
88 |
+ |
89 |
+ if ($rc =~ m/^4\d{2}$/ ) { |
90 |
+ return(DENYSOFT, "Unable to queue message ($message)"); |
91 |
+ } elsif ($rc =~ m/^5\d{2}$/ ) { |
92 |
+ return(DENY, "Unable to queue message ($message)"); |
93 |
+ } |
94 |
+ |
95 |
+ $smtp->quit(); |
96 |
+ $rc = $smtp->code; |
97 |
+ |
98 |
+ $self->log(LOGINFO, "$server would accept message to $recipient"); |
99 |
+ return DECLINED; # Internal mail server is happy |
100 |
+} |