Permalink
Browse files

Improve the test for sender's date validity

  • Loading branch information...
1 parent 99acfe8 commit f3c8fe99514394757256f1ec3e5ffcb17fc0e6c2 @manitou-mail committed Jun 19, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 lib/Manitou/MailFormat.pm
View
@@ -196,8 +196,16 @@ sub parse_sender_date {
return undef if ($hour>=24 || $min>=60 || $secs>=60);
$year += 2000 if ($year<50);
- my $t = POSIX::mktime ($secs, $min, $hour, $day,
- $month-1, $year-1900);
+ my $t = POSIX::mktime($secs, $min, $hour, $day,
+ $month-1, $year-1900, 0, 0, -1);
+ if (defined $t) {
+ # mktime does not fail on certain invalid dates.
+ # that's why we convert mktime's result back to a date in
+ # localtime and compare that to the day/month/year that
+ # we passed. If they're different, that was an invalid date.
+ my $ymd = strftime("%Y-%m-%d", localtime($t));
+ return undef if ($ymd ne sprintf("%04d-%02d-%02d", $year, $month, $day));
+ }
return (defined $t) ? ($year,$month,$day,$hour,$min,$secs,$tz) : undef;
}

0 comments on commit f3c8fe9

Please sign in to comment.