Fix missing mailboxes
This commit is contained in:
parent
609e75e43d
commit
95b28d13a3
1 changed files with 36 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue