示例#1
0
        private void CreateOofRule(ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber)
        {
            Guid guid = Guid.NewGuid();

            byte[]      replyTemplateMessageEntryID = this.CreateOofReplyTemplate(this.itemStore, guid, reply, messageClass, oofReplyType);
            Restriction restriction = this.GetRestriction(conditionType);

            RuleAction[] actions = new RuleAction[]
            {
                new RuleAction.OOFReply(replyTemplateMessageEntryID, guid)
            };
            Rule rule = new Rule();

            rule.Name              = ruleName;
            rule.Provider          = "Microsoft Exchange OOF Assistant";
            rule.StateFlags        = (RuleStateFlags.KeepOOFHistory | RuleStateFlags.OnlyWhenOOFEx);
            rule.ExecutionSequence = sequenceNumber;
            rule.Condition         = restriction;
            rule.Actions           = actions;
            if (conditionType == RuleGenerator.ConditionType.KnownExternal)
            {
                rule.IsExtended = true;
            }
            this.ruleManager.Add(rule);
            RuleGenerator.TracerPfd.TracePfd <int, string>((long)this.GetHashCode(), "PFD IWO {0} Creating OOF rule {1}", 21399, rule.Name);
        }
 internal static ReplyBodySerializer Serialize(ReplyBody replyBody)
 {
     return(new ReplyBodySerializer
     {
         Message = replyBody.RawMessage,
         LanguageTag = replyBody.LanguageTag
     });
 }
        internal ReplyBody Deserialize()
        {
            ReplyBody replyBody = ReplyBody.Create();

            replyBody.RawMessage  = this.Message;
            replyBody.LanguageTag = this.LanguageTag;
            return(replyBody);
        }
示例#4
0
 public static UserOofSettings CreateDefault()
 {
     return(new UserOofSettings
     {
         internalReply = ReplyBody.CreateDefault(),
         externalReply = ReplyBody.CreateDefault(),
         oofState = OofState.Disabled,
         setByLegacyClient = false,
         externalAudience = ExternalAudience.None
     });
 }
示例#5
0
        private void HandleSenderGroupRule(Rule rule, bool senderGroupEnabled, ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber, OofState mailboxOofState)
        {
            int i = 0;

            while (i < 5)
            {
                i++;
                try
                {
                    if (rule == null)
                    {
                        if (senderGroupEnabled && !RuleGenerator.IsEmptyString(reply.RawMessage))
                        {
                            this.CreateOofRule(reply, ruleName, messageClass, oofReplyType, conditionType, sequenceNumber);
                        }
                        else
                        {
                            RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Sender group '{1}' and rule doesn't exist. Nothing to do.", this.itemStore.MailboxOwner, ruleName);
                        }
                    }
                    else if (senderGroupEnabled && !RuleGenerator.IsEmptyString(reply.RawMessage))
                    {
                        this.UpdateOofRule(rule, reply, ruleName, messageClass, oofReplyType, conditionType, sequenceNumber, mailboxOofState);
                    }
                    else
                    {
                        this.ruleManager.Remove(rule);
                    }
                    break;
                }
                catch (SaveConflictException ex)
                {
                    if (i == 5)
                    {
                        RuleGenerator.Tracer.TraceError <IExchangePrincipal, int, SaveConflictException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retried {2} times, rethrowing", this.itemStore.MailboxOwner, 5, ex);
                        throw;
                    }
                    RuleGenerator.Tracer.TraceError <IExchangePrincipal, SaveConflictException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retrying", this.itemStore.MailboxOwner, ex);
                }
                catch (ObjectNotFoundException ex2)
                {
                    if (i == 5)
                    {
                        RuleGenerator.Tracer.TraceError <IExchangePrincipal, int, ObjectNotFoundException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retried {2} times, rethrowing", this.itemStore.MailboxOwner, 5, ex2);
                        throw;
                    }
                    RuleGenerator.Tracer.TraceError <IExchangePrincipal, ObjectNotFoundException>((long)this.GetHashCode(), "Mailbox:{0}: Exception updating item, exception = {1}, retrying", this.itemStore.MailboxOwner, ex2);
                }
            }
        }
示例#6
0
 private byte[] CreateOofReplyTemplate(MailboxSession itemStore, Guid templateGuid, ReplyBody reply, string messageClass, OofReplyType oofReplyType)
 {
     byte[] entryId;
     using (ReplyTemplate replyTemplate = ReplyTemplate.Create(itemStore, templateGuid, messageClass, oofReplyType))
     {
         RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Creating ReplyTemplate to Body: '{1}'", this.itemStore.MailboxOwner, reply.RawMessage);
         if (this.userOofSettings.SetByLegacyClient)
         {
             replyTemplate.PlainTextBody = reply.RawMessage;
         }
         else
         {
             replyTemplate.CharSet  = this.GetDefaultCharsetForCountryCode(reply.LanguageTag);
             replyTemplate.HtmlBody = reply.RawMessage;
         }
         replyTemplate.SaveChanges();
         RuleGenerator.TracerPfd.TracePfd <int, IExchangePrincipal, string>((long)this.GetHashCode(), "PFD IWO {0} Mailbox:{1}: Created ReplyTemplate to Body: '{2}'", 17303, this.itemStore.MailboxOwner, reply.RawMessage);
         entryId = replyTemplate.EntryId;
     }
     return(entryId);
 }
