internal static bool ArePolicyPropertiesValid(ContentSetting policy, object objectToTrace, string mailboxAddress)
        {
            if (policy == null)
            {
                ElcPolicySettings.Tracer.TraceDebug(0L, "{0}: Policy is null.", new object[]
                {
                    objectToTrace
                });
                return(false);
            }
            if (!policy.RetentionEnabled)
            {
                ElcPolicySettings.Tracer.TraceDebug <object, string>(0L, "{0}: Policy '{1}' is disabled.", objectToTrace, policy.Name);
                return(false);
            }
            EnhancedTimeSpan?ageLimitForRetention = policy.AgeLimitForRetention;
            TimeSpan?        timeSpan             = (ageLimitForRetention != null) ? new TimeSpan?(ageLimitForRetention.GetValueOrDefault()) : null;

            if (timeSpan == null || timeSpan.Value.TotalDays <= 0.0)
            {
                ElcPolicySettings.Tracer.TraceDebug <object, string>(0L, "{0}: Age limit of Policy '{1}' is not greater than 0.", objectToTrace, policy.Name);
                Globals.ELCLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_InvalidRetentionAgeLimit, "Managed Folder Assistant Run", new object[]
                {
                    policy.Name,
                    mailboxAddress
                });
                return(false);
            }
            return(true);
        }
        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);
        }
