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); }
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); }