-
-
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
The ContentId field on MimeEntity does not accept parentheses #542
Comments
rfc2045 defines the Content-ID header as follows:
The
The If we look at the old obsolete syntax, we get:
Here, it is allowed (via
I think there's an argument to made for the |
@reinaldocoelho do you have full control over the Content-Id value in this case? Or are you taking an existing value from a message in the wild and re-using that value? If you have control over the value, I would recommend munging the ()'s. |
The system responds or forwards the messages and uses the same content received when sending. If I replace only the ()´s, other characteres can be received. |
Ah, ok. Are you parsing one message or part and then duplicating it over to another like this? var copied = new MimePart (original.ContentType.MediaType, original.ContentType.MediaSubtype) {
ContentId = original.ContentId,
// ...
}; If so, one way to cheat here would be to do: var originalMessage = MimeMessage.Load (stream);
var forwarded = new MimeMessage ();
// ...
forwarded.Body = originalMessage.Body; A MimePart can actually be a child of multiple MimeMessages or Multiparts. Likewise, a Multipart can be a child of multiple MimeMessages or other Multiparts. Just a little trick you might be able to use ;-) |
Always the problem occours on images in the body, than, to avoid replace the body always. I update the code with below: var attached = builder.LinkedResources.Add(filenameToUse, streamImage, contentType);
try
{
attached.ContentId = item.CidHash;
}
catch (ArgumentException)
{
var editedHash = item.CidHash.Replace("(", "").Replace(")", "");
builder.HtmlBody = builder.HtmlBody.Replace($"cid:{item.CidHash}", $"cid:{editedHash}").Replace($"CID:{item.CidHash}", $"cid:{editedHash}");
attached.ContentId = editedHash;
} But It´s not the perfect solution... |
…ead of MailboxAddress.TryParse() Part of the fix for issue #542
@reinaldocoelho Understood. Don't worry, I won't make you have to do gross hacks ;-) Actually, due to ParseUtils.TryParseMsgId() being fixed to handle ()'s from issue #472, the above commit should actually fix things for you. I forgot that ParseUtils.TryParseMsgId() already got the () fix, so it turns out that MimeEntity.ContentId setter just needed to be updated to use the more lenient parser. Let me know if that doesn't solve it for you for some reason! |
This is great @jstedfast. |
Yes, this will be released as part of 2.5.3, but I don't yet have plans for a 2.5.3 release so I'm not sure when it will be. If you want, every commit produces an automated build on myget: https://www.myget.org/feed/mimekit/package/nuget/MimeKit You can use that nuget feed as an alternative for the time being. |
Thank you :-D |
Describe the bug
On forward an email with image on body and with CID like "SignaturePax(2)_21fe8b55-7001-4403-957d-3ca1e804edee.jpg" thrown an error when set ContentId with this value.
Platform (please complete the following information):
To Reproduce
Steps to reproduce the behavior (Test Code Sample):
This thrown an exception like "Invalid Content-Id format.".
Expected behavior
Accept the text with parentheses as a valid structure on ContentId like RFC2392(https://tools.ietf.org/html/rfc2392) specification.
All URL encode must be valid, and so parentheses is valid to use.
The text was updated successfully, but these errors were encountered: