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(?<header>(?:[^
]+
)*)(?<header_term>
)(?<body>.*)z";
internal static string HeadersMatch =
@"^(?<header_key>[-A-Za-z0-9]+)(?<seperator>:[ ]*)(?<header_value>([^
]|
[ ]+)*)(?<terminator>
)";
internal static string HeaderSeperator =
"
";
internal static string KeyValueSeparator =
@"A:[ ]*z";
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…