Attachment is sometimes corrupted with '* 41 EXISTS'


Weird thing !

By retrieving dozens of mails, sometimes the attachment is corrupted !
an additional header that does not belong to the file is on top of the file:
I tried Base64 or UTF8 encoding, same problem!

Any Idea ?



sliver wrote Jun 11, 2016 at 2:19 PM

Hi there,

I've the fix for that, would you like to integrate? Please explain how to proceed ?

It comes from the filtering when appending data in the method ProcessCommandResult(string data),

the one is efficiently filtering with some "FETCH" form:
                    if(data.StartsWith("*") && data.Contains("FETCH"))
                        data = CommandStartRex.Replace(data, "");
but filters are missing for '* EXISTS ...' and ' FETCH ... FLAGS'.
            if(data.StartsWith("*") && data.Contains("EXISTS"))

            if(data.StartsWith("*") && data.Contains("FETCH") && data.Contains("FLAGS"))

jstedfast wrote Jun 14, 2016 at 9:16 PM

The code shouldn't be filtering. Instead, it should be parsing the IMAP response, looking for the BODY[...] key/value pair.

Normally, the value will be one of the following:
  1. NIL (means the content is empty)
  2. "" (means the content is empty)
  3. "some text here" (very rare, although I suppose it can happen)
  4. {###}\r\nsome text here... (the most common)
In case #4, the number between the {}'s tells you how many bytes (not chars) the content is and the content will start immediately after the "}\r\n" sequence.

Hope that helps.