Skip to content

Commit

Permalink
IMAP: provide message-id in error messages
Browse files Browse the repository at this point in the history
This is handy for debug purposes when one tries to locate exact
message that was e.g. rejected by server.

Feature-request: http://comments.gmane.org/gmane.mail.imap.offlineimap.general/6491
Signed-off-by: Eygene Ryabinkin <[email protected]>
  • Loading branch information
konvpalto committed Jul 1, 2014
1 parent 863113e commit ffd1b1d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions offlineimap/folder/IMAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ def savemessage(self, uid, content, flags, rtime):
# get the date of the message, so we can pass it to the server.
date = self.__getmessageinternaldate(content, rtime)

# Message-ID is handy for debugging messages
msg_id = self.getmessageheader(content, "message-id")
if not msg_id:
msg_id = '[unknown message-id]'

retry_left = 2 # succeeded in APPENDING?
imapobj = self.imapserver.acquireconnection()
# NB: in the finally clause for this try we will release
Expand Down Expand Up @@ -569,9 +574,9 @@ def savemessage(self, uid, content, flags, rtime):
# In this case, we should immediately abort the repository sync
# and continue with the next account.
msg = \
"Saving msg in folder '%s', repository '%s' failed (abort). " \
"Saving msg (%s) in folder '%s', repository '%s' failed (abort). " \
"Server responded: %s %s\n" % \
(self, self.getrepository(), typ, dat)
(msg_id, self, self.getrepository(), typ, dat)
raise OfflineImapError(msg, OfflineImapError.ERROR.REPO)
retry_left = 0 # Mark as success
except imapobj.abort as e:
Expand All @@ -580,10 +585,10 @@ def savemessage(self, uid, content, flags, rtime):
self.imapserver.releaseconnection(imapobj, True)
imapobj = self.imapserver.acquireconnection()
if not retry_left:
raise OfflineImapError("Saving msg in folder '%s', "
raise OfflineImapError("Saving msg (%s) in folder '%s', "
"repository '%s' failed (abort). Server responded: %s\n"
"Message content was: %s" %
(self, self.getrepository(), str(e), dbg_output),
(msg_id, self, self.getrepository(), str(e), dbg_output),
OfflineImapError.ERROR.MESSAGE)
self.ui.error(e, exc_info()[2])
except imapobj.error as e: # APPEND failed
Expand All @@ -592,9 +597,9 @@ def savemessage(self, uid, content, flags, rtime):
# drop conn, it might be bad.
self.imapserver.releaseconnection(imapobj, True)
imapobj = None
raise OfflineImapError("Saving msg folder '%s', repo '%s'"
raise OfflineImapError("Saving msg (%s) folder '%s', repo '%s'"
"failed (error). Server responded: %s\nMessage content was: "
"%s" % (self, self.getrepository(), str(e), dbg_output),
"%s" % (msg_id, self, self.getrepository(), str(e), dbg_output),
OfflineImapError.ERROR.MESSAGE)
# Checkpoint. Let it write out stuff, etc. Eg searches for
# just uploaded messages won't work if we don't do this.
Expand Down

0 comments on commit ffd1b1d

Please sign in to comment.