outlook_msg
outlook_msg copied to clipboard
How to get the message received date.
I can find only msg subject, body and sender_email as the attributes for the Message object. How to get the received date?
Hi @PSvishnu93, did you find an answer to this? Thanks
I had a (soft) need for this, dug into code and I'm not familiar with MSG format to make changes so for my use case I simply ignored it. Take a look at https://github.com/HamiltonInsurance/outlook_msg/pull/6 its not clear it has that support (I did not pull it down to experiment) but its a possible starting point.
FWIW, I was able to retrieve the date using this code. I have no idea if it is comprehensive.
class EnhancedMessage(Message):
"""Enhanced message class with the ability to read the sent datetime"""
@property
def date(self):
"""
Returns the send date contained in the message.
"""
try:
return self._date
except AttributeError:
self._date = None
# From the data samples we've received, these are the 3 possible
# keys with the send date.
for key in ['Unk: 0x8040', 'Unk: 0x8039', 'Unk: 0x802B']:
try:
value = self.mfs[key]
if not isinstance(value, str):
continue
date = dateparser.parse(self.mfs[key])
if date is None:
continue
else:
self._date = date
break
except KeyError:
pass
if self._date is None:
logger.warning("Error retrieving date. Returning `None`")
return self._date