0

I have the following code to check messages in my inbox:

M = imaplib.IMAP4_SSL('imap.url.com')
M.login('myemail@my.com','myPassword')
M.select('inbox')
typ, data = M.search(None, 'ALL')
print(data)

Let's say i have two email in my inbox, the output would be something like:

[b'1 2']

However, when i delete or move these two emails to an other folder, my program keeps saying i have them there in inbox.

[b'1 2']

This is causing my program to crush, since i check (fetch) the content of these emails later in my code & when the (search) says we still have emails in inbox then the (fetch) will try to go through them and won't find a thing. It will throw then the error:

FETCH failed: Internal error occurred. Refer to server log for more information

this will happen for a long period (20 minutes) till the search command sends back the correct result.

Is there a cache management i should take care of?

It is worth mentioning that my Email server is aws.

  • "my program keeps saying..." Can you show us code that demonstrates the problem? Do you mean you call `M.search(...)` a second time and it returns the same results even after deleting the emails? Are you expunging the emails? – larsks Aug 06 '20 at 15:59
  • @larsks Hello and thank you for your reply. I did indeed show the code for the problem first? I am running the same code i wrote and getting the two emails back as a result for my search so my program output is: [b'1 2'] again although those emails are deleted or moved by the owner of the email to another folder. – Moe Joudeh Aug 07 '20 at 07:43
  • Sounds like the server implementation has a particularly bad caching implementation. But you don't show your fetching code! You could wrap a try/except around your fetch and just continue on if it fails. * NO responses can be a normal part of an IMAP conversation and you should be prepared to receive them. You can use try/except to protect against * BAD. – Max Aug 07 '20 at 18:46

0 Answers0