MaxMimeDepth=1 doesn't set HtmlBody and TextBody #1006
Description
Describe the bug
We are trying to minimize our cpu and memory usage by only extracting first level of attachments/emails under an email. MaxMimeDepth
option seems to designed for this, but when I pass new ParserOptions() { MaxMimeDepth = 1 }
to MimeMessage.Load()
it doesn't set HtmlBody and TextBody fields (although I can see them under BodyParts
collection)
I believe the reason is we get MimePart
instead of a TextPart
here when depth=MaxMimeDepth
, then it fails check in one of these places (just guessing):
- https://github.com/jstedfast/MimeKit/blob/master/MimeKit/MultipartRelated.cs#L237
- https://github.com/jstedfast/MimeKit/blob/master/MimeKit/MultipartAlternative.cs#L201
- https://github.com/jstedfast/MimeKit/blob/master/MimeKit/Multipart.cs#L375
Note: I'm not 100% sure if this is intentional or a 'bug', if not could you please guide how to extract only first level of attachments and have the body fields?
Platform (please complete the following information):
- OS: Linux
- .NET Framework: .Net Standard v2.0
- MimeKit Version: 4.1.0
To Reproduce
Steps to reproduce the behavior:
- Call
MimeMessage.Load(new ParserOptions() { MaxMimeDepth = 1 }, stream)
- Verify there are body parts with
text/html
andtext/plain
types - Verify
MimeMessage.TextBody
andMimeMessage.HtmlBody
are null
Expected behavior
I expect MimeMessage.TextBody
and MimeMessage.HtmlBody
to be not null when there are body parts with text/html
and text/plain
types
Code Snippets
If applicable, add code snippets to help explain your problem.
using (var stream = new MemoryStream(mimeBytes))
{
var res = MimeMessage.Load(new ParserOptions() { MaxMimeDepth = 1 }, stream);
Console.WriteLine(res.TextBody);
}
Additional context
Add any other context about the problem here.