Fix missing mailboxes

This commit is contained in:
Antonio J. Delgado 2024-09-22 13:48:13 +03:00
parent 609e75e43d
commit 95b28d13a3

View file

@ -53,9 +53,43 @@ class RemoveDuplicateImapMessages:
def _process_mailbox(self, mailbox):
'''Process a mailbox'''
self.imap.select(mailbox=mailbox, readonly=False)
select_result = self.imap.select(mailbox=mailbox, readonly=False)
if select_result[0] == 'NO':
self._log.error(
"Error selecting mailbox '%s'. %s",
mailbox,
select_result
)
return False
self._log.debug("Searching for all messages in mailbox '%s'...", mailbox)
typ, data = self.imap.search('UTF-8', 'ALL')
try:
typ, data = self.imap.search('UTF-8', 'ALL')
except imaplib.IMAP4.error as error:
if 'command SEARCH illegal in state AUTH' in f"{error}":
self._log.debug(
'Error searching (wrong state AUTH), trying to re-connect and re-select the mailbox...'
)
self.connect_imap()
result = self.imap.select(mailbox=mailbox, readonly=False)
self._log.debug(
"Result of select mailbox '%s': %s",
mailbox,
result
)
self._log.debug("Searching for all messages in mailbox '%s'...", mailbox)
try:
typ, data = self.imap.search('UTF-8', 'ALL')
except imaplib.IMAP4.error as sub_error:
self._log.error(
"Error searching for message. Tried to re-connect without success. %s",
sub_error
)
sys.exit(3)
self._log.error(
"Error searching for messages. %s",
error
)
sys.exit(2)
self._log.debug('Response: %s', typ)
if typ != 'OK':
self._log.error('Error, server replied: %s', data)