private static void GetDefaultPolicyInfo(MailboxSession mailboxSession, MessageItem messageItem, object compactDefaultPolicy, out Guid defaultGuid, out int periodInStartDateEtc) { defaultGuid = Guid.Empty; periodInStartDateEtc = 0; Guid guid = Guid.Empty; Guid guid2 = Guid.Empty; if (compactDefaultPolicy != null & compactDefaultPolicy is byte[]) { Dictionary <Guid, StoreTagData> dictionary = MrmFaiFormatter.Deserialize(compactDefaultPolicy as byte[], mailboxSession.MailboxOwner); List <ElcPolicySettings> list = new List <ElcPolicySettings>(); Dictionary <string, ContentSetting> itemClassToPolicyMapping = new Dictionary <string, ContentSetting>(); foreach (StoreTagData storeTagData in dictionary.Values) { if (storeTagData.Tag.Type == ElcFolderType.All) { foreach (ContentSetting contentSetting in storeTagData.ContentSettings.Values) { ElcPolicySettings.ParseContentSettings(list, contentSetting); if (contentSetting.MessageClass.Equals(ElcMessageClass.AllMailboxContent, StringComparison.CurrentCultureIgnoreCase)) { guid2 = storeTagData.Tag.RetentionId; } else if (contentSetting.MessageClass.Equals(ElcMessageClass.VoiceMail, StringComparison.CurrentCultureIgnoreCase)) { guid = storeTagData.Tag.RetentionId; } } } } string effectiveItemClass = ElcPolicySettings.GetEffectiveItemClass(messageItem.ClassName); if (effectiveItemClass.StartsWith(ElcMessageClass.VoiceMail.TrimEnd(new char[] { '*' }), StringComparison.OrdinalIgnoreCase) && !guid.Equals(Guid.Empty)) { defaultGuid = guid; } else if (!guid2.Equals(Guid.Empty)) { defaultGuid = guid2; } ContentSetting applyingPolicy = ElcPolicySettings.GetApplyingPolicy(list, messageItem.ClassName, itemClassToPolicyMapping); if (applyingPolicy != null && applyingPolicy.RetentionEnabled && applyingPolicy.AgeLimitForRetention != null) { periodInStartDateEtc = (int)applyingPolicy.AgeLimitForRetention.Value.TotalDays; return; } if (applyingPolicy == null) { defaultGuid = Guid.Empty; } } }
internal static ContentSetting GetApplyingPolicy(IEnumerable <ElcPolicySettings> elcPolicies, string itemClass, Dictionary <string, ContentSetting> itemClassToPolicyMapping, string cacheKey) { if (itemClassToPolicyMapping.ContainsKey(cacheKey)) { return(itemClassToPolicyMapping[cacheKey]); } if (elcPolicies == null) { return(null); } string effectiveItemClass = ElcPolicySettings.GetEffectiveItemClass(itemClass); ContentSetting contentSetting = null; foreach (ElcPolicySettings elcPolicySettings in elcPolicies) { if (elcPolicySettings.MessageClass == "*") { contentSetting = elcPolicySettings.ContentSettings; } else if (!string.IsNullOrEmpty(effectiveItemClass)) { if (string.Compare(itemClass, elcPolicySettings.MessageClass, StringComparison.OrdinalIgnoreCase) == 0) { contentSetting = elcPolicySettings.ContentSettings; break; } if (elcPolicySettings.MessageClass.EndsWith("*") && effectiveItemClass.StartsWith(elcPolicySettings.MessageClass.TrimEnd(new char[] { '*' }), StringComparison.OrdinalIgnoreCase)) { contentSetting = elcPolicySettings.ContentSettings; break; } } } itemClassToPolicyMapping[cacheKey] = contentSetting; return(contentSetting); }