Are there .NET Framework methods to parse an email (MIME)?

前端 未结 6 1428
遇见更好的自我
遇见更好的自我 2020-12-02 19:12

Is there a class or set of functions built into the .NET Framework (3.5+) to parse raw emails (MIME documents)?

I am not looking for anything fancy or a separate lib

6条回答
  •  有刺的猬
    2020-12-02 19:34

    I know you said no external libraries, but I have a library posted on codeplex:

    https://bitbucket.org/otac0n/mailutilities

    MimeMessage msg = new MimeMessage(/* string, stream, or Byte[] */);
    

    It has been tested with over 40,000 real-world mail messages.

    I'm not too happy with my namespace choice, but... I'm too lazy to change it.


    PS:

    Internally, my library uses these regexes as a parser:

    internal static string FullMessageMatch =
        @"\A(?
    (?:[^\r\n]+\r\n)*)(?\r\n)(?.*)\z"; internal static string HeadersMatch = @"^(?[-A-Za-z0-9]+)(?:[ \t]*)(?([^\r\n]|\r\n[ \t]+)*)(?\r\n)"; internal static string HeaderSeperator = "\r\n"; internal static string KeyValueSeparator = @"\A:[ \t]*\z";

提交回复
热议问题