///<summary> /// /// Metodo construtor para inicializar os componentes do formulario /// atraves de uma premensagem e um indicador do tipo de mensagem nova /// ///</summary> public novaMensagem(preMensagem msg, int flag, int idmensagem) { control = flag; usuario = msg.getPara(); controleAnexos = 0; InitializeComponent(); novoAssunto.Text = RE + msg.getAssunto(); novoTexto.Text = Environment.NewLine + Environment.NewLine + Environment.NewLine + TRACEJADO + Environment.NewLine + DE + msg.getDe() + EMAIL + Environment.NewLine + PARA + msg.getPara() + EMAIL + Environment.NewLine + ASSUNTO + msg.getAssunto() + Environment.NewLine + Environment.NewLine + msg.getTexto(); if (flag == 1) { string caminhoChave = ""; if (msg.getArquivoCripto().Count > 0) { foreach (string s in msg.getArquivoCripto()) { string nome = gerenciaServlet.recuperaNomeOriginalArquivo(s); nomeAnexos.Text = nome + "; " + nomeAnexos.Text; CriptoFiles.Add(caminho + s); } gerenciaChave gerenciaChaveForm = new gerenciaChave(); gerenciaChaveForm.ShowDialog(); caminhoChave = gerenciaChaveForm.getCaminho(); } if (msg.getArquivoPlain().Count > 0) { foreach (string s in msg.getArquivoPlain()) { nomeAnexos.Text = s + "; " + nomeAnexos.Text; PlainFiles.Add(caminho + s); } } if (CriptoFiles.Count > 0 || PlainFiles.Count > 0) { controleAnexos = 1; } gerenciaServlet.anexoEncaminhar(idmensagem, caminhoChave); } else { novoPara.Text = msg.getDe() + EMAIL; } }
public abrirMensagem(int id) { idmensagem = id; InitializeComponent(); string caminhoChave = ""; if (gerenciaServlet.verificaMensagemCriptografada(id)) { MessageBox.Show(MSG_CRIPTO, MSG_ATENCAO, MessageBoxButtons.OK, MessageBoxIcon.Information); gerenciaChave gerenciaChaveForm = new gerenciaChave(); gerenciaChaveForm.ShowDialog(); caminhoChave = gerenciaChaveForm.getCaminho(); } msg = gerenciaServlet.buscaMensagem(id, caminhoChave); abreDe.Text = msg.getDe(); abreAssunto.Text = msg.getAssunto(); abreTexto.Text = msg.getTexto(); foreach (string s in msg.getArquivoCripto()) { abreAnexos.Text = s + "; " + abreAnexos.Text; } foreach (string s in msg.getArquivoPlain()) { abreAnexos.Text = s + "; " + abreAnexos.Text; } if (msg.getAssunto().Equals(MSG_ERRO_ASSUNTO)) { abreResponder.Visible = false; abreEncaminhar.Visible = false; } }
///<summary> /// /// Método que cria mensagem a ser enviada a partir da pre-mensagem passada retornando /// verdadeiro caso o envio seja feito com sucesso. /// /// Retorna excecao. /// ///</summary> public static List <string> criaMensagem(preMensagem msg, string caminhoChave) { try { string destinatarios = msg.getPara() + msg.getDe() + EMAIL; string[] para = manipulaString.retornaLoginsContatos(destinatarios); string de = msg.getDe(); string assunto = msg.getAssunto(); string body = ""; string assinatura = ""; bool cripto = msg.getCriptografar(); bool sign = msg.getAssinar(); List <anexo> arquivosPlain = new List <anexo>(); List <anexo> arquivosCripto = new List <anexo>(); List <string> destinatarioInexistentes = new List <string>(); // trazendo os arquivos que nao serao criptografados para a lista foreach (string s in msg.getArquivoPlain()) { bool cript = false; anexo next = retornaConteudoAnexo(s, cript, ""); arquivosPlain.Add(next); } // criando a mensagem para enviar a cada destinatario foreach (string destinatario in para) { if (WService.verificaUsuario(destinatario)) { body = msg.getTexto(); arquivosCripto.Clear(); foreach (string s in msg.getArquivoCripto()) { string nome = s; bool cript = true; if (s.Contains(EXTENSAO_SAC)) { nome = manipulaString.recuperaNomeOriginalArquivo(s); } anexo next = retornaConteudoAnexo(nome, cript, destinatario); arquivosCripto.Add(next); } foreach (anexo ap in arquivosPlain) { arquivosCripto.Add(ap); } if (sign) { assinatura = assimetrica.assinaTexto(caminhoChave, body); } if (cripto) { string chaveCertificada = WService.retornaChavePublica(destinatario); string caminhoChaveCert = CAMINHO_TEMP + destinatario + EXTENSAO; manipulaArquivo.criaArquivoTexto(caminhoChaveCert, chaveCertificada); body = simetrica.cifraMensagem(body, caminhoChaveCert); body = simetrica.convertToHexa(body); } mensagem mensagem = new mensagem(de, destinatario, assunto, body, assinatura, cripto, sign, arquivosCripto, msg.getPara()); string xml = serial.serializarObjeto(mensagem); WService.enviaMensagem(xml); excluiArquivos(); } else { destinatarioInexistentes.Add(destinatario); } } return(destinatarioInexistentes); } catch (excecao except) { throw except; } }