Ejemplo n.º 1
0
        internal static PropertyError UpdateElcRootFolderName(DefaultFolderContext context, string newName)
        {
            PropertyError result        = null;
            StoreObjectId storeObjectId = context[DefaultFolderType.ElcRoot];

            if (storeObjectId != null)
            {
                using (MapiPropertyBag mapiPropertyBag = MapiPropertyBag.CreateMapiPropertyBag(context.Session, storeObjectId))
                {
                    PropertyDefinition[] propertyDefinitions = new PropertyDefinition[]
                    {
                        FolderSchema.DisplayName
                    };
                    PropertyError[] array = mapiPropertyBag.SetProperties(propertyDefinitions, new object[]
                    {
                        newName
                    });
                    if (array.Length > 0)
                    {
                        result = array[0];
                    }
                    mapiPropertyBag.SaveChanges(false);
                    return(result);
                }
            }
            throw new ObjectNotFoundException(ServerStrings.ExDefaultFolderNotFound(DefaultFolderType.ElcRoot));
        }
Ejemplo n.º 2
0
        internal static MapiPropertyBag CreateMapiPropertyBag(StoreSession storeSession, StoreObjectId id)
        {
            Util.ThrowOnNullArgument(storeSession, "storeSession");
            Util.ThrowOnNullArgument(id, "id");
            MapiProp        disposable      = null;
            MapiPropertyBag mapiPropertyBag = null;
            bool            flag            = false;
            MapiPropertyBag result;

            try
            {
                disposable      = storeSession.GetMapiProp(id);
                mapiPropertyBag = new MapiPropertyBag(storeSession, disposable);
                flag            = true;
                result          = mapiPropertyBag;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(mapiPropertyBag);
                    Util.DisposeIfPresent(disposable);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        internal static void ResolveAndFilterPropertyValues(NativeStorePropertyDefinition.TypeCheckingFlag typeCheckingFlag, StoreSession storeSession, MapiProp mapiProp, ExTimeZone exTimeZone, PropValue[] mapiPropValues, out NativeStorePropertyDefinition[] propertyDefinitions, out PropTag[] mapiPropTags, out object[] propertyValues)
        {
            PropTag[] array = new PropTag[mapiPropValues.Length];
            for (int i = 0; i < mapiPropValues.Length; i++)
            {
                array[i] = mapiPropValues[i].PropTag;
            }
            int num;

            NativeStorePropertyDefinition[] array2 = PropertyTagCache.Cache.InternalPropertyDefinitionsFromPropTags(typeCheckingFlag, mapiProp, storeSession, array, out num);
            propertyDefinitions = new NativeStorePropertyDefinition[num];
            mapiPropTags        = new PropTag[num];
            propertyValues      = new object[num];
            int num2 = 0;

            for (int j = 0; j < array2.Length; j++)
            {
                if (array2[j] != null)
                {
                    object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(storeSession, exTimeZone, array2[j], mapiPropValues[j]);
                    propertyDefinitions[num2] = array2[j];
                    mapiPropTags[num2]        = PropTagHelper.PropTagFromIdAndType(array[j].Id(), array2[j].MapiPropertyType);
                    propertyValues[num2]      = valueFromPropValue;
                    num2++;
                }
            }
        }
Ejemplo n.º 4
0
            internal RowEntry ToRowEntry(StoreSession session, MapiProp propertyMappingReference)
            {
                PropertyTable.Operation.MapiRowFactory mapiRowFactory = null;
                switch (base.Operation)
                {
                case ModifyTableOperationType.Add:
                    mapiRowFactory = new PropertyTable.Operation.MapiRowFactory(RowEntry.Add);
                    break;

                case ModifyTableOperationType.Modify:
                    mapiRowFactory = new PropertyTable.Operation.MapiRowFactory(RowEntry.Modify);
                    break;

                case ModifyTableOperationType.Remove:
                    mapiRowFactory = new PropertyTable.Operation.MapiRowFactory(RowEntry.Remove);
                    break;
                }
                ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions(propertyMappingReference, session, from propValue in base.Properties
                                                                                                          select(NativeStorePropertyDefinition) propValue.Property);

                PropValue[] array = new PropValue[base.Properties.Length];
                int         num   = 0;

                foreach (PropTag propTag in collection)
                {
                    array[num] = MapiPropertyBag.GetPropValueFromValue(session, session.ExTimeZone, propTag, base.Properties[num].Value);
                    num++;
                }
                return(mapiRowFactory(array));
            }
Ejemplo n.º 5
0
        private bool InternalLocalize(DefaultFolderData data, out PropertyError error)
        {
            error = null;
            if (data.FolderId == null)
            {
                return(false);
            }
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. We are trying to localize the default folder. defaultFolder = {0}.", this);
            string text = this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo);

            try
            {
                using (MapiPropertyBag mapiPropertyBag = MapiPropertyBag.CreateMapiPropertyBag(this.context.Session, data.FolderId))
                {
                    object[] properties = mapiPropertyBag.GetProperties(DefaultFolder.displayNameNativePropertyDefinition);
                    if (properties.Length <= 0)
                    {
                        return(false);
                    }
                    string text2 = properties[0] as string;
                    if (text2 == null || string.Compare(text, text2, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        PropertyDefinition[] propertyDefinitions;
                        if (this.defaultFolderInfo.DefaultFolderType == DefaultFolderType.ElcRoot)
                        {
                            propertyDefinitions = DefaultFolder.elcFolderLocalizedNamePropertyDefinition;
                        }
                        else
                        {
                            propertyDefinitions = DefaultFolder.displayNamePropertyDefinition;
                        }
                        PropertyError[] array = mapiPropertyBag.SetProperties(propertyDefinitions, new object[]
                        {
                            text
                        });
                        if (array != null && array.Length > 0)
                        {
                            if (array[0].PropertyErrorCode == PropertyErrorCode.FolderNameConflict)
                            {
                                ExTraceGlobals.DefaultFoldersTracer.TraceError <string, DefaultFolderType>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. Failed to localize default folder. Folder = {0}, defaultFolderType = {1}.", this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo), this.defaultFolderInfo.DefaultFolderType);
                                throw new DefaultFolderLocalizationException(new DefaultFolderNameClashException(this.defaultFolderInfo.LocalizableDisplayName));
                            }
                            error = array[0];
                            ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder, PropertyError>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. We failed to localize default folder due to error. defaultFolder = {0}, error = {1}.", this, error);
                        }
                        mapiPropertyBag.SaveChanges(false);
                        return(true);
                    }
                }
            }
            catch (ObjectNotFoundException)
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InternalLocalize. The default folder was missing. Localization aborted. defaultFolder = {0}.", this);
            }
            return(false);
        }
Ejemplo n.º 6
0
 protected override void LazyCreateMapiPropertyBag()
 {
     if (this.Context.CoreObject != null)
     {
         if (this.Context.CoreState.Origin == Origin.New)
         {
             return;
         }
         base.MapiPropertyBag = MapiPropertyBag.CreateMapiPropertyBag(this.context.Session, this.folderId);
     }
 }
Ejemplo n.º 7
0
 internal FolderPropertyStream(MapiPropertyBag mapiPropertyBag, NativeStorePropertyDefinition property, PropertyOpenMode streamOpenMode)
 {
     Util.ThrowOnNullArgument(mapiPropertyBag, "mapiPropertyBag");
     Util.ThrowOnNullArgument(property, "property");
     EnumValidator.ThrowIfInvalid <PropertyOpenMode>(streamOpenMode, "streamOpenMode");
     this.mapiPropertyBag = mapiPropertyBag;
     this.property        = property;
     this.openMode        = streamOpenMode;
     this.CreateStream();
     this.disposeTracker = this.GetDisposeTracker();
 }
Ejemplo n.º 8
0
        internal static PropValue[] MapiPropValuesFromXsoProperties(StoreSession storeSession, MapiProp mapiProp, PropertyDefinition[] propertyDefinitions, object[] propertyValues)
        {
            PropValue[]           array      = new PropValue[propertyValues.Length];
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(mapiProp, storeSession, false, propertyDefinitions);
            int num = 0;

            foreach (PropTag propTag in collection)
            {
                array[num] = MapiPropertyBag.GetPropValueFromValue(storeSession, storeSession.ExTimeZone, propTag, propertyValues[num]);
                num++;
            }
            return(array);
        }
Ejemplo n.º 9
0
 internal void SetQueryResultRow(PropValue[] row)
 {
     if (row.Length != this.propertyPositions.Count)
     {
         throw new ArgumentException("An array of values is different in size from an array of columns");
     }
     this.currentRowValues = new object[row.Length];
     foreach (KeyValuePair <StorePropertyDefinition, int> keyValuePair in this.propertyPositions)
     {
         StorePropertyDefinition key = keyValuePair.Key;
         int value = keyValuePair.Value;
         this.currentRowValues[value] = MapiPropertyBag.GetValueFromPropValue(this.Context.Session, this.timeZone, key, row[value]);
     }
 }
        protected List <PropValue> GetPropValuesFromValues(ExTimeZone exTimeZone, IList <PropertyDefinition> propertyDefinitions, IList <object> propertyValues)
        {
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.Session.Mailbox.MapiStore, this.Session, false, propertyDefinitions);
            List <PropValue>      list       = new List <PropValue>(propertyDefinitions.Count);
            int num = 0;

            foreach (PropTag propTag in collection)
            {
                InternalSchema.CheckPropertyValueType(propertyDefinitions[num], propertyValues[num]);
                list.Add(MapiPropertyBag.GetPropValueFromValue(this.Session, exTimeZone, propTag, propertyValues[num]));
                num++;
            }
            return(list);
        }
