andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

Debug assertion fails in ImapClient.cs #110

Closed rageshkrishna closed 11 years ago

rageshkrishna commented 11 years ago

This debug assertion in ImapClient.cs:

var n = Convert.ToChar(_Stream.ReadByte());
System.Diagnostics.Debug.Assert(n == ')');

fails when running against gMail. The value of n is 10 in this case and the ')' is actually the next character in the stream.

ghost commented 11 years ago

I've got the same problem, n =10 which is '\n'. Not all messages are erroring.

ghost commented 11 years ago

Removal of the assert seems to correctly retreive the messages.

rageshkrishna commented 11 years ago

Yes, removing the assert seems to cause no side effects, other than the loop being executed one extra time to read the ")" and ignore it. Unfortunately, I still do not know enough about IMAP parsing to make an educated guess about the right way to fix this.

andyedinborough commented 11 years ago

It's a debug assert, so it is not executed in a release build and shouldn't be an issue in production. It is there on purpose for debugging. If everything has worked correctly, the very next character should be a ). If it isn't, something has gone wrong. Can you send me example messages? The exact binary output would be perfect.

ghost commented 11 years ago

I'm not sure where to retreive the binary output, but this is the content of mail.base.body in GetMessages = "\n\r\nChauffeur: Bart\r\nDatum: 12 november 2012\r\nTijd geregistreerd: 0:00\r\nTijd gewerkt: 0:00\r\nTijd pauze: 0:00\r\nTijd werkoverleg: 0:00\r\nTijd reparatie: 0:00\r\nTijd overig: 0:00\r\nTijd ongeregistreerd: 0:00\r"

ghost commented 11 years ago

The new e-mail format is problematic as well: "\n<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\r\n\r\n Harmen\r\n 29 nov. 2012 20:54:02\r\n 29 nov. 2012 22:34:39\r\n 00:02\r\n 00:00\r\n 00:00\r\n 00:04\r\n 00:00\r\n 01:34\r\n\r"

rageshkrishna commented 11 years ago

Here's one that breaks for me:

"\n* 1 FETCH (X-GM-THRID 1419886428955103010 X-GM-MSGID 1419886428955103010 X-GM-LABELS () UID 1 FLAGS (\\Seen) BODY[HEADER] {403}\r\nMIME-Version: 1.0\r\nReceived: by 10.112.9.106; Wed, 28 Nov 2012 05:26:59 -0800 (PST)\r\nDate: Wed, 28 Nov 2012 05:26:59 -0800\r\nMessage-ID: <CADoZ-ESTNAx5XMzwmHrFmRaCiGL8OfqFAq4zvynR5O4PthTzTQ@mail.gmail.com>\r\nSubject: Get started with Gmail\r\nFrom: Gmail Team <mail-noreply@google.com>\r\nTo: Test Imap <imap.test@purplebeak.com>\r\nContent-Type: multipart/alternative; boundary=089e01182b40039d4e04cf8e1f34\r\n\r\n)\r\n
andyedinborough commented 11 years ago

Harmen, try adding this after line 416 in ImapClient.cs:

            using (var mem = new System.IO.MemoryStream()) {
                var data = Encoding.GetBytes(response);
                mem.Write(data, 0, data.Length);
                data = _Stream.Read(mail.Size);
                mem.Write(data, 0, data.Length);
                System.IO.File.WriteAllBytes(@"C:\temp.msg", mem.ToArray());
            }

It will error out afterward, but it should log the raw email to the file c:\temp.msg.

rageshkrishna commented 11 years ago

@andyedinborough The lack of debug logging is perhaps another issue I should create. :)

andyedinborough commented 11 years ago

I do accept pull requests. ;]

andyedinborough commented 11 years ago

Ragesh, I did just verify that the assertion fails when retrieving only headers. I'll get a fix out shortly.

ghost commented 11 years ago

Andy, I've send you an e-mail with the temp.msg.