/// <summary> /// Creates a new instance of the MailMessage class from a string /// containing raw RFC822/MIME mail message data. /// </summary> /// <param name="text">A string containing the mail message data to /// create the MailMessage instance from.</param> /// <returns>An initialized instance of the MailMessage class.</returns> /// <remarks>This is used when fetching entire messages instead /// of the partial-fetch mechanism because it saves redundant /// round-trips to the server.</remarks> internal static MailMessage FromMIME822(string text) { StringReader reader = new StringReader(text); StringBuilder header = new StringBuilder(); string line; while (!String.IsNullOrEmpty(line = reader.ReadLine())) { header.AppendLine(line); } MailMessage m = FromHeader(header.ToString()); MIMEPart[] parts = ParseMailBody(reader.ReadToEnd(), m.Headers); foreach (MIMEPart p in parts) { m.AddBodypart(BodypartFromMIME(p), p.body); } return(m); }