When parsing timestamps in an email message, the parser should understand the timezone offset.
Since the standard class mapping ignores timezone, I built my own subclass. I suggest that the default header registry should map to a class like this which supports timezone data.
class DateClass(UnstructuredHeader):
max_count = None
value_parser = staticmethod(headparser.get_unstructured)
@classmethod
def parse(cls, hdrtext, kw):
kw['parse_tree'] = cls.value_parser(hdrtext)
kw['decoded'] = str(kw['parse_tree'])
def init(self,*args,**kw):
super().init(*args, **kw)
timetext = str(self)
try:
timetuple = parsedate_tz(timetext)
epochstart = datetime.fromisoformat('1970-01-01T00:00:00Z')
newtime = mktime_tz(timetuple)
self.timestamp = epochstart + timedelta(seconds=newtime)
except:
self.timestamp = None
# ========== End class definition ========================