Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

A Small Mail Utility

By: a guest on Dec 22nd, 2011  |  syntax: Perl  |  size: 1.18 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /usr/bin/perl
  2. use warnings;
  3. use strict;
  4.  
  5. my ($i, $size, $line, @lines, $subject, $reply_address, $date, $from_name);
  6. $line = $subject = $reply_address = $date = $from_name = "";
  7.  
  8. open(MYFILE, "king.in") || die("Could not open file!");
  9.  
  10. # Read all the lines into an array
  11. @lines = <MYFILE>;
  12.  
  13. close(MYFILE);
  14.  
  15. $i = 1;
  16. # Iterate over the file's lines
  17. foreach $line (@lines) {
  18.  
  19.     if ($line =~ m/^\s+$/ ) { # If we have an empty line...
  20.         last; # this immediately ends the 'while' loop.
  21.     }
  22.    
  23.     if ($line =~ m/^subject: (.*)/i) {
  24.         $subject = $1;
  25.     }
  26.     if ($line =~ m/^date: (.*)/i) {
  27.         $date = $1;
  28.     }
  29.     if ($line =~ m/^reply-To: (\S+)/i) {
  30.         $reply_address = $1;
  31.     }
  32.     if ($line =~ m/^from: (\S+) \(([^()]*)\)/i) {
  33.         $reply_address = $1;
  34.         $from_name = $2;
  35.     }
  36.     $i++;
  37. }
  38.  
  39. print "To: $reply_address ($from_name)\n";
  40. print "From: jfriedl\@regex.info (Jeffrey Friedl)\n";
  41. print "Subject: Re: $subject\n";
  42. print "\n" ; # blank line to separate the header from message body.
  43. print "On $date $from_name wrote:\n";
  44. # print the body
  45. $size = @lines;
  46. for ($i; $i < $size; $i++) {
  47.     print "|> $lines[$i]";
  48. }