Parsing of bodypart fails for signed message


I tried to download a message and the bodypart parsing failed at the following response:

("multipart" "signed" ("boundary" "Apple-Mail-11-1011610758" "micalg" "sha1" "protocol" "application/pkcs7-signature") NIL NIL NIL -1 NIL NIL "de-AT" NIL)


DieBagger wrote Oct 28, 2009 at 1:11 PM

I looked a bit further into this problem and (although I'm not very familiar with the IMAP protocol) it seems that this message is invalid... The message is delivered by an Exchange Server 2007.

I found a discussion on the same topic here: http://forums.sun.com/thread.jspa?threadID=5327529

Strangely, Thunderbird and Outlook can both handle these messages. The body of the message can only be downloaded in one request (bodypart 1) and contains the html, the text AND the pkcs7-signature.

I can provide you with a sample body if needed...

DieBagger wrote Nov 4, 2009 at 10:02 PM

Small update: the message is valid but since it is signed it contains the whole body (text, html and signature) in one bodypart. Unfortunately this can't be handled by this library atm.

coda wrote Jan 26, 2010 at 8:35 AM

I found a bug in ImapCommand.BodyPartSplit () which may also be causing your problem -

ImageMessageBodyPartList BodyPartSplit(string response)
                    // Parse nested body parts
                    if (response.Substring(index, next - index).StartsWith("(("))

                        // line with bug
                        ImapMessageBodyPartList temp = BodyPartSplit(response.Substring(index, next);

                        for (int j = 0; j < temp.Count; j++)
                            temp[j].BodyPart = count.ToString() + "." + temp[j].BodyPart;
line should be
                        ImapMessageBodyPartList temp = BodyPartSplit(response.Substring(index, next - index);
first comment here. Apologies if the formatting blows,