Convert MIME tree to MailMessage

前端 未结 5 699
广开言路
广开言路 2021-01-14 15:52

I\'m writing a a C# program that processes and forwards email messages. I have a POP3 library and a MIME parser, and I need to copy the MIME tree into a System.Net.Ma

5条回答
  •  -上瘾入骨i
    2021-01-14 16:08

    From a 10,000ft overview, here is what I would do.

    Flatten your mime parts into a tree. Make sure each part contains 1, and only 1 part (not a parent like a multipart/related, or something like that).

    1. Check the following conditions for the body:

      1. If the 1st part is HTML,set it to the body of the message

      2. If the 1st part is plain text, and the 2nd part is not html, set the plain text part to the body of the message.

      3. If the first part is plain, and the 2nd part is html, create 2 alternative views. ***This assumes none of these parts has a Content-Disposition:attachment header.

    2. Loop through the remainder of the parts. Add everything else as an attachment, except

      1. images that have a content-id header set, or

      2. images that have a content-location header set.

        If one of those headers exist, then I would add those images in as a LinkedResource (only if there is actually a HTML body part).

    That should get you started, and cover about 99% of the normal email out there.

提交回复
热议问题