jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not fetch custom header

BiancaatBauer opened this issue · comments

Describe the bug
I can't get my custom header from an e-mail with the fetch method or folder.GetHeaders(...). The search is working fine and i get all e-mails in the inbox, which have the custom header. But i don't get the header it self.

The custom header is set in another program, if an e-mail is send via outlook. It is set as an X-... header and is set to the PS_INTERNET_HEADERS in the e-mail headers. The custom header is send, but it is completly in lower case. I don't know if this is a problem. The custom header is set over the PropertyAccessor of the Outlook mail item (Microsoft.Office.Interop.Outlook). The value it self is an guid with some prefix and suffix. Setting the custom header name in complete upper case dosen't change the fact, that it is send in complete lower case.

Platform (please complete the following information):

  • OS: Windows, Linux
  • .NET Runtime: no secific
  • .NET Framework: Net6.0
  • MailKit Version: 3.5.0

Exception
No exception on my side.

To Reproduce
Steps to reproduce the behavior:

  1. Adding a custom header to an Outlook e-mail
  2. Send the e-mail
  3. Check if the header is there inthe recieved e-mail
  4. Try to Load the headers from the e-mail with MailKit

Expected behavior
To get the header at least with the fetch method, with the specific header.

Code Snippets
If applicable, add code snippets to help explain your problem.

Setting custom header in extra dll

mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-Identifier", prefix_guid_suffix);

Trying to retrieve headers from e-mail

var message = await folder.GetMessageAsync(mailID, cancellationToken);

 var res = await folder.GetHeadersAsync(mailID);

var request = new FetchRequest
{
      Headers = new HeaderSet(new string[] { "x-identifier" })
};

var result = await folder.FetchAsync(new List<UniqueId> { mailID }, request, cancellationToken);
var res2 = await folder.SearchAsync(SearchQuery.HeaderContains("x-identifier", string.Empty));

var stream = folder.GetStream(mailID, section: "Header", cancellationToken);
try
{
       using var mStream = new MemoryStream();

       stream.Seek(0, SeekOrigin.Begin);

       await stream.CopyToAsync(mStream);

       mStream.Seek(0, SeekOrigin.Begin);

       File.WriteAllBytes(@"c:\Test\Headers.txt", mStream.ToArray());
        var headers = HeaderList.Load(mStream);
}
catch (Exception ex)
{
}

Protocol Logs
Please include a protocol log (scrubbed of any authentication data), especially
if you got an exception such as Syntax error in XYZ. Unexpected token: ....

Imap protocol log:

imap.txt

Additional context
Add any other context about the problem here.

Header of a recieved e-mail:

image

Result for getting headers with folder.GetHeadersAsync(mailID):

image

Result for fetch folder.FetchAsync(new List<UniqueId> { mailID }, request, cancellationToken):

image

Result for the search for e-mails with the custom header folder.SearchAsync(SearchQuery.HeaderContains("x-identifier", string.Empty)):

image

Result trying to get headers with folder.GetStream(mailID, section: "Header", cancellationToken):

image

This is a server bug. MailKit asks for the entire message and/or headers (or message stream) and if the header isn't included in the response, then the server isn't sending it.

THank you for your time. We will check our mail server what he sents.