Advertisement
Guest User

A Small Mail Utility

a guest
Dec 23rd, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.21 KB | None | 0 0
  1. #!usr/bin/perl
  2. use warnings;
  3. use strict;
  4.  
  5. my ($body, $line, $subject, $reply_address, $date, $from_name);
  6. $body = $line = $subject = $reply_address = $date = $from_name = "";
  7.  
  8. open(MYFILE, "king.in") || die("Could not open file!");
  9.  
  10. # Read the file's content line by line
  11. while ($line = <MYFILE>)
  12. {
  13.     # An empty line marks the beginning of the body
  14.     if ($line =~ m/^\s+$/ ) {
  15.         # Save the file content starting from the current line
  16.         # to the end of the file
  17.         $body = join("", <MYFILE>);
  18.     }
  19.     if ($line =~ m/^subject: (.*)/i) {
  20.         $subject = $1;
  21.     }
  22.     if ($line =~ m/^date: (.*)/i) {
  23.         $date = $1;
  24.     }
  25.     if ($line =~ m/^reply-To: (\S+)/i) {
  26.         $reply_address = $1;
  27.     }
  28.     if ($line =~ m/^from: (\S+) \(([^()]*)\)/i) {
  29.         $reply_address = $1;
  30.         $from_name = $2;
  31.     }
  32. }
  33. close(MYFILE);
  34.  
  35. print "To: $reply_address ($from_name)\n";
  36. print "From: jfriedl\@regex.info (Jeffrey Friedl)\n";
  37. print "Subject: Re: $subject\n";
  38. print "\n" ; # blank line to separate the header from message body.
  39. print "On $date $from_name wrote:\n";
  40. # Treat the $body string as multiple lines and prepend |> to every line
  41. $body =~ s/^/|> /gm;
  42. print $body;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement