internal static COWTriggerAction GetTriggerAction(FolderChangeOperation operation) { EnumValidator.ThrowIfInvalid <FolderChangeOperation>(operation, "operation"); switch (operation) { case FolderChangeOperation.Copy: return(COWTriggerAction.Copy); case FolderChangeOperation.Move: return(COWTriggerAction.Move); case FolderChangeOperation.MoveToDeletedItems: return(COWTriggerAction.MoveToDeletedItems); case FolderChangeOperation.SoftDelete: return(COWTriggerAction.SoftDelete); case FolderChangeOperation.HardDelete: return(COWTriggerAction.HardDelete); case FolderChangeOperation.DoneWithMessageDelete: return(COWTriggerAction.DoneWithMessageDelete); default: throw new NotSupportedException("Invalid folder change operation"); } }
private bool TryCreateMoveActivities(FolderChangeOperation operation, IList <StoreObjectId> itemIdsBeforeMove, IList <StoreObjectId> itemIdsAfterMove, StoreObjectId sourceFolder, StoreObjectId targetFolder, out IList <Activity> activities) { activities = null; if (itemIdsBeforeMove == null && itemIdsAfterMove == null) { return(false); } if (itemIdsAfterMove == null) { itemIdsAfterMove = itemIdsBeforeMove; } string value; switch (operation) { case FolderChangeOperation.MoveToDeletedItems: value = "Delete"; break; case FolderChangeOperation.SoftDelete: value = "SoftDelete"; break; case FolderChangeOperation.HardDelete: value = "HardDelete"; break; default: value = "Move"; break; } activities = new List <Activity>(itemIdsAfterMove.Count); for (int i = 0; i < itemIdsAfterMove.Count; i++) { StoreObjectId storeObjectId = itemIdsAfterMove[i]; StoreObjectId storeObjectId2 = (itemIdsBeforeMove == null || itemIdsBeforeMove.Count <= i) ? null : itemIdsBeforeMove[i]; Activity item = new Activity(ActivityId.Move, this.clientInfo.Id, ExDateTime.UtcNow, this.clientSessionId, this.clientInfo.Version, Interlocked.Increment(ref this.sequenceNumber), this.session, storeObjectId, storeObjectId2, new Dictionary <string, string> { { "MoveType", value }, { "SourceFolder", this.ConvertFolderIdToString(sourceFolder) }, { "TargetFolder", this.ConvertFolderIdToString(targetFolder) } }); activities.Add(item); ((List <Activity>)activities).AddRange(this.TryExtractClutterMoveActivities(storeObjectId, storeObjectId2, sourceFolder, targetFolder)); } return(true); }
public static bool TryCreate(MailboxSession mailboxSession, FolderChangeOperation operation, FolderChangeOperationFlags flags, GroupOperationResult result, StoreObjectId sourceFolderId, StoreObjectId destinationFolderId, out UserMoveActionHandler handler) { handler = null; if (operation == FolderChangeOperation.Move && result != null && result.OperationResult != OperationResult.Failed && result.ResultObjectIds != null && result.ResultObjectIds.Count > 0 && ClutterUtilities.IsClutterEnabled(mailboxSession, mailboxSession.MailboxOwner.GetConfiguration()) && sourceFolderId != null && destinationFolderId != null && !sourceFolderId.Equals(destinationFolderId)) { bool flag = mailboxSession.LogonType == LogonType.Owner || flags.HasFlag(FolderChangeOperationFlags.ClutterActionByUserOverride); handler = new UserMoveActionHandler(mailboxSession, sourceFolderId, destinationFolderId, result.ResultObjectIds, flag); return(true); } return(false); }
public void CaptureActivityAfterFolderChange(FolderChangeOperation operation, FolderChangeOperationFlags flags, IList <StoreObjectId> itemIdsBeforeChange, IList <StoreObjectId> itemIdsAfterChange, StoreObjectId sourceFolder, StoreObjectId targetFolder) { if (itemIdsBeforeChange == null || itemIdsBeforeChange.Count <= 0) { return; } IList <Activity> activities; if ((operation == FolderChangeOperation.HardDelete || operation == FolderChangeOperation.SoftDelete || operation == FolderChangeOperation.MoveToDeletedItems) && this.TryCreateDeleteActivities(operation, flags, itemIdsBeforeChange, sourceFolder, out activities)) { this.Log(activities); } if ((operation == FolderChangeOperation.HardDelete || operation == FolderChangeOperation.SoftDelete || operation == FolderChangeOperation.MoveToDeletedItems || operation == FolderChangeOperation.Move) && this.TryCreateMoveActivities(operation, itemIdsBeforeChange, itemIdsAfterChange, sourceFolder, targetFolder, out activities)) { this.Log(activities); } }
private bool TryCreateDeleteActivities(FolderChangeOperation operation, FolderChangeOperationFlags flags, IList <StoreObjectId> itemIdsBeforeMove, StoreObjectId sourceFolder, out IList <Activity> activities) { activities = null; string value; switch (operation) { case FolderChangeOperation.MoveToDeletedItems: value = "MoveToDeletedItems"; break; case FolderChangeOperation.SoftDelete: value = "SoftDelete"; break; case FolderChangeOperation.HardDelete: value = "HardDelete"; break; default: return(false); } ActivityId? activityId = null; DefaultFolderType defaultFolderType = (sourceFolder == null) ? DefaultFolderType.None : this.session.IsDefaultFolderType(sourceFolder); if (defaultFolderType == DefaultFolderType.Inbox) { activityId = new ActivityId?(ActivityId.DeleteFromInbox); } else if (defaultFolderType == DefaultFolderType.Clutter) { activityId = new ActivityId?(ActivityId.DeleteFromClutter); } bool flag = (flags & FolderChangeOperationFlags.EmptyFolder) == FolderChangeOperationFlags.EmptyFolder; bool flag2 = (flags & FolderChangeOperationFlags.DeleteAllClutter) == FolderChangeOperationFlags.DeleteAllClutter; activities = new List <Activity>(itemIdsBeforeMove.Count); foreach (StoreObjectId storeObjectId in itemIdsBeforeMove) { if (storeObjectId != null) { Activity item = new Activity(ActivityId.Delete, this.clientInfo.Id, ExDateTime.UtcNow, this.clientSessionId, this.clientInfo.Version, Interlocked.Increment(ref this.sequenceNumber), this.session, storeObjectId, null, new Dictionary <string, string> { { "DeleteType", value }, { "DeletedByEmptyFolder", flag ? bool.TrueString : bool.FalseString }, { "DeletedByDeleteAllClutter", flag2 ? bool.TrueString : bool.FalseString }, { "SourceDefaultFolderType", defaultFolderType.ToString() } }); activities.Add(item); if (activityId != null) { activities.Add(new Activity(activityId.Value, this.clientInfo.Id, ExDateTime.UtcNow, this.clientSessionId, this.clientInfo.Version, Interlocked.Increment(ref this.sequenceNumber), this.session, storeObjectId, null, null)); } } } return(true); }
public bool OnBeforeFolderChange(FolderChangeOperation operation, FolderChangeOperationFlags flags, StoreSession sourceSession, StoreSession destinationSession, StoreObjectId sourceFolderId, StoreObjectId destinationFolderId, ICollection <StoreObjectId> itemIds, CallbackContext callbackContext) { PublicFolderCOWSession.< > c__DisplayClass4 CS$ < > 8__locals1 = new PublicFolderCOWSession.< > c__DisplayClass4(); CS$ < > 8__locals1.sourceSession = sourceSession; CS$ < > 8__locals1.sourceFolderId = sourceFolderId; CS$ < > 8__locals1.< > 4__this = this; this.CheckDisposed("OnBeforeFolderChange"); EnumValidator.ThrowIfInvalid <FolderChangeOperation>(operation, "operation"); EnumValidator.ThrowIfInvalid <FolderChangeOperationFlags>(flags, "flags"); Util.ThrowOnNullArgument(callbackContext, "callbackContext"); if (this.InCallback) { return(false); } base.Results = new COWResults(this.publicFolderSession, itemIds); this.InCallback = true; try { PublicFolderCOWSession.< > c__DisplayClass7 CS$ < > 8__locals2 = new PublicFolderCOWSession.< > c__DisplayClass7(); CS$ < > 8__locals2.CS$ < > 8__locals5 = CS$ < > 8__locals1; CS$ < > 8__locals2.action = COWSessionBase.GetTriggerAction(operation); if (itemIds.Count == 0 || !COWSessionBase.IsDeleteOperation(CS$ < > 8__locals2.action)) { ExTraceGlobals.SessionTracer.TraceDebug <FolderChangeOperation, int>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - Skipping operation {0} for {1} items", operation, itemIds.Count); return(false); } CS$ < > 8__locals2.messagesToSoftDelete = new List <StoreObjectId>(itemIds.Count); List <StoreObjectId> list = new List <StoreObjectId>(itemIds.Count); CS$ < > 8__locals2.messageIds = COWSessionBase.InternalFilterItems(itemIds); foreach (StoreObjectId storeObjectId in COWSessionBase.InternalFilterFolders(itemIds)) { bool flag = CS$ < > 8__locals1.sourceFolderId != null && storeObjectId.Equals(CS$ < > 8__locals1.sourceFolderId); if (flag) { ExTraceGlobals.SessionTracer.TraceError <StoreObjectId>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - Folder {0} skipped. We currently don't support EmptyFolder operation for public folders", storeObjectId); base.Results.AddResult(new GroupOperationResult(OperationResult.PartiallySucceeded, new StoreObjectId[] { storeObjectId }, new StoragePermanentException(ServerStrings.ErrorEmptyFolderNotSupported))); } else { list.Add(storeObjectId); } } if (CS$ < > 8__locals2.messageIds.Count > 0 && (flags & FolderChangeOperationFlags.IncludeItems) == FolderChangeOperationFlags.IncludeItems) { Util.ThrowOnNullArgument(CS$ < > 8__locals1.sourceFolderId, "sourceFolderId"); ExTraceGlobals.SessionTracer.TraceDebug <COWTriggerAction, int, StoreObjectId>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - Processing action {0} for {1} messages in folder {2}", CS$ < > 8__locals2.action, CS$ < > 8__locals2.messageIds.Count, CS$ < > 8__locals1.sourceFolderId); if (CS$ < > 8__locals2.action == COWTriggerAction.HardDelete) { if (CS$ < > 8__locals2.messageIds.Count == itemIds.Count) { ExTraceGlobals.SessionTracer.TraceDebug <int>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - Skipping hard delete for all {0} messages", CS$ < > 8__locals2.messageIds.Count); return(false); } this.Execute(delegate() { using (Folder folder = Folder.Bind(CS$ < > 8__locals2.CS$ < > 8__locals5.sourceSession, CS$ < > 8__locals2.CS$ < > 8__locals5.sourceFolderId)) { CS$ < > 8__locals2.CS$ < > 8__locals5.< > 4__this.Results.AddResult(folder.InternalDeleteItems(DeleteItemFlags.HardDelete | DeleteItemFlags.SuppressReadReceipt, CS$ < > 8__locals2.messageIds.ToArray())); } }, CS$ < > 8__locals2.messageIds); } else { List <StoreObjectId> messagesFailed = new List <StoreObjectId>(CS$ < > 8__locals2.messageIds.Count); using (List <StoreObjectId> .Enumerator enumerator2 = CS$ < > 8__locals2.messageIds.GetEnumerator()) { while (enumerator2.MoveNext()) { StoreObjectId itemId = enumerator2.Current; if (itemId is OccurrenceStoreObjectId) { ExTraceGlobals.SessionTracer.TraceDebug <StoreObjectId>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - Skipping item {0} since it is an OccurrenceStoreObjectId", itemId); } else { this.Execute(delegate() { using (Item item = Item.Bind(CS$ < > 8__locals1.< > 4__this.publicFolderSession, itemId, PublicFolderCOWSession.propertiesToLoadForItems)) { if ((item.PropertyBag.GetValueOrDefault <EffectiveRights>(StoreObjectSchema.EffectiveRights, EffectiveRights.None) & EffectiveRights.Delete) == EffectiveRights.None) { ExTraceGlobals.SessionTracer.TraceError <StoreObjectId>((long)CS$ < > 8__locals1.< > 4__this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - User does not have delete permission for message id {0}", itemId); messagesFailed.Add(itemId); } else { CS$ < > 8__locals2.messagesToSoftDelete.Add(itemId); } } }, itemId); } } } if (messagesFailed.Count > 0) { ExTraceGlobals.SessionTracer.TraceError <int>((long)this.StoreSession.GetHashCode(), "PublicFolderCOWSession::OnBeforeFolderChange - {0} messages skipped due to insufficient permissions", messagesFailed.Count); base.Results.AddResult(new GroupOperationResult(OperationResult.PartiallySucceeded, messagesFailed, new AccessDeniedException(ServerStrings.NotEnoughPermissionsToPerformOperation))); } } }