public static string[] GetEmailAddresses(MailboxSession itemStore) { return(UserContacts.GetEmailAddressesFromContacts(itemStore)); }
private static string[] GetEmailAddressesFromContacts(MailboxSession itemStore) { List <string> list = new List <string>(); PropertyDefinition[] dataColumns = new PropertyDefinition[] { ItemSchema.Id, ContactSchema.Email1EmailAddress, ContactSchema.Email2EmailAddress, ContactSchema.Email3EmailAddress, StoreObjectSchema.ItemClass, ContactSchema.Email1AddrType, ContactSchema.Email2AddrType, ContactSchema.Email3AddrType }; List <StoreObjectId> contactsFolders = UserContacts.GetContactsFolders(itemStore); foreach (StoreObjectId storeObjectId in contactsFolders) { try { using (Folder folder = Folder.Bind(itemStore, storeObjectId)) { using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, null, dataColumns)) { for (;;) { object[][] rows = queryResult.GetRows(100); if (rows.GetLength(0) == 0) { break; } foreach (object[] array2 in rows) { string text = array2[4] as string; if (!string.IsNullOrEmpty(text)) { if (ObjectClass.IsContact(text)) { int num = 5; int j = 1; while (j <= 3) { string text2 = array2[j] as string; string a = array2[num] as string; if (!(a == "EX") && !string.IsNullOrEmpty(text2)) { string text3 = text2.Trim(); if (text3.Length > 0) { list.Add(text3); } } j++; num++; } } else if (ObjectClass.IsDistributionList(text)) { VersionedId versionedId = array2[0] as VersionedId; if (versionedId != null) { Participant[] array3 = DistributionList.ExpandDeep(itemStore, versionedId.ObjectId); foreach (Participant participant in array3) { if (!(participant.RoutingType == "EX") && !string.IsNullOrEmpty(participant.EmailAddress)) { string text4 = participant.EmailAddress.Trim(); if (text4.Length > 0) { list.Add(text4); } } } } } } } } } } } catch (ObjectNotFoundException arg) { UserContacts.Tracer.TraceDebug <IExchangePrincipal, StoreObjectId, ObjectNotFoundException>(0L, "Mailbox:{0}: Exception while binding or query folder={0}, while mining emails for known contacts, exception={2}", itemStore.MailboxOwner, storeObjectId, arg); } } return(UserContacts.SortAndRemoveDuplicates(list.ToArray(), itemStore)); }
private Restriction GetRestriction(RuleGenerator.ConditionType conditionType) { Restriction result; if (conditionType == RuleGenerator.ConditionType.Internal) { result = RuleConditionFactory.CreateInternalSendersGroupCondition(); } else if (conditionType == RuleGenerator.ConditionType.KnownExternal) { result = RuleConditionFactory.CreateKnownExternalSendersGroupCondition(UserContacts.GetEmailAddresses(this.itemStore)); } else { if (conditionType != RuleGenerator.ConditionType.AllExternal) { throw new ArgumentException("Unknown ConditionType"); } result = RuleConditionFactory.CreateAllExternalSendersGroupCondition(); } return(result); }