Example #1
0
 public static void ProcessRecord(Action action, ManageInboxRule.ThrowTerminatingErrorDelegate handleError, object identity)
 {
     try
     {
         action();
     }
     catch (InboxRuleOperationException ex)
     {
         handleError(new InvalidOperationException(ex.Message), ErrorCategory.InvalidOperation, identity);
     }
     catch (RulesTooBigException)
     {
         handleError(new InvalidOperationException(Strings.ErrorInboxRuleTooBig), ErrorCategory.InvalidOperation, identity);
     }
 }
Example #2
0
        public static void VerifyRange <T>(T min, T max, bool allowEqual, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler, LocalizedString errorMessage)
        {
            if (min == null || max == null)
            {
                return;
            }
            int num = ((IComparable)((object)min)).CompareTo(max);

            if (!allowEqual && num == 0)
            {
                errorHandler(new LocalizedException(errorMessage), ErrorCategory.InvalidArgument, null);
            }
            if (num > 0)
            {
                errorHandler(new LocalizedException(errorMessage), ErrorCategory.InvalidArgument, null);
            }
        }
Example #3
0
 internal void ValidateInterdependentParameters(ManageInboxRule.ThrowTerminatingErrorDelegate writeError)
 {
     if (base.IsModified(InboxRuleSchema.ReceivedAfterDate) || base.IsModified(InboxRuleSchema.ReceivedBeforeDate))
     {
         ManageInboxRule.VerifyRange <ExDateTime?>(this.ReceivedAfterDate, this.ReceivedBeforeDate, false, writeError, Strings.ErrorInvalidDateRangeCondition);
     }
     if (base.IsModified(InboxRuleSchema.ExceptIfReceivedAfterDate) || base.IsModified(InboxRuleSchema.ExceptIfReceivedBeforeDate))
     {
         ManageInboxRule.VerifyRange <ExDateTime?>(this.ExceptIfReceivedAfterDate, this.ExceptIfReceivedBeforeDate, false, writeError, Strings.ErrorInvalidDateRangeException);
     }
     if (base.IsModified(InboxRuleSchema.WithinSizeRangeMinimum) || base.IsModified(InboxRuleSchema.WithinSizeRangeMaximum))
     {
         ManageInboxRule.VerifyRange <ByteQuantifiedSize?>(this.WithinSizeRangeMinimum, this.WithinSizeRangeMaximum, true, writeError, Strings.ErrorInvalidSizeRangeCondition);
     }
     if (base.IsModified(InboxRuleSchema.ExceptIfWithinSizeRangeMinimum) || base.IsModified(InboxRuleSchema.ExceptIfWithinSizeRangeMaximum))
     {
         ManageInboxRule.VerifyRange <ByteQuantifiedSize?>(this.ExceptIfWithinSizeRangeMinimum, this.ExceptIfWithinSizeRangeMaximum, true, writeError, Strings.ErrorInvalidSizeRangeException);
     }
 }
Example #4
0
        public static ADRecipientOrAddress[] ResolveRecipients(IList <RecipientIdParameter> recipientIDs, DataAccessHelper.GetDataObjectDelegate getRecipientObject, IRecipientSession recipientSession, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler)
        {
            if (recipientIDs == null || recipientIDs.Count == 0)
            {
                return(null);
            }
            ADRecipientOrAddress[] array = new ADRecipientOrAddress[recipientIDs.Count];
            int num = 0;

            foreach (RecipientIdParameter recipientIdParameter in recipientIDs)
            {
                try
                {
                    recipientIdParameter.SearchWithDisplayName = false;
                    ADRecipient adEntry = (ADRecipient)getRecipientObject(recipientIdParameter, recipientSession, null, null, new LocalizedString?(Strings.ErrorRecipientNotFound(recipientIdParameter.ToString())), new LocalizedString?(Strings.ErrorRecipientNotUnique(recipientIdParameter.ToString())));
                    array[num++] = new ADRecipientOrAddress(new Participant(adEntry));
                }
                catch (ManagementObjectNotFoundException)
                {
                    MimeRecipient mimeRecipient = null;
                    try
                    {
                        mimeRecipient = MimeRecipient.Parse(recipientIdParameter.RawIdentity, AddressParserFlags.IgnoreComments | AddressParserFlags.AllowSquareBrackets);
                    }
                    catch (MimeException)
                    {
                    }
                    if (mimeRecipient == null || string.IsNullOrEmpty(mimeRecipient.Email) || !SmtpAddress.IsValidSmtpAddress(mimeRecipient.Email))
                    {
                        errorHandler(new LocalizedException(Strings.ErrorInboxRuleUserInvalid(recipientIdParameter.ToString())), ErrorCategory.InvalidArgument, null);
                    }
                    string text = string.Empty;
                    try
                    {
                        text = mimeRecipient.DisplayName;
                    }
                    catch (MimeException)
                    {
                    }
                    if (string.IsNullOrEmpty(text))
                    {
                        text = mimeRecipient.Email;
                    }
                    array[num++] = new ADRecipientOrAddress(new Participant(text, mimeRecipient.Email, "smtp"));
                }
            }
            return(array);
        }