Ejemplo n.º 11
0
        private static AdrEntry GetAdrEntry(StoreSession session, ExTimeZone timeZone, RuleAction.ForwardActionBase.ActionRecipient recipient)
        {
            Util.ThrowOnNullArgument(recipient, "recipient");
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions(session.Mailbox.MapiStore, session, recipient.PropertyDefinitions);

            PropValue[] array = new PropValue[recipient.PropertyDefinitions.Count];
            int         num   = 0;

            foreach (PropTag propTag in collection)
            {
                array[num] = MapiPropertyBag.GetPropValueFromValue(session, timeZone, propTag, recipient.PropertyValues[num]);
                num++;
            }
            return(new AdrEntry(array));
        }
Ejemplo n.º 12
0
 private static RuleAction.ForwardActionBase.ActionRecipient GetRecipient(StoreSession session, ExTimeZone timeZone, AdrEntry adrEntry)
 {
     Util.ThrowOnNullArgument(adrEntry, "adrEntry");
     PropTag[] array = new PropTag[adrEntry.Values.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = adrEntry.Values[i].PropTag;
     }
     NativeStorePropertyDefinition[] array2 = PropertyTagCache.Cache.SafePropertyDefinitionsFromPropTags(session, array);
     object[] array3 = new object[adrEntry.Values.Length];
     for (int j = 0; j < array3.Length; j++)
     {
         array3[j] = MapiPropertyBag.GetValueFromPropValue(session, timeZone, array2[j], adrEntry.Values[j]);
     }
     return(new RuleAction.ForwardActionBase.ActionRecipient(array2, array3));
 }
