public ToxyEmail Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } ToxyEmail email = new ToxyEmail(); using (FileStream stream = File.OpenRead(Context.Path)) { var message = MsgReader.Mime.Message.Load(stream); email.From = message.Headers.From.Raw; email.To = new List <string>(String.Join(";", message.Headers.To).Split(';')); if (message.Headers.Cc.Count != 0) { email.Cc = new List <string>(String.Join(";", message.Headers.Cc).Split(';')); } if (message.TextBody != null) { email.TextBody = message.TextBody.GetBodyAsText(); } if (message.HtmlBody != null) { email.HtmlBody = message.HtmlBody.GetBodyAsText(); } email.Subject = message.Headers.Subject; email.ArrivalTime = message.Headers.DateSent; // well, not quite correct } return(email); }
public ToxyEmail Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } ToxyEmail email = new ToxyEmail(); using (FileStream stream = File.OpenRead(Context.Path)) { EMLReader reader = new EMLReader(stream); email.From = new List <string>(reader.From.Split(';')); email.To = new List <string>(reader.To.Split(';')); if (reader.CC != null) { email.Cc = new List <string>(reader.CC.Split(';')); } email.Body = reader.Body; email.HtmlBody = reader.HTMLBody; email.Subject = reader.Subject; email.ArrivalTime = reader.X_OriginalArrivalTime; } return(email); }
public void ReadEmlTest() { string path = TestDataSample.GetEmailPath("test.eml"); ParserContext context = new ParserContext(path); IEmailParser parser = ParserFactory.CreateEmail(context); ToxyEmail email = parser.Parse(); Assert.IsNotNullOrEmpty(email.From); Assert.AreEqual(1, email.To.Count); Assert.AreEqual("=?utf-8?B?5ouJ5Yu+572R?= <*****@*****.**>", email.From); Assert.AreEqual("*****@*****.**", email.To[0]); Assert.IsTrue(email.Subject.StartsWith("=?utf-8?B?5LiK5rW35YiG5LyX5b635bOw5bm/5ZGK?= =?utf-8?B?5Lyg5p")); Assert.IsTrue(email.TextBody.StartsWith("------=_Part_4546_1557510524.1418357602217\r\nContent-Type: text")); Assert.IsNull(email.HtmlBody); }
public void ReadCnmTest() { string path = TestDataSample.GetCNMPath("Y0B6E8H2.CNM"); ParserContext context = new ParserContext(path); IEmailParser parser = ParserFactory.CreateEmail(context) as IEmailParser; ToxyEmail email = parser.Parse(); Assert.AreEqual(1, email.From.Count); Assert.AreEqual(1, email.To.Count); Assert.AreEqual("Тюльпаны <*****@*****.**>", email.From[0]); Assert.AreEqual("<*****@*****.**>", email.To[0]); Assert.AreEqual("Тюльпаны", email.Subject); Assert.IsTrue(email.Body.StartsWith("Тел: 960-51-57;Продажа тюльпанов")); Assert.IsTrue(email.HtmlBody.StartsWith("<!DOCTYPE HTML")); }
public ToxyEmail Parse() { ToxyEmail result = new ToxyEmail(); using (var stream = File.OpenRead(this.Context.Path)) using (var reader = new Storage.Message(stream)) { if (reader.Sender != null) { result.From = string.IsNullOrEmpty(reader.Sender.DisplayName) ? reader.Sender.Email : string.Format("{0}<{1}>", reader.Sender.DisplayName, reader.Sender.Email); } if (reader.Recipients.Count > 0) { foreach (var recipient in reader.Recipients) { string sRecipient = null; if (string.IsNullOrEmpty(recipient.DisplayName)) { sRecipient = recipient.Email; } else { sRecipient = string.Format("{0}<{1}>", recipient.DisplayName, recipient.Email); } if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.To) { result.To.Add(sRecipient); } else if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.Cc) { result.Cc.Add(sRecipient); } else if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.Bcc) { result.Bcc.Add(sRecipient); } } } result.Subject = reader.Subject; result.TextBody = reader.BodyText; result.HtmlBody = reader.BodyHtml; } return(result); }
public void ReadEmlTest() { string path = TestDataSample.GetEmailPath("test.eml"); ParserContext context = new ParserContext(path); IEmailParser parser = ParserFactory.CreateEmail(context); ToxyEmail email = parser.Parse(); Assert.IsNotNull(email.From); Assert.IsNotEmpty(email.From); Assert.AreEqual(1, email.To.Count); Assert.AreEqual(email.From, "\u62C9\u52FE\u7F51 <*****@*****.**>"); Assert.AreEqual(email.To[0], "*****@*****.**"); Assert.AreEqual(email.Subject, "\u4E0A\u6D77\u5206\u4F17\u5FB7\u5CF0\u5E7F\u544A\u4F20\u64AD\u6709\u9650\u516C\u53F8-\u9AD8\u7EA7.NET\u8F6F\u4EF6\u5DE5\u7A0B\u5E08\u62DB\u8058\u53CD\u9988\u901A\u77E5"); Assert.IsTrue(email.HtmlBody.StartsWith("<html>\r\n")); Assert.IsNull(email.TextBody); }
public ToxyEmail Parse() { ToxyEmail result = new ToxyEmail(); using (var stream = File.OpenRead(this.Context.Path)) using (var reader = new Storage.Message(stream)) { if (reader.Sender != null) { result.From = string.IsNullOrEmpty(reader.Sender.DisplayName) ? reader.Sender.Email : string.Format("{0}<{1}>", reader.Sender.DisplayName, reader.Sender.Email); } if (reader.Recipients.Count > 0) { foreach (var recipient in reader.Recipients) { string sRecipient = null; if (string.IsNullOrEmpty(recipient.DisplayName)) { sRecipient = recipient.Email; } else { sRecipient = string.Format("{0}<{1}>", recipient.DisplayName, recipient.Email); } if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.To) { result.To.Add(sRecipient); } else if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.Cc) { result.Cc.Add(sRecipient); } else if (recipient.Type == MsgReader.Outlook.Storage.Recipient.RecipientType.Bcc) { result.Bcc.Add(sRecipient); } } } result.Subject = reader.Subject; result.TextBody = reader.BodyText; result.HtmlBody = reader.BodyHtml; } return result; }
public ToxyEmail Parse() { if (!File.Exists(Context.Path)) throw new FileNotFoundException("File " + Context.Path + " is not found"); FileInfo fi = new FileInfo(Context.Path); CnmFile reader = new CnmFile(fi); reader.Parse(); ToxyEmail email=new ToxyEmail(); email.From = reader.From; email.To = new List<string>(reader.To.Split(';')); email.TextBody = reader.TextPlain; using (var sr=new StreamReader(reader.TextHtml)) { email.HtmlBody = sr.ReadToEnd(); } email.Subject = reader.Subject; return email; }
public ToxyEmail Parse() { if (!File.Exists(Context.Path)) throw new FileNotFoundException("File " + Context.Path + " is not found"); ToxyEmail email = new ToxyEmail(); using (FileStream stream = File.OpenRead(Context.Path)) { EMLReader reader = new EMLReader(stream); email.From = new List<string>(reader.From.Split(';')); email.To = new List<string>(reader.To.Split(';')); email.Cc = new List<string>(reader.CC.Split(';')); email.Body = reader.Body; email.HtmlBody = reader.HTMLBody; email.Subject = reader.Subject; email.ArrivalTime = reader.X_OriginalArrivalTime; } return email; }
public ToxyEmail Parse() { if (!File.Exists(Context.Path)) { throw new FileNotFoundException("File " + Context.Path + " is not found"); } FileInfo fi = new FileInfo(Context.Path); CnmFile reader = new CnmFile(fi); reader.Parse(); ToxyEmail email = new ToxyEmail(); email.From = reader.From; email.To = new List <string>(reader.To.Split(';')); email.TextBody = reader.TextPlain; using (var sr = new StreamReader(reader.TextHtml)) { email.HtmlBody = sr.ReadToEnd(); } email.Subject = reader.Subject; return(email); }