예제 #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);
 }
예제 #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);
            }
        }
예제 #3
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);
        }
예제 #4
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);
                }
            }
        }
예제 #5
0
 public static ReplyTemplate Create(MailboxSession session, Guid templateGuid, string messageClass, OofReplyType oofReplyType)
 {
     ReplyTemplate.Tracer.TraceDebug <IExchangePrincipal, Guid, string>(0L, "Mailbox:{0}: Creating new reply template. GUID={1}, MessageClass={2}", session.MailboxOwner, templateGuid, messageClass);
     ReplyTemplate.TracerPfd.TracePfd(0L, "PFD IWO {0} Mailbox:{1}: Created new reply template. GUID={2}, MessageClass={3}", new object[]
     {
         23447,
         session.MailboxOwner,
         templateGuid,
         messageClass
     });
     return(new ReplyTemplate(session, templateGuid, messageClass, oofReplyType));
 }
예제 #6
0
 private ReplyTemplate(MailboxSession session, Guid templateGuid, string messageClass, OofReplyType oofReplyType)
 {
     using (Folder folder = Folder.Bind(session, DefaultFolderType.Inbox))
     {
         this.messageItem = MessageItem.CreateAssociated(session, folder.Id);
         using (this.messageItem.Body.OpenWriteStream(ReplyTemplate.ReplyTemplateBodyConfigurationPlain))
         {
         }
         object[] propertyValues = new object[]
         {
             templateGuid.ToByteArray(),
                  oofReplyType
         };
         this.messageItem.SetProperties(ReplyTemplate.NewPropsArray, propertyValues);
         this.messageItem.ClassName = messageClass;
     }
 }