New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"End of stream" problem while trying to parse eml file #348
Comments
An update: I've printed stream position to understand which part of the email is causing problem. It prints 3538 character as stream position on exception. But I've checked the email and it has total 3476 character. How can it be? |
Hello again, I've checked last two characters which are 0x0a 0x0d (3537. and 3538. characters) |
I've tried to delete those characters to see if they are causing trouble, but now this time it gave same exception with position 3536. So I think they dont have problem with parsing. Still researching a solution.. |
The |
Ok, so the problem is that if the last message in an mbox does not contain a message body (like yours), it will throw "End of stream". I've just modified the code such that it doesn't throw anymore. Could you grab the latest source code and test that it solves your problem and let me know how it works? I'm planning to make a release this week(end), so try to get back to me as soon as possible. |
Can you give me compiled nuget package for testing? |
I'm not on a Windows machine right now, so no :( |
I'm working with dotnet core. So which class library project should I compile? |
You'll want the MimeKit.NetStandard.csproj |
I've successfully compiled MimeKit.NetStandard.csproj project and added as reference to my project. I'm trying to parse same message but this time I get "Failed to parse message headers." (MimeParser.cs: line 1535) |
Do you have an mbox or just a message file? An mbox starts with "From ..." (i.e. "From" + SPACE + more text) |
Is there any way you could email me this message so I can test it? |
Looking at the parser logic, the only way this can happen is if you have invalid headers and the parser is bailing because it thinks you gave it something that isn't a MIME message. |
I have only eml files no mbox. So I'm trying to find if any header causes trouble. If I find the header that causes problem I'll send you the sample to investigate soon |
BTW, you want to use MimeFormat.Entity for .eml files. |
If it helps, the part of the header that will be invalid is the field name (not the value). |
Well I'm already using MimeFormat.Entity to parse .eml files. I've found that the last character must be 0x0A For my example, the file was ending with 0x0A 0x0D When I add 0x0A as last character using a Hex editor to the file it parsed without any problem. (So it becomes 0x0A 0x0D 0x0A Its an interesting issue. |
Not really, that just terminates the header block. |
Just send me the message and I can probably have it fixed in a matter of minutes :) |
I sent a mail to jestedfa@microsoft.com which contains sample mail message that you want to see. |
It works fine for me. Are you sure that it's just:
I've tried with and without the blank line after the Mime-Version header and still no exception being thrown. |
e.g. can you get the subject of mail? In my code it throws
And then it leaves the while and |
The attachment that you sent to me was only the 2 headers I pasted above. Maybe you sent me the wrong file? |
I resent the mail. |
Ok, just got it. Thanks. I can reproduce what you are seeing. I've already traced the problem to https://github.com/jstedfast/MimeKit/blob/master/MimeKit/MimeParser.cs#L896 As you can tell from the comment in the code, the problem is that the headers aren't properly terminated (which is why when you add another newline character, it works). |
Great. So how can we solve it :) Are you going to update the library to have a maybe optional paramater on parsing for fixing header termination problem? Or something else? |
|
@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 using (var memory = new MemoryStream ()) {
memory.Write (buffer, 0, buffer.Length);
memory.Position = 0;
var message = MimeMessage.Load (memory);
} |
I would have to see the content of the stream to provide any further help... Are you sure there's a MIME message in that stream? |
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:
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
The text was updated successfully, but these errors were encountered: