private void UpdateMessage(SMEmail message) { var emailType = message.GetType(); var cache = _graph.Caches[emailType]; message = (SMEmail)cache.Update(message); _graph.EnsureCachePersistence(emailType); var cached = _graph.Caches[message.GetType()].Locate(message); _graph.Persist(); _graph.SelectTimeStamp(); message = (SMEmail)cache.CreateCopy(cached); }
private void PreProcessMessage(SMEmail message) { var messageCopy = (SMEmail)_graph.Caches[message.GetType()].CreateCopy(message); messageCopy.MPStatus = MailStatusListAttribute.InProcess; messageCopy.Exception = null; if (messageCopy.MessageId == null) { messageCopy.MessageId = "<" + Guid.NewGuid() + "_acumatica@" + _account.OutcomingHostName + ">"; } UpdateMessage(messageCopy); _graph.Caches[message.GetType()].RestoreCopy(message, messageCopy); }
public void Process(SMEmail message) { using (PXTransactionScope sc = new PXTransactionScope()) { try { PreProcessMessage(message); } catch (Exception) { //Unable to change status - leave message alone. return; } try { ProcessMessage(message); PostProcessMessage(message); } catch (Exception ex) { this._graph.Clear(); if (message == null || _graph.Caches[message.GetType()].GetStatus(message) == PXEntryStatus.Inserted) { return; } message = PXSelect <SMEmail, Where <SMEmail.noteID, Equal <Required <SMEmail.noteID> > > > .SelectWindowed(_graph, 0, 1, message.NoteID); if (message != null) { var messageCopy = (SMEmail)_graph.Caches[message.GetType()].CreateCopy(message); messageCopy.Exception = ex.Message; messageCopy.MPStatus = MailStatusListAttribute.Failed; UpdateMessage(messageCopy); _graph.Caches[message.GetType()].RestoreCopy(message, messageCopy); } } sc.Complete(); } }
private void CreateEmail() { PXCache cache = _graph.Caches[typeof(SMEmail)]; _message = (SMEmail)cache.CreateCopy(cache.Insert()); _message.RefNoteID = _activity.NoteID; _message.MailAccountID = _account.EmailAccountID; var mimeMessage = _email.Message; _message.MailFrom = mimeMessage.From.With(_ => _.ToString()) ?? string.Empty; _message.MailReply = mimeMessage.ReplyTo.With(_ => _.ToString()) ?? string.Empty; _message.MailTo = mimeMessage.To.With(_ => _.ToString()) ?? string.Empty; _message.MailCc = mimeMessage.Cc.With(_ => _.ToString()) ?? string.Empty; _message.MailBcc = mimeMessage.Bcc.With(_ => _.ToString()) ?? string.Empty; _message.Subject = mimeMessage.Subject.With(_ => _.ToString()) ?? " "; if (!string.IsNullOrEmpty(_email.UID)) { if (_account.IncomingHostProtocol == IncomingMailProtocolsAttribute._IMAP) { _message.ImapUID = int.Parse(_email.UID); } else { _message.Pop3UID = _email.UID; } } _message.IsIncome = true; _message.MessageId = mimeMessage.MessageID; _message.MPStatus = MailStatusListAttribute.PreProcess; //TODO: need move into Automation steps var body = mimeMessage.BodyHtmlText; if (body == null) { if (mimeMessage.BodyText != null) { body = PX.Common.Tools.ConvertSimpleTextToHtml(mimeMessage.BodyText); } } else { body = mimeMessage.BodyHtmlText. Replace(Environment.NewLine, " "). Replace("<spanstyle", "<span style"); //NOTE: ms outlook style conflicts with our system style Regex baseTag = new Regex(@"<base(.|\n)*?>"); body = baseTag.Replace(body, String.Empty); } _message.Body = body ?? string.Empty; string clearedSubject; var ticket = DecodeTicket(_message.Subject, out clearedSubject); if (ticket != null) { _message.Ticket = CorrectTicket(ticket); } _message.Subject = clearedSubject; _message = (SMEmail)cache.CreateCopy(cache.Update(_message)); _graph.EnsureCachePersistence(_message.GetType()); var cached = _graph.Caches[_message.GetType()].Locate(_message); _graph.Persist(); _graph.SelectTimeStamp(); _message = (SMEmail)cache.CreateCopy(cached); }