I work for an ISP with our own propriatary SMTP Daemon,
one night our Daemon crashed and stayed down
for 2 hours, in the mean time sendmail came up,
started processing all the messages and (not being
able to send them) dumped them all to a dead.letter
file (150 Mb).
Using the following script (wrote it in 10 mins Whoohoo!)
we were able to extract all the messages, including
bodyparts, and send them to our customers:
#!/usr/local/bin/perl -w
use strict;
$| = 1;
my @Message;
my $MsgId;
my $Found;
my $Number=0;
while(<>)
{
if (/^Return-Path:/)
{
$Found=0;
push @Message, $_;
while(<>)
{
push @Message,$_;
last if (($Found==1)&&(/^--$MsgId\S*--/));
if ((/internal id (\S+);/)&&($Found==0))
{
$MsgId=$1;
$Found=1;
};
};
open FILE,">good/$MsgId.$Number.msg" or die "Error writing to $MsgId
+.msg\n";
print FILE @Message;
close FILE;
@Message="";
$Number++;
};
};
Edited by dws to add <code> tags
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.