Exemplo n.º 1
0
        public static ReplyTemplate Find(MailboxSession session, RuleAction.OOFReply ruleAction)
        {
            ReplyTemplate result;

            try
            {
                if (ruleAction.ReplyTemplateMessageEntryID == null)
                {
                    result = ReplyTemplate.FindByTemplateGuid(session, ruleAction);
                }
                else
                {
                    StoreObjectId messageId   = StoreObjectId.FromProviderSpecificId(ruleAction.ReplyTemplateMessageEntryID);
                    MessageItem   messageItem = MessageItem.Bind(session, messageId, new PropertyDefinition[]
                    {
                        ItemSchema.ReplyTemplateId
                    });
                    messageItem.OpenAsReadWrite();
                    ReplyTemplate.Tracer.TraceDebug <IExchangePrincipal, ByteArray>(0L, "Mailbox:{0}: Found reply template by entry Id. Entry id={1}", session.MailboxOwner, new ByteArray(ruleAction.ReplyTemplateMessageEntryID));
                    ReplyTemplate.TracerPfd.TracePfd <int, IExchangePrincipal, ByteArray>(0L, "PFD IWO {0} Mailbox:{1}: Found reply template by entry Id. Entry id={2}", 31639, session.MailboxOwner, new ByteArray(ruleAction.ReplyTemplateMessageEntryID));
                    result = new ReplyTemplate(messageItem);
                }
            }
            catch (ObjectNotFoundException)
            {
                ReplyTemplate.Tracer.TraceDebug <IExchangePrincipal, ByteArray>(0L, "Mailbox:{0}: Found no reply template by entry Id. Entry id={1}", session.MailboxOwner, new ByteArray(ruleAction.ReplyTemplateMessageEntryID));
                result = ReplyTemplate.FindByTemplateGuid(session, ruleAction);
            }
            return(result);
        }
Exemplo n.º 2
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.º 3
0
        private static ReplyTemplate FindByTemplateGuid(MailboxSession session, RuleAction.OOFReply ruleAction)
        {
            MessageItem messageItem = null;

            try
            {
                using (Folder folder = Folder.Bind(session, DefaultFolderType.Inbox))
                {
                    byte[] replyTemplateEntryIdFromTemplateGuid = ReplyTemplate.GetReplyTemplateEntryIdFromTemplateGuid(folder, ruleAction.ReplyTemplateGuid);
                    if (replyTemplateEntryIdFromTemplateGuid != null)
                    {
                        StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(replyTemplateEntryIdFromTemplateGuid);
                        messageItem = MessageItem.Bind(session, storeObjectId, new PropertyDefinition[]
                        {
                            ItemSchema.ReplyTemplateId
                        });
                        messageItem.OpenAsReadWrite();
                        ReplyTemplate.Tracer.TraceDebug <IExchangePrincipal, Guid, byte[]>(0L, "Mailbox:{0}: Found reply template by GUID. GUID={1}, Entry Id={2}", session.MailboxOwner, ruleAction.ReplyTemplateGuid, storeObjectId.GetBytes());
                    }
                    else
                    {
                        ReplyTemplate.Tracer.TraceDebug <IExchangePrincipal, Guid>(0L, "Mailbox:{0}: Found no reply template by GUID. GUID={1}", session.MailboxOwner, ruleAction.ReplyTemplateGuid);
                        messageItem = null;
                    }
                }
            }
            catch (ObjectNotFoundException)
            {
                return(null);
            }
            if (messageItem != null)
            {
                return(new ReplyTemplate(messageItem));
            }
            return(null);
        }
Exemplo n.º 4
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);
            }
        }