Skip to content

Commit

Permalink
gracefully handle non-parseable dates (fixes kdeldycke#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Spiers committed Mar 21, 2013
1 parent 7f624b6 commit a2bc66e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion maildir-deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ def get_canonical_header_value(header, value):
elif header == 'date':
# Date timestamps can differ by seconds or hours for various
# reasons, so let's only honour the date for now.
utc_timestamp = email.utils.mktime_tz(email.utils.parsedate_tz(value))
try:
parsed = email.utils.parsedate_tz(value)
utc_timestamp = email.utils.mktime_tz(parsed)
except TypeError: # if parsedate_tz cannot parse the date
return value

return time.strftime('%Y/%m/%d UTC', time.gmtime(utc_timestamp))
elif header == 'to':
# Sometimes email.parser strips the <> brackets from a To:
Expand Down

0 comments on commit a2bc66e

Please sign in to comment.