public List <OrigenDestinoDTO> getListaOrigenDestino(string correoParaObtener) { List <OrigenDestinoDTO> lista = new List <OrigenDestinoDTO>(); String correos = correoParaObtener; while (correos.Length > 0) { if (correos.IndexOf(';') != -1) { OrigenDestinoDTO destinos = new OrigenDestinoDTO(); destinos.Direccion = correos.Substring(0, correos.IndexOf(';')); lista.Add(destinos); int ini = correos.IndexOf(';') + 1; int fin = correos.Length - 1; correos = correos.Substring(ini); } else if (correos.Equals("")) { } else { OrigenDestinoDTO destinos = new OrigenDestinoDTO(); destinos.Direccion = correos; lista.Add(destinos); correos = ""; } } return(lista); }
/// <summary> /// /// </summary> /// <param name="read"></param> /// <param name="sent"></param> /// <param name="cant"></param> /// <returns></returns> public List <CorreoDTO> list(bool read, bool sent, int cant, CuentaDTO cuenta = null) { CorreoDTO correo; List <CorreoDTO> correos = new List <CorreoDTO>(); try { connection.Open(); MySqlCommand myCommand = new MySqlCommand(); myCommand.Connection = connection; MySqlDataAdapter myAdapter = new MySqlDataAdapter(); DataTable myData = new DataTable(); string query = "SELECT idcorreo,asunto,detalle,tipocorreo,fecha,leido,cuenta_idcuenta FROM correo WHERE 1=1"; //Agrego texto a la query si así lo indica cada filtro if (cuenta != null) { query += " AND cuenta_idcuenta=?idcuenta"; } if (read) { query += " AND leido=?leido"; } if (sent) { query += " AND tipocorreo='ENVIADO'"; } else { query += " AND tipocorreo='RECIBIDO'"; } query += " ORDER BY idcorreo DESC"; if (cant != 0) { query += " LIMIT ?cant"; } myCommand.CommandText = query; if (cuenta != null) { myCommand.Parameters.Add("?idcuenta", MySqlDbType.Int16).Value = cuenta.IdCuenta; } myCommand.Parameters.Add("?leido", MySqlDbType.Int16).Value = read; myCommand.Parameters.Add("?cant", MySqlDbType.Int16).Value = cant; myAdapter.SelectCommand = myCommand; myAdapter.Fill(myData); connection.Close(); if (myData.Rows.Count != 0) { for (int i = 0; i <= myData.Rows.Count - 1; i++) { correo = new CorreoDTO(); correo.IdCorreo = int.Parse(myData.Rows[i].ItemArray.GetValue(0).ToString()); correo.Asunto = myData.Rows[i].ItemArray.GetValue(1).ToString(); correo.Detalle = myData.Rows[i].ItemArray.GetValue(2).ToString(); correo.TipoCorreo = Tipo.ENVIADO; //!!!!!!!! String fechaStr = myData.Rows[i].ItemArray.GetValue(4).ToString(); fechaStr = fechaStr.Substring(0, 10); correo.Fecha = DateTime.Parse(fechaStr); correo.Read = bool.Parse(myData.Rows[i].ItemArray.GetValue(5).ToString()); correo.IdCuenta = int.Parse(myData.Rows[i].ItemArray.GetValue(6).ToString()); List <OrigenDestinoDTO> direcciones = new List <OrigenDestinoDTO>(); try { DataTable myDataDir = new DataTable(); myCommand.CommandText = "SELECT idorigendestino,direccion,cc,cco,correo_idcorreo FROM origendestino " + "WHERE correo_idcorreo=?idcorreo"; myCommand.Parameters.Clear(); myCommand.Parameters.Add("?idcorreo", MySqlDbType.Int16).Value = correo.IdCorreo; myAdapter.SelectCommand = myCommand; myAdapter.Fill(myDataDir); if (myDataDir.Rows.Count != 0) { for (int j = 0; j <= myDataDir.Rows.Count - 1; j++) { OrigenDestinoDTO direccion = new OrigenDestinoDTO(); direccion.IdOrigenDestino = int.Parse(myDataDir.Rows[j].ItemArray.GetValue(0).ToString()); direccion.Direccion = myDataDir.Rows[j].ItemArray.GetValue(1).ToString(); direccion.Cc = bool.Parse(myDataDir.Rows[j].ItemArray.GetValue(2).ToString()); direccion.Cco = bool.Parse(myDataDir.Rows[j].ItemArray.GetValue(3).ToString()); direccion.IdCorreo = int.Parse(myDataDir.Rows[j].ItemArray.GetValue(4).ToString()); direcciones.Add(direccion); } } } catch (MySqlException e) { } correo.OrigenDestino = direcciones; List <AttachmentDTO> adjuntos = new List <AttachmentDTO>(); try { myCommand.CommandText = "SELECT idadjunto,detalle,path,correo_idcorreo FROM adjunto WHERE correo_idcorreo=?idcorreoo"; myCommand.Parameters.Add("?idcorreoo", MySqlDbType.Int16).Value = correo.IdCorreo; DataTable myDataAdj = new DataTable(); myAdapter.SelectCommand = myCommand; myAdapter.Fill(myDataAdj); if (myDataAdj.Rows.Count != 0) { for (int j = 0; j <= myDataAdj.Rows.Count - 1; j++) { AttachmentDTO adjunto = new AttachmentDTO(); adjunto.IdAttachment = int.Parse(myDataAdj.Rows[j].ItemArray.GetValue(0).ToString()); adjunto.Name = myDataAdj.Rows[j].ItemArray.GetValue(1).ToString(); adjunto.Path = myDataAdj.Rows[j].ItemArray.GetValue(2).ToString(); adjunto.IdCorreo = int.Parse(myDataAdj.Rows[j].ItemArray.GetValue(3).ToString()); adjuntos.Add(adjunto); } } } catch (MySqlException e) { } correo.Adjuntos = adjuntos; correos.Add(correo); } } } catch (MySqlException ex) { } return(correos); }
/// <summary> /// /// </summary> /// <param name="correo"></param> /// <returns></returns> public CorreoDTO get(CorreoDTO correo) { CorreoDTO correoObtenido = new CorreoDTO(); try { connection.Open(); MySqlCommand myCommand = new MySqlCommand(); MySqlDataAdapter myAdapter = new MySqlDataAdapter(); DataTable myData = new DataTable(); myCommand.Connection = connection; myCommand.CommandText = "SELECT idcorreo,asunto,detalle,tipocorreo,fecha,leido,server_idserver FROM correo WHERE idcorreo=?idcorreo"; myCommand.Parameters.Add("?idcorreo", MySqlDbType.Int16).Value = correo.IdCorreo; myAdapter.SelectCommand = myCommand; myAdapter.Fill(myData); connection.Close(); if (myData.Rows.Count != 0) { for (int i = 0; i <= myData.Rows.Count - 1; i++) { correoObtenido.IdCorreo = int.Parse(myData.Rows[i].ItemArray.GetValue(0).ToString()); correoObtenido.Asunto = myData.Rows[i].ItemArray.GetValue(1).ToString(); correoObtenido.Detalle = myData.Rows[i].ItemArray.GetValue(2).ToString(); //correoObtenido.TipoCorreo = myData.Rows[i].ItemArray.GetValue(3).ToString(); correoObtenido.TipoCorreo = Tipo.RECIBIDO; string fechaStr = myData.Rows[i].ItemArray.GetValue(4).ToString(); fechaStr = fechaStr.Substring(0, 10); correoObtenido.Fecha = DateTime.Parse(fechaStr); correoObtenido.Read = bool.Parse(myData.Rows[i].ItemArray.GetValue(5).ToString()); correoObtenido.NumeroServidorCorreo = int.Parse(myData.Rows[i].ItemArray.GetValue(6).ToString()); List <AttachmentDTO> adjuntos = new List <AttachmentDTO>(); try { myCommand.CommandText = "SELECT idadjunto,detalle,path,correo_idcorreo FROM adjunto WHERE correo_idcorreo=?idcorreoo"; myCommand.Parameters.Add("?idcorreoo", MySqlDbType.Int16).Value = correo.IdCorreo; DataTable myDataAdj = new DataTable(); myAdapter.SelectCommand = myCommand; myAdapter.Fill(myDataAdj); if (myDataAdj.Rows.Count != 0) { for (int j = 0; j <= myDataAdj.Rows.Count - 1; j++) { AttachmentDTO adjunto = new AttachmentDTO(); adjunto.IdAttachment = int.Parse(myDataAdj.Rows[j].ItemArray.GetValue(0).ToString()); adjunto.Name = myDataAdj.Rows[j].ItemArray.GetValue(1).ToString(); adjunto.Path = myDataAdj.Rows[j].ItemArray.GetValue(2).ToString(); adjunto.IdCorreo = int.Parse(myDataAdj.Rows[j].ItemArray.GetValue(3).ToString()); adjuntos.Add(adjunto); } } } catch (MySqlException e) { } correoObtenido.Adjuntos = adjuntos; List <OrigenDestinoDTO> origenes = new List <OrigenDestinoDTO>(); try { myCommand.CommandText = "SELECT idorigendestino,direccion,cc,cco,correo_idcorreo FROM origendestino WHERE correo_idcorreo=?idcorreooo"; myCommand.Parameters.Add("?idcorreooo", MySqlDbType.Int16).Value = correo.IdCorreo; DataTable myDataOri = new DataTable(); myAdapter.SelectCommand = myCommand; myAdapter.Fill(myDataOri); if (myDataOri.Rows.Count != 0) { for (int j = 0; j <= myDataOri.Rows.Count - 1; j++) { OrigenDestinoDTO origen = new OrigenDestinoDTO(); origen.IdOrigenDestino = int.Parse(myDataOri.Rows[j].ItemArray.GetValue(0).ToString()); origen.Direccion = myDataOri.Rows[j].ItemArray.GetValue(1).ToString(); origen.Cc = bool.Parse(myDataOri.Rows[j].ItemArray.GetValue(2).ToString()); origen.Cco = bool.Parse(myDataOri.Rows[j].ItemArray.GetValue(3).ToString()); origen.IdCorreo = int.Parse(myDataOri.Rows[j].ItemArray.GetValue(4).ToString()); origenes.Add(origen); } } } catch (MySqlException e) { } correoObtenido.OrigenDestino = origenes; } } } catch (MySqlException ex) { } return(correoObtenido); }
private void Enviar() { //CorreoDTO correo = new CorreoDTO(); OrigenDestinoDTO destino = new OrigenDestinoDTO(); List <OrigenDestinoDTO> destinos = new List <OrigenDestinoDTO>(); destino.Direccion = txtPara.Text; destino.Cc = false; destino.Cco = false; correo.OrigenDestino = destinos; correo.Asunto = txtAsunto.Text; correo.Detalle = txtMensaje.Text; correo.OrigenDestino.Add(destino); string fechahoyStr = ""; //fecha = DateTime.Today; fechahoyStr = DateTime.Today.ToShortDateString(); correo.Fecha = DateTime.Parse(fechahoyStr); correo.TipoCorreo = Tipo.ENVIADO; if (txtCC.Text != "") { List <OrigenDestinoDTO> listaCC = PasajeCorreos.getInstance().getListaOrigenDestino(txtCC.Text); foreach (OrigenDestinoDTO item in listaCC) { item.Cc = true; item.Cco = false; correo.OrigenDestino.Add(item); } } if (txtCCO.Text != "") { List <OrigenDestinoDTO> listaCCO = PasajeCorreos.getInstance().getListaOrigenDestino(txtCCO.Text); foreach (OrigenDestinoDTO item in listaCCO) { item.Cc = false; item.Cco = true; correo.OrigenDestino.Add(item); } } try { MailServer.getInstance().enviarCorreo(correo); Controller.Correo.getInstance().agregarCorreo(correo); MessageBox.Show("Mensaje Enviado"); ventanaprincipal.Actualizar(); } catch (Exception ex) { } this.Dispose(); }
public List <CorreoDTO> leerCorreo(CuentaDTO cuenta) { List <CorreoDTO> listaCorreos = new List <CorreoDTO>(); try { ServerDTO server = new ServerDTO(); server.Id = cuenta.Server; server = Server.getInstance().ObtenerServer(server); //Sesión AdminPop adminpop = new AdminPop(); adminpop.ConectarPop(server, cuenta); List <MailMessage> listaMensajes = adminpop.ObtenerMensajes(); //listaMensajes.Add(adminpop.ObtenerMensaje(30)); //check fechas foreach (MailMessage mensajeObtenido in listaMensajes) { CorreoDTO correo = new CorreoDTO(); correo.IdCuenta = cuenta.IdCuenta; OrigenDestinoDTO od = new OrigenDestinoDTO(); List <OrigenDestinoDTO> listaOrigenes = new List <OrigenDestinoDTO>(); od.Direccion = PasajeCorreos.getInstance().obtenerCorreoBlank(mensajeObtenido.From.ToString()); od.Cco = false; od.Cc = false; correo.OrigenDestino = listaOrigenes; correo.OrigenDestino.Add(od); MailAddressCollection listaCC = mensajeObtenido.CC; if (listaCC != null) { foreach (MailAddress ma in listaCC) { OrigenDestinoDTO ccdir = new OrigenDestinoDTO(); ccdir.Direccion = PasajeCorreos.getInstance().obtenerCorreoBlank(ma.ToString()); ccdir.Cc = true; ccdir.Cco = false; correo.OrigenDestino.Add(ccdir); } } AttachmentCollection coleccionadjuntos = mensajeObtenido.Attachments; List <AttachmentDTO> adjuntos = new List <AttachmentDTO>(); if (coleccionadjuntos.Count > 0) { //No puedo usar esto porque previamente limpié la tabla de correos, por lo tanto no hay id. //int maxid = Controller.Correo.getInstance().UltimoIdCorreo(cuenta); foreach (Attachment adj in coleccionadjuntos) { AttachmentDTO adjunto = new AttachmentDTO(); //adjunto.IdCorreo = maxid + 1; adjunto.Name = adj.Name; adjunto.Path = adj.ContentStream.ToString(); //OJO adjuntos.Add(adjunto); } } correo.Adjuntos = adjuntos; //MIRAR ACA string fechaStr = mensajeObtenido.Subject.Substring(mensajeObtenido.Subject.Length - 10, 10); correo.Fecha = DateTime.Parse(fechaStr); correo.Asunto = mensajeObtenido.Subject.Substring(0, (mensajeObtenido.Subject.Length - 10)); correo.NumeroServidorCorreo = mensajeObtenido.To.Count; correo.Detalle = mensajeObtenido.Body; correo.TipoCorreo = Tipo.RECIBIDO; listaCorreos.Add(correo); } } catch (ArgumentNullException ex) { } return(listaCorreos); }