Example #5
0
        public static MailboxFolder ResolveMailboxFolder(MailboxFolderIdParameter folderId, DataAccessHelper.GetDataObjectDelegate getUserHandler, DataAccessHelper.GetDataObjectDelegate getFolderHandler, IRecipientSession resolveUserSession, ADSessionSettings sessionSettings, ADUser adUser, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler)
        {
            if (!ManageInboxRule.TryValidateFolderId(folderId, getUserHandler, getFolderHandler, resolveUserSession, adUser, errorHandler))
            {
                return(null);
            }
            MailboxFolder result;

            using (MailboxFolderDataProvider mailboxFolderDataProvider = new MailboxFolderDataProvider(sessionSettings, adUser, "ResolveMailboxFolder"))
            {
                result = (MailboxFolder)getFolderHandler(folderId, mailboxFolderDataProvider, null, null, new LocalizedString?(Strings.ErrorMailboxFolderNotFound(folderId.ToString())), new LocalizedString?(Strings.ErrorMailboxFolderNotUnique(folderId.ToString())));
            }
            return(result);
        }
Example #6
0
 private static bool TryValidateFolderId(MailboxFolderIdParameter folderId, DataAccessHelper.GetDataObjectDelegate getUserHandler, DataAccessHelper.GetDataObjectDelegate getFolderHandler, IRecipientSession resolveUserSession, ADUser adUser, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler)
 {
     if (folderId != null)
     {
         if (folderId.RawOwner != null)
         {
             ADUser aduser = (ADUser)getUserHandler(folderId.RawOwner, resolveUserSession, null, null, new LocalizedString?(Strings.ErrorMailboxNotFound(folderId.RawOwner.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(folderId.RawOwner.ToString())));
             if (!aduser.Identity.Equals(adUser.Identity))
             {
                 errorHandler(new LocalizedException(Strings.ErrorConflictingMailboxFolder(adUser.Identity.ToString(), folderId.ToString())), ErrorCategory.InvalidOperation, null);
             }
         }
         if (folderId.InternalMailboxFolderId == null)
         {
             folderId.InternalMailboxFolderId = new Microsoft.Exchange.Data.Storage.Management.MailboxFolderId(adUser.Id, folderId.RawFolderStoreId, folderId.RawFolderPath);
         }
         return(true);
     }
     return(false);
 }
Example #7
0
        public static AggregationSubscriptionIdentity[] ResolveSubscriptions(ICollection <AggregationSubscriptionIdentity> ids, ADUser mailboxOwner, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler)
        {
            if (ids == null || ids.Count == 0)
            {
                return(new AggregationSubscriptionIdentity[0]);
            }
            List <AggregationSubscriptionIdentity> list = new List <AggregationSubscriptionIdentity>(ids.Count);

            PimSubscriptionProxy[] allSubscriptions      = InboxRuleDataProvider.GetAllSubscriptions(mailboxOwner);
            List <AggregationSubscriptionIdentity> list2 = new List <AggregationSubscriptionIdentity>(allSubscriptions.Length);

            foreach (PimSubscriptionProxy pimSubscriptionProxy in allSubscriptions)
            {
                list2.Add(pimSubscriptionProxy.Subscription.SubscriptionIdentity);
            }
            foreach (AggregationSubscriptionIdentity aggregationSubscriptionIdentity in ids)
            {
                if (!list2.Contains(aggregationSubscriptionIdentity))
                {
                    errorHandler(new LocalizedException(Strings.InvalidSubscription(aggregationSubscriptionIdentity.ToString())), ErrorCategory.InvalidArgument, null);
                }
                else if (!list.Contains(aggregationSubscriptionIdentity))
                {
                    list.Add(aggregationSubscriptionIdentity);
                }
            }
            return(list.ToArray());
        }
Example #8
0
        public static MessageClassification[] ResolveMessageClassifications(ICollection <MessageClassificationIdParameter> ids, IConfigurationSession configurationSession, ManageInboxRule.ThrowTerminatingErrorDelegate errorHandler)
        {
            if (ids == null || ids.Count == 0)
            {
                return(new MessageClassification[0]);
            }
            ADObjectId rootId = MessageClassificationIdParameter.DefaultRoot(configurationSession);
            List <MessageClassification> list = new List <MessageClassification>(ids.Count);

            foreach (MessageClassificationIdParameter messageClassificationIdParameter in ids)
            {
                IEnumerable <MessageClassification> objects = messageClassificationIdParameter.GetObjects <MessageClassification>(rootId, configurationSession);
                using (IEnumerator <MessageClassification> enumerator2 = objects.GetEnumerator())
                {
                    if (!enumerator2.MoveNext())
                    {
                        errorHandler(new LocalizedException(Strings.InvalidMessageClassification(messageClassificationIdParameter.ToString())), ErrorCategory.InvalidArgument, null);
                    }
                    do
                    {
                        list.Add(enumerator2.Current);
                    }while (enumerator2.MoveNext());
                }
            }
            return(list.ToArray());
        }