1 |
diff -Nur -x '*.orig' -x '*.rej' smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/disclaimer mezzanine_patched_smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/disclaimer |
2 |
--- smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/disclaimer 2007-06-17 08:52:46.000000000 -0600 |
3 |
+++ mezzanine_patched_smeserver-qpsmtpd-1.2.1/root/usr/share/qpsmtpd/plugins/disclaimer 2007-06-17 08:51:55.000000000 -0600 |
4 |
@@ -1,83 +1,101 @@ |
5 |
use MIME::Parser; |
6 |
use MIME::Entity; |
7 |
|
8 |
+sub register { |
9 |
+ my ($self, $qp, @args) = @_; |
10 |
+ |
11 |
+ $self->log(LOGERROR, "Bad parameters for the disclaimer plugin") |
12 |
+ if @_ % 2; |
13 |
+ |
14 |
+ %{$self->{_args}} = @args; |
15 |
+} |
16 |
+ |
17 |
sub hook_data_post { |
18 |
my ($self, $transaction) = @_; |
19 |
|
20 |
- if ($transaction->data_size > 10 * 1024 * 1024) { |
21 |
- $self->log(LOGWARN, "Message too large to sign"); |
22 |
- return DECLINED; |
23 |
- } elsif ( $transaction->header->get('X-Qpsmtp-Disclaimer') ) { |
24 |
+ if ( $transaction->header->get('X-Qpsmtp-Disclaimer') ) { |
25 |
$self->log(LOGNOTICE, "Message already has disclaimer attached"); |
26 |
return DECLINED; |
27 |
} |
28 |
|
29 |
- $self->qp->version =~ m/([\.\d]+).*/; |
30 |
- my $versionnum = $1; |
31 |
my @rcpt_hosts = ($self->qp->config("me"), $self->qp->config("rcpthosts")); |
32 |
+ my $fromhost; |
33 |
+ if ( $self->{_args}->{tag_all} ) { |
34 |
+ $fromhost = $rcpt_hosts[0]; |
35 |
+ } else { |
36 |
+ $self->qp->version =~ m/([\.\d]+).*/; |
37 |
+ my $versionnum = $1; |
38 |
|
39 |
- my $fromhost = $transaction->sender->host; |
40 |
- my $fromlocal = 0; |
41 |
- |
42 |
- for my $allowed (@rcpt_hosts) { |
43 |
- $allowed =~ s/^\s*(\S+)/$1/; |
44 |
- ($fromlocal = 1, last) if (($fromhost eq lc $allowed) or (substr($allowed,0,1) eq "." and |
45 |
- $fromhost =~ m/\Q$allowed\E$/i)); |
46 |
- } |
47 |
- |
48 |
- if (($versionnum >= 0.26) and ($fromlocal == 0)) { |
49 |
- my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map'); |
50 |
- $fromlocal = 1 if exists $more_rcpt_hosts->{$fromhost}; |
51 |
- } |
52 |
- |
53 |
- unless ($fromlocal) { |
54 |
- $self->log(LOGDEBUG, "Not from local domain"); |
55 |
- return DECLINED; |
56 |
- } |
57 |
- |
58 |
- my $toexternal=0; |
59 |
- foreach my $rcpt ( $transaction->recipients ) { |
60 |
- my $local = 0; |
61 |
- my $host = $rcpt->host; |
62 |
+ $fromhost = $transaction->sender->host; |
63 |
+ my $fromlocal = 0; |
64 |
|
65 |
for my $allowed (@rcpt_hosts) { |
66 |
$allowed =~ s/^\s*(\S+)/$1/; |
67 |
- ($local = 1, last) if (($host eq lc $allowed) or (substr($allowed,0,1) eq "." and |
68 |
- $host =~ m/\Q$allowed\E$/i)); |
69 |
+ ($fromlocal = 1, last) if (($fromhost eq lc $allowed) or (substr($allowed,0,1) eq "." and |
70 |
+ $fromhost =~ m/\Q$allowed\E$/i)); |
71 |
} |
72 |
|
73 |
- if (($versionnum >= 0.26) and ($local == 0)) { |
74 |
+ if (($versionnum >= 0.26) and ($fromlocal == 0)) { |
75 |
my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map'); |
76 |
- $local = 1 if exists $more_rcpt_hosts->{$host}; |
77 |
+ $fromlocal = 1 if exists $more_rcpt_hosts->{$fromhost}; |
78 |
} |
79 |
|
80 |
- ($toexternal = 1, last) unless $local; |
81 |
- } |
82 |
- |
83 |
- unless ($toexternal) { |
84 |
- $self->log(LOGDEBUG, "Not from local domain"); |
85 |
- return DECLINED; |
86 |
+ unless ($fromlocal) { |
87 |
+ $self->log(LOGDEBUG, "Not from local domain"); |
88 |
+ return DECLINED; |
89 |
+ } |
90 |
} |
91 |
|
92 |
- my $parser = new MIME::Parser; |
93 |
- $parser->output_under( $self->spool_dir() ); |
94 |
- $parser->extract_uuencode(1); |
95 |
- my $ent = $parser->parse_open( $transaction->body_filename() ); |
96 |
- |
97 |
+ my $specific = 0; |
98 |
my @lines; |
99 |
if ( @lines = $self->qp->config("disclaimer_$fromhost") ) { |
100 |
$self->log(LOGDEBUG, "Found disclaimer for domain: $fromhost"); |
101 |
+ $specific = 1; |
102 |
} elsif ( @lines = $self->qp->config("disclaimer") ) { |
103 |
$self->log(LOGDEBUG, "Found general disclaimer"); |
104 |
} else { |
105 |
$self->log(LOGERROR, "No disclaimer found for domain: $fromhost"); |
106 |
return DECLINED; |
107 |
} |
108 |
- $ent->make_multipart( 'mixed', Force => 1 ) if $ent->parts == 2 && $ent->mime_type eq 'multipart/alternative'; |
109 |
+ |
110 |
+ unless ( $self->{_args}->{tag_all} ) { |
111 |
+ my $toexternal=0; |
112 |
+ foreach my $rcpt ( $transaction->recipients ) { |
113 |
+ my $local = 0; |
114 |
+ my $host = $rcpt->host; |
115 |
+ |
116 |
+ ($toexternal = 1, last) if ( $specific && $host ne $fromhost); |
117 |
+ |
118 |
+ for my $allowed (@rcpt_hosts) { |
119 |
+ $allowed =~ s/^\s*(\S+)/$1/; |
120 |
+ ($local = 1, last) if (($host eq lc $allowed) or (substr($allowed,0,1) eq "." and |
121 |
+ $host =~ m/\Q$allowed\E$/i)); |
122 |
+ } |
123 |
+ |
124 |
+ if (($versionnum >= 0.26) and ($local == 0)) { |
125 |
+ my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map'); |
126 |
+ $local = 1 if exists $more_rcpt_hosts->{$host}; |
127 |
+ } |
128 |
+ |
129 |
+ ($toexternal = 1, last) unless $local; |
130 |
+ } |
131 |
+ |
132 |
+ unless ($toexternal) { |
133 |
+ $self->log(LOGDEBUG, "Not from local domain"); |
134 |
+ return DECLINED; |
135 |
+ } |
136 |
+ } |
137 |
+ |
138 |
+ my $parser = new MIME::Parser; |
139 |
+ $parser->output_under( $self->spool_dir() ); |
140 |
+ $parser->extract_uuencode(1); |
141 |
+ my $ent = $parser->parse_open( $transaction->body_filename() ); |
142 |
+ |
143 |
+ $ent->make_multipart( 'mixed', Force => 1 ) if $ent->mime_type ne 'multipart/mixed'; |
144 |
$ent->attach( Data => join("\n", @lines), |
145 |
- Encoding => '-SUGGEST', |
146 |
- Filename => 'disclaimer.txt', |
147 |
- Type => 'text/plain'); |
148 |
+ Encoding => $self->{_args}->{mime_encoding} || '-SUGGEST', |
149 |
+ Filename => $self->{_args}->{mime_filename} || 'disclaimer.txt', |
150 |
+ Type => $self->{_args}->{mime_type} || 'text/plain'); |
151 |
if ($ent->parts <= 2) { |
152 |
$transaction->header->empty(); |
153 |
$transaction->header($ent->head()); |