andyedinborough / aenetmail

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

IMAP GetMessage doesn't work on emails with attachments in latest version from Jul 13,2012. #90

Open sevzas opened 12 years ago

sevzas commented 12 years ago

It just hangs, consuming an entire core and much memory. But when I try running my code with the version with comment "1.6.1-rc" it works fine. So something has broken recently.

sevzas commented 12 years ago

here is the stacktrace where it hangs

mscorlib.dll!System.IO.MemoryStream.WriteByte(byte value) + 0x9a bytes  
AE.Net.Mail.dll!AE.Net.Mail.Utilities.ReadLine(System.IO.Stream stream = {System.IO.MemoryStream}, ref int maxLength = 0, System.Text.Encoding encoding = {System.Text.SBCSCodePageEncoding}) + 0x17c bytes 
AE.Net.Mail.dll!AE.Net.Mail.MailMessage.ParseMime(System.IO.Stream reader = {System.IO.MemoryStream}, string boundary = "Boundary_(ID_mYNHszOvk5iiHOF1x5dF5A)", int maxLength = 0) + 0x11a bytes    
AE.Net.Mail.dll!AE.Net.Mail.MailMessage.ParseMime(string body = "", string boundary = "Boundary_(ID_mYNHszOvk5iiHOF1x5dF5A)") + 0xa2 bytes  
AE.Net.Mail.dll!AE.Net.Mail.MailMessage.ParseMime(System.IO.Stream reader = {System.Net.Security.SslStream}, string boundary = "Boundary_(ID_IzgwsLXuOZUZqM0QrYtQ9w)", int maxLength = 550900) + 0x605 bytes    
AE.Net.Mail.dll!AE.Net.Mail.MailMessage.Load(System.IO.Stream reader = {System.Net.Security.SslStream}, bool headersOnly = false, int maxLength = 551080) + 0x32d bytes 
AE.Net.Mail.dll!AE.Net.Mail.ImapClient.GetMessages(string start = "56949", string end = "56949", bool uid = true, bool headersonly = false, bool setseen = false) + 0xa5e bytes 
AE.Net.Mail.dll!AE.Net.Mail.ImapClient.GetMessages(string startUID = "56949", string endUID = "56949", bool headersonly = false, bool setseen = false) + 0x56 bytes 
AE.Net.Mail.dll!AE.Net.Mail.ImapClient.GetMessage(string uid = "56949", bool headersonly = false, bool setseen = false) + 0x50 bytes    

UtilitiesCS.dll!UtilitiesCS.Net.EmailFinder.SearchMessages(string searchCondition = "(FROM \"abc@domain.com\") (SUBJECT \"the email subject\") (ON 25-Jul-2012)") Line 55 + 0x44 bytes C#

sakya commented 12 years ago

The problem is in the ParseMime function. Change this test

    var body = new StringBuilder();
    while (data != string.Empty && !data.StartsWith(bounderInner)) {

To

    var body = new StringBuilder();
    while (data != null && !data.StartsWith(bounderInner)) {

And it won't hang (but the change was made to fix an issue, so maybe the solution is not perfect).

sakya commented 12 years ago

The changelist that introduced this bug is: https://github.com/andyedinborough/aenetmail/commit/02497e901285b81e68fd0dfe9ddc22c8edcb6d61

nwoolls commented 12 years ago

Nice catch - I have been running into this bug too.