#!/usr/bin/perl -w # Scan mail headers looking for "To: someone@somewhere" # and extract person the mail was sent to. my $to; my $first=0; while (<>) { last unless ($_ or $first); # stop looking at headers at blank line, unless it's the first line. $first=1; if ( /^\s*To:\s*([^\s]*)\s*$/ ) { # Look for the "To:" line. if ($1) { $to = $1; } else { # If the end of the "To" line is empty, read the next line. ($to = <>) =~ s/\s//g; } last; } } $to = '??' unless $to; if ($to =~ /treasurer/ ) { my @lines = <>; # slurp the rest of the file. my $text = join("\n",@lines); if ($text =~ /Notification of Payment Received/) { my ($who, $email, $amount, $item, $note, $id); for ($text) { ($who) = m/^Buyer: (.*)$/gm; ($email) = m/$who \((.*?)\)/g; ($amount) = m/^Amount: \$(.*)$/gm; ($item) = m/^Item\/Product Name: (.*)$/gm; ($id) = m/^Transaction ID: (.*)$/gm; ($note) = m/Message: (.*)Thank you for using PayPal,/gs; } $note = '' unless $note; $note =~ s/\s*$//s; # remove whitespace at end of note my $ticketfile = "/home/faculty-staff/mahoney/.email/ticketlog.txt"; #my $ticketfile = "ticketlog.txt"; open TICKETLOG, ">>$ticketfile"; print TICKETLOG "------ " . scalar(localtime()) . " ------\n" . " Buyer: $who \n" . " Email: $email \n" . " Amount: $amount \n" . " Item: $item \n" . " ID: $id \n" . " Note: $note \n\n" ; close TICKETLOG; } } # Record a log of who the mail was sent to. my $logfile = "/home/faculty-staff/mahoney/.email/log.txt"; #my $logfile = "log.txt"; open LOG, ">>$logfile"; print LOG " To: $to , " . scalar localtime() . "\n"; close LOG; exit;