Search code examples
c#powershellmimekit

mimekit, how to create a TextRfc822Headers from an .eml message in a file


I need to create an TextRfc822Headers from the headers of a message stored as an .eml file on disk.

Of course I can MimeMessage.Load the complete message and set the body to null but why load and parse the full message when I only need the headers?

I can also HeaderList.Load the headers but I found no way to use the resulting HeaderList to create a new body-less MimeMessage

what is the cleverest/ most efficient way to create a TextRfc822Headers from the headers of a message stored as an .eml file on disk?


Solution

  • You should be able to do new MimeMessage (headers) and it will use the MimeMessage.ctor (params object[] args) constructor.