Skip to content

Commit

Permalink
Merge pull request #124 from HellBrick/no-body-crash
Browse files Browse the repository at this point in the history
Fixed crash on reading email without a body
  • Loading branch information
andyedinborough committed Aug 23, 2013
2 parents 3a076b2 + 7b9901c commit d26fbff
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions MailMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,30 @@ public virtual void Load(Stream reader, bool headersOnly = false, int maxLength
}
RawHeaders = headers.ToString();

if (!headersOnly) {
if ( !headersOnly )
{
string boundary = Headers.GetBoundary();
if (!string.IsNullOrEmpty(boundary)) {
if ( !string.IsNullOrEmpty( boundary ) )
{
var atts = new List<Attachment>();
var body = ParseMime(reader, boundary, ref maxLength, atts, Encoding, termChar);
if (!string.IsNullOrEmpty(body))
SetBody(body);
var body = ParseMime( reader, boundary, ref maxLength, atts, Encoding, termChar );
if ( !string.IsNullOrEmpty( body ) )
SetBody( body );

foreach (var att in atts)
(att.IsAttachment ? Attachments : AlternateViews).Add(att);
foreach ( var att in atts )
( att.IsAttachment ? Attachments : AlternateViews ).Add( att );

if (maxLength > 0)
reader.ReadToEnd(maxLength, Encoding);
if ( maxLength > 0 )
reader.ReadToEnd( maxLength, Encoding );
}
else
{
// sometimes when email doesn't have a body, we get here with maxLength == 0 and we shouldn't read any further
string body = String.Empty;
if ( maxLength > 0 )
body = reader.ReadToEnd( maxLength, Encoding );

} else {
SetBody(reader.ReadToEnd(maxLength, Encoding));
SetBody( body );
}
}

Expand Down

0 comments on commit d26fbff

Please sign in to comment.