public void TestDistributionListsMembershipDomainAliases() { var imap = new ImapClientSimulator(); var smtpClientSimulator = new SmtpClientSimulator(); Application application = SingletonProvider <TestSetup> .Instance.GetApp(); DomainAlias domainAlias = _domain.DomainAliases.Add(); domainAlias.AliasName = "dummy-example.com"; domainAlias.Save(); Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES // var recipients = new List <string>(); recipients.Clear(); recipients.Add("*****@*****.**"); DistributionList list3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); list3.Mode = eDistributionListMode.eLMMembership; list3.Save(); // THIS MESSAGE SHOULD FAIL - Membership required, unknown sender domain CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); list3.Delete(); // THIS MESSAGE SHOULD SUCCED - Membership required, sender domain is now an alias for test.com. recipients = new List <string>(); recipients.Clear(); recipients.Add("*****@*****.**"); recipients.Add("*****@*****.**"); list3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); list3.Mode = eDistributionListMode.eLMMembership; list3.Save(); smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"); ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
public void TestDistributionListsMembershipDomainAliases() { var oIMAP = new IMAPClientSimulator(); var oSMTP = new SMTPClientSimulator(); Application application = SingletonProvider <TestSetup> .Instance.GetApp(); DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); Account oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES // var oRecipients = new List <string>(); oRecipients.Clear(); oRecipients.Add("*****@*****.**"); DistributionList oList3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList3.Mode = eDistributionListMode.eLMMembership; oList3.Save(); // THIS MESSAGE SHOULD FAIL - Membership required, unknown sender domain CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); oList3.Delete(); // THIS MESSAGE SHOULD SUCCED - Membership required, sender domain is now an alias for test.com. oRecipients = new List <string>(); oRecipients.Clear(); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oList3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList3.Mode = eDistributionListMode.eLMMembership; oList3.Save(); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
public void TestRenameDomainWithList() { DistributionList oList = _domain.DistributionLists.Add(); oList.Address = "*****@*****.**"; oList.Active = true; oList.Save(); DistributionListRecipient oRecipient = oList.Recipients.Add(); oRecipient.RecipientAddress = "*****@*****.**"; oRecipient.Save(); oRecipient = oList.Recipients.Add(); oRecipient.RecipientAddress = "*****@*****.**"; oRecipient.Save(); oRecipient = oList.Recipients.Add(); oRecipient.RecipientAddress = "*****@*****.**"; oRecipient.Save(); _domain.Name = "example.com"; _domain.Save(); DistributionList list = _domain.DistributionLists[0]; Assert.AreEqual("*****@*****.**", list.Address); Assert.AreEqual("*****@*****.**", list.Recipients[0].RecipientAddress); Assert.AreEqual("*****@*****.**", list.Recipients[1].RecipientAddress); Assert.AreEqual("*****@*****.**", list.Recipients[2].RecipientAddress); }
public static ContactBase AddADRecipientToContacts(UserContext userContext, ADRecipient adRecipient) { if (userContext == null) { throw new ArgumentNullException("userContext"); } if (adRecipient == null) { throw new ArgumentNullException("adRecipient"); } Participant primaryParticipant = ContactUtilities.GetPrimaryParticipant(adRecipient); if (primaryParticipant == null) { return(null); } if (adRecipient is IADDistributionList) { DistributionList distributionList = DistributionList.Create(userContext.MailboxSession, userContext.ContactsFolderId); distributionList.Add(new Participant(adRecipient)); distributionList.DisplayName = (string)adRecipient[ADRecipientSchema.DisplayName]; distributionList.Save(SaveMode.ResolveConflicts); return(distributionList); } Contact contact = Contact.Create(userContext.MailboxSession, userContext.ContactsFolderId); ContactUtilities.AddContactProperties(userContext, contact, adRecipient, primaryParticipant); contact.Save(SaveMode.ResolveConflicts); return(contact); }
public void TestDistributionListAnnouncementFromDomainAlias() { var smtpClientSimulator = new SmtpClientSimulator(); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES // Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var recipients = new List <string>(); recipients.Add("*****@*****.**"); DistributionList list3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", recipients); list3.Mode = eDistributionListMode.eLMAnnouncement; list3.RequireSenderAddress = "*****@*****.**"; list3.Save(); // THIS MESSAGE SHOULD FAIL CustomAsserts.Throws <DeliveryFailedException>(() => smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); DomainAlias domainAlias = _domain.DomainAliases.Add(); domainAlias.AliasName = "dummy-example.com"; domainAlias.Save(); // THIS MESSAGE SHOULD SUCCEED smtpClientSimulator.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1"); ImapClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
public void TestDistributionList() { DistributionList oList = _domain.DistributionLists.Add(); oList.Address = "persis'*****@*****.**"; oList.Active = true; oList.Save(); DistributionListRecipient oRecipient = oList.Recipients.Add(); oRecipient.RecipientAddress = "test@te'st.com"; oRecipient.Save(); oRecipient.RecipientAddress = "tes'*****@*****.**"; oRecipient.Save(); oList.Delete(); }
public DistributionList AddDistributionList(Domain oDomain, string sAddress, List <string> recipients) { DistributionList oList = oDomain.DistributionLists.Add(); oList.Active = true; oList.Address = sAddress; oList.Save(); // Add recipients foreach (string recipient in recipients) { DistributionListRecipient oRecipient = oList.Recipients.Add(); oRecipient.RecipientAddress = recipient; oRecipient.Save(); Marshal.ReleaseComObject(oRecipient); } return(oList); }
public DistributionList AddDistributionList(Domain domain, string sAddress, List <string> recipients) { DistributionList list = domain.DistributionLists.Add(); list.Active = true; list.Address = sAddress; list.Save(); // Add recipients foreach (string recipientAddress in recipients) { DistributionListRecipient recipient = list.Recipients.Add(); recipient.RecipientAddress = recipientAddress; recipient.Save(); Marshal.ReleaseComObject(recipient); } return(list); }
public void TestDistributionListAnnouncementFromDomainAlias() { var oIMAP = new IMAPClientSimulator(); var oSMTP = new SMTPClientSimulator(); Application application = SingletonProvider <TestSetup> .Instance.GetApp(); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES // Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var oRecipients = new List <string>(); oRecipients.Add("*****@*****.**"); DistributionList oList3 = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList3.Mode = eDistributionListMode.eLMAnnouncement; oList3.RequireSenderAddress = "*****@*****.**"; oList3.Save(); // THIS MESSAGE SHOULD FAIL CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); // THIS MESSAGE SHOULD SUCCEED CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); }
public void TestListContainingLists() { var test = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); var daRecipients = new List <string>() { "*****@*****.**", "*****@*****.**" }; var dbRecipients = new List <string> { "*****@*****.**", "*****@*****.**", }; var dcRecipients = new List <string> { "*****@*****.**", "*****@*****.**", }; DistributionList daList = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", daRecipients); daList.Mode = eDistributionListMode.eLMPublic; daList.Save(); DistributionList dbList = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", dbRecipients); dbList.Mode = eDistributionListMode.eLMPublic; dbList.Save(); DistributionList dcList = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", dcRecipients); dbList.Mode = eDistributionListMode.eLMPublic; dbList.Save(); var recipients = new List <string>() { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; var smtpClient = new SMTPClientSimulator(); CustomAssert.IsTrue(smtpClient.Send(test.Address, recipients, "test", "test")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); // Member in list IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); // Member in list IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); // Included in To list IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); // Included in To list }
public void TestDistributionLists() { // Fetch default domain // Add distribution list var oRecipients = new List <string>(); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); Account oAccount; oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Add alias pointing at the distribution list. SingletonProvider <TestSetup> .Instance.AddAlias(_domain, "*****@*****.**", "*****@*****.**"); var oSMTP = new SMTPClientSimulator(); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 2", "Mail 2")); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 3", "Mail 3")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); oRecipients.Add("*****@*****.**"); SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 1); // Wait for the message to be completely delivered. The above assertion isn't enough to confirm that. Thread.Sleep(1000); oAccount = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test"); DistributionList oList = SingletonProvider <TestSetup> .Instance.AddDistributionList(_domain, "*****@*****.**", oRecipients); oList.Mode = eDistributionListMode.eLMAnnouncement; oList.RequireSenderAddress = oAccount.Address; oList.RequireSMTPAuth = false; oList.Save(); CustomAssert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); CustomAssert.IsTrue(oSMTP.Send(oAccount.Address, "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 2); oList.Mode = eDistributionListMode.eLMMembership; oList.Save(); CustomAssert.IsFalse(oSMTP.Send(oAccount.Address, "*****@*****.**", "Mail 1", "Mail 1")); // THIS MESSAGE SHOULD SUCCED CustomAssert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "Mail 1", "Mail 1")); IMAPClientSimulator.AssertMessageCount("*****@*****.**", "test", "Inbox", 3); }
private GetGroupResponse GetPDLData() { GetGroupResponse getGroupResponse = new GetGroupResponse(); MailboxSession mailboxIdentityMailboxSession = base.CallContext.SessionCache.GetMailboxIdentityMailboxSession(); ItemId sourceId = this.itemId; IdAndSession idAndSession = null; if (this.parentFolderid != null && this.parentFolderid.BaseFolderId != null) { IdAndSession idAndSession2 = base.GetIdAndSession(this.parentFolderid.BaseFolderId); if (idAndSession2 != null && idAndSession2.Session.IsPublicFolderSession) { idAndSession = idAndSession2; } } if (IdConverter.EwsIdIsConversationId(this.itemId.Id)) { try { Persona persona; if (idAndSession != null) { persona = Persona.LoadFromPersonaId(idAndSession.Session, null, this.itemId, Persona.FullPersonaShape, null, idAndSession.Id); } else { persona = Persona.LoadFromPersonIdWithGalAggregation(mailboxIdentityMailboxSession, IdConverter.EwsIdToPersonId(this.itemId.Id), Persona.FullPersonaShape, null); } if (persona.Attributions.Length > 0) { sourceId = persona.Attributions[0].SourceId; for (int i = 1; i < persona.Attributions.Length; i++) { StoreId storeId = IdConverter.EwsIdToMessageStoreObjectId(persona.Attributions[i].SourceId.Id); using (Item item = Item.Bind(mailboxIdentityMailboxSession, storeId, new PropertyDefinition[] { ContactSchema.PersonId })) { item.OpenAsReadWrite(); item[ContactSchema.PersonId] = PersonId.CreateNew(); item.Save(SaveMode.NoConflictResolution); } } RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Success"); } else { ExTraceGlobals.GetGroupTracer.TraceError((long)this.hashCode, "ItemId is PersonaId but Persona has no linked contacts (attributions array is empty)."); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Skipped"); } } catch (LocalizedException arg) { ExTraceGlobals.GetGroupTracer.TraceError <LocalizedException>((long)this.hashCode, "Failed to unlink PDLs: {0}", arg); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "UnlinkDupedPDLs", "Failed"); } } IdAndSession idAndSession3 = base.IdConverter.ConvertItemIdToIdAndSessionReadOnly(sourceId); StoreSession storeSession; if (idAndSession != null) { storeSession = idAndSession.Session; } else { storeSession = ((idAndSession3.Session as MailboxSession) ?? base.CallContext.SessionCache.GetMailboxIdentityMailboxSession()); } using (DistributionList distributionList = DistributionList.Bind(storeSession, idAndSession3.Id)) { if (distributionList == null) { this.WriteDebugTrace("No PDL was found"); return(getGroupResponse); } PersonId personId = (PersonId)distributionList[ContactSchema.PersonId]; getGroupResponse.PersonaId = IdConverter.PersonaIdFromPersonId(storeSession.MailboxGuid, personId); if (!distributionList.GetValueOrDefault <bool>(ItemSchema.ConversationIndexTracking, false)) { try { distributionList.OpenAsReadWrite(); distributionList[ItemSchema.ConversationIndexTracking] = true; distributionList.Save(SaveMode.NoConflictResolution); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "SetConversationIndexTracking", "Success"); } catch (LocalizedException arg2) { ExTraceGlobals.GetGroupTracer.TraceError <LocalizedException>((long)this.hashCode, "Failed to set ConversationIndexTracking on PDL: {0}", arg2); RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLogger.Current, "SetConversationIndexTracking", "Failed"); } } if (!this.IsMembersInResultSet) { return(getGroupResponse); } int count = distributionList.Count; getGroupResponse.MembersCount = count; this.WriteDebugTrace("Total PDL members count is " + count); if (this.paging.Offset < 0 || count <= this.paging.Offset) { this.WriteDebugTrace(string.Format("Provided offset is out of range - members count is {0}, offset is {1}.", count, this.paging.Offset)); return(getGroupResponse); } distributionList.Sort(this.PDlMembersComparer); List <Persona> list = new List <Persona>(); List <string> list2 = new List <string>(); Dictionary <string, int> dictionary = new Dictionary <string, int>(); int num = Math.Min(count, this.paging.Offset + this.paging.MaxRows); for (int j = this.paging.Offset; j < num; j++) { DistributionListMember distributionListMember = distributionList[j]; if (distributionListMember.Participant == null) { if (num < count) { num++; } getGroupResponse.MembersCount--; } else { bool flag = false; Persona persona2 = GetGroupCommand.CreatePersonaFromDistributionListMember(mailboxIdentityMailboxSession, distributionListMember, out flag); if (flag) { list2.Add(persona2.EmailAddress.EmailAddress); dictionary.Add(persona2.EmailAddress.EmailAddress, list.Count); } list.Add(persona2); } } if (list2.Count > 0) { IRecipientSession galscopedADRecipientSession = base.CallContext.ADRecipientSessionContext.GetGALScopedADRecipientSession(base.CallContext.EffectiveCaller.ClientSecurityContext); Result <ADRawEntry>[] array = galscopedADRecipientSession.FindByLegacyExchangeDNs(list2.ToArray(), new PropertyDefinition[] { ADObjectSchema.Id, ADRecipientSchema.DisplayName, ADRecipientSchema.PrimarySmtpAddress, ADRecipientSchema.RecipientType, ADRecipientSchema.RecipientTypeDetails, ADRecipientSchema.LegacyExchangeDN }); foreach (Result <ADRawEntry> result in array) { if (result.Data != null) { Persona personaFromADObject = GetGroupCommand.GetPersonaFromADObject(result.Data); string key = result.Data[ADRecipientSchema.LegacyExchangeDN] as string; int num2; if (dictionary.ContainsKey(key) && dictionary.TryGetValue(key, out num2) && num2 >= 0) { list[num2] = personaFromADObject; } } } } list.Sort(this.PersonaComparer); Persona[] array3 = new Persona[list.Count]; list.CopyTo(0, array3, 0, list.Count); getGroupResponse.Members = array3; this.WriteDebugTrace("PDL members count loaded in the response is " + getGroupResponse.Members.Length); } return(getGroupResponse); }