SMTP/Server.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 100 CC 9 SCAR 17.1
CC
9
Cov
0%
my_config
12.0
get_local_ip
6.0
get_hostname
6.0
CRAP 5.5
1 package Apache::SMTP::Server;
2  
3 use 5.006001;
4 use strict;
5 use warnings FATAL => 'all';
6  
7 use base 'Net::Server::Mail::SMTP';
8 use Apache::Server ();
9 use Apache::ServerUtil ();
10 use Apache::Connection ();
11  
12 our $VERSION = '0.01';
13  
14 sub my_config {
15 my ($self, $c) = @_;
16 my $s = $c->base_server;
17 die "MailHost undefined" unless defined $s->dir_config('MailHost');
18 $self->{mailport} = '25';
19 $self->{mailport} = $s->dir_config('MailPort') if
20 defined $s->dir_config('MailPort');
21 $self->{local_ip} = $c->local_ip;
22 $self->{mailhost} = $s->dir_config('MailHost');
23 $self->{remote_ip} = $c->remote_ip;
24 }
25  
26 sub get_local_ip {
27 my $self = shift;
28 my $local_ip = $self->{local_ip};
29 return($local_ip ? $local_ip : '127.0.0.1');
30 }
31  
32 sub get_hostname {
33 my $self = shift;
34 my $hostname = $self->{hostname};
35 return($hostname ? $hostname : undef);
36 }
37  
38 sub get_remote_ip {
39 my $self = shift;
40 my $remote_ip = $self->{remote_ip};
41 return($remote_ip ? $remote_ip : undef);
42 }
43  
44 sub get_mailhost {
45 my $self = shift;
46 my $mailhost = $self->{mailhost};
47 return($mailhost ? $mailhost : undef);
48 }
49  
50 sub get_mailport {
51 my $self = shift;
52 my $mailport = $self->{mailport};
53 return($mailport ? $mailport : 25);
54 }
55  
56 #this is a copy of helo from Net::Server::Mail::SMTP with the minor change
57 #of setting $self->{hostname} so we can get it later
58 sub helo
59 {
60 my($self, $hostname) = @_;
61  
62 unless(defined $hostname && length $hostname)
63 {
64 $self->reply(501, 'Syntax error in parameters or arguments');
65 return;
66 }
67 $self->{hostname} = $hostname;
68 $self->make_event
69 (
70 name => 'HELO',
71 arguments => [$hostname],
72 on_success => sub
73 {
74 # according to the RFC, HELO ensures "that both the SMTP client
75 # and the SMTP server are in the initial state"
76 $self->step_reverse_path(1);
77 $self->step_forward_path(0);
78 $self->step_maildata_path(0);
79 },
80 success_reply => [250, 'Requested mail action okay, completed'],
81 );
82  
83 return;
84 }
85  
86 1;
87 __END__