Ejemplo n.º 13
0
 protected PropValue[] FromMapiPropValueToXsoPropValue(PropValue[] propValues)
 {
     PropTag[] array = new PropTag[propValues.Length];
     for (int i = 0; i < propValues.Length; i++)
     {
         array[i] = propValues[i].PropTag;
     }
     NativeStorePropertyDefinition[] array2 = PropertyTagCache.Cache.PropertyDefinitionsFromPropTags(NativeStorePropertyDefinition.TypeCheckingFlag.DisableTypeCheck, this.MapiFolder, this.Session, array);
     PropValue[] array3 = new PropValue[propValues.Length];
     for (int j = 0; j < array2.Length; j++)
     {
         if (array2[j] == null)
         {
             throw new NotSupportedException(string.Format("The property tag cannot be resolved to a property definition. PropertyTag = {0}", array[j]));
         }
         object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(this.Session, CoreObject.GetPersistablePropertyBag(this.folder).ExTimeZone, array2[j], propValues[j]);
         array3[j] = new PropValue(array2[j], valueFromPropValue);
     }
     return(array3);
 }
Ejemplo n.º 14
0
 internal static PropValue GetPropValueFromValue(StoreSession session, ExTimeZone timeZone, PropTag propTag, object value)
 {
     return(new PropValue(propTag, MapiPropertyBag.GetMapiValueFromValue(session, timeZone, value)));
 }
        private void CreateMapiFolder()
        {
            string valueOrDefault  = base.GetValueOrDefault <string>(FolderSchema.DisplayName);
            string valueOrDefault2 = base.GetValueOrDefault <string>(FolderSchema.Description, string.Empty);

            byte[]          array           = base.Session.IsMoveUser ? base.GetValueOrDefault <byte[]>(StoreObjectSchema.EntryId, null) : null;
            MapiProp        mapiProp        = null;
            MapiPropertyBag mapiPropertyBag = null;
            bool            flag            = false;

            try
            {
                using (Folder folder = Folder.Bind(base.Session, this.parentFolderId, new PropertyDefinition[]
                {
                    StoreObjectSchema.EffectiveRights
                }))
                {
                    if (folder is SearchFolder)
                    {
                        throw new InvalidParentFolderException(ServerStrings.ExCannotCreateSubfolderUnderSearchFolder);
                    }
                    bool flag2 = (this.createMode & CreateMode.OpenIfExists) == CreateMode.OpenIfExists;
                    bool flag3 = (this.createMode & CreateMode.InstantSearch) == CreateMode.InstantSearch;
                    bool flag4 = (this.createMode & CreateMode.OptimizedConversationSearch) == CreateMode.OptimizedConversationSearch;
                    bool flag5 = (this.createMode & CreateMode.CreatePublicFolderDumpster) == CreateMode.CreatePublicFolderDumpster;
                    if (flag2 && flag3)
                    {
                        throw new ArgumentException("Cannot use both openIfExists and instantSearch folder creation flags");
                    }
                    if (this.isSecure && (flag3 || flag4 || flag5))
                    {
                        throw new ArgumentException("Cannot use isSecure in conjunction with instantSearch, optimizedConversationSearch or createPublicFolderDumpster");
                    }
                    StoreSession session = base.Session;
                    bool         flag6   = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag6 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        try
                        {
                            this.OnBeforeCreateFolder(folder);
                            if (this.isSecure)
                            {
                                mapiProp = folder.MapiFolder.CreateSecureFolder(valueOrDefault, valueOrDefault2, flag2, array);
                            }
                            else
                            {
                                mapiProp = folder.MapiFolder.CreateFolder(valueOrDefault, valueOrDefault2, flag2, this.isSearchFolder, flag3, flag4, flag5, array);
                            }
                        }
                        catch (MapiExceptionNotEnoughMemory mapiExceptionNotEnoughMemory)
                        {
                            ExTraceGlobals.StorageTracer.TraceError <MapiExceptionNotEnoughMemory>((long)this.GetHashCode(), "CreateFolderPropertyBag::CreateMapiPropertyBag. Failed to create MapiFolder due to MapiException {0}.", mapiExceptionNotEnoughMemory);
                            bool            flag7            = !string.IsNullOrEmpty(valueOrDefault2);
                            string          errorDescription = mapiExceptionNotEnoughMemory.ToString();
                            PropertyError[] array2           = new PropertyError[flag7 ? 2 : 1];
                            array2[0] = new PropertyError(FolderSchema.DisplayName, PropertyErrorCode.NotEnoughMemory, errorDescription);
                            if (flag7)
                            {
                                array2[1] = new PropertyError(FolderSchema.Description, PropertyErrorCode.NotEnoughMemory, errorDescription);
                            }
                            throw PropertyError.ToException(array2);
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(valueOrDefault), ex, session, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("CreateFolderPropertyBag::CreateMapiPropertyBag.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotCreateFolder(valueOrDefault), ex2, session, this, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("CreateFolderPropertyBag::CreateMapiPropertyBag.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag6)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                }
                this.Context.CoreState.Origin = Origin.Existing;
                base.MemoryPropertyBag.ClearChangeInfo(FolderSchema.DisplayName);
                if (array != null)
                {
                    base.MemoryPropertyBag.ClearChangeInfo(StoreObjectSchema.EntryId);
                }
                if (this.createMode == CreateMode.CreateNew)
                {
                    base.MemoryPropertyBag.ClearChangeInfo(FolderSchema.Description);
                }
                mapiPropertyBag      = new MapiPropertyBag(base.Session, mapiProp);
                base.MapiPropertyBag = mapiPropertyBag;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(mapiPropertyBag);
                    Util.DisposeIfPresent(mapiProp);
                }
            }
        }
