// Token: 0x06000B9B RID: 2971 RVA: 0x0005148C File Offset: 0x0004F68C public static bool Edit(string oldEmail, string newEmail, JunkEmailListType junkEmailListType, UserContext userContext, bool isFromOptions, out string message) { if (string.IsNullOrEmpty(oldEmail)) { throw new ArgumentNullException("oldEmail", "oldEmail cannot be null or empty"); } if (string.IsNullOrEmpty(newEmail)) { throw new ArgumentNullException("newEmail", "newEmail cannot be null or empty"); } if (userContext == null) { throw new ArgumentNullException("userContext"); } bool flag = true; message = string.Empty; string empty = string.Empty; JunkEmailRule junkEmailRule = userContext.MailboxSession.JunkEmailRule; string[] email = new string[] { oldEmail }; JunkEmailUtilities.InternalRemove(junkEmailRule, email, junkEmailListType, userContext); if (!JunkEmailUtilities.InternalAdd(junkEmailRule, newEmail, junkEmailListType, userContext, isFromOptions, out message)) { flag = false; } if (flag) { junkEmailRule.Save(); } return(flag); }
// Token: 0x06000B9C RID: 2972 RVA: 0x00051524 File Offset: 0x0004F724 public static void SaveOptions(bool isEnabled, bool isContactsTrusted, bool safeListsOnly, UserContext userContext) { if (userContext == null) { throw new ArgumentNullException("userContext"); } JunkEmailRule junkEmailRule = userContext.MailboxSession.JunkEmailRule; junkEmailRule.IsEnabled = isEnabled; if (isEnabled) { if (userContext.IsFeatureEnabled(Feature.Contacts) && junkEmailRule.IsContactsFolderTrusted != isContactsTrusted) { if (isContactsTrusted) { Utilities.JunkEmailRuleSynchronizeContactsCache(junkEmailRule); } else { junkEmailRule.ClearContactsCache(); } } junkEmailRule.TrustedListsOnly = safeListsOnly; } junkEmailRule.Save(); userContext.RefreshIsJunkEmailEnabled(); }
private void SaveRule(JunkEmailRule rule) { try { rule.Save(); } catch (ObjectDisposedException) { throw new DataSourceTransientException(ServerStrings.JunkEmailObjectDisposedException); } catch (InvalidOperationException) { throw new DataSourceTransientException(ServerStrings.JunkEmailInvalidOperationException); } }
// Token: 0x06000B9A RID: 2970 RVA: 0x0005143C File Offset: 0x0004F63C public static void Remove(string[] email, JunkEmailListType junkEmailListType, UserContext userContext) { if (email == null || email.Length <= 0) { throw new ArgumentNullException("email", "email cannot be null or empty"); } if (userContext == null) { throw new ArgumentNullException("userContext"); } JunkEmailRule junkEmailRule = userContext.MailboxSession.JunkEmailRule; JunkEmailUtilities.InternalRemove(junkEmailRule, email, junkEmailListType, userContext); junkEmailRule.Save(); }
public override void Apply(MrsPSHandler psHandler, MailboxSession mailboxSession) { JunkEmailRule junkEmailRule = mailboxSession.JunkEmailRule; if (this.TrustedSenderDomain != null) { this.AddEntriesToCollection(junkEmailRule.TrustedSenderDomainCollection, "TrustedSenderDomainCollection", mailboxSession.MailboxGuid, this.TrustedSenderDomain); } if (this.TrustedSenderEmail != null) { this.AddEntriesToCollection(junkEmailRule.TrustedSenderEmailCollection, "TrustedSenderEmailCollection", mailboxSession.MailboxGuid, this.TrustedSenderEmail); } if (this.BlockedSenderDomain != null) { this.AddEntriesToCollection(junkEmailRule.BlockedSenderDomainCollection, "BlockedSenderDomainCollection", mailboxSession.MailboxGuid, this.BlockedSenderDomain); } if (this.BlockedSenderEmail != null) { this.AddEntriesToCollection(junkEmailRule.BlockedSenderEmailCollection, "BlockedSenderEmailCollection", mailboxSession.MailboxGuid, this.BlockedSenderEmail); } if (this.TrustedRecipientDomain != null) { this.AddEntriesToCollection(junkEmailRule.TrustedRecipientDomainCollection, "TrustedRecipientDomainCollection", mailboxSession.MailboxGuid, this.TrustedRecipientDomain); } if (this.TrustedRecipientEmail != null) { this.AddEntriesToCollection(junkEmailRule.TrustedRecipientEmailCollection, "TrustedRecipientEmailCollection", mailboxSession.MailboxGuid, this.TrustedRecipientEmail); } if (this.TrustedContactsEmail != null) { IRecipientSession adrecipientSession = mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); if (adrecipientSession == null) { string itemList = this.TrustedContactsEmail.Aggregate((string result, string email) => result + ", " + email); throw new MailboxSettingsJunkMailErrorPermanentException("TrustedContactsEmail", itemList, "error getting RecipientSession"); } junkEmailRule.SynchronizeContactsCache(); foreach (string email2 in this.TrustedContactsEmail) { junkEmailRule.AddTrustedContact(email2, adrecipientSession); } } if (this.SendAsEmail != null) { this.AddEntriesToCollection(junkEmailRule.TrustedSenderEmailCollection, "TrustedSenderEmailCollection", mailboxSession.MailboxGuid, this.SendAsEmail); } junkEmailRule.Save(); }
// Token: 0x06000B98 RID: 2968 RVA: 0x000512F8 File Offset: 0x0004F4F8 public static bool Add(string email, JunkEmailListType junkEmailListType, UserContext userContext, bool isFromOptions, out string message) { if (string.IsNullOrEmpty(email)) { throw new ArgumentNullException("email", "email cannot be null or empty"); } if (userContext == null) { throw new ArgumentNullException("userContext"); } JunkEmailRule junkEmailRule = userContext.MailboxSession.JunkEmailRule; bool flag = JunkEmailUtilities.InternalAdd(junkEmailRule, email, junkEmailListType, userContext, isFromOptions, out message); if (flag) { junkEmailRule.Save(); } return(flag); }
// Token: 0x06000B31 RID: 2865 RVA: 0x00048204 File Offset: 0x00046404 private static void EnsureJunkEmailRule(MailboxSession session, MapiEvent mapiEvent) { if (session == null) { throw new ArgumentNullException("session"); } if (mapiEvent == null) { throw new ArgumentNullException("mapiEvent"); } if (!session.Capabilities.CanHaveJunkEmailRule) { JunkEmailOptionsAssistant.Tracer.TraceDebug <Guid>(0L, "Skipping mailbox {0} because it can't have a junk e-mail rule. Possibly an alternate mailbox.", session.MailboxOwner.MailboxInfo.MailboxGuid); return; } JunkEmailOptionsAssistant.Tracer.TraceDebug <Guid>(0L, "Ensuring junk e-mail rule for mailbox {0}", session.MailboxOwner.MailboxInfo.MailboxGuid); StoreObjectId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.Inbox); StoreObjectId defaultFolderId2 = session.GetDefaultFolderId(DefaultFolderType.JunkEmail); if (defaultFolderId == null || defaultFolderId2 == null) { JunkEmailOptionsAssistant.Tracer.TraceDebug <Guid>(0L, "Cannot create junk e-mail rule for mailbox {0} because either the inbox or junk e-mail folder does not exist.", session.MailboxOwner.MailboxInfo.MailboxGuid); return; } if (JunkEmailOptionsAssistant.IsFolderCreationEvent(mapiEvent) && !JunkEmailOptionsAssistant.IsInboxOrJunkFolder(mapiEvent.ItemEntryId, defaultFolderId, defaultFolderId2)) { JunkEmailOptionsAssistant.Tracer.TraceDebug(0L, "Created folder is not Inbox or Junk E-mail folder. Skipping uninteresting event."); return; } JunkEmailRule.JunkEmailStatus junkEmailRuleStatus = session.GetJunkEmailRuleStatus(); if (junkEmailRuleStatus != JunkEmailRule.JunkEmailStatus.None) { return; } JunkEmailOptionsAssistant.Tracer.TraceDebug <Guid>(0L, "Creating and enabling junk e-mail rule for mailbox {0}.", session.MailboxOwner.MailboxInfo.MailboxGuid); JunkEmailRule junkEmailRule = session.JunkEmailRule; junkEmailRule.IsEnabled = true; junkEmailRule.Save(); }
private void CheckAndCreateJunkEmailRule(MailboxSession session) { if (session == null) { throw new ArgumentNullException("session"); } StoreObjectId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.Inbox); StoreObjectId defaultFolderId2 = session.GetDefaultFolderId(DefaultFolderType.JunkEmail); if (defaultFolderId == null || defaultFolderId2 == null) { this.WriteWarning(Strings.CannotCreateJunkEmailRule(this.Identity.ToString())); return; } if (session.GetJunkEmailRuleStatus() == JunkEmailRule.JunkEmailStatus.None) { JunkEmailRule filteredJunkEmailRule = session.FilteredJunkEmailRule; filteredJunkEmailRule.IsEnabled = true; filteredJunkEmailRule.Save(); base.WriteObject(Strings.CreatedJunkEmailRule(this.Identity.ToString()).ToString()); } }
private void UpdateJunkEmailContacts() { if (this.junkEmailUpdates.Count > 0) { MailboxSession mailboxSession = base.Session as MailboxSession; if (mailboxSession != null && mailboxSession.LogonType != LogonType.Delegated && mailboxSession.Capabilities.CanHaveJunkEmailRule && !mailboxSession.MailboxOwner.ObjectId.IsNullOrEmpty()) { JunkEmailRule junkEmailRule = mailboxSession.JunkEmailRule; if (junkEmailRule.IsContactsFolderTrusted) { try { junkEmailRule.SynchronizeContactsCache(); junkEmailRule.Save(); } catch (JunkEmailValidationException) { } catch (DataSourceOperationException ex) { throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex, this, "Contact.UpdateJunkEmailContacts. Failed due to directory exception {0}.", new object[] { ex }); } catch (DataSourceTransientException ex2) { throw StorageGlobals.TranslateDirectoryException(ServerStrings.ADException, ex2, this, "Contact.UpdateJunkEmailContacts. Failed due to directory exception {0}.", new object[] { ex2 }); } } } } }
protected override void InternalProcessRecord() { TaskLogger.LogEnter(); bool flag = false; this.summary = default(UpdateSafeList.SafeListSummary); CmdletProxy.ThrowExceptionIfProxyIsNeeded(base.CurrentTaskContext, (ADUser)this.DataObject, false, this.ConfirmationMessage, null); try { ADUser aduser = this.DataObject as ADUser; if (aduser == null || (aduser.RecipientType != RecipientType.UserMailbox && aduser.RecipientType != RecipientType.MailUser)) { base.WriteError(new RecipientTypeInvalidException(this.Identity.ToString()), ErrorCategory.InvalidData, aduser); } ExchangePrincipal mailboxOwner = ExchangePrincipal.FromADUser(base.SessionSettings, aduser); using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, "Client=Management;Action=Update-SafeList")) { if (!mailboxSession.Capabilities.CanHaveJunkEmailRule) { base.WriteError(new MailboxNotJunkRuleCapableException(this.Identity.ToString()), ErrorCategory.InvalidData, aduser); } else if (this.EnsureJunkEmailRule) { this.CheckAndCreateJunkEmailRule(mailboxSession); } else { JunkEmailRule filteredJunkEmailRule = mailboxSession.FilteredJunkEmailRule; switch (this.Type) { case UpdateType.SafeSenders: case UpdateType.SafeRecipients: case UpdateType.BlockedSenders: flag = this.CheckAndUpdateHashes(filteredJunkEmailRule, this.Type); break; case UpdateType.Both: if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeRecipients)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeSenders)) { flag = true; } break; case UpdateType.All: if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeRecipients)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.SafeSenders)) { flag = true; } if (this.CheckAndUpdateHashes(filteredJunkEmailRule, UpdateType.BlockedSenders)) { flag = true; } break; } if (flag) { base.InternalProcessRecord(); if ((this.Type == UpdateType.SafeSenders || this.Type == UpdateType.Both || this.Type == UpdateType.All) && (this.summary.SkippedContacts > 0 || this.summary.SkippedSafeSenderDomains > 0 || this.summary.SkippedSafeSenders > 0)) { this.WriteWarning(Strings.SafeSendersNotUpdated(this.summary.SkippedContacts, this.summary.SkippedSafeSenders, this.summary.SkippedSafeSenderDomains, this.Identity.ToString())); } if ((this.Type == UpdateType.SafeRecipients || this.Type == UpdateType.Both || this.Type == UpdateType.All) && (this.summary.SkippedSafeRecipientDomains > 0 || this.summary.SkippedSafeRecipients > 0)) { this.WriteWarning(Strings.SafeRecipientsNotUpdated(this.summary.SkippedSafeRecipients, this.summary.SkippedSafeRecipientDomains, this.Identity.ToString())); } if ((this.Type == UpdateType.BlockedSenders || this.Type == UpdateType.All) && (this.summary.SkippedBlockedSenderDomains > 0 || this.summary.SkippedBlockedSenders > 0)) { this.WriteWarning(Strings.BlockedSendersNotUpdated(this.summary.SkippedBlockedSenders, this.summary.SkippedBlockedSenderDomains, this.Identity.ToString())); } } if (flag || !filteredJunkEmailRule.AllRestrictionsLoaded) { filteredJunkEmailRule.Save(); } } } } catch (JunkEmailValidationException ex) { TaskLogger.LogError(ex); base.WriteError(ex, ErrorCategory.InvalidData, this.DataObject); } catch (StorageTransientException ex2) { TaskLogger.LogError(ex2); base.WriteError(ex2, ErrorCategory.ReadError, this.DataObject); } catch (StoragePermanentException ex3) { TaskLogger.LogError(ex3); base.WriteError(ex3, ErrorCategory.InvalidOperation, this.DataObject); } finally { TaskLogger.LogExit(); } }
// Token: 0x06000B4A RID: 2890 RVA: 0x00048AC0 File Offset: 0x00046CC0 private void UpdateSafeLists(MailboxSession mailboxSession) { ADObjectId adobjectId = (mailboxSession.MailboxOwner != null) ? mailboxSession.MailboxOwner.ObjectId : null; if (adobjectId == null) { JunkEmailOptionsCommiterAssistant.Tracer.TraceError <MailboxSession>((long)this.GetHashCode(), "can't determine owner of mailbox {0}", mailboxSession); return; } if (TemplateTenantConfiguration.IsTemplateTenant(mailboxSession.MailboxOwner.MailboxInfo.OrganizationId)) { JunkEmailOptionsCommiterAssistant.Tracer.TraceDebug <string, Guid>((long)this.GetHashCode(), "Skipping mailbox {0} (GUID: {1}) because it belongs to a consumer tenant.", mailboxSession.MailboxOwner.MailboxInfo.DisplayName, mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid); return; } IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(mailboxSession.MailboxOwner.MailboxInfo.OrganizationId), 318, "UpdateSafeLists", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\JunkEmailOptions\\JunkEmailOptionsCommiterAssistant.cs"); ADUser aduser = tenantOrRootOrgRecipientSession.Read(adobjectId) as ADUser; if (aduser == null) { JunkEmailOptionsCommiterAssistant.Tracer.TraceError <ADObjectId>((long)this.GetHashCode(), "can't read user object {0} from AD.", adobjectId); return; } JunkEmailRule filteredJunkEmailRule = mailboxSession.FilteredJunkEmailRule; bool flag = false; bool flag2 = false; bool flag3 = false; byte[] array = filteredJunkEmailRule.IsEnabled ? this.GetSafeSendersHash(filteredJunkEmailRule, out flag) : null; byte[] array2 = filteredJunkEmailRule.IsEnabled ? this.GetSafeRecipientsHash(filteredJunkEmailRule, out flag2) : null; byte[] array3 = filteredJunkEmailRule.IsEnabled ? this.GetBlockedSendersHash(filteredJunkEmailRule, out flag3) : null; bool flag4 = false; if (!ArrayComparer <byte> .Comparer.Equals(array, aduser.SafeSendersHash)) { aduser.SafeSendersHash = array; flag4 = true; } if (!ArrayComparer <byte> .Comparer.Equals(array2, aduser.SafeRecipientsHash)) { aduser.SafeRecipientsHash = array2; flag4 = true; } if (!ArrayComparer <byte> .Comparer.Equals(array3, aduser.BlockedSendersHash)) { aduser.BlockedSendersHash = array3; flag4 = true; } if (flag4) { JunkEmailOptionsCommiterAssistant.Tracer.TraceDebug <ADObjectId>((long)this.GetHashCode(), "Saving updated recipient object {0} to AD...", adobjectId); tenantOrRootOrgRecipientSession.Save(aduser); JunkEmailOptionsPerfCounters.TotalRecipientsUpdated.Increment(); JunkEmailOptionsCommiterAssistant.Tracer.TraceDebug <ADObjectId>((long)this.GetHashCode(), "Recipient object {0} was successfully saved", adobjectId); if (flag || flag2 || flag3) { JunkEmailOptionsPerfCounters.TotalPartialUpdates.Increment(); } } Exception ex = null; try { if (flag4 || !filteredJunkEmailRule.AllRestrictionsLoaded) { filteredJunkEmailRule.Save(); } } catch (StoragePermanentException ex2) { ex = ex2; } catch (StorageTransientException ex3) { ex = ex3; } finally { if (ex != null) { JunkEmailOptionsCommiterAssistant.EventLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_FailedToUpdateMailbox, null, new object[] { mailboxSession.MailboxGuid, ex }); } } }