From twebster at pcs.cnu.edu Thu May 23 11:42:34 2002 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:19 2004 Subject: [HRPM] an actual question! In-Reply-To: Message-ID: All, Given an email written to disk, I need a small perl driver that strips off the header information and writes the message back out to disk( minus the header ). Anyone have a clean method for this using out-of-the-box perl (without any extra CPAN modules)? I'm writing my own of course, but I'd like to see other examples in case I miss something. Been a long while since I've written any perl ... Thanks, Troy Webster Software Engineer, INRI ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From mike.patten2 at verizon.net Thu May 23 17:56:40 2002 From: mike.patten2 at verizon.net (Mike Patten) Date: Thu Aug 5 00:08:19 2004 Subject: [HRPM] an actual question! References: Message-ID: <3CED73A8.7060807@verizon.net> Troy E. Webster wrote: >All, > >Given an email written to disk, I need a small perl driver that strips >off the header information and writes the message back out to disk( minus >the header ). Anyone have a clean method for this using >out-of-the-box perl (without any extra CPAN modules)? I'm writing my own >of course, but I'd like to see other examples in case I miss >something. Been a long while since I've written any perl ... > >Thanks, > > If I'm not mistaken, there are no blank lines in the header and a blank line separates the header from the body. Assuming that's the case and that the file only contains one piece of e-mail, this should read the file from STDIN or a file specified on the command line and print the body of the message to STDOUT. #!/usr/bin/perl -w use strict; my $body = 0; while (<>) { if ($body) { print; } elsif ( m/^\s*$/ ) { # if the line contains nothing except (maybe) whitespace, $body = 1; # the body comes next } } -- "...very few phenomena can pull someone out of Deep Hack Mode, with two noted exceptions: being struck by lightning, or worse, your *computer* being struck by lightning." (By Matt Welsh) Mike Patten From chicks at chicks.net Thu May 23 21:43:33 2002 From: chicks at chicks.net (Christopher Hicks) Date: Thu Aug 5 00:08:19 2004 Subject: [HRPM] an actual question! In-Reply-To: <3CED73A8.7060807@verizon.net> Message-ID: On Thu, 23 May 2002, Mike Patten wrote: > If I'm not mistaken, there are no blank lines in the header and a blank > line separates the header from the body. Assuming that's the case and > that the file only contains one piece of e-mail, this should read the > file from STDIN or a file specified on the command line and print the > body of the message to STDOUT. > > #!/usr/bin/perl -w > > use strict; > > my $body = 0; > while (<>) { > if ($body) { > print; > } elsif ( m/^\s*$/ ) { # if the line contains nothing except > (maybe) whitespace, > $body = 1; # the body comes next > } > } TMTOWTDI. If memory isn't a concern: #!/usr/bin/perl -w use strict; my $emailfile = shift @ARGV; open(IN,$emailfile) or die "couldn't open $emailfile ($!)"; my $contents = join('',); close(IN); $contents =~ s/^.*?\n\n//s; $emailfile .= '.out'; open(OUT,">$emailfile") or die "couldn't open $emailfile ($!)"; print OUT $contents; close(OUT); -- There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies. - - C.A.R. Hoare From jrowan at visi.net Fri May 24 12:20:14 2002 From: jrowan at visi.net (Jeff Rowan) Date: Thu Aug 5 00:08:19 2004 Subject: [HRPM] an actual question! References: Message-ID: <000601c20347$44dc6110$eef310ac@apps.deca.mil> Why not go simple with something like this: #!/usr/bin/perl -wni~ $/="\n\n"; print $_ unless /Received:/; Jeff Rowan "There is nothing more difficult to plan, more doubtful of success, nor more dangerous to manage than the creation of a new system. "For the initiator has the enmity of all who would profit by the preservation of the old system and merely lukewarm defenders in those who would gain by the new one." -- Machiavelli 1513