#!usr/bin/perl
use warnings;
use strict;
my ($body, $line, $subject, $reply_address, $date, $from_name);
$body = $line = $subject = $reply_address = $date = $from_name = "";
open(MYFILE, "king.in") || die("Could not open file!");
# Read the file's content line by line
while ($line = <MYFILE>)
{
# An empty line marks the beginning of the body
if ($line =~ m/^\s+$/ ) {
# Save the file content starting from the current line
# to the end of the file
$body = join("", <MYFILE>);
}
if ($line =~ m/^subject: (.*)/i) {
$subject = $1;
}
if ($line =~ m/^date: (.*)/i) {
$date = $1;
}
if ($line =~ m/^reply-To: (\S+)/i) {
$reply_address = $1;
}
if ($line =~ m/^from: (\S+) \(([^()]*)\)/i) {
$reply_address = $1;
$from_name = $2;
}
}
close(MYFILE);
print "To: $reply_address ($from_name)\n";
print "From: jfriedl\@regex.info (Jeffrey Friedl)\n";
print "Subject: Re: $subject\n";
print "\n" ; # blank line to separate the header from message body.
print "On $date $from_name wrote:\n";
# Treat the $body string as multiple lines and prepend |> to every line
$body =~ s/^/|> /gm;
print $body;