outlook_msg icon indicating copy to clipboard operation
outlook_msg copied to clipboard

How to get the message received date.

Open PSvishnu93 opened this issue 5 years ago • 3 comments

I can find only msg subject, body and sender_email as the attributes for the Message object. How to get the received date?

PSvishnu93 avatar Oct 22 '20 09:10 PSvishnu93

Hi @PSvishnu93, did you find an answer to this? Thanks

jamie85 avatar May 15 '21 03:05 jamie85

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.

clach04 avatar Jun 08 '21 23:06 clach04

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

tmreay avatar Nov 10 '21 05:11 tmreay