Milter/Module/MailBogusNull.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 86 CC 4 SCAR 12.0
CC
4
Cov
0%
envfrom_callback
6.0
envrcpt_callback
6.0
eoh_callback
6.0
CRAP 3.3
1 # $Id: MailBogusNull.pm,v 1.2 2006/03/22 15:48:23 tvierling Exp $
2 #
3 # Copyright (c) 2006 Todd Vierling <tv@pobox.com> <tv@duh.org>
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # 3. Neither the name of the author nor the names of contributors may be used
17 # to endorse or promote products derived from this software without specific
18 # prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31  
32 package Mail::Milter::Module::MailBogusNull;
33  
34 use 5.006;
35 use base Exporter;
36 use base Mail::Milter::Object;
37  
38 use strict;
39 use warnings;
40  
41 use Carp;
42 use Sendmail::Milter 0.18; # get needed constants
43 use Socket;
44 use UNIVERSAL;
45  
46 our $VERSION = '0.01';
47  
48 =pod
49  
50 =head1 NAME
51  
52 Mail::Milter::Module::MailBogusNull - milter to reject null-sender mail to multiple recipients
53  
54 =head1 SYNOPSIS
55  
56 use Mail::Milter::Module::MailBogusNull;
57  
58 my $milter = new Mail::Milter::Module::MailBogusNull;
59  
60 my $milter2 = &MailBogusNull; # convenience
61  
62 $milter2->set_message('Null sender mail should go to only one recipient');
63  
64 =head1 DESCRIPTION
65  
66 This milter module rejects any mail from a C<null sender> (empty
67 C<E<lt>E<gt>> address) which attempts to deliver to multiple recipients.
68 Normal delivery status notifications are intended for a single message, and
69 thus should only ever be addressed to a single recipient.
70  
71 =head1 METHODS
72  
73 =over 4
74  
75 =cut
76  
77 our @EXPORT = qw(&MailBogusNull);
78  
79 sub MailBogusNull {
80 new Mail::Milter::Module::MailBogusNull(@_);
81 }
82  
83 =pod
84  
85 =item new()
86  
87 Creates a MailBogusNull object. There are no arguments to configure this
88 module, as it is a fixed check.
89  
90 =cut
91  
92 sub new ($) {
93 my $this = Mail::Milter::Object::new(shift);
94  
95 $this->{_ignoretempfail} = 0;
96 $this->{_message} = 'Sender <> delivery status notifications cannot be addressed to more than one recipient';
97  
98 $this;
99 }
100  
101 =pod
102  
103 =item set_message(MESSAGE)
104  
105 Sets the message used when rejecting messages.
106  
107 This method returns a reference to the object itself, allowing this method
108 call to be chained.
109  
110 =cut
111  
112 sub set_message ($$) {
113 my $this = shift;
114  
115 $this->{_message} = shift;
116  
117 $this;
118 }
119  
120 sub envfrom_callback {
121 my $this = shift;
122 my $ctx = shift;
123  
124 if (shift ne '<>') {
125 $ctx->setpriv(undef);
126 return SMFIS_ACCEPT;
127 }
128 $ctx->setpriv(0);
129 SMFIS_CONTINUE;
130 }
131  
132 sub envrcpt_callback {
133 my $this = shift;
134 my $ctx = shift;
135  
136 my $nullcount = $ctx->getpriv;
137 $ctx->setpriv(++$nullcount);
138  
139 if ($nullcount > 1) {
140 $ctx->setreply(554, '5.7.0', $this->{_message});
141 return SMFIS_REJECT;
142 }
143 SMFIS_CONTINUE;
144 }
145  
146 sub eoh_callback {
147 my $this = shift;
148 my $ctx = shift;
149  
150 if ($ctx->getpriv() > 1) {
151 $ctx->setreply(554, '5.7.0', $this->{_message});
152 return SMFIS_REJECT;
153 }
154 SMFIS_ACCEPT;
155 }
156  
157 1;
158 __END__