Exemplo n.º 1
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);
 }
Exemplo n.º 2
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);
            }
        }