Replies: 2 comments 3 replies
-
I probably don't want to have this in MimeKit because it looks fairly specific to your use-case, but if you have the specification for this process, I wouldn't mind taking a look and re-evaluating my initial thoughts. In the meantime, this can be done much simpler: public static class MimeMessageExtensions
{
// Note: headersToRetain should be case-insensitive. e.g:
// headersToRetain = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
public static MimeMessage WrapMessage(this MimeMessage originalMessage, HashSet<string> headersToRetain)
{
var messagePart = new MessagePart("rfc822")
{
Message = originalMessage
};
// Create the wrapper message.
var message = new MimeMessage();
// Clear the default MimeMessage headers.
message.Headers.Clear();
// Clone only the headers we want to retain.
foreach (var header in originalMessage.Headers)
{
if (headersToRetain.Contains(header.Field))
{
message.Headers.Add(header.Clone());
}
}
// Set the wrapper message's body.
message.Body = messagePart;
return message;
}
} |
Beta Was this translation helpful? Give feedback.
-
I had something similar to yours and benchmarking let me to mine. But, yours is better than my original. I just tested yours and the one I shared. Ran a couple times using the startrek.eml file. Pretty close. Yours is easier to read.
Then I ran it against a very simple message with a text/plain with one line of text. Yours edges mine out every time.
|
Beta Was this translation helpful? Give feedback.
-
I have been digging in on the SMIME features and we have worked through a couple PRS.
One of the requirements for the Direct Project is wrapping (
Content-Type: message/rfc822
) a mime message with only specific headers allowed. For example the Subject header would not be allowed. Once wrapped then we begin the encryption only the wrapping headers are seen.I wrote a WrapMessage Extension method locally. My question is, would there be any intereset to add this to MimeKit or not.
Thank you,
Joe
Beta Was this translation helpful? Give feedback.
All reactions