ecederstrand/exchangelib

item.is_read error

pythonRookie94 opened this issue · 6 comments

Describe the bug
The script was working fine for about 9 months and suddenly last week I began getting error emails related to the item.is_true.

To Reproduce

mail = Account('xxxxxxx@xxxxx.com', credentials=owa_credentials, autodiscover=False, config=owa_config, access_type=DELEGATE)
#inbox folder
folder = mail.inbox
for item in folder.all():
        #only allow mail items that were are still not read
        if item.is_read == False:

Expected behavior
The script was able to locate emails that were not read in the mailbox and then go on to perform the rest of the logic of the script. Right now the script is erroring out at "if item.is_read == False:"

Log output

Error: 
Traceback (most recent call last):
  File "w:/Scripts/Address_Validator/script.py", line 130, in <module>
    if item.is_read == False:
AttributeError: 'ErrorMimeContentConversionFailed' object has no attribute 'is_read'

Additional context
Python = 3.8.7
exchangelib = 4.9.0

QuerySet can return Message items, but also Exception instances if an individual item in the QuerySet is in error. You need to test the object type before accessing the is_read attribute.

When I add a line to get the object type it returns <class 'bool'>

You need to test item, not item.is_read.

When I tested item I got <class 'exchangelib.items.message.Message'>.

Also when I printed item I was able to locate the is_read attribute. Also since I inserted the print(item) before the item.is_read == false the script ran without issue and performed the tasks after that command.

Most of your items are of type Message. Some of them are of type ErrorMimeContentConversionFailed instead. You need to be able to handle both types in your fo loop.

Closing as I don't think there's anything to fix in exchangelib.