示例#7
0
        private void UpdateOofRule(Rule rule, ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber, OofState mailboxOofState)
        {
            bool        flag        = false;
            bool        flag2       = false;
            Restriction restriction = this.GetRestriction(conditionType);

            RuleAction.OOFReply ruleAction    = (RuleAction.OOFReply)rule.Actions[0];
            ReplyTemplate       replyTemplate = null;

            try
            {
                replyTemplate = ReplyTemplate.Find(this.itemStore, ruleAction);
                if (replyTemplate != null)
                {
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updating ReplyTemplate to Body: '{1}'", this.itemStore.MailboxOwner, reply.RawMessage);
                    if (this.userOofSettings.SetByLegacyClient)
                    {
                        flag2 = !replyTemplate.PlainTextBody.Equals(reply.RawMessage, StringComparison.Ordinal);
                        replyTemplate.PlainTextBody = reply.RawMessage;
                    }
                    else
                    {
                        string value = TextUtil.ConvertHtmlToPlainText(reply.RawMessage);
                        flag2 = !replyTemplate.PlainTextBody.Equals(value, StringComparison.Ordinal);
                        replyTemplate.CharSet  = this.GetDefaultCharsetForCountryCode(reply.LanguageTag);
                        replyTemplate.HtmlBody = reply.RawMessage;
                    }
                    replyTemplate.OofReplyType = oofReplyType;
                    replyTemplate.ClassName    = messageClass;
                    replyTemplate.SaveChanges();
                    if (flag2)
                    {
                        rule.StateFlags |= RuleStateFlags.ClearOOFHistory;
                        byte[] propValue = this.itemStore.__ContainedMapiStore.GlobalIdFromId(rule.ID);
                        OofHistory.RemoveOofHistoryEntriesWithProperty(this.itemStore, mailboxOofState != OofState.Disabled, OofHistory.PropId.GlobalRuleId, propValue);
                        RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated reply template for global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                    }
                }
                else
                {
                    Guid   guid = Guid.NewGuid();
                    byte[] replyTemplateMessageEntryID = this.CreateOofReplyTemplate(this.itemStore, guid, reply, messageClass, oofReplyType);
                    rule.Actions = new RuleAction[]
                    {
                        new RuleAction.OOFReply(replyTemplateMessageEntryID, guid)
                    };
                    flag = true;
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Created new reply template and updated global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                }
                RuleGenerator.TracerPfd.TracePfd <int, string, IExchangePrincipal>((long)this.GetHashCode(), "PFD IWO {0} Updated OOF Rule '{1}' for Mailbox:{2}", 25495, ruleName, this.itemStore.MailboxOwner);
            }
            finally
            {
                if (replyTemplate != null)
                {
                    replyTemplate.Dispose();
                }
            }
            if (!ConditionComparer.Equals(rule.Condition, restriction))
            {
                rule.Condition = restriction;
                flag           = true;
                RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated rule '{1}' with new condition", this.itemStore.MailboxOwner, ruleName);
            }
            if (flag || flag2)
            {
                this.ruleManager.Update(rule);
            }
        }
示例#8
0
        private void GenerateOofRules(Rule[] rules, string ruleNameSuffix, string replyMessageAddendum)
        {
            Rule      rule          = null;
            Rule      rule2         = null;
            Rule      rule3         = null;
            int       num           = 8;
            string    text          = "Microsoft.Exchange.OOF.InternalSenders" + ruleNameSuffix;
            string    text2         = "Microsoft.Exchange.OOF.KnownExternalSenders" + ruleNameSuffix;
            string    text3         = "Microsoft.Exchange.OOF.AllExternalSenders" + ruleNameSuffix;
            ReplyBody internalReply = this.userOofSettings.InternalReply;
            ReplyBody externalReply = this.userOofSettings.ExternalReply;

            foreach (Rule rule4 in rules)
            {
                if (rule4 != null)
                {
                    if (rule4.Provider == "Microsoft Exchange OOF Assistant")
                    {
                        if (rule4.Name == text)
                        {
                            if (rule != null)
                            {
                                this.ruleManager.Remove(rule4);
                            }
                            else
                            {
                                rule = rule4;
                            }
                        }
                        else if (rule4.Name == text3)
                        {
                            if (rule2 != null)
                            {
                                this.ruleManager.Remove(rule4);
                            }
                            else
                            {
                                rule2 = rule4;
                            }
                        }
                        else if (rule4.Name == text2)
                        {
                            if (rule3 != null)
                            {
                                this.ruleManager.Remove(rule4);
                            }
                            else
                            {
                                rule3 = rule4;
                            }
                        }
                        else
                        {
                            this.ruleManager.Remove(rule4);
                        }
                    }
                    else if (rule4.Provider == "MSFT:TDX OOF Rules" && rule4.Actions.Length > 0 && rule4.Actions[0] is RuleAction.OOFReply)
                    {
                        this.ruleManager.Remove(rule4);
                    }
                }
            }
            this.HandleSenderGroupRule(rule, this.userOofSettings.OofState != OofState.Disabled, internalReply, text, "IPM.Note.Rules.OofTemplate.Microsoft", this.userOofSettings.SetByLegacyClient ? OofReplyType.Single : OofReplyType.Internal, RuleGenerator.ConditionType.Internal, num, this.userOofSettings.OofState);
            num++;
            this.HandleSenderGroupRule(rule3, this.userOofSettings.OofState != OofState.Disabled && this.userOofSettings.ExternalAudience == ExternalAudience.Known && !this.userOofSettings.SetByLegacyClient, externalReply, text2, "IPM.Note.Rules.ExternalOofTemplate.Microsoft", OofReplyType.External, RuleGenerator.ConditionType.KnownExternal, num, this.userOofSettings.OofState);
            this.HandleSenderGroupRule(rule2, this.userOofSettings.OofState != OofState.Disabled && this.userOofSettings.ExternalAudience == ExternalAudience.All && !this.userOofSettings.SetByLegacyClient, externalReply, text3, "IPM.Note.Rules.ExternalOofTemplate.Microsoft", OofReplyType.External, RuleGenerator.ConditionType.AllExternal, num, this.userOofSettings.OofState);
        }