IMAP: ignore UID with 0 as value when searching for UIDs
Some servers are broken: they return zero as valid UID and respond "BAD invalid parameter: 0" on the FETCH command. Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
b14f37942a
commit
f00cbeed5a
@ -184,6 +184,10 @@ class IMAPFolder(BaseFolder):
|
|||||||
# On first run the first element is empty.
|
# On first run the first element is empty.
|
||||||
if ' ' in res_data[0] or res_data[0] == '':
|
if ' ' in res_data[0] or res_data[0] == '':
|
||||||
res_data = res_data[0].split()
|
res_data = res_data[0].split()
|
||||||
|
# Some servers are broken.
|
||||||
|
if 0 in res_data:
|
||||||
|
self.ui.warn("server returned UID with 0; ignoring.")
|
||||||
|
res_data.remove(0)
|
||||||
return res_data
|
return res_data
|
||||||
|
|
||||||
res_type, imapdata = imapobj.select(self.getfullname(), True, True)
|
res_type, imapdata = imapobj.select(self.getfullname(), True, True)
|
||||||
@ -229,7 +233,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
msgsToFetch = self._msgs_to_fetch(
|
msgsToFetch = self._msgs_to_fetch(
|
||||||
imapobj, min_date=min_date, min_uid=min_uid)
|
imapobj, min_date=min_date, min_uid=min_uid)
|
||||||
if not msgsToFetch:
|
if not msgsToFetch:
|
||||||
return # No messages to sync
|
return # No messages to sync.
|
||||||
|
|
||||||
# Get the flags and UIDs for these. single-quotes prevent
|
# Get the flags and UIDs for these. single-quotes prevent
|
||||||
# imaplib2 from quoting the sequence.
|
# imaplib2 from quoting the sequence.
|
||||||
@ -695,7 +699,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
break
|
break
|
||||||
except imapobj.abort as e:
|
except imapobj.abort as e:
|
||||||
fails_left -= 1
|
fails_left -= 1
|
||||||
# self.ui.error() will show the original traceback
|
# self.ui.error() will show the original traceback.
|
||||||
if fails_left <= 0:
|
if fails_left <= 0:
|
||||||
message = ("%s, while fetching msg %r in folder %r."
|
message = ("%s, while fetching msg %r in folder %r."
|
||||||
" Max retry reached (%d)"%
|
" Max retry reached (%d)"%
|
||||||
@ -703,7 +707,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
severity = OfflineImapError.ERROR.MESSAGE
|
severity = OfflineImapError.ERROR.MESSAGE
|
||||||
raise OfflineImapError(message,
|
raise OfflineImapError(message,
|
||||||
OfflineImapError.ERROR.MESSAGE)
|
OfflineImapError.ERROR.MESSAGE)
|
||||||
# Release dropped connection, and get a new one
|
# Release dropped connection, and get a new one.
|
||||||
self.imapserver.releaseconnection(imapobj, True)
|
self.imapserver.releaseconnection(imapobj, True)
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
self.ui.error("%s. While fetching msg %r in folder %r."
|
self.ui.error("%s. While fetching msg %r in folder %r."
|
||||||
@ -716,13 +720,13 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
|
|
||||||
if data == [None] or res_type != 'OK':
|
if data == [None] or res_type != 'OK':
|
||||||
#IMAP server says bad request or UID does not exist
|
# IMAP server says bad request or UID does not exist.
|
||||||
severity = OfflineImapError.ERROR.MESSAGE
|
severity = OfflineImapError.ERROR.MESSAGE
|
||||||
reason = "IMAP server '%s' failed to fetch messages UID '%s'."\
|
reason = "IMAP server '%s' failed to fetch messages UID '%s'."\
|
||||||
"Server responded: %s %s"% (self.getrepository(), uids,
|
"Server responded: %s %s"% (self.getrepository(), uids,
|
||||||
res_type, data)
|
res_type, data)
|
||||||
if data == [None]:
|
if data == [None]:
|
||||||
#IMAP server did not find a message with this UID
|
# IMAP server did not find a message with this UID.
|
||||||
reason = "IMAP server '%s' does not have a message "\
|
reason = "IMAP server '%s' does not have a message "\
|
||||||
"with UID '%s'" % (self.getrepository(), uids)
|
"with UID '%s'" % (self.getrepository(), uids)
|
||||||
raise OfflineImapError(reason, severity)
|
raise OfflineImapError(reason, severity)
|
||||||
|
Loading…
Reference in New Issue
Block a user