0

I have a MimeMessage which contains a winmail.dat attachment of type application/ms-tnef.

I believe this is an RTF formatted email, which is sent from Outlook client. I tried parsing it with the tnefpart but I'm running into the following error.

Here is my function:

ProcessMimeMessage(MimeMessage plainMime)
{
 foreach (var attachment in plainMime.Attachments)
 {
  if (attachment.GetType() == typeof(MimeKit.Tnef.TnefPart))
  {
   ReportStatus("Processing Tnef Part (RTF Message): ");
   MimeKit.Tnef.TnefPart tnefPart = (MimeKit.Tnef.TnefPart)attachment;

   try { 
    MimeMessage mimeMessage = tnetPart.ConvertToMessage();
   } catch (Exception ex) {printexception(ex);}
  }
 }
}

This is the exception that is thrown from ConvertToMessage

Invalid addr-spec token at offset 0
at MimeKit.InternetAddress.TryParseAddrspec(Byte[] text, Int32& index, Int32 endIndex, Byte[] sentinels, Boolean throwOnError, String& addrspec, Int32& at)
at MimeKit.MailboxAddress.set_Address(String value)
at MimeKit.Tnef.TnefPart.EmailAddress.TryGetMailboxAddress(MailboxAddress& mailbox)
at MimeKit.Tnef.TnefPart.ExtractMapiProperties(TnefReader reader, MimeMessage message, BodyBuilder builder)
at MimeKit.Tnef.TnefPart.ExtractTnefMessage(TnefReader reader)
at MimeKit.Tnef.TnefPart.ConvertToMessage()

Thanks

Kelvin L
  • 65
  • 1
  • 10

1 Answers1

1

This just means that the "email address" in one of the TNEF fields is not a valid email address (syntactically).

It might just be that the address type field was not "SMTP" and MimeKit tried to parse it as if it were a rfc822 address field.

I've improved the robustness in the following commit: https://github.com/jstedfast/MimeKit/commit/15f955b49dc7743d1281afbedce6d327706e161b

You can use the MyGet packages listed in the README.md file to get the fix for this.

jstedfast
  • 35,744
  • 5
  • 97
  • 110