public bool TryGetQueryFilter(out QueryFilter filter) { MailboxSession mailboxSession = base.Session as MailboxSession; if (mailboxSession == null) { throw new InvalidOperationException(ServerStrings.ExOutlookSearchFolderDoesNotHaveMailboxSession); } VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(mailboxSession, (Guid)this[InternalSchema.OutlookSearchFolderClsId]); if (versionedId == null) { filter = null; return(false); } bool result; using (MessageItem messageItem = MessageItem.Bind(mailboxSession, versionedId)) { bool flag; StoreId[] array; Restriction restriction = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out flag, out array); filter = FilterRestrictionConverter.CreateFilter(mailboxSession, mailboxSession.Mailbox.MapiStore, restriction, true); result = true; } return(result); }
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); } } }
public static StoreObjectId Recreate(MailboxSession session, Guid searchFolderClsId) { if (session == null) { throw new ArgumentNullException("session"); } if (searchFolderClsId == Guid.Empty) { throw new ArgumentException("Guid is empty", "searchFolderClsId"); } using (Folder folder = Folder.Bind(session, DefaultFolderType.SearchFolders)) { using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[] { InternalSchema.OutlookSearchFolderClsId })) { for (;;) { object[][] rows = queryResult.GetRows(10000); for (int i = 0; i < rows.Length; i++) { if (rows[i][0] is Guid && ((Guid)rows[i][0]).Equals(searchFolderClsId)) { goto Block_9; } } if (rows.Length <= 0) { goto Block_11; } } Block_9: throw new ObjectExistedException(ServerStrings.ExSearchFolderAlreadyExists(searchFolderClsId)); Block_11 :; } } VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(session, searchFolderClsId); if (versionedId == null) { throw new ObjectNotFoundException(ServerStrings.ExSearchFolderNoAssociatedItem(searchFolderClsId)); } StoreObjectId objectId; using (MessageItem messageItem = MessageItem.Bind(session, versionedId)) { bool deepTraversal; StoreId[] folderScope; Restriction restriction = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out deepTraversal, out folderScope); QueryFilter searchQuery = FilterRestrictionConverter.CreateFilter(session, session.Mailbox.MapiStore, restriction, true); SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(searchQuery, folderScope); searchFolderCriteria.DeepTraversal = deepTraversal; string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.DisplayName, string.Empty); using (OutlookSearchFolder outlookSearchFolder = OutlookSearchFolder.Create(session, valueOrDefault)) { outlookSearchFolder[InternalSchema.OutlookSearchFolderClsId] = searchFolderClsId; FolderSaveResult folderSaveResult = outlookSearchFolder.Save(); if (folderSaveResult.OperationResult != OperationResult.Succeeded) { throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult)); } outlookSearchFolder.Load(null); outlookSearchFolder.ApplyContinuousSearch(searchFolderCriteria); objectId = outlookSearchFolder.Id.ObjectId; } } return(objectId); }