private string GetText(IBodyPart emailMessage) { if (string.IsNullOrWhiteSpace(emailMessage.Body)) { return(null); } //Достанем текст письма и если оно в html то приведем его в нормальный вид var text = emailMessage.IsBodyHtml ? _htmlConverterService.ConvertHtml(emailMessage.Body) : emailMessage.Body; return(text); }
private void Convert(string file, int i) { var emailMessage = JsonConvert.DeserializeObject <EmailMessage>(File.ReadAllText(file)); var doc = emailMessage.Body; var isHtml = emailMessage.IsBodyHtml; if (!string.IsNullOrWhiteSpace(doc)) { File.WriteAllText("test.html", doc); var stopwatch = Stopwatch.StartNew(); stopwatch.Start(); const int max = 100000; if (!emailMessage.IsBodyHtml && emailMessage.Body.Length > max) { return; } if (emailMessage.IsBodyHtml && emailMessage.Body.Length > (max * 2)) { return; } var convertHtml = isHtml ? _htmlConverterService.ConvertHtml(doc) : doc; if (convertHtml.Length > max) { return; } File.WriteAllText("test.txt", convertHtml); var persons = _mailAnalyzeService.Persons(convertHtml); if (persons.Any(c => c.Emails.Any(e => { var ok = (e.EndsWith(".ru") || e.EndsWith(".com") || e.EndsWith(".net") || e.EndsWith(".info") || e.EndsWith(".su") || e.EndsWith(".org") || e.EndsWith(".tech") || e.EndsWith("D297BED0") || e.EndsWith("ae") || e.EndsWith("015d1c70")); if (!ok) { Console.WriteLine(file); Console.WriteLine(e); } return(!ok); }))) { // throw new Exception("криво"); } if (persons.Any()) { foreach (var contactSummary in emailMessage.From) { UpdateContact(persons, contactSummary); } foreach (var contactSummary in emailMessage.To) { UpdateContact(persons, contactSummary); } } stopwatch.Stop(); Statictics.Add(i, stopwatch.ElapsedMilliseconds); Console.WriteLine($"{i} {stopwatch.ElapsedMilliseconds}"); } }