public static PESAddressType IsInternal(AddressEntry entry, bool bUseRollingCache) { Logger.LogDebug( string.Format("Check RecipientCache for internal email address. AddressEntry.Address={0}, bUseRollingCache={1}", entry.Address, bUseRollingCache)); if (bUseRollingCache) { return IsInternalFromAddressEntryCache(entry, m_rollingAddressEntryCache); } return IsInternalFromAddressEntryCache(entry, m_addressEntryCache); }
public static void AddEntry(AddressEntry entry, bool isInternal, bool bRollingCache) { Logger.LogDebug( string.Format("AddEntry to cache: AddressEntry.Name={0}, IsInternal={1}, UseRollingCache={2}", entry.Name, isInternal, bRollingCache)); if (bRollingCache) { AddEntry(entry, isInternal, m_rollingAddressEntryCache, bRollingCache); } else { AddEntry(entry, isInternal, m_addressEntryCache, bRollingCache); } }
private static bool IsDistributionList(AddressEntry ae) { // TFS: 7117 (x-int 5746 fast track from 5.23) // Occasionally the user's OST file can become corrupt, which means that certain // properties on an address entry may throw a COM exception when accessed. // A work around is to delete the OST file, as it will be rebuilt. // This try-catch will keep us from crashing in these circumstances. try { return (ae.DisplayType == 1) || (ae.DisplayType == 5); // MapiDefines.DT_DISTLIST || MapiDefines.DT_PRIVATE_DISTLIST } catch (COMException ex) { Logger.LogError("Display Type for address entry is invalid."); Logger.LogError(ex); } // If the DisplayType property throws an exception then try to determine if this // is a distribution list by seeing whether there are any address entry members. return ae.Members != null; }
private static bool IsInternal(AddressEntry ae, bool bUseCache) { PESAddressType addressType = RecipientCache.IsInternal(ae, bUseCache); if (addressType == PESAddressType.Unknown) { bool isInternal = false; if (IsDistributionList(ae)) { m_trackNestedDistributionLists.Clear(); m_trackNestedDistributionLists.Add(ae.Name); isInternal = IsAllDistributionListInternal(ae.Members, bUseCache); RecipientCache.AddEntry(ae, isInternal, bUseCache); } else { isInternal = IsInternalAddress(ae, bUseCache); } return isInternal; } return (addressType == PESAddressType.Internal); }
private static PESAddressType IsInternalFromAddressEntryCache(AddressEntry entry, List<OutlookAddressEntry> addressCache) { // If there are no entries in the cache and the white list // bail out straight away. if ((addressCache.Count == 0) && (OutlookWhiteList.Count == 0)) { Logger.LogDebug("No entries in either whitelist or address cache: Return PESAddressType.Unknown"); return PESAddressType.Unknown; } string emailAddress = entry.Address; string name = entry.Name; if (String.IsNullOrEmpty(emailAddress)) emailAddress = name; if (OutlookWhiteList.IsWhiteListed(emailAddress)) { Logger.LogDebug("Found address in whitelist: Return AddressType.Internal"); return PESAddressType.Internal; } foreach (OutlookAddressEntry eae in addressCache) { if (string.Compare(emailAddress, eae.Address, true, CultureInfo.InvariantCulture) == 0) { PESAddressType addressType = eae.IsInternal ? PESAddressType.Internal : PESAddressType.External; Logger.LogDebug(string.Format("Found address in cache. Return PESAddressType.{0}", addressType.ToString())); return addressType; } } Logger.LogDebug("Address not found in whitelist or cache. Return PESAddressType.Unknown"); return PESAddressType.Unknown; }
private static void AddEntry(AddressEntry entry, bool isInternal, List<OutlookAddressEntry> addressEntryCache, bool bRollingCache) { lock (m_synchronizeCache) { string emailAddress = entry.Address; string name = entry.Name; if (String.IsNullOrEmpty(emailAddress)) emailAddress = name; foreach (OutlookAddressEntry eae in addressEntryCache) { if (string.Compare(emailAddress, eae.Address, true, CultureInfo.InvariantCulture) == 0) { return; } } addressEntryCache.Add(new OutlookAddressEntry(emailAddress, isInternal)); } }
private static bool IsAllDistributionListInternal(IEnumerator addressEntries, bool bUseCache) { if (addressEntries == null) { return AssumeInternalIfUnableToResolveDistributionList(); } while (addressEntries.MoveNext()) { AddressEntry ae = new AddressEntry(addressEntries.Current); if (IsDistributionList(ae)) { if (m_trackNestedDistributionLists.Contains(ae.Name)) { Logger.LogDebug("IsAllDistributionListInternal - Already found Group, so skipping: " + ae.Name); } else { m_trackNestedDistributionLists.Add(ae.Name); Logger.LogDebug("IsAllDistributionListInternal - checking Group: " + ae.Name); if (!IsAllDistributionListInternal(ae.Members, bUseCache)) { return false; } } } Logger.LogDebug("IsAllDistributionListInternal - checking recipient: " + ae.Name); if (!IsInternalAddress(ae, bUseCache)) { return false; } } return true; }
private static bool IsInternalAddress(AddressEntry addressEntry, bool bUseCache) { Logger.LogDebug(string.Format("Determine IsInternalAddress for AddressEntry.Name={0}, bUseCache={1}", addressEntry.Name, bUseCache)); PESAddressType addressType = RecipientCache.IsInternal(addressEntry, bUseCache); if (addressType == PESAddressType.Unknown) { Logger.LogDebug("Address not found in RecipientCache..."); string addressEntryType = addressEntry.Type; Logger.LogDebug(string.Format("AddressEntry.Type is {0}", addressEntryType)); bool isInternal = false; try { string addressEntryAddress = addressEntry.Address; if (string.Compare(addressEntryType, "EX", StringComparison.InvariantCultureIgnoreCase) == 0) { AddressType addressStandard = AddressUtils.GetAddressType(addressEntryAddress); if (addressStandard != AddressType.Smtp) { // Resolved in Exchange string smtpAddress = addressEntry.SMTPAddress; Logger.LogDebug(string.Format("Address is {0}, use AddressEntry.SMTPAddress instead.", addressStandard.ToString())); isInternal = String.IsNullOrEmpty(smtpAddress) || IsSMTPAddressInternal(smtpAddress); } else { isInternal = IsSMTPAddressInternal(addressEntryAddress); } } else if (string.Compare(addressEntryType, "SMTP", StringComparison.InvariantCultureIgnoreCase) == 0) { isInternal = IsSMTPAddressInternal(addressEntryAddress); } } catch (System.Exception e) { Logger.LogDebug(e.Message); } Logger.LogDebug(string.Format("IsInternalAddress: Return {0}", isInternal)); RecipientCache.AddEntry(addressEntry, isInternal, bUseCache); return isInternal; } return (addressType == PESAddressType.Internal); }