#32 Empty response from FETCH not handled gracefully


When attempting to FETCH defatils for a particular message number, OpenText FirstClass IMAP may return an "empty" response.
It seems the current code does not handle that very well.

Example IMAP session with OpenText FirstClass:
. EXAMINE "INBOX/foobar"
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS ()] Read-only mailbox.
* OK [UIDVALIDITY 1100080522] UIDs valid
* OK [UIDNEXT 3] Predicted next UID
. OK [READ-ONLY] Select completed.
. FETCH 1:* (RFC822.SIZE)
* 1 FETCH (RFC822.SIZE 5120)
* 3 FETCH (RFC822.SIZE 2048)
. FETCH 2 (RFC822)
. OK FETCH Completed

When trying to archive such as mailbox using the current git version of archivemail, it fails like this:

34:57.74 > KKFK128 FETCH 2 (FLAGS)
34:57.77 < KKFK128 OK FETCH Completed
34:57.77 matched r'(?P<tag>KKFK\d+) (?P<type>[A-Z]+) (?P<data>.*)' => ('KKFK128', 'OK', 'FETCH Completed')
cleaning up ...
removing stale temporary mbox '/tmp/tmpwh4hnzarchivemail/tmp9HUS2s'
removing stale tempfile directory '/tmp/tmpwh4hnzarchivemail'
Traceback (most recent call last):
File "archivemail", line 1822, in <module>
File "archivemail", line 697, in main
File "archivemail", line 1118, in archive
File "archivemail", line 1379, in _archive_imap
msg_flags = imaplib.ParseFlags(response[0])
File "/usr/lib/python2.6/imaplib.py", line 1374, in ParseFlags
mo = Flags.match(resp)
TypeError: expected string or buffer


  • Nikolaus Schulz

    Nikolaus Schulz - 2010-10-20

    Thanks for reporting. Please test the attached patch, it should fix an empty reply to "FETCH (FLAGS)".

    Your example IMAP session looks interesting. Did you send the "FETCH (RFC822)" before the server completed your first FETCH command? And, which FETCH command was completed there by the "OK FETCH Completed"? I hope it wasn't a "FETCH (RFC822*)" command? Because I would expect that data not to be empty...

    By the way, feel free to contact me by email about this, microschulz at web.de. This web bug tracker thingy is horrible for serious communication.

  • Nikolaus Schulz

    Nikolaus Schulz - 2010-10-20
    • assigned_to: nobody --> nikosch
  • Nikolaus Schulz

    Nikolaus Schulz - 2010-10-24

    I have discussed this issue with the submitter by email, and it turned out that this IMAP server returns no untagged FETCH responses for certain email messages that are corrupted. This means that the server is in an error state which it fails to report it to the client.

    Since archivemail generally refrains from continuing after any error on the server side, and it turned out this particular error can be fixed by deleting the messages in question, I'm closing this bug as `Wont Fix'.

    For the record, I have attached a patch from the email exchange with the submitter which lets archivemail skip such messages; however, this patch is not going to be applied.

  • Nikolaus Schulz

    Nikolaus Schulz - 2010-10-24
    • status: open --> closed-wont-fix

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks