1

The following code:

#!/usr/bin/env python
from exchangelib import ServiceAccount, Configuration, Account, DELEGATE

import os
import logging
from config import cfg
logging.basicConfig()

credentials = ServiceAccount(username=cfg['imap_user'],
                             password=cfg['imap_password'])

config = Configuration(server=cfg['imap_server'], credentials=credentials)
account = Account(primary_smtp_address=cfg['smpt_address'], config=config,
                  autodiscover=False, access_type=DELEGATE)
unread = account.inbox.filter(is_read=False)   # returns unread emails
for msg in unread:
    print("last_modified_time={}".format(msg.last_modified_time))
    print("datetime_sent     ={}".format(msg.datetime_sent))
    print("#" * 80)

gives me the output

last_modified_time=2017-08-01 09:37:56+00:00
datetime_sent     =2017-08-01 09:37:15+00:00
################################################################################
last_modified_time=2017-07-31 14:41:55+00:00
datetime_sent     =2017-07-31 14:40:34+00:00
################################################################################

Why is the datetime_sent before last_modified_time? Is it the time of the senders email server (hence it could be anything)? Was the email modified afterwards by the receiving server? How can received emails be modified? Are flag modifications (e.g. set to "read") also changing last_modified_time?

Lars Nordin
  • 2,785
  • 1
  • 22
  • 25
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • I think 'last_modified_time' field is only present if the message is an Attachment. That's basically the timestamp of the last modification of the attached file. – ant1g Aug 01 '17 at 10:05
  • @aramaki Both messages are Multipart (I think), but only one has an attachment. – Martin Thoma Aug 01 '17 at 10:42
  • All the current Message timestamps are set automatically by the server, so this depends on the rules in place on said server. It's not specific to exchangelib, but rather a general EWS/Exchange question. – Erik Cederstrand Aug 15 '17 at 12:24

0 Answers0