internal static SmtpAddress Lookup(RecipientIdParameter recipId, IRecipientSession recipSession, OrganizationId orgId, bool getRecipientType, out Microsoft.Exchange.Data.Directory.Recipient.RecipientType?recipientType) { recipientType = null; bool flag = SmtpAddress.IsValidSmtpAddress(recipId.RawIdentity); if (!getRecipientType && flag) { return(SmtpAddress.Parse(recipId.RawIdentity)); } if (flag) { SmtpAddress smtpAddress = SmtpAddress.Parse(recipId.RawIdentity); ADRecipient adrecipientBySmtpAddress = JournalRuleObject.GetADRecipientBySmtpAddress(smtpAddress); if (adrecipientBySmtpAddress != null) { recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipientBySmtpAddress.RecipientType); } return(smtpAddress); } IEnumerable <ADRecipient> objects = recipId.GetObjects <ADRecipient>((null == orgId) ? null : orgId.OrganizationalUnit, recipSession ?? DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, orgId.ToADSessionSettings(), 429, "Lookup", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\JournalRule\\JournalRuleObject.cs")); ADRecipient adrecipient = null; using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { MimeRecipient mimeRecipient = null; try { mimeRecipient = MimeRecipient.Parse(recipId.RawIdentity, AddressParserFlags.IgnoreComments | AddressParserFlags.AllowSquareBrackets); } catch (MimeException) { } if (mimeRecipient == null || string.IsNullOrEmpty(mimeRecipient.Email) || !SmtpAddress.IsValidSmtpAddress(mimeRecipient.Email)) { throw new RecipientInvalidException(Strings.NoRecipients); } return(new SmtpAddress(mimeRecipient.Email)); } else { adrecipient = enumerator.Current; if (enumerator.MoveNext()) { throw new RecipientInvalidException(Strings.MoreThanOneRecipient); } } } if (adrecipient is IADOrgPerson && adrecipient.PrimarySmtpAddress.Equals(SmtpAddress.Empty)) { throw new RecipientInvalidException(Strings.NoSmtpAddress); } recipientType = new Microsoft.Exchange.Data.Directory.Recipient.RecipientType?(adrecipient.RecipientType); return(adrecipient.PrimarySmtpAddress); }
private void WriteRuleObject(TransportRule transportRule) { JournalingRule journalingRule = null; ParserException ex = null; try { journalingRule = (JournalingRule)JournalingRuleParser.Instance.GetRule(transportRule.Xml); } catch (ParserException ex2) { ex = ex2; } Exception ex3 = null; if (journalingRule != null && journalingRule.GccRuleType != GccType.None && !this.LawfulInterception) { return; } if (journalingRule != null && journalingRule.GccRuleType == GccType.None && this.LawfulInterception) { return; } JournalRuleObject journalRuleObject; if (journalingRule == null) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex.Message)); } else if (journalingRule.IsTooAdvancedToParse) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CannotParseRuleDueToVersion(transportRule.Name)); } else { journalRuleObject = new JournalRuleObject(); try { journalRuleObject.Deserialize(journalingRule); } catch (RecipientInvalidException ex4) { ex3 = ex4; } catch (JournalRuleCorruptException ex5) { ex3 = ex5; } } if (ex3 != null) { journalRuleObject = JournalRuleObject.CreateCorruptJournalRuleObject(transportRule, Strings.CorruptRule(transportRule.Name, ex3.Message)); } journalRuleObject.SetTransportRule(transportRule); this.WriteResult(journalRuleObject); }
internal JournalRuleObject(string name, bool enabled, SmtpAddress?recipient, SmtpAddress journalEmailAddress, JournalRuleScope ruleScope, DateTime?expiryDate, GccType gccRuleType) { base.Name = name; this.enabled = enabled; this.recipient = recipient; this.ruleScope = ruleScope; this.journalEmailAddress = journalEmailAddress; this.expiryDate = expiryDate; this.ruleType = JournalRuleObject.ConvertGccTypeToJournalRuleType(gccRuleType); }
internal static JournalNdrValidationCheckResult ValidateJournalNdrMailboxSetting(IConfigDataProvider dataProvider, SmtpAddress journalNdrToAddress) { ADJournalRuleStorageManager adjournalRuleStorageManager = null; bool flag = false; try { adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", dataProvider); } catch (RuleCollectionNotInAdException) { } if (adjournalRuleStorageManager != null) { adjournalRuleStorageManager.LoadRuleCollection(); RoutingAddress value = new RoutingAddress(journalNdrToAddress.ToString()); if (value == RoutingAddress.NullReversePath) { if (adjournalRuleStorageManager.Count > 0) { return(JournalNdrValidationCheckResult.JournalNdrCannotBeNullReversePath); } } else { foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in adjournalRuleStorageManager.GetRuleCollection()) { TransportRule transportRule = (TransportRule)rule; JournalRuleObject journalRuleObject = new JournalRuleObject(); journalRuleObject.Deserialize(transportRule as JournalingRule); if (journalRuleObject.Recipient != null && journalRuleObject.Recipient != null && journalNdrToAddress == journalRuleObject.Recipient.Value) { return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleRecipient); } if (journalNdrToAddress == journalRuleObject.JournalEmailAddress) { flag = true; } } } } if (!flag) { return(JournalNdrValidationCheckResult.JournalNdrValidationPassed); } return(JournalNdrValidationCheckResult.JournalNdrExistInJournalRuleJournalEmailAddress); }
internal JournalingRule Serialize() { Microsoft.Exchange.MessagingPolicies.Rules.Condition condition = this.CreateScopeCondition(); Microsoft.Exchange.MessagingPolicies.Rules.Condition condition2 = this.CreateRecipientCondition(); Microsoft.Exchange.MessagingPolicies.Rules.Condition condition3 = this.CombineUsingAnd(new Microsoft.Exchange.MessagingPolicies.Rules.Condition[] { condition, condition2 }); Microsoft.Exchange.MessagingPolicies.Rules.Action item = this.CreateAction(); JournalingRule journalingRule = (JournalingRule)JournalingRuleParser.Instance.CreateRule(base.Name); journalingRule.Condition = condition3; journalingRule.Actions.Add(item); journalingRule.ExpiryDate = this.ExpiryDate; journalingRule.GccRuleType = JournalRuleObject.ConvertJournalRuleTypeToGccType(this.RuleType); journalingRule.Enabled = (this.enabled ? RuleState.Enabled : RuleState.Disabled); return(journalingRule); }
internal void Deserialize(JournalingRule rule) { base.Name = rule.Name; this.ReadAction(rule); this.enabled = (rule.Enabled == RuleState.Enabled); this.ExpiryDate = rule.ExpiryDate; this.RuleType = JournalRuleObject.ConvertGccTypeToJournalRuleType(rule.GccRuleType); this.Recipient = null; this.Scope = JournalRuleScope.Global; if (rule.Condition.ConditionType == ConditionType.True) { return; } if (this.TryReadScopeCondition(rule.Condition)) { return; } if (this.TryReadRecipientCondition(rule.Condition)) { return; } if (rule.Condition.ConditionType != ConditionType.And) { throw new JournalRuleCorruptException(); } List <Microsoft.Exchange.MessagingPolicies.Rules.Condition> subConditions = ((AndCondition)rule.Condition).SubConditions; if (subConditions.Count != 2) { throw new JournalRuleCorruptException(); } foreach (Microsoft.Exchange.MessagingPolicies.Rules.Condition condition in subConditions) { if (!this.TryReadScopeCondition(condition) && !this.TryReadRecipientCondition(condition)) { throw new JournalRuleCorruptException(); } } }
protected override void InternalProcessRecord() { ADJournalRuleStorageManager adjournalRuleStorageManager = null; try { adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", base.DataSession); } catch (RuleCollectionNotInAdException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); return; } int num = 0; TransportRule transportRule = null; SmtpAddress journalingReportNdrToSmtpAddress = JournalRuleObject.GetJournalingReportNdrToSmtpAddress(this.ResolveCurrentOrganization(), this.ConfigurationSession); JournalRuleObject journalRuleObject; try { if (VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& journalingReportNdrToSmtpAddress == SmtpAddress.NullReversePath) { base.WriteError(new InvalidOperationException(Strings.JournalNdrMailboxCannotBeNull), ErrorCategory.InvalidOperation, null); } bool flag = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled&& !this.LawfulInterception; SmtpAddress smtpAddress; if (!JournalRuleObject.LookupAndCheckAllowedTypes(this.JournalEmailAddress, base.TenantGlobalCatalogSession, base.SessionSettings.CurrentOrganizationId, flag, out smtpAddress)) { base.WriteError(new InvalidOperationException(Strings.JournalingToExternalOnly), ErrorCategory.InvalidOperation, null); return; } if (smtpAddress == journalingReportNdrToSmtpAddress) { this.WriteWarning(Strings.JournalingReportNdrToSameAsJournalEmailAddress); } if (flag) { adjournalRuleStorageManager.LoadRuleCollection(); if (adjournalRuleStorageManager.Count >= 10) { base.WriteError(new InvalidOperationException(Strings.ErrorTooManyJournalRules(10)), ErrorCategory.InvalidOperation, null); return; } } if (this.Recipient != null && this.Recipient != null && this.Recipient.Value == journalingReportNdrToSmtpAddress) { base.WriteError(new InvalidOperationException(Strings.JournalingReportNdrToSameAsRecipient), ErrorCategory.InvalidOperation, null); return; } GccType gccRuleType = GccType.None; if (this.LawfulInterception) { this.ValidateLawfulInterceptionTenantConfiguration(); if ((base.Fields.IsChanged("FullReport") || base.Fields.IsModified("FullReport")) && this.FullReport) { gccRuleType = GccType.Full; } else { gccRuleType = GccType.Prtt; } } DateTime?expiryDate = null; if (this.ExpiryDate != null) { expiryDate = new DateTime?(this.ExpiryDate.Value.ToUniversalTime()); } journalRuleObject = new JournalRuleObject(base.Name, this.Enabled, this.Recipient, smtpAddress, this.Scope, expiryDate, gccRuleType); } catch (DataValidationException exception2) { base.WriteError(exception2, ErrorCategory.InvalidArgument, base.Name); return; } catch (RecipientInvalidException exception3) { base.WriteError(exception3, ErrorCategory.InvalidArgument, this.JournalEmailAddress); return; } try { JournalingRule rule = journalRuleObject.Serialize(); adjournalRuleStorageManager.NewRule(rule, this.ResolveCurrentOrganization(), ref num, out transportRule); } catch (RulesValidationException) { base.WriteError(new ArgumentException(Strings.RuleNameAlreadyExists, "Name"), ErrorCategory.InvalidArgument, base.Name); return; } catch (ParserException exception4) { base.WriteError(exception4, ErrorCategory.InvalidData, null); return; } if (Utils.Exchange12HubServersExist(this)) { this.WriteWarning(Strings.NewRuleSyncAcrossDifferentVersionsNeeded); } journalRuleObject.SetTransportRule(transportRule); if (journalingReportNdrToSmtpAddress == SmtpAddress.NullReversePath) { this.WriteWarning(Strings.JournalingReportNdrToNotSet); } base.WriteObject(journalRuleObject); }
protected override void InternalProcessRecord() { if (!base.ShouldContinue(Strings.PromptToOverwriteRulesOnImport)) { return; } ADJournalRuleStorageManager adjournalRuleStorageManager; try { adjournalRuleStorageManager = new ADJournalRuleStorageManager("JournalingVersioned", base.DataSession); } catch (RuleCollectionNotInAdException exception) { base.WriteError(exception, ErrorCategory.InvalidOperation, null); return; } TransportRuleCollection transportRuleCollection = null; using (Stream stream = new MemoryStream(this.FileData)) { try { transportRuleCollection = (TransportRuleCollection)JournalingRuleParser.Instance.LoadStream(stream); } catch (ParserException exception2) { base.WriteError(exception2, ErrorCategory.InvalidData, "FileData"); return; } } JournalRuleObject journalRuleObject = new JournalRuleObject(); foreach (Microsoft.Exchange.MessagingPolicies.Rules.Rule rule in transportRuleCollection) { JournalingRule journalingRule = (JournalingRule)rule; try { journalRuleObject.Deserialize(journalingRule); } catch (RecipientInvalidException exception3) { base.WriteError(exception3, ErrorCategory.InvalidArgument, journalRuleObject.JournalEmailAddress); return; } catch (JournalRuleCorruptException exception4) { base.WriteError(exception4, ErrorCategory.InvalidArgument, journalingRule.Name); } if (journalingRule.IsTooAdvancedToParse) { base.WriteError(new InvalidOperationException(Strings.CannotCreateRuleDueToVersion(journalingRule.Name)), ErrorCategory.InvalidOperation, null); return; } } try { adjournalRuleStorageManager.ReplaceRules(transportRuleCollection, this.ResolveCurrentOrganization()); } catch (DataValidationException exception5) { base.WriteError(exception5, ErrorCategory.InvalidArgument, null); } }
internal static bool LookupAndCheckAllowedTypes(RecipientIdParameter recipId, IRecipientSession recipSession, OrganizationId orgId, bool isNonGccInDc, out SmtpAddress address) { Microsoft.Exchange.Data.Directory.Recipient.RecipientType?recipientType; address = JournalRuleObject.Lookup(recipId, recipSession, orgId, isNonGccInDc && JournalRuleObject.isJournalAddressCheckEnabled, out recipientType); return(!isNonGccInDc || !JournalRuleObject.isJournalAddressCheckEnabled || recipientType == null || !(recipientType != Microsoft.Exchange.Data.Directory.Recipient.RecipientType.MailUser) || !(recipientType != Microsoft.Exchange.Data.Directory.Recipient.RecipientType.MailContact)); }