diff options
Diffstat (limited to 'Decompiler/Gestor.Application.Helpers/MailHelper.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.Helpers/MailHelper.cs | 746 |
1 files changed, 746 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Helpers/MailHelper.cs b/Decompiler/Gestor.Application.Helpers/MailHelper.cs new file mode 100644 index 0000000..8a56cdc --- /dev/null +++ b/Decompiler/Gestor.Application.Helpers/MailHelper.cs @@ -0,0 +1,746 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Mail; +using System.Net.Mime; +using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using CsQuery.ExtensionMethods.Internal; +using Gestor.Application.ViewModels; +using Gestor.Common.Helpers; +using Gestor.Common.Validation; +using Gestor.Infrastructure.UnitOfWork.Generic; +using Gestor.Infrastructure.UnitOfWork.Logic; +using Gestor.Model.Common; +using Gestor.Model.Domain.Common; +using Gestor.Model.Domain.Ferramentas; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.MalaDireta; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.Helper; +using Google.Apis.Auth.OAuth2; +using Google.Apis.Gmail.v1; +using Google.Apis.Gmail.v1.Data; +using Google.Apis.Http; +using Google.Apis.Requests; +using Google.Apis.Services; +using Google.Apis.Util.Store; +using Microsoft.Identity.Client; +using MimeKit; + +namespace Gestor.Application.Helpers; + +public class MailHelper +{ + public async Task<LogEnvio> SendAsync(Credencial credencial, Destinatario destinatario, FiltroArquivoDigital filtro = null, List<MalaDireta> maladireta = null, TipoTela tela = 0, bool confirmarLeitura = false) + { + //IL_002f: Unknown result type (might be due to invalid IL or missing references) + //IL_0031: Unknown result type (might be due to invalid IL or missing references) + IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); + TipoTela telaEmail; + return await Task.Run((Func<LogEnvio>)delegate + { + //IL_0007: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: Unknown result type (might be due to invalid IL or missing references) + //IL_0018: Unknown result type (might be due to invalid IL or missing references) + //IL_0029: Expected O, but got Unknown + //IL_03ba: Unknown result type (might be due to invalid IL or missing references) + //IL_03c1: Expected O, but got Unknown + //IL_053e: Unknown result type (might be due to invalid IL or missing references) + //IL_0545: Invalid comparison between Unknown and I4 + //IL_0607: Unknown result type (might be due to invalid IL or missing references) + //IL_060c: Unknown result type (might be due to invalid IL or missing references) + //IL_060e: Unknown result type (might be due to invalid IL or missing references) + //IL_0611: Unknown result type (might be due to invalid IL or missing references) + //IL_064b: Expected I4, but got Unknown + //IL_0658: Unknown result type (might be due to invalid IL or missing references) + //IL_064f: Unknown result type (might be due to invalid IL or missing references) + //IL_0661: Unknown result type (might be due to invalid IL or missing references) + //IL_066a: Unknown result type (might be due to invalid IL or missing references) + //IL_0673: Unknown result type (might be due to invalid IL or missing references) + //IL_067d: Unknown result type (might be due to invalid IL or missing references) + //IL_0687: Unknown result type (might be due to invalid IL or missing references) + //IL_0691: Unknown result type (might be due to invalid IL or missing references) + //IL_069b: Unknown result type (might be due to invalid IL or missing references) + //IL_06a5: Unknown result type (might be due to invalid IL or missing references) + //IL_06af: Unknown result type (might be due to invalid IL or missing references) + //IL_06b9: Unknown result type (might be due to invalid IL or missing references) + //IL_06c3: Unknown result type (might be due to invalid IL or missing references) + //IL_0e32: Unknown result type (might be due to invalid IL or missing references) + //IL_0e37: Unknown result type (might be due to invalid IL or missing references) + //IL_0e43: Unknown result type (might be due to invalid IL or missing references) + //IL_0e4e: Unknown result type (might be due to invalid IL or missing references) + //IL_0e56: Unknown result type (might be due to invalid IL or missing references) + //IL_0e58: Unknown result type (might be due to invalid IL or missing references) + //IL_0e62: Unknown result type (might be due to invalid IL or missing references) + //IL_0e74: Unknown result type (might be due to invalid IL or missing references) + //IL_0e86: Unknown result type (might be due to invalid IL or missing references) + //IL_0e97: Unknown result type (might be due to invalid IL or missing references) + //IL_0ea8: Unknown result type (might be due to invalid IL or missing references) + //IL_0eba: Unknown result type (might be due to invalid IL or missing references) + //IL_0ec5: Unknown result type (might be due to invalid IL or missing references) + //IL_0ed0: Unknown result type (might be due to invalid IL or missing references) + //IL_0edb: Unknown result type (might be due to invalid IL or missing references) + //IL_06cc: Unknown result type (might be due to invalid IL or missing references) + //IL_0204: Unknown result type (might be due to invalid IL or missing references) + //IL_0209: Unknown result type (might be due to invalid IL or missing references) + //IL_020b: Unknown result type (might be due to invalid IL or missing references) + //IL_020e: Invalid comparison between Unknown and I4 + //IL_021d: Unknown result type (might be due to invalid IL or missing references) + //IL_0222: Unknown result type (might be due to invalid IL or missing references) + //IL_022d: Unknown result type (might be due to invalid IL or missing references) + //IL_025d: Expected O, but got Unknown + //IL_0263: Unknown result type (might be due to invalid IL or missing references) + //IL_0268: Unknown result type (might be due to invalid IL or missing references) + //IL_0285: Expected O, but got Unknown + //IL_0285: Unknown result type (might be due to invalid IL or missing references) + //IL_028a: Unknown result type (might be due to invalid IL or missing references) + //IL_0291: Unknown result type (might be due to invalid IL or missing references) + //IL_02a1: Expected O, but got Unknown + //IL_029c: Unknown result type (might be due to invalid IL or missing references) + //IL_0210: Unknown result type (might be due to invalid IL or missing references) + //IL_0213: Invalid comparison between Unknown and I4 + //IL_0828: Unknown result type (might be due to invalid IL or missing references) + //IL_082e: Invalid comparison between Unknown and I4 + //IL_06e8: Unknown result type (might be due to invalid IL or missing references) + //IL_06ed: Unknown result type (might be due to invalid IL or missing references) + //IL_06f9: Unknown result type (might be due to invalid IL or missing references) + //IL_070a: Unknown result type (might be due to invalid IL or missing references) + //IL_0715: Unknown result type (might be due to invalid IL or missing references) + //IL_071d: Unknown result type (might be due to invalid IL or missing references) + //IL_071f: Unknown result type (might be due to invalid IL or missing references) + //IL_0729: Unknown result type (might be due to invalid IL or missing references) + //IL_073b: Unknown result type (might be due to invalid IL or missing references) + //IL_074d: Unknown result type (might be due to invalid IL or missing references) + //IL_075e: Unknown result type (might be due to invalid IL or missing references) + //IL_076f: Unknown result type (might be due to invalid IL or missing references) + //IL_0781: Unknown result type (might be due to invalid IL or missing references) + //IL_078c: Unknown result type (might be due to invalid IL or missing references) + //IL_0797: Unknown result type (might be due to invalid IL or missing references) + //IL_07a2: Unknown result type (might be due to invalid IL or missing references) + //IL_02f8: Unknown result type (might be due to invalid IL or missing references) + //IL_02ff: Expected O, but got Unknown + //IL_030e: Unknown result type (might be due to invalid IL or missing references) + //IL_0313: Unknown result type (might be due to invalid IL or missing references) + //IL_031f: Expected O, but got Unknown + //IL_0f1e: Expected O, but got Unknown + //IL_0955: Unknown result type (might be due to invalid IL or missing references) + //IL_095b: Invalid comparison between Unknown and I4 + //IL_0833: Unknown result type (might be due to invalid IL or missing references) + //IL_0838: Unknown result type (might be due to invalid IL or missing references) + //IL_0844: Unknown result type (might be due to invalid IL or missing references) + //IL_084f: Unknown result type (might be due to invalid IL or missing references) + //IL_0861: Unknown result type (might be due to invalid IL or missing references) + //IL_0869: Unknown result type (might be due to invalid IL or missing references) + //IL_086c: Unknown result type (might be due to invalid IL or missing references) + //IL_0876: Unknown result type (might be due to invalid IL or missing references) + //IL_0888: Unknown result type (might be due to invalid IL or missing references) + //IL_089a: Unknown result type (might be due to invalid IL or missing references) + //IL_08ab: Unknown result type (might be due to invalid IL or missing references) + //IL_08bc: Unknown result type (might be due to invalid IL or missing references) + //IL_08ce: Unknown result type (might be due to invalid IL or missing references) + //IL_08d9: Unknown result type (might be due to invalid IL or missing references) + //IL_08e4: Unknown result type (might be due to invalid IL or missing references) + //IL_08ef: Unknown result type (might be due to invalid IL or missing references) + //IL_0a82: Unknown result type (might be due to invalid IL or missing references) + //IL_0a88: Invalid comparison between Unknown and I4 + //IL_0960: Unknown result type (might be due to invalid IL or missing references) + //IL_0965: Unknown result type (might be due to invalid IL or missing references) + //IL_0971: Unknown result type (might be due to invalid IL or missing references) + //IL_097c: Unknown result type (might be due to invalid IL or missing references) + //IL_098e: Unknown result type (might be due to invalid IL or missing references) + //IL_0996: Unknown result type (might be due to invalid IL or missing references) + //IL_0999: Unknown result type (might be due to invalid IL or missing references) + //IL_09a3: Unknown result type (might be due to invalid IL or missing references) + //IL_09b5: Unknown result type (might be due to invalid IL or missing references) + //IL_09c7: Unknown result type (might be due to invalid IL or missing references) + //IL_09d8: Unknown result type (might be due to invalid IL or missing references) + //IL_09e9: Unknown result type (might be due to invalid IL or missing references) + //IL_09fb: Unknown result type (might be due to invalid IL or missing references) + //IL_0a06: Unknown result type (might be due to invalid IL or missing references) + //IL_0a11: Unknown result type (might be due to invalid IL or missing references) + //IL_0a1c: Unknown result type (might be due to invalid IL or missing references) + //IL_0baf: Unknown result type (might be due to invalid IL or missing references) + //IL_0bb5: Invalid comparison between Unknown and I4 + //IL_0a8d: Unknown result type (might be due to invalid IL or missing references) + //IL_0a92: Unknown result type (might be due to invalid IL or missing references) + //IL_0a9e: Unknown result type (might be due to invalid IL or missing references) + //IL_0aa9: Unknown result type (might be due to invalid IL or missing references) + //IL_0abb: Unknown result type (might be due to invalid IL or missing references) + //IL_0ac3: Unknown result type (might be due to invalid IL or missing references) + //IL_0ac6: Unknown result type (might be due to invalid IL or missing references) + //IL_0ad0: Unknown result type (might be due to invalid IL or missing references) + //IL_0ae2: Unknown result type (might be due to invalid IL or missing references) + //IL_0af4: Unknown result type (might be due to invalid IL or missing references) + //IL_0b05: Unknown result type (might be due to invalid IL or missing references) + //IL_0b16: Unknown result type (might be due to invalid IL or missing references) + //IL_0b28: Unknown result type (might be due to invalid IL or missing references) + //IL_0b33: Unknown result type (might be due to invalid IL or missing references) + //IL_0b3e: Unknown result type (might be due to invalid IL or missing references) + //IL_0b49: Unknown result type (might be due to invalid IL or missing references) + //IL_07e5: Expected O, but got Unknown + //IL_0cdc: Unknown result type (might be due to invalid IL or missing references) + //IL_0bba: Unknown result type (might be due to invalid IL or missing references) + //IL_0bbf: Unknown result type (might be due to invalid IL or missing references) + //IL_0bcb: Unknown result type (might be due to invalid IL or missing references) + //IL_0bd6: Unknown result type (might be due to invalid IL or missing references) + //IL_0be8: Unknown result type (might be due to invalid IL or missing references) + //IL_0bf0: Unknown result type (might be due to invalid IL or missing references) + //IL_0bf3: Unknown result type (might be due to invalid IL or missing references) + //IL_0bfd: Unknown result type (might be due to invalid IL or missing references) + //IL_0c0f: Unknown result type (might be due to invalid IL or missing references) + //IL_0c21: Unknown result type (might be due to invalid IL or missing references) + //IL_0c32: Unknown result type (might be due to invalid IL or missing references) + //IL_0c43: Unknown result type (might be due to invalid IL or missing references) + //IL_0c55: Unknown result type (might be due to invalid IL or missing references) + //IL_0c60: Unknown result type (might be due to invalid IL or missing references) + //IL_0c6b: Unknown result type (might be due to invalid IL or missing references) + //IL_0c76: Unknown result type (might be due to invalid IL or missing references) + //IL_0930: Unknown result type (might be due to invalid IL or missing references) + //IL_0933: Unknown result type (might be due to invalid IL or missing references) + //IL_093f: Expected O, but got Unknown + //IL_0ce6: Unknown result type (might be due to invalid IL or missing references) + //IL_0ceb: Unknown result type (might be due to invalid IL or missing references) + //IL_0cf7: Unknown result type (might be due to invalid IL or missing references) + //IL_0d02: Unknown result type (might be due to invalid IL or missing references) + //IL_0a5d: Unknown result type (might be due to invalid IL or missing references) + //IL_0a60: Unknown result type (might be due to invalid IL or missing references) + //IL_0a6c: Expected O, but got Unknown + //IL_0b8a: Unknown result type (might be due to invalid IL or missing references) + //IL_0b8d: Unknown result type (might be due to invalid IL or missing references) + //IL_0b99: Expected O, but got Unknown + //IL_0d1c: Unknown result type (might be due to invalid IL or missing references) + //IL_0d24: Unknown result type (might be due to invalid IL or missing references) + //IL_0d2b: Unknown result type (might be due to invalid IL or missing references) + //IL_0d3d: Unknown result type (might be due to invalid IL or missing references) + //IL_0d4f: Unknown result type (might be due to invalid IL or missing references) + //IL_0d60: Unknown result type (might be due to invalid IL or missing references) + //IL_0d71: Unknown result type (might be due to invalid IL or missing references) + //IL_0d83: Unknown result type (might be due to invalid IL or missing references) + //IL_0d8e: Unknown result type (might be due to invalid IL or missing references) + //IL_0d99: Unknown result type (might be due to invalid IL or missing references) + //IL_0da4: Unknown result type (might be due to invalid IL or missing references) + //IL_0cb7: Unknown result type (might be due to invalid IL or missing references) + //IL_0cba: Unknown result type (might be due to invalid IL or missing references) + //IL_0cc6: Expected O, but got Unknown + //IL_0de5: Unknown result type (might be due to invalid IL or missing references) + //IL_0de8: Unknown result type (might be due to invalid IL or missing references) + //IL_0df4: Expected O, but got Unknown + LogEnvio log = new LogEnvio + { + Credencial = credencial, + Destinatario = destinatario + }; + AlternateView item = CreateAlternateView(destinatario.Corpo); + try + { + MailMessage message = new MailMessage + { + From = new MailAddress(credencial.Email, string.IsNullOrWhiteSpace(credencial.Header) ? Recursos.Empresa.Nome : credencial.Header), + BodyEncoding = Encoding.UTF8, + Subject = destinatario.Assunto, + AlternateViews = { item }, + ReplyToList = + { + new MailAddress(string.IsNullOrWhiteSpace(credencial.Replyto) ? credencial.Email : credencial.Replyto) + }, + DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure, + IsBodyHtml = true + }; + if (confirmarLeitura) + { + message.Headers.Add("Disposition-Notification-To", credencial.Email); + } + destinatario.Email.Split(new char[1] { ';' }).ToList().ForEach(delegate(string s) + { + if (ValidationHelper.ValidacaoEmail(s)) + { + message.To.Add(new MailAddress(s)); + } + }); + List<string> listaCopia = new List<string>(); + destinatario.EncaminharOculto?.ForEach(delegate(string x) + { + if (!string.IsNullOrEmpty(x)) + { + if (!x.Contains(";")) + { + if (ValidationHelper.ValidacaoEmail(x)) + { + listaCopia.Add(x); + } + } + else + { + x.Split(new char[1] { ';' }).ToList().ForEach(delegate(string s) + { + if (ValidationHelper.ValidacaoEmail(s)) + { + listaCopia.Add(s); + } + }); + } + } + }); + destinatario.Encaminhar?.ForEach(delegate(string x) + { + if (!string.IsNullOrEmpty(x)) + { + if (!x.Contains(";")) + { + if (ValidationHelper.ValidacaoEmail(x)) + { + listaCopia.Add(x); + } + } + else + { + x.Split(new char[1] { ';' }).ToList().ForEach(delegate(string s) + { + if (ValidationHelper.ValidacaoEmail(s)) + { + listaCopia.Add(s); + } + }); + } + } + }); + listaCopia.ForEach(delegate(string x) + { + message.Bcc.Add(new MailAddress(x)); + }); + destinatario.Anexos?.ForEach(delegate(ArquivoDigital x) + { + Attachment item2 = new Attachment(new MemoryStream(x.Arquivo), x.Descricao + ValidationHelper.GetDefaultExtension(x.Extensao)); + message.Attachments.Add(item2); + }); + if (credencial.Email.Contains("@gmail.com")) + { + credencial.Tipo = (TipoEmail)1; + } + TipoEmail tipo = credencial.Tipo; + if ((int)tipo != 1) + { + if ((int)tipo == 2) + { + StringContent val = new StringContent(""); + IPublicClientApplication val2 = ((AbstractApplicationBuilder<PublicClientApplicationBuilder>)(object)PublicClientApplicationBuilder.Create("8d1c32fe-4c17-4d5b-a21b-55b5529c3e12").WithDefaultRedirectUri()).WithCacheOptions(new CacheOptions + { + UseSharedCache = true + }).Build(); + string[] array = new string[2] { "user.read", "https://graph.microsoft.com/Mail.Send" }; + AuthenticationResult val3; + try + { + val = ConverteMailMessageParaStringContent(message); + IEnumerable<IAccount> result = ((IClientApplicationBase)val2).GetAccountsAsync().Result; + val3 = ((result != null && result.Count() != 0) ? ((AbstractAcquireTokenParameterBuilder<AcquireTokenSilentParameterBuilder>)(object)((IClientApplicationBase)val2).AcquireTokenSilent((IEnumerable<string>)array, result?.FirstOrDefault())).ExecuteAsync().Result : ((AbstractAcquireTokenParameterBuilder<AcquireTokenInteractiveParameterBuilder>)(object)val2.AcquireTokenInteractive((IEnumerable<string>)array)).ExecuteAsync().Result); + } + catch + { + val3 = ((AbstractAcquireTokenParameterBuilder<AcquireTokenInteractiveParameterBuilder>)(object)val2.AcquireTokenInteractive((IEnumerable<string>)array)).ExecuteAsync().Result; + } + HttpClient val4 = new HttpClient(); + try + { + ((HttpHeaders)val4.DefaultRequestHeaders).Clear(); + ((HttpHeaders)val4.DefaultRequestHeaders).Add("Authorization", "Bearer " + ((val3 != null) ? val3.AccessToken : null)); + HttpResponseMessage result2 = val4.PostAsync("https://graph.microsoft.com/v1.0/me/sendMail", (HttpContent)(object)val).Result; + log.Enviado = result2.IsSuccessStatusCode; + } + finally + { + ((IDisposable)val4)?.Dispose(); + } + } + else + { + string password = EncryptionHelper.Decrypt(credencial.Senha); + NetworkCredential credentials = new NetworkCredential + { + Password = password, + UserName = (credencial.Usuario ?? credencial.Email) + }; + SmtpClient smtpClient = new SmtpClient(); + smtpClient.EnableSsl = credencial.Seguro; + smtpClient.Host = credencial.Dominio; + smtpClient.Port = credencial.Porta.GetValueOrDefault(587); + smtpClient.UseDefaultCredentials = false; + smtpClient.Credentials = credentials; + smtpClient.SendCompleted += delegate(object sender, AsyncCompletedEventArgs args) + { + log.Enviado = !args.Cancelled || args.Error != null; + if (args.Error != null) + { + log.Erro = args.Error.ToString(); + } + }; + smtpClient.Send(message); + log.Enviado = true; + } + } + else + { + UserCredential result3 = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets + { + ClientId = "378618252089-fm92uqgnk2jivf25mk2tv9s735n4nf6u.apps.googleusercontent.com", + ClientSecret = "kUiTfSuwZLLfteqwX7x6glsu" + }, (IEnumerable<string>)new string[1] { Scope.GmailSend }, credencial.Email, CancellationToken.None, (IDataStore)null, (ICodeReceiver)null).Result; + Message val5 = new Message + { + Raw = Encode(((object)MimeMessage.CreateFromMailMessage(message)).ToString()) + }; + SendRequest obj2 = new GmailService(new Initializer + { + HttpClientInitializer = (IConfigurableHttpClientInitializer)(object)result3, + ApplicationName = "AGGER GESTOR" + }).Users.Messages.Send(val5, credencial.Email); + log.Enviado = false; + if (((ClientServiceRequest<Message>)(object)obj2).Execute().LabelIds.Contains("SENT")) + { + log.Enviado = true; + } + } + } + catch (Exception ex) + { + log.Enviado = false; + string erro = ((ex.InnerException == null) ? ex.Message : (ex.Message + " | " + ex.InnerException.Message)); + log.Erro = erro; + } + if ((int)tela == 40) + { + return log; + } + UnitOfWork commited = Instancia.Commited; + try + { + List<string> list = new List<string> { destinatario.Email }; + if (destinatario.Encaminhar != null) + { + list.AddRange(destinatario.Encaminhar); + } + List<string> list2 = new List<string>(); + if (destinatario.EncaminharOculto != null) + { + list2.AddRange(destinatario.EncaminharOculto); + } + List<string> list3 = destinatario.Anexos?.Select((ArquivoDigital x) => x.Descricao + ValidationHelper.GetDefaultExtension(x.Extensao)).ToList(); + DateTime networkTime = Funcoes.GetNetworkTime(); + if (filtro != null) + { + TipoArquivoDigital tipo2 = filtro.Tipo; + switch (tipo2 - 1) + { + case 1: + telaEmail = (TipoTela)2; + break; + case 0: + telaEmail = (TipoTela)1; + break; + case 2: + telaEmail = (TipoTela)5; + break; + case 3: + telaEmail = (TipoTela)3; + break; + case 4: + telaEmail = (TipoTela)7; + break; + case 5: + telaEmail = (TipoTela)15; + break; + case 6: + telaEmail = (TipoTela)23; + break; + case 7: + telaEmail = (TipoTela)13; + break; + case 8: + telaEmail = (TipoTela)25; + break; + case 9: + telaEmail = (TipoTela)24; + break; + case 10: + telaEmail = (TipoTela)33; + break; + case 11: + telaEmail = (TipoTela)16; + break; + case 12: + telaEmail = (TipoTela)18; + break; + default: + telaEmail = (TipoTela)0; + break; + } + if (list3 != null && log.Enviado) + { + LogEmail val6 = new LogEmail + { + Credencial = credencial, + EntityId = filtro.Id, + Usuario = Recursos.Usuario, + Data = networkTime, + Tela = telaEmail, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString() + }; + commited.RegistroLogRepository.SaveOrUpdate(val6); + } + ((GenericUnitOfWork)commited).Commit(); + } + else if (maladireta != null) + { + foreach (MalaDireta maladiretum in maladireta) + { + if ((int)maladiretum.Tela == 1) + { + LogEmail val7 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario, + EntityId = ((DomainBase)maladiretum.Cliente).Id, + Data = networkTime, + Tela = maladiretum.Tela, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + Relatorio = maladiretum.Relatorio + }; + commited.RegistroLogRepository.SaveOrUpdate(val7); + } + else if ((int)maladiretum.Tela == 2) + { + LogEmail val8 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario, + EntityId = ((DomainBase)maladiretum.Apolice).Id, + Data = networkTime, + Tela = maladiretum.Tela, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + Relatorio = maladiretum.Relatorio + }; + commited.RegistroLogRepository.SaveOrUpdate(val8); + } + else if ((int)maladiretum.Tela == 5) + { + LogEmail val9 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario, + EntityId = ((DomainBase)maladiretum.Parcela).Id, + Data = networkTime, + Tela = maladiretum.Tela, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + Relatorio = maladiretum.Relatorio + }; + commited.RegistroLogRepository.SaveOrUpdate(val9); + } + else if ((int)maladiretum.Tela == 7) + { + LogEmail val10 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario, + EntityId = ((DomainBase)maladiretum.Sinistro).Id, + Data = networkTime, + Tela = maladiretum.Tela, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + Relatorio = maladiretum.Relatorio + }; + commited.RegistroLogRepository.SaveOrUpdate(val10); + } + else if ((int)maladiretum.Tela == 0) + { + LogEmail val11 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario + }; + Documento apolice = maladiretum.Apolice; + val11.EntityId = ((apolice != null) ? ((DomainBase)apolice).Id : 0); + val11.Data = networkTime; + val11.Tela = (TipoTela)2; + val11.Destinatarios = string.Join(";", list); + val11.Cco = string.Join(";", list2); + val11.Assunto = destinatario.Assunto; + val11.Corpo = destinatario.Corpo; + val11.Anexos = string.Join(";", list3); + val11.Versao = LoginViewModel.VersaoAtual; + val11.NomeMaquina = Environment.MachineName; + val11.UsuarioMaquina = Environment.UserName; + val11.Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(); + val11.Relatorio = maladiretum.Relatorio; + LogEmail val12 = val11; + commited.RegistroLogRepository.SaveOrUpdate(val12); + } + } + ((GenericUnitOfWork)commited).Commit(); + } + else + { + if (list3 != null) + { + LogEmail val13 = new LogEmail + { + Credencial = credencial, + Usuario = Recursos.Usuario, + Data = networkTime, + Tela = tela, + Destinatarios = string.Join(";", list), + Cco = string.Join(";", list2), + Assunto = destinatario.Assunto, + Corpo = destinatario.Corpo, + Anexos = string.Join(";", list3), + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString() + }; + commited.RegistroLogRepository.SaveOrUpdate(val13); + } + ((GenericUnitOfWork)commited).Commit(); + } + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + return log; + }); + } + + private static StringContent ConverteMailMessageParaStringContent(MailMessage message) + { + //IL_004f: Unknown result type (might be due to invalid IL or missing references) + //IL_0056: Expected O, but got Unknown + MimeMessage val = (MimeMessage)message; + using MemoryStream memoryStream = new MemoryStream(); + val.WriteTo((Stream)memoryStream, default(CancellationToken)); + memoryStream.Position = 0L; + using StreamReader streamReader = new StreamReader(memoryStream); + string s = streamReader.ReadToEnd(); + return new StringContent(Convert.ToBase64String(Encoding.ASCII.GetBytes(s)), Encoding.UTF8, "text/plain"); + } + + public static string Encode(string text) + { + return Convert.ToBase64String(Encoding.UTF8.GetBytes(text)).Replace('+', '-').Replace('/', '_') + .Replace("=", ""); + } + + public static AlternateView CreateAlternateView(string mailBody) + { + List<LinkedResource> list = new List<LinkedResource>(); + string[] array = (from Match m in Regex.Matches(mailBody, "<img(.*?)src=\"file:(///).*?>", RegexOptions.IgnoreCase) + select m.Groups[0].Value).ToArray(); + for (int i = 0; i < array.Length; i++) + { + string value = Regex.Match(array[i], "(?<=src=\")(.*?)(?=\")", RegexOptions.IgnoreCase).Value; + string text = Regex.Match(value, "file:(///).*\\.(.*)", RegexOptions.IgnoreCase).Groups[2].Value; + if (text == "jpg") + { + text = "jpeg"; + } + if (Uri.IsWellFormedUriString(value, UriKind.Absolute)) + { + Uri uri = new Uri(value); + if (File.Exists(uri.LocalPath)) + { + mailBody = mailBody.Replace(value, "data:image/" + text + ";base64," + Convert.ToBase64String(File.ReadAllBytes(uri.LocalPath))); + } + } + } + array = (from Match m in Regex.Matches(mailBody, "<img.*?>", RegexOptions.IgnoreCase) + select m.Groups[0].Value).ToArray(); + foreach (string text2 in array) + { + string value2 = Regex.Match(text2, "(?<=src=\").*(?=\")", RegexOptions.IgnoreCase).Value; + string value3 = Regex.Match(value2, "(?<=data:).*(?=;)", RegexOptions.IgnoreCase).Value; + if (ValidationHelper.IsNullOrEmpty(value3) || ValidationHelper.IsNullOrEmpty(value2)) + { + mailBody = mailBody.Replace(text2, string.Empty); + continue; + } + byte[] buffer = Convert.FromBase64String(Regex.Match(value2, "(?<=base64,)[^\"]*", RegexOptions.IgnoreCase).Value); + string text3 = Guid.NewGuid().ToString(); + LinkedResource item = new LinkedResource(new MemoryStream(buffer), value3) + { + ContentId = text3, + TransferEncoding = TransferEncoding.Base64 + }; + list.Add(item); + string newValue = "cid:" + text3; + mailBody = mailBody.Replace(value2, newValue); + } + AlternateView alternateView = AlternateView.CreateAlternateViewFromString(mailBody, null, "text/html"); + ExtensionMethods.AddRange<LinkedResource>((ICollection<LinkedResource>)alternateView.LinkedResources, (IEnumerable<LinkedResource>)list); + return alternateView; + } + + public List<LogEnvio> Send(Credencial credencial, List<Destinatario> destinatarios, TipoTela tela, long id) + { + List<LogEnvio> logs = new List<LogEnvio>(); + int count = 100; + destinatarios.ForEach(async delegate(Destinatario i) + { + if (count == 0) + { + count = 100; + await Task.Delay(1000); + } + List<LogEnvio> list = logs; + list.Add(await SendAsync(credencial, i, null, null, (TipoTela)0)); + count--; + }); + return logs; + } +} |