/// <summary> /// Metodo per il caricamento del messaggio di reply /// </summary> /// <returns></returns> private bool LoadMessageReply() { ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = WebMailClientManager.getAccount(); if (mailUser == null) { onAccountInvalid(); return(false); } Message msg = GetCurrentMessage(); if (msg == null) { onMessageInvalid(); return(false); } msg.To.Clear(); msg.To.Add(msg.From); msg.From = new Address(mailUser.EmailAddress, mailUser.DisplayName); msg.ReplyTo = new Address(); msg.Bcc.Clear(); msg.Subject = String.Concat("Re:", msg.Subject); ToTextBox.ReadOnly = true; SubjectTextBox.ReadOnly = true; return(true); }
/// <summary> /// Metodo per il caricamento del messaggio di reply to all /// </summary> /// <returns></returns> private bool LoadMessageReplyAll() { ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = WebMailClientManager.getAccount(); if (mailUser == null) { onAccountInvalid(); return(false); } Message msg = GetCurrentMessage(); if (msg == null) { onMessageInvalid(); return(false); } if (selectEmail(msg.To).Contains(mailUser.EmailAddress)) { msg.To = (AddressCollection)msg.To.Where(x => !x.Email.Equals(mailUser.EmailAddress)).ToList(); } msg.To.Add(msg.From); if (selectEmail(msg.Cc).Contains(mailUser.EmailAddress)) { msg.Cc = (AddressCollection)msg.Cc.Where(x => !x.Email.Equals(mailUser.EmailAddress)).ToList(); } msg.Bcc.Clear(); msg.From = new Address(mailUser.EmailAddress, mailUser.DisplayName); msg.ReplyTo = new Address(); msg.Subject = String.Concat("Re:", msg.Subject); ToTextBox.ReadOnly = true; SubjectTextBox.ReadOnly = true; CCTextBox.ReadOnly = true; return(true); }
public HttpResponseMessage AbilitaUsers(string idemail, string itemselector) { FoldersSendersModel model = new FoldersSendersModel(); BackendUserService bus = new BackendUserService(); if (string.IsNullOrEmpty(idemail) && string.IsNullOrEmpty(itemselector)) { model.success = "false"; model.message = "Valori insufficienti nella richiesta"; this.Request.CreateResponse <FoldersSendersModel>(HttpStatusCode.OK, model); } try { // model.FoldersList = listaCartelleNonAbilitate.ToArray(); string[] users = itemselector.Split(';'); var usersAbilitati = bus.GetDipendentiDipartimentoAbilitati(int.Parse(idemail)).Select(z => z.UserId).ToArray(); var ff = Array.ConvertAll(usersAbilitati, x => x.ToString()); var usersda = users.Except(ff); var usersa = ff.Except(users); foreach (string s in usersda) { bus.InsertAbilitazioneEmail(Convert.ToInt32(s), Convert.ToInt32(idemail), 0); } foreach (string s in usersa) { { bus.RemoveAbilitazioneEmail(Convert.ToInt32(s), Convert.ToInt32(idemail)); } } MailUser m = WebMailClientManager.getAccount(); if (m != null) { WebMailClientManager.AccountRemove(); MailServerConfigFacade facade = MailServerConfigFacade.GetInstance(); MailUser account = facade.GetUserByUserId(m.UserId); MailServerFacade serverFacade = MailServerFacade.GetInstance(account); account.Validated = true; WebMailClientManager.SetAccount(account); } model.success = "true"; } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ManagedException mEx = new ManagedException("Eccezione nellA ABILITAZIONE UTENTI", "ERR_U005", string.Empty, ex.Message, null); ErrorLogInfo er = new ErrorLogInfo(mEx); er.objectID = idemail.ToString(); log.Error(er); model.success = "false"; model.message = mEx.Message; } else { model.success = "false"; model.message = ex.Message; } } return(this.Request.CreateResponse <FoldersSendersModel>(HttpStatusCode.OK, model)); }
protected void Page_PreRender(object sender, EventArgs e) { if (WebMailClientManager.AccountIsValid()) { MailUser m = WebMailClientManager.getAccount(); Account = m.Casella; //if (m.IsPec) Pec = true; Json = createJson(); } }
protected void Page_PreRender(object sender, EventArgs e) { if (WebMailClientManager.AccountIsValid()) { MailUser m = WebMailClientManager.getAccount(); hfCurrentFolder.Value = "1"; hfPFolder.Value = "I"; JsonCartella = createJsonCartella(m.IsManaged); JsonStatus = createJsonStatus(); } }
//protected void ucPaging_Init(object sender, EventArgs e) //{ // this.ucPaging = sender as UCPaging; //} protected void BindDataViews(bool refresh) { if (WebMailClientManager.AccountIsValid()) { MailUser user = WebMailClientManager.getAccount(); this.Visible = true; } else { this.Visible = false; } }
private string createJsonCartella(bool IsManaged) { StringBuilder stBuilder = new StringBuilder(); MailUser m = WebMailClientManager.getAccount(); string Nom = string.Empty; if (m == null) { return("[]"); } if (IsManaged) { List <Folder> Folders = m.Folders; stBuilder.Append("["); if (Folders != null && Folders.Count > 0) { for (int i = 0; i < Folders.Count; i++) { if (i > 0) { stBuilder.Append(","); } switch (Folders[i].TipoFolder) { case "I": Nom = string.Empty; break; case "O": Nom = string.Empty; break; case "E": case "A": case "D": Nom = " Archivio"; break; case "C": Nom = " Cestino"; break; } stBuilder.Append("['" + Folders[i].Id + "','" + Folders[i].Nome + Nom + "']"); } stBuilder.Append("]"); } else { return("[]"); } } return(stBuilder.ToString()); }
private void calcVisibility() { if (WebMailClientManager.AccountIsValid()) { this.CurrentMail = WebMailClientManager.getAccount().Casella; IbLogOff.Visible = true; panLogin.Visible = false; } else { this.CurrentMail = "Login"; IbLogOff.Visible = false; panLogin.Visible = true; ManagedAccount.Checked = true; } }
/// <summary> /// Metodo per il caricamento del messaggio di send /// </summary> /// <returns></returns> private bool LoadMessageSend() { ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = WebMailClientManager.getAccount(); if (mailUser == null) { onAccountInvalid(); return(false); } Message msg = CreateNewMessage(); if (msg == null) { onMessageInvalid(); return(false); } msg.From = new Address(mailUser.EmailAddress, mailUser.DisplayName); msg.ReplyTo = new Address(); return(true); }
protected void Page_Load(object sender, EventArgs e) { MailUser mailuser = WebMailClientManager.getAccount(); if (!(WebMailClientManager.AccountIsValid())) { (this.Page as BasePage).info.AddMessage("Account non più valido. Ripetere la selezione della casella di posta", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO); } if (Page.IsPostBack) { string test = HidHtml.Value; if (!(string.IsNullOrEmpty(test))) { SessionManager <string> .set(SessionKeys.TESTO_MAIL, test); } } else { SessionManager <string> .del(SessionKeys.TESTO_MAIL); } }
/// <summary> /// Metodo per il caricamento del messaggio di forward /// </summary> /// <returns></returns> private bool LoadMessageForward() { ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = WebMailClientManager.getAccount(); if (mailUser == null) { onAccountInvalid(); return(false); } Message msg = GetCurrentMessage(); if (msg == null) { onMessageInvalid(); return(false); } msg.From = new Address(mailUser.EmailAddress, mailUser.DisplayName); msg.To.Clear(); msg.Cc.Clear(); msg.Bcc.Clear(); msg.Subject = String.Concat("Fw:", msg.Subject); return(true); }
private HttpResponseMessage createJsonActions(string folder) { FoldersResponse folderResponse = new FoldersResponse(); MailUser m = WebMailClientManager.getAccount(); if (m == null) { folderResponse.message = "Sessione scaduta"; folderResponse.success = "false"; return(this.Request.CreateResponse <FoldersResponse>(HttpStatusCode.OK, folderResponse)); } bool managed = m.IsManaged; if (managed) { List <Folder> Folders = m.Folders; int idfolder = 0; int.TryParse(folder, out idfolder); if (Folders != null && Folders.Count > 0 && idfolder > 0) { var results = (from f in Folders where f.Id == idfolder select f.Azioni).ToList(); folderResponse.ActionsList = results[0]; //List<ActiveUp.Net.Common.DeltaExt.Action> actions =(List<ActiveUp.Net.Common.DeltaExt.Action>) Folders.Where(f => f.TipoFolder.ToUpper() == tipoFolder && f.Id == idfolder).ToList().First().Azioni; //folderResponse.data = new Actions(actions); folderResponse.success = "true"; folderResponse.total = folderResponse.ActionsList.Count; } else { folderResponse.message = "Nessuna azione"; folderResponse.success = "false"; } } return(this.Request.CreateResponse <FoldersResponse>(HttpStatusCode.OK, folderResponse)); }
protected void Button1_Click(object sender, EventArgs e) { try { Message msg; ComunicazioniService comunicazioniService = new ComunicazioniService(); if (MailMessageComposer.CurrentSendMailExist()) { msg = MailMessageComposer.CurrentSendMailGet(); } else { msg = new Message(); } msg.Subject = SubjectTextBox.Text; if (String.IsNullOrEmpty(ToTextBox.Text.Trim()) && String.IsNullOrEmpty(CCTextBox.Text.Trim()) && String.IsNullOrEmpty(BCCTextBox.Text.Trim())) { ErrorLabel.Text = "Inserire almeno un destinatario"; ErrorLabel.Visible = true; return; } msg.To.Clear(); msg.Cc.Clear(); msg.Bcc.Clear(); this.addEmailsTo(ToTextBox.Text, msg); this.addEmailsCc(CCTextBox.Text, msg); this.addEmailCcn(BCCTextBox.Text, msg); msg.Date = System.DateTime.Now; //mantengo il vecchio testo perché in caso di ErrorEventArgs lo devo ripristinare bodyBag = msg.BodyHtml.Text; SendMail.Model.BodyChunk bb = new SendMail.Model.BodyChunk(); string txt = BodyTextBox.Text; string[] lst = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string l in lst) { bb.Line.Add(l); } //inserisco il testo libero in testa a quello preformattato HtmlNode newNode = null; if (bb.Line.Count != 0) { newNode = HtmlNode.CreateNode(bb.getAsHtml()); } HtmlDocument d = new HtmlDocument(); if (!String.IsNullOrEmpty(PreformattedBody.Text)) { d.LoadHtml(PreformattedBody.Text); } if (newNode != null) { if (d.DocumentNode.Descendants().Count() != 0) { HtmlNode root = d.DocumentNode.Descendants().SingleOrDefault(x => x.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase)); if (root == null) { root = d.DocumentNode.Descendants().FirstOrDefault(x => x.NodeType == HtmlNodeType.Element); } if (root != null) { root.PrependChild(newNode); } else { d.DocumentNode.PrependChild(newNode); } } else { d.DocumentNode.PrependChild(newNode); } } msg.BodyHtml.Text = d.DocumentNode.InnerHtml; //se non sono inclusi gli allegati originali if (MailEditabile == true && cbIncludiAllegati.Checked == false) { for (int i = 0; i < msg.Attachments.Count; i++) { //rimuovo gli allegati originali if (msg.Attachments[i].ParentMessage != null) { msg.Attachments.RemoveAt(i); } } } foreach (MimePart mm in msg.Attachments) { if (mm.BinaryContent == null || mm.BinaryContent.Length < 10) { if (!String.IsNullOrEmpty(mm.ContentId)) { string idAttach = mm.ContentId.Trim(new char[] { '<', '>' }); long idAtt = -1; if (long.TryParse(idAttach, out idAtt)) { ComAllegato all = comunicazioniService .LoadAllegatoComunicazioneById(long.Parse(idAttach)); mm.BinaryContent = all.AllegatoFile; } } } } switch (CurrentAction) { case MailActions.REPLY_TO: case MailActions.REPLY_ALL: case MailActions.RE_SEND: case MailActions.FORWARD: msg.InReplyTo = msg.Id.ToString(); break; } ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = null; if (WebMailClientManager.AccountExist()) { mailUser = WebMailClientManager.getAccount(); } if (mailUser != null) { MailServerFacade f = MailServerFacade.GetInstance(mailUser); if (mailUser.IsManaged) { try { SendMail.Model.ComunicazioniMapping.Comunicazioni c = new SendMail.Model.ComunicazioniMapping.Comunicazioni( SendMail.Model.TipoCanale.MAIL, this.SottoTitolo, msg, MySecurityProvider.CurrentPrincipal.MyIdentity.UserName, 2, "O"); if (c.MailComunicazione.MailRefs != null && c.MailComunicazione.MailRefs.Count != 0) { c.RubricaEntitaUsed = (from cont in c.MailComunicazione.MailRefs select new SendMail.Model.ComunicazioniMapping.RubrEntitaUsed { Mail = cont.MailDestinatario, TipoContatto = cont.TipoRef }).ToList(); } comunicazioniService.InsertComunicazione(c); } catch (Exception ex) { ManagedException mex = new ManagedException("Errore nel salvataggio della mail", "MAIL_CMP_002", "", ex.StackTrace, ex); ErrorLog err = new ErrorLog(mex); _log.Error(err); ErrorLabel.Text = "Errore nell'invio del messaggio"; ErrorLabel.Visible = true; return; } } else { f.sendMail(msg); } (this.Page as BasePage).info.AddInfo("Il messaggio e' stato spedito correttamente"); MailMessageComposer.CurrentSendMailClear(); onMailSent(); } else { ((BasePage)this.Page).info.AddInfo("Account inesistente."); } } catch (Exception ex) { if (ex.GetType() != typeof(ManagedException)) { _log.Error(new Com.Delta.Logging.Errors.ErrorLog(new ManagedException(ex.Message, "FAC_007", string.Empty, string.Empty, ex))); } //_log.Error(new Com.Delta.Logging.Errors.ErrorLog("FAC_007", ex, string.Empty, string.Empty, string.Empty)); MailMessageComposer.CurrentSendMailGet().BodyHtml.Text = bodyBag; ErrorLabel.Visible = true; ErrorLabel.Text = ex.Message; return; } Label5.Visible = true; }
protected void btnSend_OnClick(object sender, EventArgs e) { if (HeaderNew.DestinatarioSelected != null && HeaderNew.DestinatarioSelected.Length > 0) { if (HeaderNew.SottoTitoloSelected != string.Empty && HeaderNew.TitoloSelected != "-- Selezionare un titolo --" && HeaderNew.SottoTitoloSelected.Length > 0) { try { SendMail.Model.ComunicazioniMapping.Comunicazioni comun = new SendMail.Model.ComunicazioniMapping.Comunicazioni(); // gestione allegati List <ComAllegato> allegati = new List <ComAllegato>(); if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE)) { Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE); List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList(); foreach (DTOFileUploadResult d in dto) { SendMail.Model.ComunicazioniMapping.ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato(); allegato.AllegatoExt = d.Extension; allegato.AllegatoFile = d.CustomData; allegato.AllegatoName = d.FileName; allegato.AllegatoTpu = ""; allegato.FlgInsProt = AllegatoProtocolloStatus.FALSE; allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE; allegati.Add(allegato); } } comun.ComAllegati = allegati; string[] destinatari = HeaderNew.DestinatarioSelected.Split(';'); for (int i = 0; i < destinatari.Length; i++) { var match = Regex.Match(destinatari[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { ((BasePage)this.Page).info.AddMessage("Attenzione mail destinatario non valida ", LivelloMessaggio.ERROR); return; } } // gestione destinatari ContactsApplicationMapping c = new ContactsApplicationMapping { Mail = HeaderNew.DestinatarioSelected, IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected), IdTitolo = long.Parse(HeaderNew.TitoloSelected) }; Collection <ContactsApplicationMapping> en = new Collection <ContactsApplicationMapping>(); en.Add(c); if (HeaderNew.ConoscenzaSelected != string.Empty) { string[] conoscenze = HeaderNew.ConoscenzaSelected.Split(';'); for (int i = 0; i < conoscenze.Length; i++) { var match = Regex.Match(conoscenze[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { ((BasePage)this.Page).info.AddMessage("Attenzione mail conoscenza non valida ", LivelloMessaggio.ERROR); return; } } ContactsApplicationMapping c1 = new ContactsApplicationMapping { Mail = HeaderNew.ConoscenzaSelected, IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected), IdTitolo = long.Parse(HeaderNew.TitoloSelected) }; Collection <ContactsApplicationMapping> en1 = new Collection <ContactsApplicationMapping>(); en1.Add(c1); comun.SetMailDestinatari(en1, AddresseeType.CC); } if (HeaderNew.BCCSelected != string.Empty) { string[] bcc = HeaderNew.BCCSelected.Split(';'); for (int i = 0; i < bcc.Length; i++) { var match = Regex.Match(bcc[i], regexMail, RegexOptions.IgnoreCase); if (!match.Success) { ((BasePage)this.Page).info.AddMessage("Attenzione mail BCC non valida ", LivelloMessaggio.ERROR); return; } } ContactsApplicationMapping c2 = new ContactsApplicationMapping { Mail = HeaderNew.BCCSelected, IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected), IdTitolo = long.Parse(HeaderNew.TitoloSelected) }; Collection <ContactsApplicationMapping> en2 = new Collection <ContactsApplicationMapping>(); en2.Add(c2); comun.SetMailDestinatari(en2, AddresseeType.CCN); } comun.SetMailDestinatari(en, AddresseeType.TO); // gestione body email MailContent content = new MailContent(); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); string html = CacheManager <XmlDocument> .EmptyHtml; HtmlAgilityPack.HtmlNode body = null; if (string.IsNullOrEmpty(html) == false) { doc.LoadHtml(html); doc.OptionAutoCloseOnEnd = true; doc.OptionFixNestedTags = true; body = doc.DocumentNode.Descendants() .Where(n => n.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); } var ele = new HtmlAgilityPack.HtmlNode(HtmlAgilityPack.HtmlNodeType.Element, doc, 0); ele.Name = "div"; ele.InnerHtml = HidHtml.Value; content.MailSubject = HeaderNew.ObjectSelected; content.MailText = ele.OuterHtml; // gestione sender MailUser mailuser = WebMailClientManager.getAccount(); content.MailSender = mailuser.EmailAddress; c.IdTitolo = long.Parse(HeaderNew.TitoloSelected); c.IdSottotitolo = long.Parse(HeaderNew.SottoTitoloSelected); comun.UtenteInserimento = MySecurityProvider.CurrentPrincipal.MyIdentity.UserName; comun.MailComunicazione = content; // da scommentare comun.FolderTipo = "O"; comun.FolderId = 2; ComunicazioniService com = new ComunicazioniService(); com.InsertComunicazione(comun); // ((baseLayoutDelta.BasePage)this.Page).info.ClearMessage(); ((BasePage)this.Page).info.AddMessage("Email correttamente inviata", LivelloMessaggio.INFO); btnSend.Visible = false; SessionManager <Dictionary <string, DTOFileUploadResult> > .del(SessionKeys.DTO_FILE); } catch (Exception ex) { if (ex.GetType() != typeof(ManagedException)) { ManagedException mEx = new ManagedException("Errore invio nuova mail. Dettaglio: " + ex.Message + "StackTrace: " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : " vuoto "), "ERR317", string.Empty, string.Empty, ex.InnerException); ErrorLogInfo err = new ErrorLogInfo(mEx); log.Error(err); } btnSend.Enabled = true; ((BasePage)this.Page).info.AddMessage(/*error.logCode + */ " - Errore durante l'inserimento della mail:" + ex.Message, LivelloMessaggio.ERROR); } return; } ((BasePage)this.Page).info.AddMessage("Attenzione sottotitolo non selezionato ", LivelloMessaggio.ERROR); return; } else { ((BasePage)this.Page).info.AddMessage("Attenzione email destinatario non corretta ", LivelloMessaggio.ERROR); return; } }
public HttpResponseMessage SendMailExt(FormDataCollection collection) { MailModel model = new MailModel(); string bodyBag; try { Message msg; ComunicazioniService comunicazioniService = new ComunicazioniService(); if (MailMessageComposer.CurrentSendMailExist()) { msg = MailMessageComposer.CurrentSendMailGet(); } else { msg = new Message(); } msg.Subject = collection["Oggetto"]; if (String.IsNullOrEmpty(collection["DestinatarioA"]) && String.IsNullOrEmpty(collection["DestinatarioCC"]) && String.IsNullOrEmpty(collection["DestinatarioBCC"])) { model.message = "Inserire almeno un destinatario"; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } msg.To.Clear(); msg.Cc.Clear(); msg.Bcc.Clear(); this.addEmailsTo(collection["DestinatarioA"].Trim(), msg); if (!(string.IsNullOrEmpty(collection["DestinatarioCC"]))) { this.addEmailsCc(collection["DestinatarioCC"], msg); } if (!(string.IsNullOrEmpty(collection["DestinatarioBCC"]))) { this.addEmailCcn(collection["DestinatarioBCC"], msg); } msg.Date = System.DateTime.Now; //mantengo il vecchio testo perché in caso di ErrorEventArgs lo devo ripristinare bodyBag = msg.BodyHtml.Text; SendMail.Model.BodyChunk bb = new SendMail.Model.BodyChunk(); string txt = collection["TestoMail"]; string[] lst = txt.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); foreach (string l in lst) { bb.Line.Add(l); } //inserisco il testo libero in testa a quello preformattato HtmlNode newNode = null; if (bb.Line.Count != 0) { newNode = HtmlNode.CreateNode(bb.getAsHtml()); } HtmlDocument d = new HtmlDocument(); if (newNode != null) { if (d.DocumentNode.Descendants().Count() != 0) { HtmlNode root = d.DocumentNode.Descendants().SingleOrDefault(x => x.Name.Equals("body", StringComparison.InvariantCultureIgnoreCase)); if (root == null) { root = d.DocumentNode.Descendants().FirstOrDefault(x => x.NodeType == HtmlNodeType.Element); } if (root != null) { root.PrependChild(newNode); } else { d.DocumentNode.PrependChild(newNode); } } else { d.DocumentNode.PrependChild(newNode); } } msg.BodyHtml.Text = d.DocumentNode.InnerHtml; //se non sono inclusi gli allegati originali if (!(string.IsNullOrEmpty(collection["IncludiAllegati"])) && collection["IncludiAllegati"].ToUpper() == "FALSE") { for (int i = 0; i < msg.Attachments.Count; i++) { //rimuovo gli allegati originali if (msg.Attachments[i].ParentMessage != null) { msg.Attachments.RemoveAt(i); } } } msg.InReplyTo = msg.Id.ToString(); ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = null; if (WebMailClientManager.AccountExist()) { mailUser = WebMailClientManager.getAccount(); } if (mailUser != null) { MailServerFacade f = MailServerFacade.GetInstance(mailUser); msg.From = new Address(mailUser.Casella); if (mailUser.IsManaged) { try { SendMail.Model.ComunicazioniMapping.Comunicazioni c = new SendMail.Model.ComunicazioniMapping.Comunicazioni( SendMail.Model.TipoCanale.MAIL, "0", msg, MySecurityProvider.CurrentPrincipal.MyIdentity.UserName, 2, "O"); if (c.MailComunicazione.MailRefs != null && c.MailComunicazione.MailRefs.Count != 0) { c.RubricaEntitaUsed = (from cont in c.MailComunicazione.MailRefs select new SendMail.Model.ComunicazioniMapping.RubrEntitaUsed { Mail = cont.MailDestinatario, TipoContatto = cont.TipoRef }).ToList(); } if (SessionManager <Dictionary <string, DTOFileUploadResult> > .exist(SessionKeys.DTO_FILE)) { Dictionary <string, DTOFileUploadResult> dictDto = SessionManager <Dictionary <string, DTOFileUploadResult> > .get(SessionKeys.DTO_FILE); List <DTOFileUploadResult> dto = (List <DTOFileUploadResult>)dictDto.Values.ToList(); c.ComAllegati = new List <ComAllegato>(); foreach (DTOFileUploadResult dd in dto) { ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato(); allegato.AllegatoExt = dd.Extension; allegato.AllegatoFile = dd.CustomData; allegato.AllegatoName = dd.FileName; allegato.AllegatoTpu = ""; allegato.FlgInsProt = AllegatoProtocolloStatus.FALSE; allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE; c.ComAllegati.Add(allegato); } } foreach (MimePart mm in msg.Attachments) { if (mm.BinaryContent != null || mm.BinaryContent.Length > 10) { if (c.ComAllegati == null) { c.ComAllegati = new List <ComAllegato>(); } ComAllegato allegato = new SendMail.Model.ComunicazioniMapping.ComAllegato(); FileInfo info = new FileInfo(mm.Filename); allegato.AllegatoExt = info.Extension; allegato.AllegatoFile = mm.BinaryContent; allegato.AllegatoName = mm.Filename; allegato.AllegatoTpu = ""; allegato.FlgInsProt = AllegatoProtocolloStatus.FALSE; allegato.FlgProtToUpl = AllegatoProtocolloStatus.FALSE; c.ComAllegati.Add(allegato); } } comunicazioniService.InsertComunicazione(c); } catch (Exception ex) { ManagedException mex = new ManagedException("Errore nel salvataggio della mail", "MAIL_CMP_002", "", ex.StackTrace, ex); ErrorLog err = new ErrorLog(mex); log.Error(err); model.message = "Errore nell'invio del messaggio"; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } } else { f.sendMail(msg); } model.message = "Email memorizzata correttamente"; model.success = "true"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } else { model.message = "Account inesistente"; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } } catch (Exception ex) { if (ex.GetType() != typeof(ManagedException)) { log.Error(new Com.Delta.Logging.Errors.ErrorLog(new ManagedException(ex.Message, "FAC_007", string.Empty, string.Empty, ex))); } model.message = ex.Message; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } model.message = "Email memorizzata correttamente"; model.success = "true"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); }
public HttpResponseMessage GetMail(int idmail, string tipo) { ActiveUp.Net.Mail.DeltaExt.MailUser mailUser = WebMailClientManager.getAccount(); SessionManager <Dictionary <string, DTOFileUploadResult> > .del(SessionKeys.DTO_FILE); MailModel model = new MailModel(); SessionManager <List <ViewAttachement> > .del(SessionKeys.ATTACHEMENTS_LIST); ViewMail v = new ViewMail(); if (mailUser == null) { model.message = "Account non selezionato"; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } try { Message msg = GetCurrentMessage(); if (msg == null) { model.message = "Messaggio non valido ripetere la selezione"; model.success = "false"; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } v.Mail = mailUser.EmailAddress; if (tipo != "f") { if (selectEmail(msg.To).Contains(mailUser.EmailAddress)) { List <Address> l = msg.To.Where(x => !x.Email.Equals(mailUser.EmailAddress)).ToList(); v.DestinatarioA = string.Join(";", (from e in l select e.Email).ToArray()); v.DestinatarioA += msg.From.Email; } else { v.DestinatarioA = msg.From.Email; } } v.DestinatarioABlank = false; if (selectEmail(msg.Cc).Contains(mailUser.EmailAddress)) { List <Address> lc = msg.Cc.Where(x => !x.Email.Equals(mailUser.EmailAddress)).ToList(); v.DestinatarioCC = string.Join(";", (from e in lc select e.Email).ToArray()); } v.Oggetto = String.Concat("Re:", msg.Subject); v.TestoMailOriginale = msg.BodyText.TextStripped; v.Allegati = new List <ViewAttachement>(); if (msg.Attachments.Count > 0) { foreach (MimePart a in msg.Attachments) { ViewAttachement va = new ViewAttachement(); va.NomeFile = a.Filename; va.ContentiId = a.ContentId; va.Dimensione = a.Size; v.Allegati.Add(va); } } model.Mail = new List <ViewMail>(); model.Mail.Add(v); model.success = "true"; model.Totale = "1"; SessionManager <List <ViewAttachement> > .set(SessionKeys.ATTACHEMENTS_LIST, model.Mail.FirstOrDefault().Allegati); } catch (Exception bex) { if (bex.GetType() != typeof(ManagedException)) { ManagedException mEx = new ManagedException(bex.Message, "ERR_E005", string.Empty, string.Empty, bex); ErrorLogInfo er = new ErrorLogInfo(mEx); log.Error(er); model.success = "false"; model.message = bex.Message; return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); } } return(this.Request.CreateResponse <MailModel>(HttpStatusCode.OK, model)); }
public HttpResponseMessage GetTreeStructure(string idM) { JSONTreeNodeModel model = new JSONTreeNodeModel(); if (string.IsNullOrEmpty(idM)) { ManagedException mEx = new ManagedException("Il parametro idNode è nullo", "ERR_G005", string.Empty, string.Empty, null); ErrorLogInfo er = new ErrorLogInfo(mEx); er.objectID = idM; log.Error(er); model.success = "false"; model.Message = mEx.Message; return(this.Request.CreateResponse <JSONTreeNodeModel>(HttpStatusCode.OK, model)); } long idMail = -1; if (!long.TryParse(idM, out idMail)) { ManagedException mEx = new ManagedException("Il parametro idNode non è numerico", "ERR_G006", string.Empty, string.Empty, null); ErrorLogInfo er = new ErrorLogInfo(mEx); er.objectID = idM; log.Error(er); model.success = "false"; model.Message = mEx.Message; return(this.Request.CreateResponse <JSONTreeNodeModel>(HttpStatusCode.OK, model)); } MailUser us = WebMailClientManager.getAccount(); if (us == null) { ManagedException mEx = new ManagedException("Non esiste un account loggato", "ERR_G007", string.Empty, string.Empty, null); ErrorLogInfo er = new ErrorLogInfo(mEx); er.objectID = idM; log.Error(er); model.success = "false"; model.Message = mEx.Message; return(this.Request.CreateResponse <JSONTreeNodeModel>(HttpStatusCode.OK, model)); } MailLocalService mailService = new MailLocalService(); IEnumerable <HierarchyNode <SimpleTreeItem> > hl = null; List <SimpleTreeItem> result = mailService.LoadMailTree(us.EmailAddress, idMail) as List <SimpleTreeItem>; if (result.Count > 0) { Func <List <SimpleTreeItem>, SimpleTreeItem> getRoot = l => l.FirstOrDefault(x => !l.Select(y => y.Value).Contains(x.Padre)); hl = result.AsHierarchy( e => e.Value, e => e.Padre, e => e.Value, getRoot(result).Value); } JSONTreeNode[] nodes = ConvertToJSON(hl); model.success = "true"; model.data = nodes.ToList(); model.TotalCount = model.data.Count.ToString(); return(this.Request.CreateResponse <JSONTreeNodeModel>(HttpStatusCode.OK, model)); //DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JSONTreeNode[])); //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //ser.WriteObject(ms, nodes); //string json = Encoding.UTF8.GetString(ms.ToArray()); //ms.Close(); //context.Response.ContentType = "application/json"; //context.Response.AddHeader("Content-Type", "text/json"); //context.Response.Write(json); }
// Testare bene todo modificare mailmove protected void MailViewer1_OnRequireAction(object sender, MailActionEventArgs action, string parentFolder) { switch (action.Action) { case MailActions.ACQUIRE: if (WebMailClientManager.CurrentMailExist() && WebMailClientManager.AccountIsValid()) { MailUser muser = WebMailClientManager.getAccount(); Message msg = WebMailClientManager.CurrentMailGet(); while (msg.Container != null) { msg = msg.Container; WebMailClientManager.CurrentMailRemove(); } if (!WebMailClientManager.CurrentMailExist()) { WebMailClientManager.CurrentMailSet(msg); } if (!String.IsNullOrEmpty(msg.HeaderFields["x-trasporto"]) && msg.HeaderFields["x-trasporto"].Equals("posta-certificata", StringComparison.InvariantCultureIgnoreCase)) { string uid = msg.Uid; int id = msg.Id; msg = msg.SubMessages[0]; msg.Uid = uid; msg.Id = id; } try { //TODO:ACQUISIOZNE MAIL INIT BEAKPONT - ALBERTO if (msg.Uid == null) { msg.Uid = MailViewer1.hfUIDMailValue; } //Richiesta req = FaxPec.ServiceContracts.ServiceLocator.GetServiceFactory().RichiestaService.ProcessMail(muser, msg, parentFolder); //if (req != null) //{ // List<string> uids = new List<string>(); // uids.Add(msg.Uid); // string utente = Com.Delta.Anag.Security.MySecurityProvider.CurrentPrincipalName; // ServiceLocator.GetServiceFactory().getMailServerFacade(muser).MailMove(uids, MailStatus.LETTA, "1", utente, parentFolder); // FaxPec.Caching.Session.SessionManager<Richiesta>.set(FaxPec.Caching.Session.SessionKeys.FAXPEC_RICHIESTA, req); //} } catch (ManagedException bex) { if (bex.GetType() != typeof(ManagedException)) { ManagedException mEx = new ManagedException(bex.Message, "ERR_G043", string.Empty, string.Empty, bex); ErrorLogInfo er = new ErrorLogInfo(mEx); log.Error(er); } ((BasePage)Page).info.AddMessage(bex, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } // Response.Redirect("~/pages/Istruz/IstruzioneRichiesta.aspx?m=m"); } break; case MailActions.FORWARD: case MailActions.REPLY_TO: case MailActions.RE_SEND: ucSendMail.Visible = true; if (WebMailClientManager.AccountIsValid()) { ucSendMail.LoginVisibile(false); } ucSendMail.Initialize(action.Action); break; case MailActions.SEND: throw new NotImplementedException(); } }
private string createJson() { StringBuilder stBuilder = new StringBuilder(); MailUser m = WebMailClientManager.getAccount(); if (m.FlgManaged == 1 || m.FlgManaged == 2) { string leaf = "true"; List <Folder> Folders = m.Folders; if (Folders != null) { stBuilder.Append("["); var TreeReceived = (from r in Folders where r.TipoFolder == "I" orderby r.Id select r).ToList(); var TreeSent = (from r in Folders where r.TipoFolder == "O" orderby r.Id select r).ToList(); var TreeArchivedSent = (from r in Folders where (r.TipoFolder.Equals("A") && r.IdNome == "2") || r.TipoFolder == "D" orderby r.Id select r).ToList(); var TreeArchivedReceived = (from r in Folders where (r.TipoFolder.Equals("A") && (r.IdNome == "1" || r.IdNome == "3")) || (r.TipoFolder == "E") orderby r.Id select r).ToList(); var TreeCancelled = (from r in Folders where r.TipoFolder.Equals("C") orderby r.Id select r).ToList(); stBuilder.Append(TreeBuilder("Ricevuta", "I", "I", TreeReceived)); stBuilder.Append(","); stBuilder.Append(TreeBuilder("Inviata", "O", "O", TreeSent)); stBuilder.Append(","); stBuilder.Append(TreeBuilder("Archivio Ricevuta", "A", "I", TreeArchivedReceived)); stBuilder.Append(","); stBuilder.Append(TreeBuilder("Archivio Inviata", "AO", "O", TreeArchivedSent)); stBuilder.Append(","); stBuilder.Append(TreeCustomBuilder("Cestino", TreeCancelled)); stBuilder.Append("]"); } else { string InboxUnManaged = "{ 'text': 'Posta Ricevuta','leaf': true, 'cls': 'folder', id:'1' }"; string OutBox = "{ 'text': 'Posta Inviata','leaf': true, 'expanded':false, 'cls': 'folder', id:'3' }"; stBuilder.Append(String.Format("[{0},{1}]", InboxUnManaged, OutBox)); } } else { string InboxUnManaged = "{ 'text': 'Posta Ricevuta','leaf': true,'expanded':false, 'cls': 'folder', id:'1' }"; string OutBox = "{ 'text': 'Posta Inviata','leaf': true, 'expanded':false, 'cls': 'folder', id:'2' }"; stBuilder.Append(String.Format("[{0},{1}]", InboxUnManaged, OutBox)); } return(stBuilder.ToString()); }
public void ProcessRequest(HttpContext context) { bool response = false; string idMail = context.Request["idMail"]; string account = context.Request["account"]; int rating = -1; if (!String.IsNullOrEmpty(idMail) && !String.IsNullOrEmpty(account)) { int risp = 0; if (int.TryParse(context.Request["rating"], out rating) && (rating >= 0 && rating <= 4)) { try { MailServerFacade mailserverFacade = MailServerFacade.GetInstance((WebMailClientManager.getAccount())); risp = mailserverFacade.AssignMessageRating(idMail, rating); } catch (Exception e) { //TASK: Allineamento log - Ciro if (e.GetType() != typeof(ManagedException)) { ManagedException mEx = new ManagedException("Detagli errore: " + e.Message, "ERR_RAT", "", "", e); ErrorLogInfo err = new ErrorLogInfo(mEx); err.objectID = idMail; _log.Error(err); } //ErrorLog err = new ErrorLog("ERR_RAT", e, "", "", ""); //_log.Error(err); } } if (risp == 1) { response = true; } } context.Response.ContentType = "text/plain"; context.Response.Write(response.ToString().ToLower()); }
private string createJsonStatus() { MailUser m = WebMailClientManager.getAccount(); if (m == null) { return("[]"); } if (m.FlgManaged == 1) { StringBuilder stBuilder = new StringBuilder(); List <Folder> Folders = m.Folders; if (Folders != null) { var CustomFolders = (from r in Folders where r.Abilitata.Contains("E") orderby r.Id select r).ToList(); stBuilder.Append("["); stBuilder.Append("["); stBuilder.Append((int)MailStatus.SCARICATA); stBuilder.Append(",'Da leggere','#1I#1A#3I#3A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.LETTA); stBuilder.Append(",'Letta','#1I#1A#3I#3A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.INOLTRATA); stBuilder.Append(",'Inoltrata','#1I#1A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.REPLY_ONE); stBuilder.Append(",'Con risposta','#1I#1A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.REPLY_ALL); stBuilder.Append(",'Con risposta a tutti','#1I#1A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.CANCELLED); stBuilder.Append(",'Cancellata dalla posta ricevuta','#1C#3C"); stBuilder.Append(AppendCustomFolders(CustomFolders, "I", "O", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.SCARICATA_INCOMPLETA); stBuilder.Append(",'Incompleta','#1I#3I"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "O", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.INSERTED); stBuilder.Append(",'Salvata','#2I"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.PROCESSING); stBuilder.Append(",'In lavorazione','#-1"); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.SEND_AGAIN); stBuilder.Append(",'Da reinviare','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.SENT); stBuilder.Append(",'Inviata al server','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.ERROR); stBuilder.Append(",'In errore','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.CANCELLED); stBuilder.Append(",'Cancellata dalla posta inviata','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.ACCETTAZIONE); stBuilder.Append(",'Accettata dal server','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.NON_ACCETTAZIONE); stBuilder.Append(",'Non accettata dal server','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.AVVENUTA_CONSEGNA); stBuilder.Append(",'Consegnata','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.ERRORE_CONSEGNA); stBuilder.Append(",'Errore di consegna','#2O"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "A")); stBuilder.Append("'],["); stBuilder.Append((int)MailStatus.ARCHIVIATA); stBuilder.Append(",'Archiviata','#1A#2A#3A"); stBuilder.Append(AppendCustomFolders(CustomFolders, "C", "I", "")); stBuilder.Append("']]"); } return(stBuilder.ToString()); // fields: [{name: 'idItem', type: 'string'}, {name: 'displayText', type: 'string'}, {name: 'folder', type: 'string'}], //data: [[eval('<%= (int)MailStatus.SCARICATA %>'), 'Da leggere', '#<%= (int)MailFolder.Ricevute %>#<%= (int)MailFolder.RicevutePEC %>#'], // [eval('<%= (int)MailStatus.LETTA %>'), 'Letta', '#<%= (int)MailFolder.Ricevute %>#<%= (int)MailFolder.RicevutePEC %>#'], // [eval('<%= (int)MailStatus.INOLTRATA %>'), 'Inoltrata', '#<%= (int)MailFolder.Ricevute %>#'], // [eval('<%= (int)MailStatus.REPLY_ONE %>'), 'Con risposta', '#<%= (int)MailFolder.Ricevute %>#'], // [eval('<%= (int)MailStatus.REPLY_ALL %>'), 'Con risposta a tutti', '#<%= (int)MailFolder.Ricevute %>#'], // [eval('<%= (int)MailStatus.CANCELLATA %>'), 'Cancellata dalla posta ricevuta', '#<%= (int)MailFolder.Cestino %>#'], // [eval('<%= (int)MailStatus.SCARICATA_INCOMPLETA %>'), 'Incompleta', '#<%= (int)MailFolder.Ricevute %>#'], // [eval('<%= (int)MailStatus.INSERTED %>'), 'Salvata', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.PROCESSING %>'), 'In lavorazione', '#-1#'], // [eval('<%= (int)MailStatus.SEND_AGAIN %>'), 'Da reinviare', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.SENT %>'), 'Inviata al server', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.ERROR %>'), 'In errore', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.CANCELLED %>'), 'Cancellata dalla posta inviata', '#<%= (int)MailFolder.Cestino %>#'], // [eval('<%= (int)MailStatus.ACCETTAZIONE %>'), 'Accettata dal server', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.NON_ACCETTAZIONE %>'), 'Non accettata dal server', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.AVVENUTA_CONSEGNA %>'), 'Consegnata', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.ERRORE_CONSEGNA %>'), 'Errore di consegna', '#<%= (int)MailFolder.Inviate %>#'], // [eval('<%= (int)MailStatus.ARCHIVIATA %>'), 'Archiviata', '#<%= (int)MailFolder.ArchivioRicevute %>#<%= (int)MailFolder.ArchivioInviate %>#']] } else { return("[]"); } }
public HttpResponseMessage GetMails(int start, int limit, string folder, string parFolder, string mailAction, string mailIds, string filter, int page) { IEnumerable <Carrier> listCarrier = new List <Carrier>(); CarrierModel model = new CarrierModel(); int mailAct = 0; start++; if (mailAction.ToString() != "NaN") { mailAct = int.Parse(mailAction); } string message = null; MailUser acc = WebMailClientManager.getAccount(); if (string.IsNullOrEmpty(mailIds)) { mailIds = string.Empty; } message = DoAction(folder, parFolder, mailAct, mailIds, message, acc); ResultList <MailHeader> m = new ResultList <MailHeader>(start, limit, new List <MailHeader>(), 0); // IEnumerable<string> items = null; if (acc != null && acc.IsManaged && !String.IsNullOrEmpty(filter)) { DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(Filter)); System.IO.MemoryStream ms = new System.IO.MemoryStream(); byte[] res = new byte[filter.Length]; Encoding.UTF8.GetBytes(filter, 0, filter.Length, res, 0); ms.Write(res, 0, res.Length); ms.Seek(0, System.IO.SeekOrigin.Begin); Filter filtro = (Filter)s.ReadObject(ms); Dictionary <MailIndexedSearch, List <string> > sValues = new Dictionary <MailIndexedSearch, List <string> >(); if (filtro.text.tipo != MailIndexedSearch.UNKNOWN && (filtro.text.values != null && filtro.text.values.Length > 0)) { sValues.Add(filtro.text.tipo, filtro.text.values.ToList()); } if (filtro.status.tipo != MailIndexedSearch.UNKNOWN && (filtro.status.values != null && filtro.status.values.Length > 0)) { sValues.Add(filtro.status.tipo, filtro.status.values.Select(e => ((int)e).ToString()).ToList()); } MailLocalService mailService = new MailLocalService(); ResultList <MailHeaderExtended> rl = mailService.GetMailsByParams(acc.EmailAddress, folder, parFolder, sValues, start, limit); m.Per = rl.Per; m.List = (rl.List == null) ? null : rl.List.Cast <MailHeader>().ToList() as ICollection <MailHeader>; m.Totale = rl.Totale; } else { MailServerFacade mailServerFacade = MailServerFacade.GetInstance(acc); m = mailServerFacade.MailHeader_ResultList_Fetch(folder, parFolder, start, limit); } if (m != null && m.List != null) { CultureInfo ci = CultureInfo.InvariantCulture; System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Carrier)); if (acc.IsManaged) { listCarrier = m.List.Cast <MailHeaderExtended>().Select(h => { string mStatus = ""; string destinatario = ""; switch (parFolder) { case "I": mStatus = h.MailRating.ToString(); destinatario = h.From; break; case "O": case "AO": mStatus = ((int)h.MailStatus).ToString(); //per gestire il semaforo per gli invii da server non PEC if (!acc.IsPec && h.MailStatus == MailStatus.SENT) { mStatus = ((int)MailStatus.AVVENUTA_CONSEGNA).ToString(); } destinatario = h.To; break; default: MailUser muser = WebMailClientManager.getAccount(); string idnome = (from f in muser.Folders where f.Id.ToString() == folder select f.IdNome).First(); string tipo = (from f in muser.Folders where f.Id.ToString() == folder select f.TipoFolder).First(); switch (idnome) { case "1": case "3": mStatus = h.MailRating.ToString(); destinatario = h.From; break; case "2": mStatus = ((int)h.MailStatus).ToString(); //per gestire il semaforo per gli invii da server non PEC if (!acc.IsPec && h.MailStatus == MailStatus.SENT) { mStatus = ((int)MailStatus.AVVENUTA_CONSEGNA).ToString(); } destinatario = h.To; break; default: switch (tipo) { case "E": mStatus = h.MailRating.ToString(); destinatario = h.From; break; case "D": mStatus = ((int)h.MailStatus).ToString(); //per gestire il semaforo per gli invii da server non PEC if (!acc.IsPec && h.MailStatus == MailStatus.SENT) { mStatus = ((int)MailStatus.AVVENUTA_CONSEGNA).ToString(); } destinatario = h.To; break; } break; } break; } ActiveUp.Net.Mail.Address add = ActiveUp.Net.Mail.Parser.ParseAddress(destinatario); if (String.IsNullOrEmpty(add.Name)) { destinatario = add.Email; } else { destinatario = System.Text.RegularExpressions.Regex.Replace(add.Name, "Per conto di:?", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Trim(); if (destinatario.EndsWith("\"")) { destinatario.Replace("\"", ""); } } Carrier c = new Carrier { id = h.UniqueId, from = destinatario.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\"", "\\\""), date = h.Date.ToString("dd/MM/yyyy HH:mm:ss", ci), subject = h.Subject.Replace("\"", "\\\""), sStatus = mStatus, mStatus = ((int)h.MailStatus).ToString(), attach = Convert.ToInt16(h.HasAttachments).ToString(), utente = ((h.MailStatus == MailStatus.SCARICATA) ? "" : h.Utente), dimen = h.Dimensione }; return(c); //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //ser.WriteObject(ms, c); //string jsonString = Encoding.UTF8.GetString(ms.ToArray()); //ms.Close(); //return jsonString; }); } else { listCarrier = m.List.Select(h => { Carrier c = new Carrier() { id = h.UniqueId, from = h.From.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\"", "\\\""), date = h.Date.ToString("dd/MM/yyyy HH:mm:ss", ci), subject = h.Subject.Replace("\"", "\\\""), mStatus = ((int)MailStatus.UNKNOWN).ToString(), sStatus = "", attach = "" }; return(c); //System.IO.MemoryStream ms = new System.IO.MemoryStream(); //ser.WriteObject(ms, c); //string jsonString = Encoding.UTF8.GetString(ms.ToArray()); //ms.Close(); //return jsonString; }); } } else { model.Message = "Nessun ritrovamento"; return(this.Request.CreateResponse <CarrierModel>(HttpStatusCode.OK, model)); //message = "Nessun ritrovamento"; } //StringBuilder sb = new StringBuilder(); //sb.Append("{\"TotalCount\":\"" + m.Totale.ToString() + "\","); //sb.Append("\"Message\":\"" + message + "\""); //if (items != null) //{ // sb.Append(",\"Data\":[" + String.Join(",", items.ToArray()) + "]"); //} //else //{ // sb.Append(",\"Data\": []"); //} //sb.Append("}"); model.TotalCount = m.Totale.ToString(); model.data = listCarrier.ToList(); model.success = "true"; return(this.Request.CreateResponse <CarrierModel>(HttpStatusCode.OK, model)); //context.Response.ContentType = "application/json"; //context.Response.AppendHeader("Content-type", "text/json"); //context.Response.Write(sb.ToString()); }
public HttpResponseMessage AbilitaFolders(string idemail, string itemselector) { FoldersSendersModel model = new FoldersSendersModel(); SendersFoldersService sfs = new SendersFoldersService(); if (string.IsNullOrEmpty(idemail) && string.IsNullOrEmpty(itemselector)) { model.success = "false"; model.message = "Valori insufficienti nella richiesta"; this.Request.CreateResponse <FoldersSendersModel>(HttpStatusCode.OK, model); } try { // model.FoldersList = listaCartelleNonAbilitate.ToArray(); string[] folders = itemselector.Split(';'); var foldersAbilitati = sfs.GetFoldersAbilitatiByIdSender(int.Parse(idemail)).Select(z => z.IdNome).ToArray(); var ff = Array.ConvertAll(foldersAbilitati, x => x.ToString()); var foldersda = folders.Except(ff); var foldersa = ff.Except(folders); foreach (string s in foldersda) { sfs.InsertAbilitazioneFolder(Convert.ToInt32(s), Convert.ToInt32(idemail), 0); } foreach (string s in foldersa) { if (s != "1" && s != "2" && s != "3") { sfs.DeleteAbilitazioneFolder(Convert.ToInt32(s), Convert.ToInt32(idemail)); } } MailUser m = WebMailClientManager.getAccount(); if (m != null) { WebMailClientManager.AccountRemove(); MailServerConfigFacade facade = MailServerConfigFacade.GetInstance(); MailUser account = facade.GetUserByUserId(m.UserId); MailServerFacade serverFacade = MailServerFacade.GetInstance(account); account.Validated = true; WebMailClientManager.SetAccount(account); } model.success = "true"; MailLocalService mailLocalService = new MailLocalService(); CacheManager <List <ActiveUp.Net.Common.DeltaExt.Action> > .set(CacheKeys.FOLDERS_ACTIONS, mailLocalService.GetFolderDestinationForAction()); } catch (Exception ex) { if (!ex.GetType().Equals(typeof(ManagedException))) { ManagedException mEx = new ManagedException("Eccezione nella lettura delle cartelle", "ERR_F005", string.Empty, ex.Message, null); ErrorLogInfo er = new ErrorLogInfo(mEx); er.objectID = idemail.ToString(); log.Error(er); model.success = "false"; model.message = mEx.Message; } else { model.success = "false"; model.message = ex.Message; } } return(this.Request.CreateResponse <FoldersSendersModel>(HttpStatusCode.OK, model)); }