X-Git-Url: https://code.delx.au/offlineimap/blobdiff_plain/f11a49f263ff9648302a57ec8915d03ff659046d..39a18fef6078388dac7a1db386cdfd2900f5263c:/offlineimap/folder/IMAP.py diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 45978b5..7cb334a 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from Base import BaseFolder from offlineimap import imaputil, imaplib @@ -161,11 +161,13 @@ class IMAPFolder(BaseFolder): matchinguids = imapobj.uid('search', 'HEADER', headername, headervalue)[1][0] except imapobj.error, err: # IMAP server doesn't implement search or had a problem. - raise ValueError, "Got IMAP error while attempting to find UID for message with header %s: %s" % (headername, err) + ui.debug('imap', "savemessage_searchforheader: got IMAP error '%s' while attempting to UID SEARCH for message with header %s" % (err, headername)) + return 0 ui.debug('imap', 'savemessage_searchforheader got initial matchinguids: ' + repr(matchinguids)) if matchinguids == '': - raise ValueError, "Search for UID for message with header %s yielded no results" % headername + ui.debug('imap', "savemessage_searchforheader: UID SEARCH for message with header %s yielded no results" % headername) + return 0 matchinguids = matchinguids.split(' ') ui.debug('imap', 'savemessage_searchforheader: matchinguids now ' + \ @@ -229,11 +231,11 @@ class IMAPFolder(BaseFolder): assert(imapobj.check()[0] == 'OK') # Keep trying until we get the UID. - try: - ui.debug('imap', 'savemessage: first attempt to get new UID') - uid = self.savemessage_searchforheader(imapobj, headername, - headervalue) - except ValueError: + ui.debug('imap', 'savemessage: first attempt to get new UID') + uid = self.savemessage_searchforheader(imapobj, headername, + headervalue) + # See docs for savemessage in Base.py for explanation of this and other return values + if uid <= 0: ui.debug('imap', 'savemessage: first attempt to get new UID failed. Going to run a NOOP and try again.') assert(imapobj.noop()[0] == 'OK') uid = self.savemessage_searchforheader(imapobj, headername, @@ -241,7 +243,9 @@ class IMAPFolder(BaseFolder): finally: self.imapserver.releaseconnection(imapobj) - self.messagelist[uid] = {'uid': uid, 'flags': flags} + if uid: # avoid UID FETCH 0 crash happening later on + self.messagelist[uid] = {'uid': uid, 'flags': flags} + ui.debug('imap', 'savemessage: returning %d' % uid) return uid