3 # Uploader: upload the "rplctn\dump\log\seq-err.log" file to a (local)
4 # SMTP server for on-delivery. Addressees for the message are
5 # specified in a err-conf.ph file.
7 # Written by Andrew McMillan, 2/5/1998. All credit to Ewen McNeill, for
8 # the programs (encoder.pl / uploader.pl) which this is plagiarised from,
9 # and of course the errors are all mine.
11 # This program looks for the log file which (if it exists) is converted into
12 # an internet e-mail message and then instantiated as a Mail::Internet object,
13 # to be delivered with SMTP to the local SMTP server.
15 #---------------------------------------------------------------------------
19 use DirHandle
; # Read directories (the OO way)
22 use Net
::SMTP
; # Simple Mail Transfer Protocol
24 require "sendconf.ph"; # Sender configuration information
25 require "recvconf.ph"; # Receiver configuration information
26 require "err-conf.ph"; # Error notification configuration
28 #---------------------------------------------------------------------------
32 # SendMessage: expects filename of message to send (and that the file will
33 # exist in the outbound directory).
35 # Sends the message to the SMTP server for on-delivery, and if that is successful
36 # moves the original file into the sent area.
38 # Returns 1 if the file is delivered to the SMTP server, and 0 otherwise.
43 die "No file to send\n" if (! defined($filename));
45 if ( ! open(MSG
, "<$SendConf::outgoing/$filename") )
47 warn "Unable to open \"$SendConf::outgoing/$filename\" -- skipping file\n";
51 # Note: need to specify who to say on the HELO line, because Windows isn't
52 # particularly good at figuring it out.
53 my $smtp = Net
::SMTP
->new($SendConf::SMTPserver
,
54 Hello
=> $SendConf::myhostname
);
57 warn "Cannot contact SMTP server: $SendConf::SMTPserver\n";
58 warn "Skipping file: $filename\n";
64 # Do the envelope stuff
65 $rc = $smtp -> mail
($SendConf::myemail
);
67 { warn "Error encountered sending envelope from\n"; }
70 $rc = $smtp -> to
($SendConf::theiremail
);
72 { warn "Error encountered sending envelope to\n"; }
77 warn "Cannot start mail. Abandoning mail transfer ($filename).\n";
87 warn "Problems starting message data ($filename). Abandoning transfer.\n";
95 $rc = $smtp->datasend($_);
97 { warn "Problems sending data line: $_\n";
98 warn "Attempting to continue.\n"; # XXX -- is this wise?
101 $rc = $smtp->dataend();
103 { # Message was delivered correctly, tidy up.
107 unlink("$SendConf::outgoingprocessed/$filename") &&
108 warn "Removed older copy of \"$filename\" from processed directory\n";
110 rename("$SendConf::outgoing/$filename",
111 "$SendConf::outgoingprocessed/$filename") ||
112 warn "Message transfered correctly, unable to move out of way ($filename)\n";
117 { # Problems sending the message -- leave it alone.
121 warn "Problems sending message ($filename). Leaving to try again later.\n";
129 #---------------------------------------------------------------------------
130 # constructmessage: expects a filename to process (including directory);
132 # At present this simply prepends suitable RFC822 headers and cutesy bits
134 # Returns 1 if the file is processed correctly, 0 otherwise.
139 die "Filename undefined" if (!defined($pathname));
141 my @fileparts = split( '/', $pathname );
144 ($filename, $remainder) = reverse @fileparts;
146 print "Filename to process = ", $pathname, "\n";
147 print "Base filename = ", $filename, "\n";
149 # Now we have the filename we can start building the message.
151 if (open MESSAGE
, ">$SendConf::outgoing/$filename")
153 # Now we can rock and roll. We've got an input file and an output file.
154 # Let's build the header first.
156 my $header = new Mail
::Header
;
157 $header->add("From", $SendConf::myemail
);
158 $header->add("To", $ErrorConf::sendlogto
);
159 $header->add("Subject", "HELP\! Replication file not received in sequence\!");
161 # And spit it out to the file.
162 $header->print(\
*MESSAGE
);
165 print MESSAGE
"OK, I seem to be having a problem here with a replication file which\n";
166 print MESSAGE
"has gone missing. If one of you could arrange for the file indicated\n";
167 print MESSAGE
"in the error message below to be re-sent I could continue to do my job.\n";
169 print MESSAGE
"------------------- start of error messages -----------------\n";
171 # Now we need to append the file of errors
172 if (open FROM
, "<$pathname")
175 while( read( FROM
, $filebuf, 4096)) {
176 print MESSAGE
$filebuf;
180 # Now some trailer stuff.
181 print MESSAGE
"-------------------- end of error messages ------------------\n";
184 print MESSAGE
"All help gratefully appreciated,\n";
185 print MESSAGE
" Deus Ex Machina\n";
188 # And we're done -- clean things up.
195 warn "Could not open output file: ", $SendConf::outgoing
, "/", $filename, "\n";
201 #---------------------------------------------------------------------------
205 # Check configuration values are set
207 die "No outgoing directory" if (! defined($SendConf::outgoing
));
208 die "No processed directory" if (! defined($SendConf::outgoingprocessed
));
209 die "No SMTP server" if (! defined($SendConf::SMTPserver
));
210 die "No local email address" if (! defined($SendConf::myemail
));
211 die "No remote email address" if (! defined($SendConf::theiremail
));
212 die "Who am I anyway?" if (! defined($SendConf::myhostname
));
214 my $numprocessed = 0;
216 if (-f
"$ErrorConf::seqlogfile")
218 constructmessage
($ErrorConf::seqlogfile
);
220 my $dir = new DirHandle
$SendConf::outgoing
;
223 print "Scanning directory: ", $SendConf::outgoing
, "\n";
225 while (defined($file = $dir->read))
227 if (-f
"$SendConf::outgoing/$file")
228 { if (sendmessage
($file))
231 unlink $ErrorConf::seqlogfile
;
238 warn "Unable to read from directory: ", $SendConf::senddir
, "\n";
239 print "0 files processed.\n";
245 if ($numprocessed != 1)
246 { print "$numprocessed messages processsed.\n"; }
248 { print "1 message processed.\n"; }