View Single Post
  #4 (permalink)  
Old 04-11-05, 04:51 PM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
I thikn you're going to have a hard time with this one. If I'm not mistaken the IP address will not always be there and the exact format can vary. You'll have to tweak the regex to fit:

Code:
#!/usr/bin/perl
use strict;
use warnings;
use Time::Piece;
use CGI::Carp qw/fatalsToBrowser/;

print "Content-Type: Text/HTML\n\n";
print "<pre>\n";
foreach my $header (<DATA>) {
  next unless $header =~ /^Received: from/;
  my ($ip, $date) = $header =~ /\[(.*)\]\).*>; (.*)$/;
  if ($ip) {
    my $t = Time::Piece->strptime($date);
    my $date = $t->year . $t->mon . $t->mday;
    print "$ip, $date\n";
    last;
  }
}
print "</pre>\n";

__DATA__
Return-Path: dkg@sparrow.spearhead.net
Received: from linus.vsource.com (root@linus.vsource.com [198.169.201.2]) by hal.qcc.sk.ca (8.8.0/8.7.3) with ESMTP id VAA08699 for <bguenter@hal.qcc.sk.ca>; Fri, 12 Dec 1997 21:47:07 -0600
From: dkg@sparrow.spearhead.net
Received: from sparrow.spearhead.net ([209.136.73.165]) by linus.vsource.com (8.8.0/8.6.9) with ESMTP id VAA02022 for <bguenter@gemprint.com>; Fri, 12 Dec 1997 21:46:56 -0600
Received: by sparrow.spearhead.net (8.8.4/8.8.4) with SMTP
id LAA23280; Sat, 13 Dec 1997 11:34:13 -0500
Date: Sat, 13 Dec 1997 11:34:13 -0500
Message-Id: <199712131634.LAA23280@sparrow.spearhead.net>
To: dkg@sparrow.spearhead.net
Subject: A Personal Message...
You'll have to work out looping though your messages/folders bit but that is the easy part

You may also want to look at the Mail::Box[1] suite of modules. That will give you a nice set of objects to manipulate the folders/messages/headers.

~Charlie

[1] http://search.cpan.org/~markov/Mail-...b/Mail/Box.pod
Reply With Quote