python-o365
python-o365 copied to clipboard
Fetching Same message at timestamp
So this my function to fetch new mail after a set data, After 2024-06-05 01:41:32-04:00 the fetches the same mail with the same exact timesstamp even though there is newer mail in the mailbox. But I tweak the time parameter by increasing the previous date by a second it starts retrieving the newer mail
def _read_mail_auto(account, limit = DEFAULT_MAIL_FETCH_NUM, last_read_file_path = DEFAULT_LAST_READ_PATH, date = default_date):
''' default date = '2024-06-02 00:00:00-04:00' '''
last_message = read_last_saved(last_read_file_path)
message_cache = list()
try:
time_filter = datetime.strptime(str(last_message['timestamp']),DATE_FORMAT)
mailbox = account.mailbox()
query = mailbox.new_query()
query = query.on_attribute('receivedDateTime').greater(time_filter)
msg_num = 0
for message in mailbox.get_messages(query=query,limit=limit):
print(message.received, message.sender)
message_cache.append(message)
msg_num += 1
So, I figured out what caused the bug. At that exact timestamp down to the last second, the mailbox received similar but different messages. and when I tried to read the next message after the timestamp, it returned the very first message that that had that timestamp hence the impasse