private void ParseEML(FileStream fsEML) { Attachments = new List <byte[]>(); StreamReader sr = new StreamReader(fsEML); string sLine; // Read file to a list List <string> listAll = new List <string>(); while ((sLine = sr.ReadLine()) != null) { listAll.Add(sLine); } fsEML.Close(); int bodyStart = -1; // Convert to array string[] allContent = new string[listAll.Count]; listAll.CopyTo(allContent); // Itterate array, merge continuation lines and add result to new list listAll = new List <string>(); List <string> header = new List <string>(); for (int i = 0; i < allContent.Length; i++) { string sFullValue = allContent[i]; MergeSplitValue(allContent, ref i, ref sFullValue); listAll.Add(sFullValue); // If body has not started yet add value to header list if (bodyStart == -1) { header.Add(sFullValue); } // Body starts with first empty line. If empty line is found and body has not started yet then this is body start line number if (allContent[i] == string.Empty && bodyStart == -1) { bodyStart = i; } } // Transfer list to array to work with allContent = new string[listAll.Count]; listAll.CopyTo(allContent); // Set main EMLFile field from header SetFields(header.ToArray()); // Exit in case of no body if (bodyStart == -1) { return; } // Multipart email with HTML body if (Content_Type != null && (Content_Type.ToLower().Contains("multipart"))) { ParseMultipart(allContent); } // Plain text body type only else { Body = string.Empty; for (int n = bodyStart + 1; n < allContent.Length; n++) { Body += allContent[n] + "\r\n"; } } if ("base64".Equals(Content_Transfer_Encoding)) { Body = Encoding.UTF8.GetString(Convert.FromBase64String(Body)); } Body = FormatBody(Body); }
private void ParseEML(Stream fsEML) { StreamReader sr = new StreamReader(fsEML); string sLine; List <string> listAll = new List <string>(); while ((sLine = sr.ReadLine()) != null) { listAll.Add(sLine); } List <string> list = new List <string>(); int nStartBody = -1; string[] saAll = new string[listAll.Count]; listAll.CopyTo(saAll); for (int i = 0; i < saAll.Length; i++) { if (saAll[i] == string.Empty) { nStartBody = i; break; } string sFullValue = saAll[i]; GetFullValue(saAll, ref i, ref sFullValue); list.Add(sFullValue); //Debug.WriteLine(sFullValue); } SetFields(list.ToArray()); if (nStartBody == -1) // no body ? { return; } // Get the body info out of saAll and set the Body and/or HTMLBody properties if (Content_Type != null && Content_Type.ToLower().Contains("multipart/alternative")) // set for HTMLBody messages { int ix = Content_Type.ToLower().IndexOf("boundary"); // boundary is used to separate the different body types if (ix == -1) { return; } string sBoundaryMarker = Content_Type.Substring(ix + 8).Trim(new char[] { '=', '"', ' ', '\t' }); // save this boundaries elements into a list of strings list = new List <string>(); for (int n = nStartBody + 1; n < saAll.Length; n++) { if (saAll[n].Contains(sBoundaryMarker)) { if (list.Count > 0) { SetBody(list); list = new List <string>(); } continue; } list.Add(saAll[n]); } } else // plain text body type only { Body = string.Empty; for (int n = nStartBody + 1; n < saAll.Length; n++) { Body += saAll[n] + "\r\n"; } } }