private Restriction GetRestriction(RuleGenerator.ConditionType conditionType) { Restriction result; if (conditionType == RuleGenerator.ConditionType.Internal) { result = RuleConditionFactory.CreateInternalSendersGroupCondition(); } else if (conditionType == RuleGenerator.ConditionType.KnownExternal) { result = RuleConditionFactory.CreateKnownExternalSendersGroupCondition(UserContacts.GetEmailAddresses(this.itemStore)); } else { if (conditionType != RuleGenerator.ConditionType.AllExternal) { throw new ArgumentException("Unknown ConditionType"); } result = RuleConditionFactory.CreateAllExternalSendersGroupCondition(); } return(result); }
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); }
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); } }
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); } } }