Example #4
0
        private static Dictionary <Guid, StoreTagData> Deserialize(Stream xmlStream, IExchangePrincipal mailboxOwner, out List <Guid> deletedTags, out RetentionHoldData retentionHoldData, bool returnRetentionHoldData, out Dictionary <Guid, StoreTagData> defaultArchiveTagData, out bool fullCrawlRequired)
        {
            fullCrawlRequired = false;
            Dictionary <Guid, StoreTagData> dictionary = new Dictionary <Guid, StoreTagData>();

            defaultArchiveTagData = new Dictionary <Guid, StoreTagData>();
            retentionHoldData     = default(RetentionHoldData);
            deletedTags           = new List <Guid>();
            if (xmlStream.Length == 0L)
            {
                MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0} has empty config message.", mailboxOwner);
                return(dictionary);
            }
            using (XmlTextReader xmlTextReader = SafeXmlFactory.CreateSafeXmlTextReader(xmlStream))
            {
                Exception ex = null;
                try
                {
                    xmlTextReader.MoveToContent();
                    if (returnRetentionHoldData)
                    {
                        if (!xmlTextReader.ReadToFollowing("RetentionHold"))
                        {
                            MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}. Config item exists, but there is no RetentionHold node in it.", mailboxOwner);
                        }
                        else
                        {
                            if (xmlTextReader.MoveToAttribute("Enabled"))
                            {
                                retentionHoldData.HoldEnabled = bool.Parse(xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("RetentionComment"))
                            {
                                retentionHoldData.Comment = xmlTextReader.Value;
                            }
                            if (xmlTextReader.MoveToAttribute("RetentionUrl"))
                            {
                                retentionHoldData.Url = xmlTextReader.Value;
                            }
                            MrmFaiFormatter.Tracer.TraceDebug(0L, "Mailbox:{0}. Config item exists, and there is a RetentionHold node in it. HoldEnabled: {1}. Comment: {2}. Url: {3}", new object[]
                            {
                                mailboxOwner,
                                retentionHoldData.HoldEnabled,
                                retentionHoldData.Comment,
                                retentionHoldData.Url
                            });
                        }
                    }
                    while (!MrmFaiFormatter.IsTagNode(xmlTextReader) && !MrmFaiFormatter.IsArchiveSyncNode(xmlTextReader) && xmlTextReader.Read())
                    {
                    }
                    if (string.CompareOrdinal(xmlTextReader.Name, "ArchiveSync") == 0)
                    {
                        if (xmlTextReader.MoveToAttribute("FullCrawlRequired"))
                        {
                            fullCrawlRequired = bool.Parse(xmlTextReader.Value);
                        }
                        while (!MrmFaiFormatter.IsTagNode(xmlTextReader))
                        {
                            if (!xmlTextReader.Read())
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}. Config item exists, but there is no ArchiveSync node in it.", mailboxOwner);
                    }
                    for (;;)
                    {
                        bool flag  = string.CompareOrdinal(xmlTextReader.Name, "PolicyTag") == 0;
                        bool flag2 = string.CompareOrdinal(xmlTextReader.Name, "ArchiveTag") == 0;
                        bool flag3 = string.CompareOrdinal(xmlTextReader.Name, "DefaultArchiveTag") == 0;
                        bool flag4 = string.CompareOrdinal(xmlTextReader.Name, "DeletedTag") == 0;
                        if (!flag && !flag2 && !flag3 && !flag4)
                        {
                            break;
                        }
                        MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}. Found at least 1 tag in Config item.", mailboxOwner);
                        if (flag4)
                        {
                            Guid empty = System.Guid.Empty;
                            if (xmlTextReader.MoveToAttribute("Guid"))
                            {
                                empty = new Guid(xmlTextReader.Value);
                            }
                            deletedTags.Add(empty);
                            xmlTextReader.Read();
                        }
                        else
                        {
                            StoreTagData storeTagData = new StoreTagData();
                            storeTagData.Tag = new RetentionTag();
                            storeTagData.Tag.IsArchiveTag = flag2;
                            if (xmlTextReader.MoveToAttribute("ObjectGuid"))
                            {
                                storeTagData.Tag.Guid = new Guid(xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("Guid"))
                            {
                                storeTagData.Tag.RetentionId = new Guid(xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("Name"))
                            {
                                storeTagData.Tag.Name = xmlTextReader.Value;
                            }
                            if (xmlTextReader.MoveToAttribute("Comment"))
                            {
                                storeTagData.Tag.Comment = xmlTextReader.Value;
                            }
                            if (xmlTextReader.MoveToAttribute("Type"))
                            {
                                storeTagData.Tag.Type = (ElcFolderType)Enum.Parse(typeof(ElcFolderType), xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("MustDisplayComment"))
                            {
                                storeTagData.Tag.MustDisplayCommentEnabled = bool.Parse(xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("IsVisible"))
                            {
                                storeTagData.IsVisible = bool.Parse(xmlTextReader.Value);
                            }
                            if (xmlTextReader.MoveToAttribute("OptedInto"))
                            {
                                storeTagData.OptedInto = bool.Parse(xmlTextReader.Value);
                            }
                            xmlTextReader.Read();
                            if (string.CompareOrdinal(xmlTextReader.Name, "LocalizedName") == 0)
                            {
                                storeTagData.Tag.LocalizedRetentionPolicyTagName = MrmFaiFormatter.ReadLocalizedStrings(xmlTextReader, "Name");
                            }
                            if (string.CompareOrdinal(xmlTextReader.Name, "LocalizedComment") == 0)
                            {
                                storeTagData.Tag.LocalizedComment = MrmFaiFormatter.ReadLocalizedStrings(xmlTextReader, "Comment");
                            }
                            MrmFaiFormatter.Tracer.TraceDebug(0L, "Mailbox:{0}. Done reading the tag. Name: {1}. Type: {2}. IsVisible: {3}. OptedInto: {4}", new object[]
                            {
                                mailboxOwner,
                                storeTagData.Tag.Name,
                                storeTagData.Tag.Type,
                                storeTagData.IsVisible,
                                storeTagData.OptedInto
                            });
                            while (string.CompareOrdinal(xmlTextReader.Name, "ContentSettings") == 0)
                            {
                                ContentSetting contentSetting = new ContentSetting();
                                Guid           key;
                                if (xmlTextReader.MoveToAttribute("Guid"))
                                {
                                    key = new Guid(xmlTextReader.Value);
                                }
                                else
                                {
                                    key = default(Guid);
                                }
                                if (xmlTextReader.MoveToAttribute("ExpiryAgeLimit"))
                                {
                                    contentSetting.AgeLimitForRetention = new EnhancedTimeSpan?(EnhancedTimeSpan.FromDays(double.Parse(xmlTextReader.Value)));
                                }
                                contentSetting.RetentionEnabled = true;
                                if (xmlTextReader.MoveToAttribute("MessageClass"))
                                {
                                    contentSetting.MessageClass = xmlTextReader.Value;
                                }
                                if (xmlTextReader.MoveToAttribute("RetentionAction"))
                                {
                                    contentSetting.RetentionAction = (RetentionActionType)Enum.Parse(typeof(RetentionActionType), xmlTextReader.Value, true);
                                }
                                storeTagData.ContentSettings[key] = contentSetting;
                                MrmFaiFormatter.Tracer.TraceDebug(0L, "Mailbox:{0}. Done reading the content setting. RetentionEnabled: {1}. MessageClass: {2}. RetentionAction: {3}", new object[]
                                {
                                    mailboxOwner,
                                    contentSetting.RetentionEnabled,
                                    contentSetting.MessageClass,
                                    contentSetting.RetentionAction
                                });
                                xmlTextReader.Read();
                            }
                            if (!flag3)
                            {
                                dictionary[storeTagData.Tag.RetentionId] = storeTagData;
                            }
                            else
                            {
                                defaultArchiveTagData[storeTagData.Tag.RetentionId] = storeTagData;
                            }
                        }
                        if ((string.CompareOrdinal(xmlTextReader.Name, "PolicyTag") == 0 || string.CompareOrdinal(xmlTextReader.Name, "ArchiveTag") == 0 || string.CompareOrdinal(xmlTextReader.Name, "DefaultArchiveTag") == 0 || string.CompareOrdinal(xmlTextReader.Name, "DeletedTag") == 0) && xmlTextReader.NodeType == XmlNodeType.EndElement)
                        {
                            xmlTextReader.Read();
                        }
                    }
                    MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal>(0L, "Mailbox:{0}. Found no MTA or retention or DefaultArchive or Deleted tag in Config item.", mailboxOwner);
                }
                catch (XmlException ex2)
                {
                    ex = ex2;
                }
                catch (ArgumentException ex3)
                {
                    ex = ex3;
                }
                catch (FormatException ex4)
                {
                    ex = ex4;
                }
                if (ex != null)
                {
                    xmlStream.Position = 0L;
                    string text = new StreamReader(xmlStream).ReadToEnd();
                    MrmFaiFormatter.Tracer.TraceDebug <IExchangePrincipal, string, Exception>(0L, "Mailbox:{0}. Config item is corrupt. Config item: '{1}'. Exception: '{2}'", mailboxOwner, text, ex);
                    Globals.ELCLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_CorruptTagConfigItem, null, new object[]
                    {
                        mailboxOwner,
                        text,
                        ex.ToString()
                    });
                }
            }
            return(dictionary);
        }
 internal static void ParseContentSettings(List <ElcPolicySettings> policyList, ContentSetting elcContentSetting)
 {
     if (ElcMessageClass.IsMultiMessageClass(elcContentSetting.MessageClass))
     {
         string[] array = elcContentSetting.MessageClass.Split(ElcMessageClass.MessageClassDelims, StringSplitOptions.RemoveEmptyEntries);
         foreach (string text in array)
         {
             policyList.Add(new ElcPolicySettings(elcContentSetting, text));
         }
         return;
     }
     policyList.Add(new ElcPolicySettings(elcContentSetting, elcContentSetting.MessageClass));
 }
 internal ElcPolicySettings(ContentSetting contentSettings, string messageClass)
 {
     this.contentSettings = contentSettings;
     this.messageClass    = messageClass;
 }