In my python script I am trying to scan my inbox retrieve emails in reverse date-time order and by filtering on a subject. However, if my inbox has no emails with that subject, I get a NoneType
error, object
is not iterable"
If there is an email with that subject, it all works fine.
However when there is no email with that subject, I get this error.
How to resolve it?
I have tried to use try catch blocks but the exception is not being caught
for item in account.inbox.all().filter(subject__contains='foo').order_by('-datetime_received')[:100]:
if there is no email with that subject, then there is a none type error.
if I check
if (account.inbox.all().filter(subject__contains='foo').order_by('-datetime_received')[:100] is None):
print("none type error")
the print
statement is not executed.
I would like to be able to skip the loop if there is no email at all in the mailbox