| 9 |
# |
# |
| 10 |
# ============================================================ |
# ============================================================ |
| 11 |
# $Log$ |
# $Log$ |
| 12 |
|
# Revision 1.6 2003/03/23 21:12:20 root |
| 13 |
|
# + sub jerror and related modifications |
| 14 |
|
# |
| 15 |
|
# Revision 1.5 2003/01/30 23:20:21 root |
| 16 |
|
# + fixed and enhanced |
| 17 |
|
# |
| 18 |
# Revision 1.4 2003/01/22 17:58:21 root |
# Revision 1.4 2003/01/22 17:58:21 root |
| 19 |
# + fixed and enhanced many things |
# + fixed and enhanced many things |
| 20 |
# - refactored code to Data::Code |
# - refactored code to Data::Code |
| 45 |
|
|
| 46 |
use base qw( |
use base qw( |
| 47 |
DesignPattern::Object |
DesignPattern::Object |
| 48 |
|
DesignPattern::Bridge |
| 49 |
); |
); |
| 50 |
# DesignPattern::Object::Logger |
# DesignPattern::Object::Logger |
| 51 |
|
|
| 56 |
|
|
| 57 |
use Data::Code::Symbol qw( export_symbols ); |
use Data::Code::Symbol qw( export_symbols ); |
| 58 |
use Data::Storage::Handler::File qw( a2f ); |
use Data::Storage::Handler::File qw( a2f ); |
| 59 |
use org::netfrag::shortcuts qw( now get_chomped ); |
use org::netfrag::shortcuts qw( now get_chomped run_cmd ); |
| 60 |
|
|
| 61 |
|
|
| 62 |
sub _init { |
sub _init { |
| 70 |
|
|
| 71 |
sub _init_options { |
sub _init_options { |
| 72 |
my $self = shift; |
my $self = shift; |
| 73 |
foreach (qw( user base rules LOG VERBOSE TRACE )) { |
foreach (qw( user base rules LOG VERBOSE TRACE mode newsgroup )) { |
| 74 |
$self->{options}->{$_} = $self->{$_}; |
$self->{options}->{$_} = $self->{$_}; |
| 75 |
} |
} |
| 76 |
} |
} |
| 96 |
sub _init_settings_paths { |
sub _init_settings_paths { |
| 97 |
my $self = shift; |
my $self = shift; |
| 98 |
$self->{settings}->{MAILDIR} = "$self->{settings}->{HOME}/Mail"; |
$self->{settings}->{MAILDIR} = "$self->{settings}->{HOME}/Mail"; |
| 99 |
$self->{settings}->{RULESFILE} = "$self->{settings}->{HOME}/.dispatchmailrc.pm"; |
#$self->{settings}->{RULESFILE} = "$self->{settings}->{HOME}/.dispatchmailrc.pm"; |
| 100 |
|
$self->{settings}->{RULESFILE} = "$self->{settings}->{HOME}/.dispatchmailrc"; |
| 101 |
#$self->{settings}->{LOCKFILE} = "$self->{settings}->{HOME}/.procmail.lockfile"; |
#$self->{settings}->{LOCKFILE} = "$self->{settings}->{HOME}/.procmail.lockfile"; |
| 102 |
$self->{settings}->{LOCKFILE} = "$self->{settings}->{HOME}/.dispatchmail.lockfile"; |
$self->{settings}->{LOCKFILE} = "$self->{settings}->{HOME}/.dispatchmail.lockfile"; |
| 103 |
$self->{settings}->{LOGFILE} = "$self->{settings}->{MAILDIR}/.dispatchmail.log"; |
$self->{settings}->{LOGFILE} = "$self->{settings}->{MAILDIR}/.dispatchmail.log"; |
| 121 |
# main |
# main |
| 122 |
# - - - - - - - - - - - - - - - - - - - - |
# - - - - - - - - - - - - - - - - - - - - |
| 123 |
|
|
| 124 |
sub traceEntry { |
sub run { |
|
my $self = shift; |
|
|
$self->appendLog('-' x 40 . ' TRACE ' . '-' x 10); |
|
|
$self->appendLog("From: " . get_chomped($self->{incoming}->from)); |
|
|
$self->appendLog("To: " . get_chomped($self->{incoming}->to)); |
|
|
$self->appendLog("Subject: " . get_chomped($self->{incoming}->subject)); |
|
|
$self->appendLog('-' x 40 . ' TRACE ' . '-' x 10); |
|
|
} |
|
|
|
|
|
|
|
|
sub _run { |
|
|
|
|
| 125 |
my $self = shift; |
my $self = shift; |
| 126 |
|
|
| 127 |
|
$self->{options}->{mode} ||= 'recieve'; |
| 128 |
|
my $call = '_' . $self->{options}->{mode}; |
| 129 |
|
|
| 130 |
# "jump" into processing of new incoming mail and get a "handler" to this mail |
# "jump" into processing of new incoming mail and get a "handler" to this mail |
| 131 |
$self->{incoming} = Mail::Audit->new(); |
$self->{incoming} = Mail::Audit->new(); |
| 132 |
|
|
| 133 |
|
my $result = $self->$call(@_); |
| 134 |
|
return $result; |
| 135 |
|
|
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
sub _recieve { |
| 139 |
|
|
| 140 |
|
my $self = shift; |
| 141 |
|
|
| 142 |
# 0.a. pre flight tracing |
# 0.a. pre flight tracing |
| 143 |
my $now = now(); |
my $now = now(); |
| 144 |
$self->report("$now - $0 running for user '$self->{settings}->{USER}'."); |
$self->report("$now - $0 running for user '$self->{settings}->{USER}'."); |
| 150 |
|
|
| 151 |
# check if $self->{settings}->{HOME} exists |
# check if $self->{settings}->{HOME} exists |
| 152 |
if (! -e $self->{settings}->{MAILDIR}) { |
if (! -e $self->{settings}->{MAILDIR}) { |
| 153 |
my $msg = "Delivery failed, base directory $self->{settings}->{MAILDIR} does not exist."; |
my $msg = "ERROR: Delivery failed, base directory '$self->{settings}->{MAILDIR}' does not exist."; |
| 154 |
$self->report($msg); |
$self->jerror($msg); |
|
$self->forward_delivery(); |
|
| 155 |
} |
} |
| 156 |
|
|
| 157 |
# 1. include rules or fallback |
# 1. include rules or fallback |
| 158 |
# check if $self->{settings}->{RULESFILE} exists |
# check if $self->{settings}->{RULESFILE} exists |
| 159 |
if (-f $self->{settings}->{RULESFILE}) { |
if (-f $self->{settings}->{RULESFILE}) { |
| 160 |
$self->report("Loading rules from \"$self->{settings}->{RULESFILE}\"."); |
$self->report("RULES: Loading from \"$self->{settings}->{RULESFILE}\"."); |
| 161 |
require $self->{settings}->{RULESFILE}; |
my $evalstr = "require '$self->{settings}->{RULESFILE}';"; |
| 162 |
|
eval($evalstr); |
| 163 |
|
if ($@) { |
| 164 |
|
my $msg = "ERROR: Delivery failed, '$self->{settings}->{RULESFILE}' had syntax errors:\n$@"; |
| 165 |
|
$self->jerror($msg); |
| 166 |
|
} |
| 167 |
} else { |
} else { |
| 168 |
#die("$self->{settings}->{RULESFILE} doesn't exist"); |
#die("$self->{settings}->{RULESFILE} doesn't exist"); |
| 169 |
$self->report("Configured rulesfile \"$self->{settings}->{RULESFILE}\" doesn't exist."); |
$self->jerror("Configured rulesfile \"$self->{settings}->{RULESFILE}\" doesn't exist."); |
|
$self->forward_delivery(); |
|
| 170 |
} |
} |
| 171 |
|
|
| 172 |
# 2. export required stuff to rules namespace |
# 2. export required stuff to rules namespace |
| 173 |
my @symbols = qw( jaccept report compareTarget ); |
my @symbols = qw( jaccept report compareTarget accept copy ignore ); |
| 174 |
export_symbols(\@symbols, 'rules'); |
export_symbols(\@symbols, 'rules'); |
| 175 |
|
|
| 176 |
# 3. run dispatcher |
# 3. run dispatcher |
| 177 |
$self->report("Running \"rules::dispatch\"."); |
$self->report("RULES: Running Perl sub \"rules::dispatch\"."); |
| 178 |
rules::dispatch($self); |
rules::dispatch($self); |
| 179 |
|
|
| 180 |
# 4. dispatcher didn't do anything |
# 4. dispatcher didn't do anything |
| 191 |
|
|
| 192 |
} |
} |
| 193 |
|
|
| 194 |
sub run { |
sub jerror { |
| 195 |
my $self = shift; |
my $self = shift; |
| 196 |
return $self->_run(@_); |
my $msg = shift; |
| 197 |
|
$self->report("ERROR: $msg"); |
| 198 |
|
$self->forward_delivery(); |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
sub _mail2news { |
| 202 |
|
my $self = shift; |
| 203 |
|
$self->report("MAIL2NEWS: $self->{options}->{newsgroup}"); |
| 204 |
|
my $plugin = 'Newsgate'; |
| 205 |
|
$self->load($plugin); |
| 206 |
|
$self->$plugin($self->{options}->{newsgroup}); |
| 207 |
} |
} |
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
# - - - - - - - - - - - - - - - - - - - - |
# - - - - - - - - - - - - - - - - - - - - |
| 212 |
# tracing & reporting |
# tracing & reporting |
| 213 |
# - - - - - - - - - - - - - - - - - - - - |
# - - - - - - - - - - - - - - - - - - - - |
| 214 |
|
sub traceEntry { |
| 215 |
|
my $self = shift; |
| 216 |
|
$self->appendLog('-' x 40 . ' TRACE ' . '-' x 10); |
| 217 |
|
$self->appendLog("From: " . get_chomped($self->{incoming}->from)); |
| 218 |
|
$self->appendLog("To: " . get_chomped($self->{incoming}->to)); |
| 219 |
|
$self->appendLog("Subject: " . get_chomped($self->{incoming}->subject)); |
| 220 |
|
$self->appendLog('-' x 40 . ' TRACE ' . '-' x 10); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
sub appendLog { |
sub appendLog { |
| 224 |
my $self = shift; |
my $self = shift; |
| 225 |
my $msg = shift; |
my $msg = shift; |
| 252 |
return $ok; |
return $ok; |
| 253 |
} |
} |
| 254 |
|
|
| 255 |
|
sub accept_spool { |
| 256 |
|
my $self = shift; |
| 257 |
|
my $path = "/var/spool/mail/$self->{settings}->{USER}"; |
| 258 |
|
$self->report("defaulting to spool delivery ($path)"); |
| 259 |
|
$self->{incoming}->accept($path); |
| 260 |
|
} |
| 261 |
|
|
| 262 |
|
sub forward_delivery { |
| 263 |
|
my $self = shift; |
| 264 |
|
$self->report("Forwarding delivery to next handler in queue (probably /var/spool/mail)."); |
| 265 |
|
return $self->{incoming}->accept; |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 269 |
sub jaccept { |
sub jaccept { |
| 270 |
my $self = shift; |
my $self = shift; |
| 271 |
my $deliver_to = shift; |
my $deliver_to = shift; |
| 274 |
|
|
| 275 |
# check deliver_to path |
# check deliver_to path |
| 276 |
if (! -e $deliver_to) { |
if (! -e $deliver_to) { |
| 277 |
$self->report("deliver_to path \"$deliver_to\" doesn't exist"); |
my $good = 0; |
| 278 |
$self->forward_delivery(); |
$self->report("ERROR: TARGET Path/File doesn't exist."); |
| 279 |
return; |
if ($self->{settings}->{AUTOCREATE_FOLDERS}) { |
| 280 |
|
my $cmd = "touch $deliver_to"; |
| 281 |
|
$self->report("TARGET: AUTOCREATE_FOLDERS is enabled: touching TARGET."); |
| 282 |
|
#if (mkdir $deliver_to) { |
| 283 |
|
run_cmd($cmd); |
| 284 |
|
# re-test TARGET - for existance now |
| 285 |
|
if (-e $deliver_to) { |
| 286 |
|
$good = 1; |
| 287 |
|
} else { |
| 288 |
|
$self->report("ERROR: TARGET creation failed (command was: '$cmd')."); |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
|
if (!$good) { |
| 292 |
|
$self->forward_delivery(); |
| 293 |
|
return; |
| 294 |
|
} |
| 295 |
} |
} |
| 296 |
|
|
| 297 |
$self->{incoming}->accept($deliver_to); |
return $self->{incoming}->accept($deliver_to); |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
sub accept_spool { |
|
| 301 |
|
sub accept { |
| 302 |
my $self = shift; |
my $self = shift; |
| 303 |
my $path = "/var/spool/mail/$self->{settings}->{USER}"; |
return $self->jaccept(@_); |
|
$self->report("defaulting to spool delivery ($path)"); |
|
|
$self->{incoming}->accept($path); |
|
| 304 |
} |
} |
| 305 |
|
|
| 306 |
sub forward_delivery { |
sub copy { |
| 307 |
my $self = shift; |
my $self = shift; |
| 308 |
$self->report("Forwarding delivery to next handler in queue (probably /var/spool/mail)."); |
my $plugin = shift; |
| 309 |
$self->{incoming}->accept; |
my $deliver_to = shift; |
| 310 |
|
|
| 311 |
|
$self->report("COPY: $plugin: $deliver_to"); |
| 312 |
|
|
| 313 |
|
$self->load($plugin); |
| 314 |
|
return $self->$plugin($deliver_to); |
| 315 |
} |
} |
| 316 |
|
|
| 317 |
|
sub ignore { |
| 318 |
|
my $self = shift; |
| 319 |
|
$self->report("IGNORE"); |
| 320 |
|
return $self->{incoming}->ignore; |
| 321 |
|
} |
| 322 |
|
|
| 323 |
1; |
1; |