private static void VerifyDataForFullParams(Dictionary <string, object> request, PrivateApiResponse <Dictionary <string, object> > response, QueryLogic queryLogic, From from, To to, Cc cc, Bcc bcc, Subject subject, Body body, Date date, Box box, Attachment attachment) { ExceptedCases(response, FieldQueryParameters.From.ToString(), from.ToString()); ExceptedCases(response, FieldQueryParameters.To.ToString(), to.ToString()); ExceptedCases(response, FieldQueryParameters.Cc.ToString(), cc.ToString()); ExceptedCases(response, FieldQueryParameters.Bcc.ToString(), bcc.ToString()); ExceptedCases(response, FieldQueryParameters.Subject.ToString(), subject.ToString()); ExceptedCases(response, FieldQueryParameters.Body.ToString(), body.ToString()); ExceptedCases(response, FieldQueryParameters.Date.ToString(), date.ToString()); ExceptedCases(response, FieldQueryParameters.Box.ToString(), box.ToString()); PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK)); var hits = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(response.Result["hits"].ToString()); if (box == Box.Two) { PrAssert.That(hits.Count, PrIs.EqualTo(0), "Still able to get box 2."); } else { PrAssert.That(response.Result["totalHits"], PrIs.GreaterThan(0), "The response is empty."); if (queryLogic == QueryLogic.And) { foreach (var result in hits) { PrAssert.That( CompareValues[from.ToString()](result[FieldQueryParameters.From.GetEnumStringValue()], FromMail) && CompareValues[to.ToString()](result[FieldQueryParameters.To.GetEnumStringValue()], ToMails.First()) && CompareValues[subject.ToString()](result[FieldQueryParameters.Subject.GetEnumStringValue()], SubjectMail) && CompareValues[body.ToString()](result["preview"].ToString(), BodyMail) && CompareValues[date.ToString()](result[FieldQueryParameters.Date.GetEnumStringValue()], DateListMultipleMail.ElementAt(NumberOfMail / 2)) && CompareValues[box != Box.Missing ? Operations.Eq.ToString() : box.ToString()](result[FieldQueryParameters.Box.GetEnumStringValue()], box == Box.One ? 1 : 2) && CompareValues[attachment != Attachment.Missing ? Operations.Eq.ToString() : attachment.ToString()](result[FieldQueryParameters.HasAttachment.GetEnumStringValue()], attachment == Attachment.Zero ? 0 : 1) ); } } else { foreach (var result in hits) { PrAssert.That( CompareValues[from.ToString()](result[FieldQueryParameters.From.GetEnumStringValue()], FromMail) || CompareValues[to.ToString()](result[FieldQueryParameters.To.GetEnumStringValue()], ToMails.First()) || CompareValues[subject.ToString()](result[FieldQueryParameters.Subject.GetEnumStringValue()], SubjectMail) || CompareValues[body.ToString()](result["preview"].ToString(), BodyMail) || CompareValues[date.ToString()](result[FieldQueryParameters.Date.GetEnumStringValue()], DateListMultipleMail.ElementAt(NumberOfMail / 2)) || CompareValues[box != Box.Missing ? Operations.Eq.ToString() : box.ToString()](result[FieldQueryParameters.Box.GetEnumStringValue()], box == Box.One ? 1 : 2) || CompareValues[attachment != Attachment.Missing ? Operations.Eq.ToString() : attachment.ToString()](result[FieldQueryParameters.HasAttachment.GetEnumStringValue()], attachment == Attachment.Zero ? 0 : 1) ); } } } }
public static List <object> BaixaEmails(ImapClient client, IList <UniqueId> mails, int count, string pasta, IMailFolder folder, Parametros parametros) { if (count > 0) { Console.Clear(); Console.WriteLine(" Fazendo Downloads da(o) " + pasta + "...\n"); Thread.Sleep(3000); List <object> allMessages = new List <object>(); IList <UniqueId> UniMails = new List <UniqueId>(); double i = 1.0; double ii = 1.0; double porcentagem = 0; var qtdGrava = 0; foreach (var mail in mails) { porcentagem = (i / count) * 100; if (ii == 50) { ii = 1; Console.Clear(); Console.WriteLine(" Fazendo Downloads da(o) " + pasta + "...\n"); Console.SetCursorPosition(1, 1); Console.Write(i + "/" + count + " - " + Convert.ToInt32(porcentagem) + "/100%"); Console.SetCursorPosition(Convert.ToInt32(ii), 2); Console.Write("█"); } else { Console.SetCursorPosition(1, 1); Console.Write(i + "/" + count + " - " + Convert.ToInt32(porcentagem) + "/100%"); Console.SetCursorPosition(Convert.ToInt32(ii), 2); Console.Write("█"); } var message = folder.GetMessage(mail); Emails emails = new Emails(); emails.IdEmail = message.MessageId; emails.Titulo = message.Subject; emails.DtHrEnvio = message.Date.Date.ToString("dd/MM/yyyy"); emails.De = message.From[0].ToString().Contains("<") ? message.From[0].ToString()?.Split('<')?[1]?.Replace(">", "") : message.From[0].ToString(); emails.Para = message.To.ToString().Contains("<") ? message.To.ToString()?.Split('<')?[1]?.Replace(">", "") : message.To.ToString(); emails.Html = message.HtmlBody; emails.Body = message.TextBody; foreach (var Cc in message.Cc) { var Address = Cc.ToString().Contains("<") ? Cc.ToString()?.Split('<')?[1]?.Replace(">", "") : Cc.ToString(); emails.CC += string.IsNullOrEmpty(emails.CC) ? Address : "; " + Address; } foreach (var attachment in message.Attachments) { if (attachment is MessagePart) { var fileName = attachment.ContentDisposition?.FileName; var rfc822 = (MessagePart)attachment; if (string.IsNullOrEmpty(fileName)) { fileName = "attached-message.eml"; } fileName = fileName.Replace("/", "_").Replace(":", "").Replace("?", "").Replace("*", "").Replace(",", "").Replace("&", "").Replace("!", "").Replace("%", "").Replace("\"", "").Replace("|", "").Replace("<", "").Replace(">", ""); var caminho = string.IsNullOrEmpty(parametros.Caminho) ? _Configuration.GetSection("Folder").Value : parametros.Caminho; caminho = caminho.EndsWith("//") ? caminho : caminho + "//"; caminho += (mail.Id + "_" + fileName).Replace(" ", ""); emails.CaminhoAnexos += emails.CaminhoAnexos.Contains(";") ? "; " + caminho : caminho; using (var stream = File.Create(caminho)) rfc822.Message.WriteTo(stream); } else { var part = (MimePart)attachment; var fileName = part.FileName.Replace("/", "_").Replace(":", "").Replace("?", "").Replace("*", "").Replace(",", "").Replace("&", "").Replace("!", "").Replace("%", "").Replace("\"", "").Replace("|", "").Replace("<", "").Replace(">", ""); var caminho = string.IsNullOrEmpty(parametros.Caminho) ? _Configuration.GetSection("Folder").Value : parametros.Caminho; caminho = caminho.EndsWith("//") ? caminho : caminho + "//"; caminho += (mail.Id + "_" + fileName).Replace(" ", ""); emails.CaminhoAnexos = ""; emails.CaminhoAnexos += emails.CaminhoAnexos.Contains(";") ? "; " + caminho : caminho; using (var stream = File.Create(caminho)) part.Content.DecodeTo(stream); } } allMessages.Add(emails); UniMails.Add(mail); i++; ii++; qtdGrava++; if (qtdGrava == 10) { qtdGrava = 0; GravaBanco(allMessages); if (parametros.ApagaEmails) { DeleteEmails(client, UniMails, folder); } allMessages.Clear(); UniMails.Clear(); } } if (parametros.ApagaEmails) { DeleteEmails(client, mails, folder); } Console.Clear(); return(allMessages); } return(null); }