python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

Fetching Same message at timestamp

Open Blaygh opened this issue 1 year ago • 1 comments

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

Blaygh avatar Jun 06 '24 20:06 Blaygh

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

Blaygh avatar Jun 07 '24 03:06 Blaygh