andyedinborough / aenetmail

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

Small issue with attachments #87

Open mediocreguy opened 12 years ago

mediocreguy commented 12 years ago

Great assembly! However, when implementing the assembly in a project I was working on, I was having a small problem with the attachments I was processing. Sometimes text attachments would have extra blank lines and would cause MailMessage.ParseMime() to read attempt to read past the end of the message. I think when reading the part body the method needs to read until it encounters the next boundary instead of stopping on a blank line. I would suggest trying the following patch to MailMessage.cs:

-        // header body
+        // read part body - must read to the next inner boundary
         data = reader.ReadLine(ref maxLength, Encoding);
         var body = new StringBuilder();
-        while (data != string.Empty && !data.StartsWith(bounderInner)) {
+        while (!data.StartsWith(bounderInner) && (maxLength > 0 || !maxLengthSpecified)) {
           body.AppendLine(data);
           data = reader.ReadLine(ref maxLength, Encoding);
         }
+

I've done some limited testing and it appears to work.