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
- Modified MimeParser to always fail gracefully when the headers end prematurely Fixes issue #348 — committed to jstedfast/MimeKit by jstedfast 7 years ago
@bogdansantaGam that typically means you forgot to rewind the stream before trying to parse it.
In other words, you’re doing something like this:
What you need to do is rewind the stream (aka
memory.Position = 0;
) like this: