Hi Pavel,
There are a few problems I see in the ImapX code.
It's a bit worrisome is that I can't find where you handle literal strings in responses from the IMAP server. It seems to me that you use a StreamReader to read line-by-line, and simply assume that the text after the first line is the message body until you reach a line beginning with a ")". This, however, is incorrect for at least 2 reasons:
Hopefully I am just misunderstanding your code.
There are a few problems I see in the ImapX code.
-
It doesn't appear to me that ImapX handles parsing of LIST responses that use literals for the mailbox name (unless the regex logic somehow handles it, but I didn't know where to look for the regex pattern).
-
In Folder.cs, in the AppendMessage() method, your code assumes that the email.Length is the same as the octet length, but they are not. The String.Length property is the unicode character count, not the octet count. You need to convert to a byte[] and then use that length.
var options = MimeKit.FormatOptions.Default.Clone ();
options.NewLineFormat = MimeKit.NewLineFormat.Dos;
long octets;
using (var measure = new MimeKit.IO.MeasureStream ()) {
message.WriteTo (options, measure);
octets = measure.Length;
}
A measure stream is just there to measure the number of bytes written to it but doesn't actually store any data, so it's really useful for this sort of thing.It's a bit worrisome is that I can't find where you handle literal strings in responses from the IMAP server. It seems to me that you use a StreamReader to read line-by-line, and simply assume that the text after the first line is the message body until you reach a line beginning with a ")". This, however, is incorrect for at least 2 reasons:
-
What if a line in the message begins with ")"? I have some LISP emails that have lines beginning with a ")" that your ImapX client library would likely break on if I tried to fetch them over an ImapXClient connection.
-
The message data itself isn't required to end with a CRLF which means that the last line of the literal may end mid-line which means that the ")" would also be mid-line and not at the beginning of a line like your code seems to depend on.
Hopefully I am just misunderstanding your code.