Ejemplo n.º 16
0
        internal static RuleAction ConvertRuleAction(StoreSession session, ExTimeZone timeZone, RuleAction ruleAction)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(timeZone, "timeZone");
            Util.ThrowOnNullArgument(ruleAction, "ruleAction");
            switch (ruleAction.ActionType)
            {
            case RuleAction.Type.OP_MOVE:
            {
                RuleAction.MoveCopy moveCopy = (RuleAction.MoveCopy)ruleAction;
                if (moveCopy.FolderIsInThisStore)
                {
                    return(new RuleAction.MoveAction(moveCopy.UserFlags, RuleActionConverter.EntryIdToStoreObjectId(moveCopy.FolderEntryID, StoreObjectType.Folder)));
                }
                return(new RuleAction.MoveAction(moveCopy.UserFlags, moveCopy.StoreEntryID, moveCopy.FolderEntryID));
            }

            case RuleAction.Type.OP_COPY:
            {
                RuleAction.MoveCopy moveCopy2 = (RuleAction.MoveCopy)ruleAction;
                if (moveCopy2.FolderIsInThisStore)
                {
                    return(new RuleAction.CopyAction(moveCopy2.UserFlags, RuleActionConverter.EntryIdToStoreObjectId(moveCopy2.FolderEntryID, StoreObjectType.Folder)));
                }
                return(new RuleAction.CopyAction(moveCopy2.UserFlags, moveCopy2.StoreEntryID, moveCopy2.FolderEntryID));
            }

            case RuleAction.Type.OP_REPLY:
            {
                RuleAction.Reply reply = (RuleAction.Reply)ruleAction;
                return(new RuleAction.ReplyAction(reply.UserFlags, RuleActionConverter.MapiReplyFlagsToReplyFlags(reply.Flags), RuleActionConverter.GetReplyTemplateStoreObjectId(reply.ReplyTemplateMessageEntryID), reply.ReplyTemplateGuid));
            }

            case RuleAction.Type.OP_OOF_REPLY:
            {
                RuleAction.OOFReply oofreply = (RuleAction.OOFReply)ruleAction;
                return(new RuleAction.OutOfOfficeReplyAction(oofreply.UserFlags, RuleActionConverter.GetReplyTemplateStoreObjectId(oofreply.ReplyTemplateMessageEntryID), oofreply.ReplyTemplateGuid));
            }

            case RuleAction.Type.OP_DEFER_ACTION:
            {
                RuleAction.Defer defer = (RuleAction.Defer)ruleAction;
                return(new RuleAction.DeferAction(defer.UserFlags, defer.Data));
            }

            case RuleAction.Type.OP_BOUNCE:
            {
                RuleAction.Bounce bounce = (RuleAction.Bounce)ruleAction;
                return(new RuleAction.BounceAction(bounce.UserFlags, (uint)bounce.Code));
            }

            case RuleAction.Type.OP_FORWARD:
            {
                RuleAction.Forward forward = (RuleAction.Forward)ruleAction;
                return(new RuleAction.ForwardAction(forward.UserFlags, RuleActionConverter.GetRecipients(session, timeZone, forward.Recipients), RuleActionConverter.MapiForwardFlagsToForwardFlags(forward.Flags)));
            }

            case RuleAction.Type.OP_DELEGATE:
            {
                RuleAction.Delegate @delegate = (RuleAction.Delegate)ruleAction;
                return(new RuleAction.DelegateAction(@delegate.UserFlags, RuleActionConverter.GetRecipients(session, timeZone, @delegate.Recipients)));
            }

            case RuleAction.Type.OP_TAG:
            {
                RuleAction.Tag tag = (RuleAction.Tag)ruleAction;
                NativeStorePropertyDefinition propertyDefinition = null;
                try
                {
                    propertyDefinition = PropertyTagCache.Cache.SafePropertyDefinitionsFromPropTags(session, new PropTag[]
                        {
                            tag.Value.PropTag
                        })[0];
                }
                catch (CorruptDataException)
                {
                    if (session.IsMoveUser)
                    {
                        return(new RuleAction.TagAction(tag.UserFlags, InternalSchema.RuleError, 0));
                    }
                    throw;
                }
                object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(session, timeZone, propertyDefinition, tag.Value);
                return(new RuleAction.TagAction(tag.UserFlags, propertyDefinition, valueFromPropValue));
            }

            case RuleAction.Type.OP_DELETE:
            {
                RuleAction.Delete delete = (RuleAction.Delete)ruleAction;
                return(new RuleAction.DeleteAction(delete.UserFlags));
            }

            case RuleAction.Type.OP_MARK_AS_READ:
            {
                RuleAction.MarkAsRead markAsRead = (RuleAction.MarkAsRead)ruleAction;
                return(new RuleAction.MarkAsReadAction(markAsRead.UserFlags));
            }

            default:
                throw new ArgumentException(string.Format("Invalid action type {0}.", ruleAction.ActionType));
            }
        }
