1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#!/usr/bin/perl -w
use warnings;
use strict;
use Test::More tests => 16;
use Test::Differences;
sub parse_tree_ok {
my ($received, $expect, $name) = @_;
eq_or_diff $received->parse_tree, $expect, $name
or note $received->diagnostics;
}
BEGIN { use_ok('Mail::Field::Received'); }
my $received = Mail::Field->new('Received');
isa_ok $received, 'Mail::Field::Received';
is $received->tag, 'Received', 'tag';
$received->debug(5);
is $received->debug, 5, 'debug level';
# date format 3
my $in =
'from tr909.mediaconsult.com (mediacons.tecc.co.uk [193.128.6.132]) by host5.hostingcheck.com (8.9.3/8.9.3) with ESMTP id VAA24164 for <adam@spiers.net>; Tue, 1 Feb 2000 21:57:18 -0500';
my $parse_tree = {
'by' => {
'domain' => 'host5.hostingcheck.com',
'whole' => 'by host5.hostingcheck.com',
'comments' => ['(8.9.3/8.9.3)'],
},
'date_time' => {
'year' => '2000',
'week_day' => 'Tue',
'minute' => '57',
'day_of_year' => '1 Feb',
'month_day' => ' 1',
'zone' => '-0500',
'second' => '18',
'hms' => '21:57:18',
'date_time' => 'Tue, 1 Feb 2000 21:57:18 -0500',
'hour' => '21',
'month' => 'Feb',
'rest' => '2000 21:57:18 -0500',
'whole' => 'Tue, 1 Feb 2000 21:57:18 -0500'
},
'with' => {
'with' => 'ESMTP',
'whole' => 'with ESMTP'
},
'from' => {
'domain' => 'mediacons.tecc.co.uk',
'HELO' => 'tr909.mediaconsult.com',
'from' => 'tr909.mediaconsult.com',
'address' => '193.128.6.132',
'comments' => [ '(mediacons.tecc.co.uk [193.128.6.132])', ],
'whole' =>
'from tr909.mediaconsult.com (mediacons.tecc.co.uk [193.128.6.132])
'
},
'id' => {
'id' => 'VAA24164',
'whole' => 'id VAA24164'
},
'comments' => [ '(mediacons.tecc.co.uk [193.128.6.132])', '(8.9.3/8.9.3)' ],
'for' => {
'for' => '<adam@spiers.net>',
'whole' => 'for <adam@spiers.net>'
},
'whole' =>
'from tr909.mediaconsult.com (mediacons.tecc.co.uk [193.128.6.132]) by host5.hostingcheck.com (8.9.3/8.9.3) with ESMTP id VAA24164 for <adam@spiers.net>; Tue, 1 Feb 2000 21:57:18 -0500'
};
$received->parse($in);
is $received->parsed_ok, 1, 'date format 3 parsed ok';
parse_tree_ok($received, $parse_tree, 'date format 3 parse tree');
# date format 3 again
$in = '(qmail 7119 invoked from network); 22 Feb 1999 22:01:53 -0000';
$parse_tree = {
'date_time' => {
'year' => '1999',
'week_day' => undef,
'minute' => '01',
'day_of_year' => '22 Feb',
'month_day' => '22',
'zone' => '-0000',
'second' => '53',
'date_time' => '22 Feb 1999 22:01:53 -0000',
'hms' => '22:01:53',
'hour' => '22',
'month' => 'Feb',
'rest' => '1999 22:01:53 -0000',
'whole' => '22 Feb 1999 22:01:53 -0000'
},
'comments' => ['(qmail 7119 invoked from network)'],
'whole' => '(qmail 7119 invoked from network); 22 Feb 1999 22:01:53 -0000'
};
$received->parse($in);
is $received->parsed_ok, 1, 'date format 3 again parsed ok';
parse_tree_ok($received, $parse_tree, 'date format 3 again parse tree');
# date format 1
my $new_date = '22 Feb';
my $new_rest = '22:01:53 1999 -0000';
my $new_date_time = "$new_date $new_rest";
$in = "(qmail 7119 invoked from network); $new_date_time";
$parse_tree->{date_time}{whole} = $new_date_time;
$parse_tree->{date_time}{date_time} = $new_date_time;
$parse_tree->{date_time}{rest} = $new_rest;
$parse_tree->{whole} = $in;
$received->parse($in);
is $received->parsed_ok, 1, 'date format 1 parsed ok';
parse_tree_ok($received, $parse_tree, 'date format 1 parse tree');
# date format 2
$new_date = '22 Feb';
$new_rest = '22:01:53 -0000 1999';
$new_date_time = "$new_date $new_rest";
$in = "(qmail 7119 invoked from network); $new_date_time";
$parse_tree->{date_time}{whole} = $new_date_time;
$parse_tree->{date_time}{date_time} = $new_date_time;
$parse_tree->{date_time}{rest} = $new_rest;
$parse_tree->{whole} = $in;
$received->parse($in);
is $received->parsed_ok, 1, 'date format 2 parsed ok';
parse_tree_ok($received, $parse_tree, 'date format 2 parse tree');
# IP-based hostname
TODO: {
local $TODO = 'parsing IP-based hostname fails (see RT #51169)';
$in =
'Received: from 140.85.213.193.static.cust.telenor.com ([193.213.85.140]) by einstein.junkemailfilter.com with esmtp (Exim 4.69) id 1N63Ug-0008GI-Vp on interface=64.71.167.93 for xxxxx@xxxxxcom; Thu, 05 Nov 2009 06:39:23 -0800';
$received->parse($in);
is $received->parsed_ok, 1, 'IP-based hostname parsed ok';
# parse_tree_ok($received, $parse_tree, 'date format 2 parse tree');
}
# alternate constructor call
$in =
'from lists.securityfocus.com (lists.securityfocus.com [207.126.127.68]) by lists.securityfocus.com (Postfix) with ESMTP id 1C2AF1F138; Mon, 14 Feb 2000 10:24:11 -0800 (PST)';
$parse_tree = {
'by' => {
'domain' => 'lists.securityfocus.com',
'whole' => 'by lists.securityfocus.com',
'comments' => ['(Postfix)'],
},
'date_time' => {
'year' => '2000',
'week_day' => 'Mon',
'minute' => '24',
'day_of_year' => '14 Feb',
'month_day' => '14',
'zone' => '-0800 (PST)',
'second' => '11',
'date_time' => 'Mon, 14 Feb 2000 10:24:11 -0800 (PST)',
'hour' => '10',
'hms' => '10:24:11',
'month' => 'Feb',
'rest' => '2000 10:24:11 -0800 (PST)',
'whole' => 'Mon, 14 Feb 2000 10:24:11 -0800 (PST)'
},
'with' => {
'with' => 'ESMTP',
'whole' => 'with ESMTP'
},
'from' => {
'domain' => 'lists.securityfocus.com',
'from' => 'lists.securityfocus.com',
'HELO' => 'lists.securityfocus.com',
'address' => '207.126.127.68',
'comments' => [ '(lists.securityfocus.com [207.126.127.68])', ],
'whole' =>
'from lists.securityfocus.com (lists.securityfocus.com [207.126.127.68])
'
},
'id' => {
'id' => '1C2AF1F138',
'whole' => 'id 1C2AF1F138'
},
'comments' => [ '(lists.securityfocus.com [207.126.127.68])', '(Postfix)' ],
'whole' =>
'from lists.securityfocus.com (lists.securityfocus.com [207.126.127.68]) by lists.securityfocus.com (Postfix) with ESMTP id 1C2AF1F138; Mon, 14 Feb 2000 10:24:11 -0800 (PST)'
};
my $received2 = Mail::Field->new('Received', $in);
is $received2->parsed_ok, 1, 'alternate constructor parsed ok';
parse_tree_ok($received2, $parse_tree, 'alternate constructor parse tree');
$received2->diagnose('squr', 'gle');
like $received2->diagnostics, qr/^squrgle$/m, 'diagnostics';
|