System.FormatException while downloading messages

Topics: Issues
Jan 22, 2014 at 6:54 PM
Edited Jan 22, 2014 at 10:45 PM
Hi Pavel, I've this issue:

A first chance exception of type 'System.FormatException' occurred in System.dll

I've tried several MessageFetchMode. If I use MessageFetchMode.Size it works, but the code raises the same exception at the m.Download

Here is the complete code:
 ' connection is ok 
Dim f As ImapX.Folder = cli.Folders.Inbox 
f.Messages.Download("UNSEEN", Enums.MessageFetchMode.Tiny) 
For Each m As ImapX.Message In f.Messages 
     m.Download(Enums.MessageFetchMode.Tiny) 
     Dim mySubject As String = m.Subject.ToString.ToUpper
 Debug.Print(m.Subject) 
Next 
Then, while iterating, the progams always hangs itself at the m.Download (iteration n. 8, maybe depending on the message content ?)

I've debugged. The problem is in this method. I had to add a row (see comments inline):
     private string ReadQuotedString(bool trimSpaces = true)
        {
            if (trimSpaces)
                SkipSpaces();

            char prevChar = '\0', currentChar;
            var sb = new StringBuilder();
            while ((currentChar = (char)_reader.Read()) != '"')
            {
                sb.Append(currentChar);
                if (sb.ToString() == "NIL")
                    return string.Empty;

                // I've fixed by adding the following row:
                 if (currentChar == Convert.ToChar(65535)) return string.Empty;
            }

            while ((currentChar = (char)_reader.Read()) != '"' || prevChar == '\\')
            {
                prevChar = currentChar;
                sb.Append(currentChar);
            }

            if (trimSpaces)
                SkipSpaces();

            return sb.ToString();
        }
Same problem and same "fix" here:
    private ContentDisposition ReadDisposition()
        {
            SkipSpaces();
            var sb = new StringBuilder();
            char currentChar;

            while ((currentChar = (char)_reader.Read()) != '(')
            {
                sb.Append(currentChar);
                if (sb.ToString() == "NIL")
                    return null;
                // my Added row
                if (currentChar == Convert.ToChar(65535)) return null;
            }
            var type = ReadString().ToLower();
            var paramaters = ReadParameterList();
            var disposition = new ContentDisposition(type);

            foreach (var paramater in paramaters)
            {
                switch (paramater.Key)
                {
                    case "filename":
                    case "name":
                        disposition.FileName = StringDecoder.Decode(paramater.Value, true);
                        break;
                }
            }

            SkipSpaces();
            _reader.Read(); // read ')'
            SkipSpaces();
            return disposition;
        }
I do not know if those fix are good or not. Please, could you check if all is ok ?

Thanks Francesco