Ejemplo n.º 17
0
        internal static RuleAction ConvertRuleAction(StoreSession session, ExTimeZone timeZone, RuleAction ruleAction)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(timeZone, "timeZone");
            Util.ThrowOnNullArgument(ruleAction, "ruleAction");
            RuleAction ruleAction2;

            switch (ruleAction.ActionType)
            {
            case RuleActionType.Move:
            {
                RuleAction.MoveAction moveAction = (RuleAction.MoveAction)ruleAction;
                if (moveAction.ExternalDestinationFolderId != null)
                {
                    ruleAction2 = new RuleAction.ExternalMove(moveAction.DestinationStoreEntryId, moveAction.ExternalDestinationFolderId);
                }
                else
                {
                    ruleAction2 = new RuleAction.InMailboxMove(moveAction.DestinationFolderId.ProviderLevelItemId);
                }
                break;
            }

            case RuleActionType.Copy:
            {
                RuleAction.CopyAction copyAction = (RuleAction.CopyAction)ruleAction;
                if (copyAction.ExternalDestinationFolderId != null)
                {
                    ruleAction2 = new RuleAction.ExternalCopy(copyAction.DestinationStoreEntryId, copyAction.ExternalDestinationFolderId);
                }
                else
                {
                    ruleAction2 = new RuleAction.InMailboxCopy(copyAction.DestinationFolderId.ProviderLevelItemId);
                }
                break;
            }

            case RuleActionType.Reply:
            {
                RuleAction.ReplyAction replyAction = (RuleAction.ReplyAction)ruleAction;
                ruleAction2 = new RuleAction.Reply(RuleActionConverter.GetReplyTemplateMessageEntryId(replyAction.ReplyTemplateMessageId), replyAction.ReplyTemplateGuid, RuleActionConverter.ReplyFlagsToMapiReplyFlags(replyAction.Flags));
                break;
            }

            case RuleActionType.OutOfOfficeReply:
            {
                RuleAction.OutOfOfficeReplyAction outOfOfficeReplyAction = (RuleAction.OutOfOfficeReplyAction)ruleAction;
                ruleAction2 = new RuleAction.OOFReply(RuleActionConverter.GetReplyTemplateMessageEntryId(outOfOfficeReplyAction.ReplyTemplateMessageId), outOfOfficeReplyAction.ReplyTemplateGuid);
                break;
            }

            case RuleActionType.DeferAction:
            {
                RuleAction.DeferAction deferAction = (RuleAction.DeferAction)ruleAction;
                ruleAction2 = new RuleAction.Defer(deferAction.Data);
                break;
            }

            case RuleActionType.Bounce:
            {
                RuleAction.BounceAction bounceAction = (RuleAction.BounceAction)ruleAction;
                ruleAction2 = new RuleAction.Bounce((RuleAction.Bounce.BounceCode)bounceAction.BounceCode);
                break;
            }

            case RuleActionType.Forward:
            {
                RuleAction.ForwardAction forwardAction = (RuleAction.ForwardAction)ruleAction;
                ruleAction2 = new RuleAction.Forward(RuleActionConverter.GetAdrEntries(session, timeZone, forwardAction.Recipients), RuleActionConverter.ForwardFlagsToMapiForwardFlags(forwardAction.Flags));
                break;
            }

            case RuleActionType.Delegate:
            {
                RuleAction.DelegateAction delegateAction = (RuleAction.DelegateAction)ruleAction;
                ruleAction2 = new RuleAction.Delegate(RuleActionConverter.GetAdrEntries(session, timeZone, delegateAction.Recipients));
                break;
            }

            case RuleActionType.Tag:
            {
                RuleAction.TagAction tagAction = (RuleAction.TagAction)ruleAction;
                PropTag propTag = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions(session.Mailbox.MapiStore, session, new NativeStorePropertyDefinition[]
                    {
                        tagAction.PropertyDefinition
                    }).First <PropTag>();
                ruleAction2 = new RuleAction.Tag(MapiPropertyBag.GetPropValueFromValue(session, timeZone, propTag, tagAction.PropertyValue));
                break;
            }

            case RuleActionType.Delete:
            {
                RuleAction.DeleteAction deleteAction = (RuleAction.DeleteAction)ruleAction;
                ruleAction2 = new RuleAction.Delete();
                break;
            }

            case RuleActionType.MarkAsRead:
            {
                RuleAction.MarkAsReadAction markAsReadAction = (RuleAction.MarkAsReadAction)ruleAction;
                ruleAction2 = new RuleAction.MarkAsRead();
                break;
            }

            default:
                throw new ArgumentException(string.Format("Invalid action type {0}.", ruleAction.ActionType));
            }
            ruleAction2.UserFlags = ruleAction.UserFlags;
            return(ruleAction2);
        }
