package DateTime::Format::Mail;
# $Id: Mail.pm 3746 2007-08-30 19:56:22Z autarch $
use strict;
use 5.005;
use Carp;
use DateTime 0.1705;
use Params::Validate qw( validate validate_pos SCALAR );
use vars qw( $VERSION );
$VERSION = '0.3001';
my %validations = (
year_cutoff => {
type => SCALAR,
callbacks => {
'greater than or equal to zero, less than 100' => sub {
defined $_[0]
and $_[0] =~ /^ \d+ $/x
and $_[0] >= 0
and $_[0] < 100
},
},
}
);
# Timezones for strict parser.
my %timezones = qw(
EDT -0400 EST -0500 CDT -0500 CST -0600
MDT -0600 MST -0700 PDT -0700 PST -0800
GMT +0000 UT +0000
);
my $tz_RE = join( '|', sort keys %timezones );
$tz_RE= qr/(?:$tz_RE)/;
$timezones{UTC} = $timezones{UT};
# Strict parser regex
# Lovely regex. Mostly a translation of the BNF in 2822.
# XXX - need more thorough tests to ensure it's *strict*.
my $strict_RE = qr{
^ \s* # optional
# [day-of-week "," ]
(?:
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) ,
\s+
)?
# date => day month year
(\d{1,2}) # day => 1*2DIGIT
\s+
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) # month-name
\s*
((?:\d\d)?\d\d) # year
# FWS
\s+
# time
(\d\d):(\d\d):(\d\d) # time
(?:
\s+ (
[+-] \d{4} # standard form
| $tz_RE # obsolete form (mostly ignored)
| [A-IK-Za-ik-z] # including military (no 'J')
) # time zone (optional)
)?
\s* $
}ox;
# Loose parser regex
my $loose_RE = qr{
^ \s* # optional
(?i:
(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun|[A-Z][a-z][a-z]) ,? # Day name + comma
)?
# (empirically optional)
\s*
(\d{1,2}) # day of month
[-\s]*
(?i: (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ) # month
[-\s]*
((?:\d\d)?\d\d) # year
\s+
(\d?\d):(\d?\d) (?: :(\d?\d) )? # time
(?:
\s+ "? (
[+-] \d{4} # standard form
| [A-Z]+ # obsolete form (mostly ignored)
| GMT [+-] \d+ # empirical (converted)
| [A-Z]+\d+ # bizarre empirical (ignored)
| [a-zA-Z/]+ # linux style (ignored)
| [+-]{0,2} \d{3,5} # corrupted standard form
) "? # time zone (optional)
)?
(?: \s+ \([^\)]+\) )? # (friendly tz name; empirical)
\s* \.? $
}x;
sub _set_parse_method
{
my $self = shift;
=1= |