def safe_parse_date(date_hdr):
 try:
  if (';' in date_hdr):
   date_hdr = date_hdr.split(';')[(-1)].strip()
  msg_ts = long(rfc822.mktime_tz(rfc822.parsedate_tz(date_hdr)))
  if ((msg_ts > (time.time() + (24 * 3600))) or (msg_ts < 1)):
   return None
  else:
   return msg_ts
 except (ValueError, TypeError, OverflowError):
  return None

def safe_parse_date ( date_hdr ) : try : if ( ';' in date_hdr ) : date_hdr = date_hdr . split ( ';' ) [ ( - 1 ) ] . strip ( ) msg_ts = long ( rfc822 . mktime_tz ( rfc822 . parsedate_tz ( date_hdr ) ) ) if ( ( msg_ts > ( time . time ( ) + ( 24 * 3600 ) ) ) or ( msg_ts < 1 ) ) : return None else : return msg_ts except ( ValueError , TypeError , OverflowError ) : return None
parse a date: or received: header into a unix timestamp .