MimeKit: "End of stream" problem while trying to parse eml file

Hello,

I’m having issues with some mails. Exception is similar one with issue #261 which is “Failed to Parse Message Headers”.

I’ve tried your suggestion:

using (FileStream stream = new FileStream (@"mbox.txt", FileMode.Open)) {
    MimeParser parser = new MimeParser (stream, MimeFormat.Mbox);
    MimeMessage current = null;

    while (!parser.IsEndOfStream) {
        try {
            current = parser.ParseMessage ();
        } catch (FormatException e) {
            // Reset parser state and continue parsing from the current parser position
            stream.Position = parser.Position;
            parser.SetStream (stream, MimeFormat.Entity); // Also tried other MimeFormats too.
            continue;
        }
    }
}

But no success. I’ve checked mail content and it doesnt has any mail body. Only Headers and from to cc etc. headers. But I can open it with Outlook.

How can I solve the parsing problem?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 29 (17 by maintainers)

Commits related to this issue

Most upvoted comments

@bogdansantaGam that typically means you forgot to rewind the stream before trying to parse it.

In other words, you’re doing something like this:

using (var memory = new MemoryStream ()) {
    memory.Write (buffer, 0, buffer.Length);

    var message = MimeMessage.Load (memory);
}

What you need to do is rewind the stream (aka memory.Position = 0;) like this:

using (var memory = new MemoryStream ()) {
    memory.Write (buffer, 0, buffer.Length);
    memory.Position = 0;

    var message = MimeMessage.Load (memory);
}