This project is read-only.

OutOfMemoryException on MIME Parsing

Jul 12, 2011 at 7:57 PM

It appears that the MIME parser fails when the email (at least a multipart one) contains a line that begins but doesn't end with "--" if that line is NOT a boundary separator.  I've seen at least Yahoo mail use --- to begin the identifier line for a quoted email.  This results in the Equinox MIME parser looking for boundary terminator that looks like "--- On Wed, 8/20/08, John Doe<> wrote:--".  Since the terminator doesn't exist, and a null line does not cause the loop in Entity.ReadBoundaryBlocks() to break, the result is an OutOfMemoryException from the StringWriter.

Jul 12, 2011 at 9:59 PM


technically this should not happen since the parser is supposed to only search for boundary seperators which are declared inside the entities header (--XXX) segment; Once found, it looks for the exact match --XXX-- skipping everything else.

Is it possible to get a copy of such a mail ? It would be helpful in debugging this issue.


Jul 12, 2011 at 10:36 PM


I just checked the code and it seems I was a bit sloppy.

Currently I only check whether we expect a boundary not if the found boundary value actually equals the expected one. Fortunately this is an easy fix.

The following code in line 252 

if (current.IsBoundaryStart) {
   // (...)

will need to be altered to look something like this

if (current.IsBoundaryStart && IsExpectedBoundary(current)) {
   // (...)

private bool IsExpectedBoundary(LineInfo line) {
    return line.Text.ToLower() == ContentTypeHeaderField.BoundaryName.ToLower();