ap2 - 2009-05-27

Hi,

I found that some of IMAP mail servers send different response to command FETCH BODYSTRUCTURE.
This client expects that all named RegEx values will be send back, eg:
("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "8bit" 502 19 NIL NIL NIL)

but sometimes last three NILs are skipped, eg:
("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "8bit" 502 19)

I fixed it by changing RegEx non_attach constant value in ImapMessageBodyPart.cs to the new value:
        const string non_attach = "^\\((?<type>(\&quot;[^\&quot;]*\&quot;|NIL))\\s(?<subtype>(\&quot;[^\&quot;]*\&quot;|NIL))\\s(?<attr>(\\([^\\)]*\\)|NIL))\\s(?<id>(\&quot;[^\&quot;]*\&quot;|NIL))\\s(?<desc>(\&quot;[^\&quot;]*\&quot;|NIL))\\s(?<encoding>(\&quot;[^\&quot;]*\&quot;|NIL))\\s(?<size>(\\d+|NIL))\\s(?<lines>(\\d+|NIL))\\s?(?<md5>(\&quot;[^\&quot;]*\&quot;|NIL))?\\s?(?<disposition>(\\([^\\)]*\\)|NIL))?\\s?(?<lang>(\&quot;[^\&quot;]*\&quot;|NIL))?\\)$";

After that change last three NILs are optional.

That forced extra change to the ParseNIL(string data) function. New body of it:

            data = data.Trim();
            if (data == "NIL" || data == string.Empty)
                return null;
            return data;

I'm not 100% sure if these changes are not against some standards but I had been made tests of this IMAP server with Outlook and Thunderbird and all went fine so I decided to write about this here.

AP2