Milter/Module/HeaderFromMissing.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 55 CC 3 SCAR 12.0
CC
3
Cov
0%
header_callback
6.0
eoh_callback
6.0
HeaderFromMissing
2.0
CRAP 3.3
1 # $Id: HeaderFromMissing.pm,v 1.4 2004/02/26 19:24:52 tvierling Exp $
2 #
3 # Copyright (c) 2002-2004 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::HeaderFromMissing;
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 Sendmail::Milter 0.18; # get needed constants
42  
43 our $VERSION = '0.03';
44  
45 =pod
46  
47 =head1 NAME
48  
49 Mail::Milter::Module::HeaderFromMissing - milter to reject messages missing a From: header
50  
51 =head1 SYNOPSIS
52  
53 use Mail::Milter::Module::HeaderFromMissing;
54  
55 my $milter = new Mail::Milter::Module::HeaderFromMissing();
56  
57 my $milter2 = &HeaderFromMissing; # convenience
58  
59 =head1 DESCRIPTION
60  
61 This milter module rejects any message at the DATA stage that is missing
62 the From: header. This header should never be absent on any message,
63 even if that message is missing Date: or Subject:.
64  
65 =cut
66  
67 our @EXPORT = qw(&HeaderFromMissing);
68  
69 sub HeaderFromMissing {
70 new Mail::Milter::Module::HeaderFromMissing(@_);
71 }
72  
73 sub envfrom_callback {
74 shift; # $this
75 my $ctx = shift;
76  
77 $ctx->setpriv(0);
78  
79 SMFIS_CONTINUE;
80 }
81  
82 sub header_callback {
83 shift; # $this
84 my $ctx = shift;
85 my $hname = shift;
86  
87 $ctx->setpriv(1) if (lc($hname) eq 'from');
88  
89 SMFIS_CONTINUE;
90 }
91  
92 sub eoh_callback {
93 shift; # $this
94 my $ctx = shift;
95  
96 unless ($ctx->getpriv()) {
97 $ctx->setreply("554", "5.7.1", "Mandatory From: header missing from message");
98 return SMFIS_REJECT;
99 }
100  
101 SMFIS_ACCEPT;
102 }
103  
104 1;
105 __END__