protected override bool Process(Package package) { var account = package.Account; if (account.IncomingProcessing != true || account.CreateActivity != true) { return(false); } PXGraph graph = package.Graph; var message = package.Message; if (!string.IsNullOrEmpty(message.Exception) || message.RefNoteID != null) { return(false); } List <String> addressesList = new List <String>( ); addressesList.Add(package.Address); if (package.Message.IsIncome == false && package.Message.MailTo != null && package.Account.EmailAccountType == EmailAccountTypesAttribute.Exchange) { addressesList.InsertRange(0, EmailParser.ParseAddresses(message.MailTo).Select(m => m.Address)); } foreach (String address in addressesList) { PXSelect <Contact, Where <Contact.eMail, Equal <Required <Contact.eMail> > > > . Clear(package.Graph); var contact = (Contact)PXSelect <Contact, Where <Contact.eMail, Equal <Required <Contact.eMail> > > > . SelectWindowed(package.Graph, 0, 1, address); if (contact != null && contact.ContactID != null) { graph.EnsureCachePersistence(typeof(Contact)); graph.EnsureCachePersistence(typeof(BAccount)); message.ContactID = contact.ContactID; PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Clear(package.Graph); BAccount baCcount = PXSelect <BAccount, Where <BAccount.bAccountID, Equal <Required <BAccount.bAccountID> > > > . Select(package.Graph, contact.BAccountID); if (baCcount != null) { message.BAccountID = baCcount.BAccountID; } return(true); } } return(false); }
protected static void AddCachesIntoGraph(PXGraph graph, IEnumerable <Type> caches) { foreach (Type cache in caches) { graph.EnsureCachePersistence(cache); graph.Caches[cache].AllowInsert = graph.Caches[cache].AllowUpdate = graph.Caches[cache].AllowDelete = false; } }
protected override bool Process(Package package) { PXGraph graph = package.Graph; EMailAccount account = package.Account; CRSMEmail message = package.Message; if (account != null && ( (account.ForbidRouting ?? false) || !(account.RouteEmployeeEmails ?? false) )) { return(false); } bool?isFromInternalUser = IsFromInternalUser(graph, message); var recipients = new MailAddressList(); if (isFromInternalUser == true) { recipients.AddRange(GetExternalRecipient(graph, message)); } else if (isFromInternalUser == false) { recipients.AddRange(GetInternalRecipient(graph, message)); } else { return(false); // for those users and employees which are disabled or RouteEmails switched off } RemoveAddress(recipients, message.MailFrom); RemoveAddress(recipients, message.MailTo); RemoveAddress(recipients, message.MailCc); RemoveAddress(recipients, message.MailBcc); if (recipients.Count == 0) { return(false); } if (isFromInternalUser == true) { SendCopyMessageToOutside(graph, package.Account, message, recipients); MarkAsRoutingEmail(graph, message); MarkAsRead(graph, message); } else { SendCopyMessageToInside(graph, package.Account, message, recipients); } graph.EnsureCachePersistence(message.GetType()); return(true); }
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 SendCopyMessage(PXGraph graph, EMailAccount account, CRSMEmail message, string email) { var cache = graph.Caches[message.GetType()]; var copy = (CRSMEmail)cache.CreateCopy(message); copy.NoteID = null; copy.EmailNoteID = null; copy.IsIncome = false; copy.ParentNoteID = message.NoteID; copy.MailTo = email; //TODO: need add address description copy.MailCc = null; copy.MailBcc = null; copy.MPStatus = MailStatusListAttribute.PreProcess; copy.ClassID = CRActivityClass.EmailRouting; new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy)); copy.RefNoteID = null; copy.BAccountID = null; copy.ContactID = null; copy.Pop3UID = null; copy.ImapUID = null; var imcUid = Guid.NewGuid(); copy.ImcUID = imcUid; copy.MessageId = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty); copy.OwnerID = null; copy.WorkgroupID = null; copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy)); //Update owner and reset owner if employee not found copy.OwnerID = message.OwnerID; try { cache.Update(copy); } catch (PXSetPropertyException) { copy.OwnerID = null; copy = (CRSMEmail)cache.CreateCopy(cache.Update(copy)); } copy.WorkgroupID = message.WorkgroupID; var noteFiles = PXNoteAttribute.GetFileNotes(cache, message); if (noteFiles != null) { PXNoteAttribute.SetFileNotes(cache, copy, noteFiles); } graph.EnsureCachePersistence(copy.GetType()); }
public static PXView GetView(this PXGraph graph, Type fieldType, BqlCommand select) { PXView view; graph.Views.TryGetValue(fieldType.FullName, out view); if (view == null) { view = new PXView(graph, false, @select); graph.Views.Add(fieldType.FullName, view); graph.EnsureCachePersistence(fieldType.DeclaringType); } return(view); }
private void CreateFile(PXGraph graph, Guid noteId, Guid newFileId, string name, byte[] content) { var noteDocCache = graph.Caches[typeof(NoteDoc)]; var noteDoc = (NoteDoc)noteDocCache.CreateInstance(); noteDoc.NoteID = noteId; noteDoc.FileID = newFileId; noteDocCache.Insert(noteDoc); graph.EnsureCachePersistence(typeof(NoteDoc)); var uploadFileCache = graph.Caches[typeof(CommonMailReceiveProvider.UploadFile)]; var uploadFile = (CommonMailReceiveProvider.UploadFile)uploadFileCache.CreateInstance(); uploadFile.FileID = newFileId; uploadFile.LastRevisionID = 1; uploadFile.Versioned = true; uploadFile.IsPublic = false; if (name.Length > 200) { name = name.Substring(0, 200); } uploadFile.Name = newFileId + @"\" + name; uploadFile.PrimaryScreenID = "CR306015"; //TODO: need review uploadFileCache.Insert(uploadFile); graph.EnsureCachePersistence(typeof(CommonMailReceiveProvider.UploadFile)); var fileRevisionCache = graph.Caches[typeof(UploadFileRevision)]; var fileRevision = (UploadFileRevision)fileRevisionCache.CreateInstance(); fileRevision.FileID = newFileId; fileRevision.FileRevisionID = 1; fileRevision.Data = content; fileRevision.Size = UploadFileHelper.BytesToKilobytes(content.Length); fileRevisionCache.Insert(fileRevision); graph.EnsureCachePersistence(typeof(UploadFileRevision)); }
protected override bool Process(Package package) { PXGraph graph = package.Graph; EMailAccount account = package.Account; CRSMEmail message = package.Message; if (account != null && (account.ForbidRouting ?? false)) { return(false); } var isFromInternalUser = IsFromInternalUser(graph, message); var recipients = new MailAddressList(); if (isFromInternalUser) { recipients.AddRange(GetExternalRecipient(graph, message)); } else { recipients.AddRange(GetInternalRecipient(graph, message)); } RemoveAddress(recipients, message.MailFrom); RemoveAddress(recipients, message.MailTo); RemoveAddress(recipients, message.MailCc); RemoveAddress(recipients, message.MailBcc); if (recipients.Count == 0) { return(false); } if (isFromInternalUser) { SendCopyMessageToOutside(graph, package.Account, message, recipients); MarkAsRoutingEmail(graph, message); MarkAsRead(graph, message); } else { SendCopyMessageToInside(graph, package.Account, message, recipients); } graph.EnsureCachePersistence(message.GetType()); return(true); }
protected override bool Process(Package package) { PXGraph graph = package.Graph; CRSMEmail message = package.Message; if (message.IsIncome != true) { return(false); } var isFromInternalUser = message.ClassID == CRActivityClass.EmailRouting; var recipients = new MailAddressList(); if (isFromInternalUser) { recipients.AddRange(GetFromInternal(graph, message)); } else { recipients.AddRange(GetFromExternal(graph, message)); } RemoveAddress(recipients, message.MailFrom); RemoveAddress(recipients, message.MailTo); RemoveAddress(recipients, message.MailCc); RemoveAddress(recipients, message.MailBcc); if (recipients.Count == 0) { return(false); } SendCopyMessageToInside(package.Graph, package.Account, message, recipients); graph.EnsureCachePersistence(message.GetType()); return(true); }