-
-
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
Malformed message id (I don't think it is a bug in MimeKit) #835
Comments
Ugh, yea, that is invalid syntax :( I guess the easiest solution would be to use I wonder how common this is... I tried to make the Message-ID parser more lenient but I guess it needs to be even more lenient - as in something ridiculous like: int lessThan = header.Value.IndexOf ('<');
int greaterThan = header.Value.IndexOf ('>', lessThan + 1);
msgId = header.Value.Substring (lessThan + 1, greaterThan - (lessThan + 1)); |
I use the message id as a unique key in a database to identify if I have seen an e-mail before so I'll try your solution with |
A few points:
I was going to try taking a closer look at the code that parses Message-Ids before I close this to see if there isn't a way I can improve the code to handle this case. I am wondering if perhaps that space could have come from some folding logic in the sending software because the value is so long and if that is the case, it's arguable that MimeKit should better handle that. If you look at the raw original header of the message, does it look like this?
(Either way, I think I'd like to try and handle this case because this scenario is at least plausible even if not true in your specific case) |
I know that the message id is not unieke enough because everyone can just generate something but it is unique enough for me. The primary key in my database is also build up with more then one field so just not only the message id. Because someone can sent the same e-mail to more then one e-mail adress and in that case all those e-mails have the same message id. I mainly use the message id to track logging and things like that because I want to know if the e-mail was sent to more then one e-mail address. I also could just generate a random guid as an id but then the logic fails to match it with the same e-mail on another e-mail address. So in my case this was the best solution for me. The header was copied from the raw headers. I just opened the EML file in notepad on windows and got it from there. |
Okay, thanks for the info. |
Hey @jstedfast , I encountered a similar problem with a MessageId. The Is there a way to get the (faulty?) MessageId - maybe by parsing the |
What you could try is something like this: var messageId = message.Headers[HeaderId.MessageId]?.Trim()?.TrimStart('<')?.TrimEnd('>').Replace(" ", string.Empty).Replace("\t", string.Empty); I have been hesitant about reducing MimeKit's Message-ID parser to something so brutish, but I'm seeing less and less possibility of having an actual Message-ID parser that actually works in all cases, no matter how lenient I make it, unless I reduce it to something like the above code snippet. It's depressing. I think I'm going to have to do something like that because I'd really like the |
Hey @jstedfast thanks for your advice and thoughts. Another question comes to my mind, have you thought about making the I dislike the idea to write a wrapper class with an own interface around it, because I wanted to test the rare case where the |
@rogatec it is something I've thought about. Can you submit a new issue to track that? I agree it's worth doing. I've been thinking of changing things to make use of Microsoft.DependencyInjection and interfaces would be a good step toward that. |
I used the latest version.
We received an e-mail with what I think is a malformed message-id, because of that mimekit is returning
null
for the e-mail id.Is there a way to get the message id even when it is malformed?
The text was updated successfully, but these errors were encountered: