Re: Mail lives forever (Re: Bill Joy kicks around XML for fun :-)

From: Håkon Wium Lie (howcome@opera.com)
Date: Sun Feb 25 2001 - 15:47:45 PST


Also sprach Joseph S. Barrera III:

> Rohit Khare writes:
> > BJ doesn't get it. Data lives forever. Programs are only mortal.
>
> Okay, may I do a little poll, and ask everyone in what format they
> keep their megabytes (or gigabytes) of mail?

Berkeley for use with emacs/vm.

Each month I start a new file so I have files like inbox-jan-00,
inbox-feb-00 etc.

I've written a perl script (enclosed) to search through the files --
it's slightly more intelligent than grep.

-h&kon

#!/Perl/bin/perl.exe

undef $/;
$*=1;

while (@ARGV && $ARGV[0] =~ m/^-/)
{
  $arg = shift(@ARGV);
  $findsender = $1, next if $arg =~ m/^-f=(.+)$/;
  $findsubject = $1, next if $arg =~ m/^-s=(.+)$/;
  $findrecipient = $1, next if $arg =~ m/^-t=(.+)$/;
  $findcontent = $1, next if $arg =~ m/^-b=(.+)$/;
  $help = $1, next if $arg =~ m/^(-h)/;
  $verbose = 1, next if $arg =~ m/^-v$/;
}

if ($help) {
    die "usage: mgrep -f=<from> -t=<to> -s=<subject> -b=<body> -v files\n";
}

while (<>) {
  
  foreach $message (split(/^\nFrom /,$_)) {
    $_=$message;
    if (/From (.*)/) { $sender=$1; $first_sender=$1; };
    if (/From: (.*)/) { $sender=$1; };
    if (/Subject: (.*)/) { $subject=$1; };
    if (/Date: (.*)/) { $date=$1; };
    if (/\n\n([\s\S\n]*)/) { $content=$1 };
    if (/To: (.*)/) { $recipient=$1; };

    next if (! ($findsender || $findsubject || $findcontent || $findrecipient));

    if (
        ((! $findsender)||(
                           ($findsender) && ($sender =~ /$findsender/i)
                           ))
          && ((! $findsubject) || (($findsubject) && ($subject =~ /$findsubject/i)))
          && ((! $findrecipient) || (($findrecipient) && ($recipient =~ /$findrecipient/i)))
          && ((! $findcontent) || (($findcontent) && ($content =~ /$findcontent/i)))

       )
    {
      if ($verbose) {
        print $message, "\n";
      } else {
        print "FROM: ", $sender, "\n";
        print "TO: ", $recipient, "\n";
        print "SUBJECT: ", $subject, "\n";
        print "DATE: ", $date, "\n";
      }
      print "\n";

      $sender="";
      $first_sender="";
      $subject="";
      $content = "";
      $date = "";
      $to = "";
    }
  }
}



This archive was generated by hypermail 2b29 : Fri Apr 27 2001 - 23:18:32 PDT