Ejemplo n.º 18
0
        private void RetryBigProperties(IList <NativeStorePropertyDefinition> allPropDefs, ICollection <PropTag> allPropTags, object[] allValues)
        {
            List <int> list  = null;
            int        count = allPropDefs.Count;

            for (int i = 0; i < count; i++)
            {
                if (PropertyError.IsPropertyValueTooBig(allValues[i]) && MapiPropertyBag.IsPropertyRetriable(allPropDefs[i]))
                {
                    if (list == null)
                    {
                        list = new List <int>(10);
                    }
                    list.Add(i);
                }
            }
            if (list == null)
            {
                return;
            }
            PropTag[] array = new PropTag[count];
            allPropTags.CopyTo(array, 0);
            bool flag = true;

            while (flag && list.Count > 0)
            {
                flag = false;
                PropTag[] array2 = new PropTag[list.Count];
                for (int j = 0; j < array2.Length; j++)
                {
                    array2[j] = array[list[j]];
                }
                PropValue[]  array3       = null;
                StoreSession storeSession = this.StoreSession;
                bool         flag2        = false;
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.BeginMapiCall();
                        storeSession.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    array3 = this.mapiProp.GetProps(array2);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (storeSession != null)
                        {
                            storeSession.EndMapiCall();
                            if (flag2)
                            {
                                storeSession.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                for (int k = array3.Length - 1; k >= 0; k--)
                {
                    int    num = list[k];
                    object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(this.storeSession, this.ExTimeZone, InternalSchema.ToStorePropertyDefinition(allPropDefs[num]), array3[k]);
                    if (!PropertyError.IsPropertyValueTooBig(valueFromPropValue))
                    {
                        allValues[num] = valueFromPropValue;
                        list.RemoveAt(k);
                        flag = true;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private PropertyError[] InternalSetProperties(PropertyDefinition[] propertyDefinitions, object[] propertyValues, MapiPropertyBag.MapiSetProps mapiSetProps)
        {
            this.CheckDisposed("SetProperties");
            if (propertyDefinitions == null)
            {
                throw new ArgumentNullException(ServerStrings.ExNullParameter("propertyDefinitions", 1));
            }
            if (propertyValues == null)
            {
                throw new ArgumentNullException(ServerStrings.ExNullParameter("propertyValues", 2));
            }
            if (propertyDefinitions.Length == 0)
            {
                return(MapiPropertyBag.EmptyPropertyErrorArray);
            }
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions <PropertyDefinition>(this.MapiProp, this.storeSession, (this.saveFlags & PropertyBagSaveFlags.IgnoreUnresolvedHeaders) == PropertyBagSaveFlags.IgnoreUnresolvedHeaders, true, (this.saveFlags & PropertyBagSaveFlags.DisableNewXHeaderMapping) != PropertyBagSaveFlags.DisableNewXHeaderMapping, propertyDefinitions);
            List <PropValue>      list       = new List <PropValue>(propertyDefinitions.Length);
            int num = 0;

            foreach (PropTag propTag in collection)
            {
                if (propTag != PropTag.Unresolved)
                {
                    InternalSchema.CheckPropertyValueType(propertyDefinitions[num], propertyValues[num]);
                    list.Add(MapiPropertyBag.GetPropValueFromValue(this.storeSession, this.ExTimeZone, propTag, propertyValues[num]));
                }
                num++;
            }
            PropProblem[] array        = null;
            StoreSession  storeSession = this.StoreSession;
            bool          flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                try
                {
                    array = mapiSetProps(list.ToArray());
                }
                catch (MapiExceptionNotEnoughMemory mapiExceptionNotEnoughMemory)
                {
                    ExTraceGlobals.StorageTracer.TraceError <MapiExceptionNotEnoughMemory>((long)this.GetHashCode(), "MapiPropertyBag::InternalSetProperties. Failed to SetProps due to MapiException {0}.", mapiExceptionNotEnoughMemory);
                    string errorDescription    = mapiExceptionNotEnoughMemory.ToString();
                    List <PropertyError> list2 = new List <PropertyError>();
                    foreach (PropertyDefinition propertyDefinition in propertyDefinitions)
                    {
                        list2.Add(new PropertyError(propertyDefinition, PropertyErrorCode.NotEnoughMemory, errorDescription));
                    }
                    throw PropertyError.ToException(list2.ToArray());
                }
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetProps, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::InternalSetProperties.", new object[0]),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotSetProps, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::InternalSetProperties.", new object[0]),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            PropertyError[] array2 = MapiPropertyBag.EmptyPropertyErrorArray;
            if (array != null)
            {
                array2 = new PropertyError[array.Length];
                for (int j = 0; j < array.Length; j++)
                {
                    int scode = array[j].Scode;
                    PropertyDefinition propertyDefinition2 = null;
                    int num2 = 0;
                    foreach (PropTag propTag2 in collection)
                    {
                        if (array[j].PropTag == propTag2)
                        {
                            propertyDefinition2 = propertyDefinitions[num2];
                            break;
                        }
                        num2++;
                    }
                    string            errorDescription2;
                    PropertyErrorCode error = MapiPropertyHelper.MapiErrorToXsoError(scode, out errorDescription2);
                    array2[j] = new PropertyError(propertyDefinition2, error, errorDescription2);
                    ExTraceGlobals.StorageTracer.TraceError <string, MapiProp, PropertyError>((long)this.GetHashCode(), "MapiPropertyBag::InternalSetProperties. Failed. PropDef display name= {0}, MapiProp = {1}, Error = {2}.", propertyDefinition2.Name, this.MapiProp, array2[j]);
                }
            }
            return(array2);
        }
Ejemplo n.º 20
0
 private static bool IsPropertyRetriable(NativeStorePropertyDefinition propDef)
 {
     return((propDef.PropertyFlags & PropertyFlags.Streamable) != PropertyFlags.Streamable && MapiPropertyBag.IsVariableLength(propDef));
 }
Ejemplo n.º 21
0
        internal static object GetValueFromPropValue(StoreSession storeSession, ExTimeZone exTimeZone, StorePropertyDefinition propertyDefinition, PropValue propertyValue)
        {
            if (propertyValue.IsError())
            {
                int num = propertyValue.GetErrorValue();
                if (num == -2147220732 && (propertyDefinition.SpecifiedWith == PropertyTypeSpecifier.GuidId || propertyDefinition.SpecifiedWith == PropertyTypeSpecifier.GuidString))
                {
                    num = -2147221233;
                }
                return(MapiPropertyBag.CreatePropertyError(num, propertyDefinition));
            }
            PropType propType = propertyValue.PropTag.ValueType();

            if (propType == PropType.Restriction)
            {
                if (storeSession == null)
                {
                    throw new NotSupportedException("PT_RESTRICTION is not supported when we do not have a session. This very likely is an attachment.");
                }
                return(FilterRestrictionConverter.CreateFilter(storeSession, storeSession.Mailbox.MapiStore, (Restriction)propertyValue.Value, false));
            }
            else
            {
                if (propertyValue.Value == null)
                {
                    return(MapiPropertyBag.CreatePropertyError(-2147221233, propertyDefinition));
                }
                if (propType == PropType.Actions)
                {
                    if (storeSession == null)
                    {
                        throw new NotSupportedException("RuleAction type not supported without a session.");
                    }
                    RuleAction[] array  = (RuleAction[])propertyValue.Value;
                    RuleAction[] array2 = new RuleAction[array.Length];
                    for (int i = 0; i < array2.Length; i++)
                    {
                        array2[i] = RuleActionConverter.ConvertRuleAction(storeSession, exTimeZone, array[i]);
                    }
                    return(array2);
                }
                else if (propType == PropType.SysTime)
                {
                    DateTime dateTime = (DateTime)propertyValue.Value;
                    if (ExDateTime.IsValidDateTime(dateTime))
                    {
                        return(new ExDateTime(exTimeZone, dateTime));
                    }
                    return(MapiPropertyBag.CreatePropertyError(-2147221221, propertyDefinition));
                }
                else
                {
                    if (propType == PropType.SysTimeArray)
                    {
                        DateTime[] array3 = (DateTime[])propertyValue.Value;
                        foreach (DateTime dateTime2 in array3)
                        {
                            if (!ExDateTime.IsValidDateTime(dateTime2))
                            {
                                return(MapiPropertyBag.CreatePropertyError(-2147221221, propertyDefinition));
                            }
                        }
                        return(ExTimeZoneHelperForMigrationOnly.ToExDateTimeArray(exTimeZone, array3));
                    }
                    return(propertyValue.Value);
                }
            }
        }
Ejemplo n.º 22
0
        internal static Folder BindToSubfolderByName(StoreSession session, StoreObjectId containerId, string folderName, params PropertyDefinition[] propsToReturn)
        {
            Folder result;

            using (Folder folder = Folder.Bind(session, containerId))
            {
                MapiFolder mapiFolder = null;
                Folder     folder2    = null;
                bool       flag       = false;
                try
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        mapiFolder = folder.MapiFolder.OpenSubFolderByName(folderName);
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenFolder, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("DefaultFolderCreator::BindToSubfolderByName. Unable to open folder by name.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                    using (MapiPropertyBag mapiPropertyBag = new MapiPropertyBag(session, mapiFolder))
                    {
                        byte[] entryId = (byte[])mapiPropertyBag.GetProperties(new NativeStorePropertyDefinition[]
                        {
                            InternalSchema.EntryId
                        })[0];
                        StoreObjectId folderObjectId = StoreObjectId.FromProviderSpecificId(entryId);
                        folder2 = Folder.InternalBind <Folder>(session, mapiFolder, folderObjectId, null, propsToReturn);
                        mapiPropertyBag.DetachMapiProp();
                    }
                    flag   = true;
                    result = folder2;
                }
                finally
                {
                    if (!flag)
                    {
                        Util.DisposeIfPresent(folder2);
                        Util.DisposeIfPresent(mapiFolder);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 23
0
        internal object[] GetProperties(IList <NativeStorePropertyDefinition> propertyDefinitions)
        {
            this.CheckDisposed("GetProperties");
            if (propertyDefinitions == null)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "MapiPropertyBag::GetProperties. {0} == null.", "propertyDefinitions");
                throw new ArgumentNullException("propertyDefinitions");
            }
            int count = propertyDefinitions.Count;

            if (count == 0)
            {
                ExTraceGlobals.StorageTracer.TraceError <string>((long)this.GetHashCode(), "MapiPropertyBag::GetProperties. {0} contain zero elements.", "propertyDefinitions");
                throw new ArgumentException(ServerStrings.ExEmptyCollection("propertyDefinitions"), "propertyDefinitions");
            }
            object[] array = new object[count];
            ICollection <PropTag> collection = PropertyTagCache.Cache.PropTagsFromPropertyDefinitions(this.MapiProp, this.storeSession, true, !this.storeSession.Capabilities.IsReadOnly, !this.storeSession.Capabilities.IsReadOnly, propertyDefinitions);

            PropValue[]  array2       = null;
            StoreSession storeSession = this.StoreSession;
            bool         flag         = false;

            try
            {
                if (storeSession != null)
                {
                    storeSession.BeginMapiCall();
                    storeSession.BeginServerHealthCall();
                    flag = true;
                }
                if (StorageGlobals.MapiTestHookBeforeCall != null)
                {
                    StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                }
                array2 = this.MapiProp.GetProps(collection);
            }
            catch (MapiPermanentException ex)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::GetProperties. MapiProp = {0}.", this.MapiProp),
                    ex
                });
            }
            catch (MapiRetryableException ex2)
            {
                throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[]
                {
                    string.Format("MapiPropertyBag::GetProperties. MapiProp = {0}.", this.MapiProp),
                    ex2
                });
            }
            finally
            {
                try
                {
                    if (storeSession != null)
                    {
                        storeSession.EndMapiCall();
                        if (flag)
                        {
                            storeSession.EndServerHealthCall();
                        }
                    }
                }
                finally
                {
                    if (StorageGlobals.MapiTestHookAfterCall != null)
                    {
                        StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                    }
                }
            }
            for (int i = 0; i < count; i++)
            {
                array[i] = MapiPropertyBag.GetValueFromPropValue(this.storeSession, this.ExTimeZone, InternalSchema.ToStorePropertyDefinition(propertyDefinitions[i]), array2[i]);
            }
            this.RetryBigProperties(propertyDefinitions, collection, array);
            return(array);
        }