| 1 | package MailBot::Config; | ||||||||||
| 2 | |||||||||||
| 3 | 26 | ▶ | use MailBot::IniConf; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 26 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 26 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 26 | my $gRoot = "/tmp/mailbot"; | |||||||||
| 9 | 26 | my $gCurrentConfig; | |||||||||
| 10 | |||||||||||
| 11 | sub setRoot | ||||||||||
| 12 | 0 | ▶ | { | ||||||||
|
Subroutine
setRoot: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 13 | 0 | my $self = shift; | |||||||||
| 14 | 0 | my $rootDir = shift; | |||||||||
| 15 | |||||||||||
| 16 | 0 | $gRoot = $rootDir; | |||||||||
| 17 | |||||||||||
| 18 | 0 | $gCurrentConfig = new MailBot::Config($gRoot); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | sub current | ||||||||||
| 22 | 0 | ▶ | { | ||||||||
|
Subroutine
current: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 23 | 0 | ▶ | $gCurrentConfig or croak "have not yet set root"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | $gCurrentConfig; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | sub getRoot | ||||||||||
| 28 | 0 | ▶ | { | ||||||||
|
Subroutine
getRoot: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 29 | 0 | $gRoot; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub getIni | ||||||||||
| 33 | 0 | ▶ | { | ||||||||
|
Subroutine
getIni: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 34 | 0 | my $ini = shift -> {INI}; | |||||||||
| 35 | 0 | ▶ | croak "unloaded inifile" if ! defined $ini; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | $ini; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub getMaxSize | ||||||||||
| 40 | 0 | ▶ | { | ||||||||
|
Subroutine
getMaxSize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 41 | 0 | shift -> getIniVal("load","maxsize",500000); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub getEnvelopeVal | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
getEnvelopeVal: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 46 | 0 | my $self = shift; | |||||||||
| 47 | 0 | my $condition = shift; | |||||||||
| 48 | 0 | my $param = shift; | |||||||||
| 49 | |||||||||||
| 50 | 0 | my $lower = lc $condition; | |||||||||
| 51 | 0 | $lower =~ s/ /_/g; | |||||||||
| 52 | 0 | my $section = "envelope.$lower"; | |||||||||
| 53 | |||||||||||
| 54 | # check if we should use default | ||||||||||
| 55 | 0 | my @aSection = $self -> getIni -> Sections; | |||||||||
| 56 | 0 | ▶ | grep($_ eq $section,@aSection) or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | $section = "envelope."; | ||||||||||
| 58 | |||||||||||
| 59 | 0 | $self -> getIniVal($section,$param); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | sub getIniVal | ||||||||||
| 63 | 0 | ▶ | { | ||||||||
|
Subroutine
getIniVal: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 64 | 0 | my $ini = shift -> getIni; | |||||||||
| 65 | 0 | my ($section,$param,$default) = @_; | |||||||||
| 66 | 0 | my $val = scalar($ini -> val($section,$param)); | |||||||||
| 67 | 0 | ▶ | return $val if defined $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | $default; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | sub getSplitSize | ||||||||||
| 72 | 0 | ▶ | { | ||||||||
|
Subroutine
getSplitSize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 73 | 0 | shift -> getIniVal('smtp','split_size'); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub getSplitMultiplier | ||||||||||
| 77 | 0 | ▶ | { | ||||||||
|
Subroutine
getSplitMultiplier: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 78 | 0 | shift -> getIniVal('smtp','split_multiplier'); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | sub neverSend | ||||||||||
| 82 | 0 | ▶ | { | ||||||||
|
Subroutine
neverSend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 83 | 0 | shift -> getIniVal('smtp','never_send'); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub new | ||||||||||
| 87 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 88 | 0 | my $type = shift; | |||||||||
| 89 | 0 | my $root = shift; | |||||||||
| 90 | |||||||||||
| 91 | 0 | my $self = { | |||||||||
| 92 | INTERACTIVE => 0 | ||||||||||
| 93 | }; | ||||||||||
| 94 | |||||||||||
| 95 | 0 | my $mailBotConfigFile = "$root/config/mailbot.config"; | |||||||||
| 96 | 0 | my $iniConf = new MailBot::IniConf -file => $mailBotConfigFile; | |||||||||
| 97 | 0 | $$self{INI} = $iniConf; | |||||||||
| 98 | |||||||||||
| 99 | 0 | bless($self,$type); | |||||||||
| 100 | |||||||||||
| 101 | 0 | $self; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub isInteractive | ||||||||||
| 105 | 0 | ▶ | { | ||||||||
|
Subroutine
isInteractive: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 106 | 0 | my $self = shift; | |||||||||
| 107 | 0 | $self -> {INTERACTIVE}; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub getLocalSpool | ||||||||||
| 111 | 0 | ▶ | { | ||||||||
|
Subroutine
getLocalSpool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 112 | 0 | my $spoolDir = shift -> getDir('spool'); | |||||||||
| 113 | |||||||||||
| 114 | 0 | my $progName = $0; | |||||||||
| 115 | 0 | $progName =~ s/.+\///; | |||||||||
| 116 | 0 | $progName =~ s/\.pl$//; | |||||||||
| 117 | 0 | return "$spoolDir/rfc822.in.$progName"; | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | sub getMailSpool | ||||||||||
| 121 | 0 | ▶ | { | ||||||||
|
Subroutine
getMailSpool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 122 | 0 | shift -> {SPOOL}; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | sub setMailSpool | ||||||||||
| 126 | 0 | ▶ | { | ||||||||
|
Subroutine
setMailSpool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 127 | 0 | my $self = shift; | |||||||||
| 128 | 0 | $self -> {SPOOL} = shift; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | sub setInteractive | ||||||||||
| 132 | 0 | ▶ | { | ||||||||
|
Subroutine
setInteractive: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 133 | 0 | my $self = shift; | |||||||||
| 134 | 0 | $self -> {INTERACTIVE} = 1; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | sub isCGI | ||||||||||
| 138 | 0 | ▶ | { | ||||||||
|
Subroutine
isCGI: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 139 | 0 | my $self = shift; | |||||||||
| 140 | 0 | $self -> {CGI}; | |||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | sub setCGI | ||||||||||
| 144 | 0 | ▶ | { | ||||||||
|
Subroutine
setCGI: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 145 | 0 | my $self = shift; | |||||||||
| 146 | 0 | $self -> {CGI} = 1; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | sub getBody | ||||||||||
| 150 | 0 | ▶ | { | ||||||||
|
Subroutine
getBody: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 151 | 0 | shift -> {BODY}; | |||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | sub getBounceAddr | ||||||||||
| 155 | 0 | ▶ | { | ||||||||
|
Subroutine
getBounceAddr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 156 | 0 | my $ini = shift -> {INI}; | |||||||||
| 157 | 0 | ▶ | return undef if ! defined $ini; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 0 | $ini -> val('address','bounce'); | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | sub setBody | ||||||||||
| 162 | 0 | ▶ | { | ||||||||
|
Subroutine
setBody: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 163 | 0 | my $self = shift; | |||||||||
| 164 | 0 | $self -> {BODY} = shift; | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | sub getSubject | ||||||||||
| 168 | 0 | ▶ | { | ||||||||
|
Subroutine
getSubject: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 169 | 0 | shift -> {SUBJECT}; | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | sub setSubject | ||||||||||
| 173 | 0 | ▶ | { | ||||||||
|
Subroutine
setSubject: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 174 | 0 | my $self = shift; | |||||||||
| 175 | 0 | $self -> {SUBJECT} = shift; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | sub getDir | ||||||||||
| 179 | 0 | ▶ | { | ||||||||
|
Subroutine
getDir: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 180 | 0 | my $self = shift; | |||||||||
| 181 | 0 | my $dirName = shift; | |||||||||
| 182 | |||||||||||
| 183 | 0 | my $path = "$gRoot/$dirName"; | |||||||||
| 184 | 0 | ▶ | if (! -d $path) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 185 | { | ||||||||||
| 186 | 0 | ▶ | mkdir($path,0777) or die "could not mkdir $path: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 187 | } | ||||||||||
| 188 | 0 | $path; | |||||||||
| 189 | } | ||||||||||
| 190 | |||||||||||
| 191 | sub getSaveDir | ||||||||||
| 192 | 0 | ▶ | { | ||||||||
|
Subroutine
getSaveDir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 193 | 0 | shift -> getDir('save'); | |||||||||
| 194 | } | ||||||||||
| 195 | |||||||||||
| 196 | sub getQuotaDir | ||||||||||
| 197 | 0 | ▶ | { | ||||||||
|
Subroutine
getQuotaDir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 198 | 0 | shift -> getDir('quota'); | |||||||||
| 199 | } | ||||||||||
| 200 | |||||||||||
| 201 | sub getPubDir | ||||||||||
| 202 | 0 | ▶ | { | ||||||||
|
Subroutine
getPubDir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 203 | 0 | "$gRoot/pub"; | |||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | sub getLogDir | ||||||||||
| 207 | 0 | ▶ | { | ||||||||
|
Subroutine
getLogDir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 208 | 0 | shift -> getDir('log'); | |||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | sub log | ||||||||||
| 212 | 0 | ▶ | { | ||||||||
|
Subroutine
log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 213 | 0 | my $self = shift; | |||||||||
| 214 | 0 | my $string = join('',@_); | |||||||||
| 215 | 0 | chomp($string); | |||||||||
| 216 | 0 | $string =~ s/\n/\\n/g; | |||||||||
| 217 | |||||||||||
| 218 | 0 | my $logDir = $self -> getLogDir(); | |||||||||
| 219 | 0 | my $logFile = "$logDir/log"; | |||||||||
| 220 | |||||||||||
| 221 | 0 | my $logString = scalar(localtime()) . ": " . $string . "\n"; | |||||||||
| 222 | |||||||||||
| 223 | 0 | ▶ | if (open(LOG,">>$logFile")) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 224 | { | ||||||||||
| 225 | 0 | print LOG $logString; | |||||||||
| 226 | 0 | close(LOG); | |||||||||
| 227 | } | ||||||||||
| 228 | else | ||||||||||
| 229 | { | ||||||||||
| 230 | 0 | print STDERR $logString; | |||||||||
| 231 | } | ||||||||||
| 232 | } | ||||||||||
| 233 | |||||||||||
| 234 | 26 | 1; | |||||||||