-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Unable to parse status groups in some cases #837
Comments
The problem is that the content of the message/delivery-status part isn't valid syntax (i.e. it does not contain status group headers)
|
An example (from rfc3464) of what it should look like:
In the above example, there are 2 status groups (i.e. 2 groups of headers) as the content of the message/delivery-status MIME part. |
I think the solution is to catch any exceptions when accessing the Unfortunately, that means that you can't actually process the message/delivery-status content programatically (unless you can implement some sort of free-form natural language parser for the text/plain content?). If you only ever deal with this particular SMTP server, then it might be possible to use regex to extract the recipient address and the "reason" text. I think I have to close this as BTW, while we're here, I would recommend changing this line of code: var deliveryStatus = msg.BodyParts.FirstOrDefault(p => p.ContentType.MimeType == "message/delivery-status") as MessageDeliveryStatus; to: var deliveryStatus = msg.BodyParts.OfType<MessageDeliveryStatus>().FirstOrDefault(); That's a bit simpler expression/easier to read and I think that will be faster (but feel free to verify before using). |
Thanks for taking a look at this issue. I can see that FWIW, we see a a very large (7 figure) amount of NDRs per day, and we encounter malformed NDRs of this type ~100 times per day right now, from different MTAs. Try/catch is absolutely a simple change for us to make, of course. I just wanted to have the conversation here just in case I was missing something. Thanks again! |
I would consider returning I think that, if I were to put myself in the shoes of a developer trying to write an app using MimeKit, I think I'd also expect (and probably prefer) |
Okay, so taking a look at MessageDeliveryStatus, it looks like the code catches ParseException instead of FormatException, likely by mistake (I originally planned to make the MimeParser throw ParseException instead of FormatException). Secondly, if the Content is null, then the code creates an empty StatusGroups, so I think instead of returning null, I'll do the same when the content is invalid. |
…nstead of ParseException Fixes issue #837
I guess it turns out that this was a legit "bug" after all. Catching ParseException was pointless, it really did need to catch FormatException. |
Hey there! It seems that Mimekit throws an exception when parsing NDR status groups for some real-world NDRs we're seeing.
Platform
To Reproduce
The attached NDR is an anonymised real-world NDR we have received. Using the following code, Mimekit throws an exception:
It throws a FormatException, "failed to parse headers", at the following stack trace:
fail.txt
The text was updated successfully, but these errors were encountered: