private List <MailAddress> GetExternalMailOutside(CRSMEmail message) { var prevActivity = message; var result = new List <MailAddress>(); if (prevActivity == null) { return(result); } if (prevActivity.IsIncome == true) { var mailFrom = prevActivity.MailFrom.With(_ => _.Trim()); if (!string.IsNullOrEmpty(mailFrom)) { result = EmailParser.ParseAddresses(mailFrom); } } else { result = EmailParser.ParseAddresses(prevActivity.MailTo); } return(result); }
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); }
//TODO: need optimizae DB requests internal static bool IsFromInternalUser(PXGraph graph, CRSMEmail message) { var @from = EmailParser.ParseAddresses(message.MailFrom).FirstOrDefault().With(_ => _?.Address).With(_ => _?.Trim()); PXSelect <Users, Where2 <Where <Users.guest, Equal <False>, Or <Users.guest, IsNull> >, And <Users.email, Equal <Required <Users.email> > > > > . Clear(graph); var usersEmail = (Users)PXSelect <Users, Where2 <Where <Users.guest, Equal <False>, Or <Users.guest, IsNull> >, And <Users.email, Equal <Required <Users.email> > > > > . Select(graph, @from) != null; if (usersEmail) { return(true); } PXSelectJoin <EPEmployee, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > >, Where <EPEmployee.userID, IsNotNull, And <Contact.eMail, Equal <Required <Contact.eMail> > > > > . Clear(graph); return((EPEmployee)PXSelectJoin <EPEmployee, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > >, Where <EPEmployee.userID, IsNotNull, And <Contact.eMail, Equal <Required <Contact.eMail> > > > > . Select(graph, @from) != null); }
//TODO: need optimizae DB requests internal static bool?IsFromInternalUser(PXGraph graph, CRSMEmail message) { var @from = EmailParser.ParseAddresses(message.MailFrom).FirstOrDefault().With(_ => _?.Address).With(_ => _?.Trim()); PXSelect <Users, Where2 < Where <Users.guest, Equal <False>, Or <Users.guest, IsNull> >, And <Users.email, Equal <Required <Users.email> > > > > .Clear(graph); var users = PXSelect <Users, Where2 < Where <Users.guest, Equal <False>, Or <Users.guest, IsNull> >, And <Users.email, Equal <Required <Users.email> > > > > .Select(graph, @from); bool disabledUser = users.Count > 0 && users.RowCast <Users>().All(_ => _.State == Users.state.Disabled); if (disabledUser) { return(null); } if (users.Count > 0) { return(true); } PXSelectJoin <EPEmployee, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > >, Where < EPEmployee.userID, IsNotNull, And <Contact.eMail, Equal <Required <Contact.eMail> > > > > .Clear(graph); var employees = PXSelectJoin <EPEmployee, LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > >, Where < EPEmployee.userID, IsNotNull, And <Contact.eMail, Equal <Required <Contact.eMail> > > > > .Select(graph, @from); bool disabledEmployee = employees.Count > 0 && employees.RowCast <EPEmployee>().All(_ => _.Status == EPEmployee.status.Inactive); if (disabledEmployee) { return(null); } if (employees.Count > 0) { return(true); } return(false); }
internal static bool IsOwnerEqualUser(PXGraph graph, CRSMEmail message, Guid?owner) { var @from = EmailParser.ParseAddresses(message.MailFrom).FirstOrDefault().With(_ => _.Address).With(_ => _.Trim()); PXSelect <Users, Where <Users.email, Equal <Required <Users.email> > > > .Clear(graph); var usersEmail = (Users)PXSelect <Users, Where <Users.email, Equal <Required <Users.email> > > > .Select(graph, @from); if (usersEmail != null) { return(usersEmail.PKID == owner); } return(false); }
protected void RemoveAddress(MailAddressList recipients, string addrStr) { if (string.IsNullOrEmpty(addrStr) || recipients.Count == 0) { return; } var addresses = EmailParser.ParseAddresses(addrStr); foreach (MailAddress address in addresses) { recipients.Remove(address); } }
public static EmailAddressType ParceAddress(string address) { if (String.IsNullOrEmpty(address)) { return(null); } foreach (MailAddress item in EmailParser.ParseAddresses(address)) { return(new EmailAddressType() { EmailAddress = item.Address, Name = item.DisplayName }); } return(null); }
public static EmailAddressType[] ParceAddresses(string address) { if (String.IsNullOrEmpty(address)) { return(null); } List <EmailAddressType> addresses = new List <EmailAddressType>(); foreach (MailAddress item in EmailParser.ParseAddresses(address)) { addresses.Add(new EmailAddressType() { EmailAddress = item.Address, Name = item.DisplayName }); } return(addresses.ToArray()); }
protected static string MergeAddressList(CRSMEmail email, string addressList, string sourceList) { if (string.IsNullOrEmpty(addressList)) { return(sourceList); } List <MailAddress> result = new List <MailAddress>(); var index = new HashSet <string>(); foreach (MailAddress address in EmailParser.ParseAddresses(addressList)) { if (index.Contains(address.Address)) { continue; } if (email.MailTo != null && email.MailTo.Contains(address.Address, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (email.MailCc != null && email.MailCc.Contains(address.Address, StringComparison.InvariantCultureIgnoreCase)) { continue; } if (email.MailBcc != null && email.MailBcc.Contains(address.Address, StringComparison.InvariantCultureIgnoreCase)) { continue; } index.Add(address.Address); result.Add(address); } return(result.Count == 0 ? sourceList : string.IsNullOrEmpty(sourceList) ? PXDBEmailAttribute.ToString(result) : PXDBEmailAttribute.AppendAddresses(sourceList, PXDBEmailAttribute.ToString(result))); }
protected List <MailAddress> GenerateAddress(Contact employeeContact, Users user) { string displayName = null; string address = null; if (user != null && user.PKID != null) { var userDisplayName = user.FullName.With(_ => _.Trim()); if (!string.IsNullOrEmpty(userDisplayName)) { displayName = userDisplayName; } var userAddress = user.Email.With(_ => _.Trim()); if (!string.IsNullOrEmpty(userAddress)) { address = userAddress; } } if (employeeContact != null && employeeContact.BAccountID != null) { var employeeDisplayName = employeeContact.DisplayName.With(_ => _.Trim()); if (!string.IsNullOrEmpty(employeeDisplayName)) { displayName = employeeDisplayName; } var employeeAddress = employeeContact.EMail.With(_ => _.Trim()); if (!string.IsNullOrEmpty(employeeAddress)) { address = employeeAddress; } } return(string.IsNullOrEmpty(address) ? null : EmailParser.ParseAddresses( PXDBEmailAttribute.FormatAddressesWithSingleDisplayName(address, displayName) )); }
public virtual IEnumerable checkForDuplicates(PXAdapter adapter) { DuplicateDocument duplicateDocument = DuplicateDocuments.Current ?? DuplicateDocuments.Select(); if (duplicateDocument == null) { return(adapter.Get()); } var prevStatus = duplicateDocument.DuplicateStatus; var prevIsDirty = Base.Caches[DuplicateDocuments.Cache.GetMain(duplicateDocument).GetType()].IsDirty; if (CheckIsActive()) { duplicateDocument.DuplicateFound = true; duplicateDocument = DuplicateDocuments.Update(duplicateDocument); Duplicates.View.Clear(); var result = Duplicates.Select().ToList(); bool anyFound = result != null && result.Count > 0; duplicateDocument.DuplicateFound = anyFound; duplicateDocument.DuplicateStatus = anyFound ? DuplicateStatusAttribute.PossibleDuplicated : DuplicateStatusAttribute.Validated; duplicateDocument = DuplicateDocuments.Update(duplicateDocument); if (duplicateDocument.ContactType?.IsIn(ContactTypesAttribute.Lead, ContactTypesAttribute.Person) == true && Setup.Current?.ContactEmailUnique == true && !String.IsNullOrWhiteSpace(duplicateDocument.Email)) { try { var parsedEmail = EmailParser.ParseAddresses(duplicateDocument.Email).FirstOrDefault(); if (result .Select(item => item.GetItem <DuplicateContact>()) .Where(item => !String.IsNullOrWhiteSpace(item.EMail) && item.ContactType.IsIn(ContactTypesAttribute.Lead, ContactTypesAttribute.Person)) .Any(item => item.EMail.Contains(parsedEmail.Address))) { DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.email>( duplicateDocument, duplicateDocument.Email, new PXSetPropertyException(Messages.ContactEmailNotUnique, PXErrorLevel.Warning)); } } catch (Exception) { } } } if (duplicateDocument.DuplicateStatus != prevStatus) { Base.Actions.PressSave(); } else { Base.Caches[DuplicateDocuments.Cache.GetMain(duplicateDocument).GetType()].IsDirty = prevIsDirty; } if (duplicateDocument.DuplicateStatus == DuplicateStatusAttribute.PossibleDuplicated || duplicateDocument.DuplicateFound == true) { DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.duplicateStatus>(duplicateDocument, duplicateDocument.DuplicateStatus, new PXSetPropertyException(WarningMessage, PXErrorLevel.Warning)); } else { DuplicateDocuments.Cache.RaiseExceptionHandling <DuplicateDocument.duplicateStatus>(duplicateDocument, duplicateDocument.DuplicateStatus, null); } return(adapter.Get()); }