internal static MapiFolder GetFolderByPath(MapiStore mapiStore, MapiFolderPath folderPath) { MapiFolder mapiFolder = null; MapiFolder folderByPath; try { folderByPath = Folder.GetFolderByPath(mapiStore, folderPath, out mapiFolder); } finally { if (mapiFolder != null) { mapiFolder.Dispose(); } } return(folderByPath); }
internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity) { MapiFolder mapiFolder = null; MapiFolder result; try { FolderId folderId = null; result = Folder.RetrieveMapiFolder(store, identity, ref mapiFolder, null, out folderId); } finally { if (mapiFolder != null) { mapiFolder.Dispose(); } } return(result); }
public override void Execute() { if (!this.ShouldExecuteOnThisStage) { return; } if (base.Context.DetectLoop()) { string[] valueOrDefault = base.Context.Message.GetValueOrDefault <string[]>(MessageItemSchema.XLoop, null); if (valueOrDefault == null || valueOrDefault.Length != 1) { return; } base.Context.TraceDebug("Sending OOF even though loop was detected due to 1 XLoop header in the message."); } if (string.IsNullOrEmpty(base.Context.SenderAddress)) { base.Context.TraceDebug("Sender address was empty, this OOF reply work item is not executed."); return; } MapiFolder nonIpmSubtreeFolder = null; MapiFolder oofHistoryFolder = null; OofHistory oofHistory = null; try { MailboxSession mailboxSession = base.Context.StoreSession as MailboxSession; bool shouldSendOofReply = true; bool shouldKeepOofHistory = true; if ((base.Rule.StateFlags & RuleStateFlags.KeepOOFHistory) == (RuleStateFlags)0) { base.Context.TraceError("Rule does not have 'keep OOF history' flag set, OOF history operation skipped."); shouldKeepOofHistory = false; } if (shouldKeepOofHistory && mailboxSession == null) { base.Context.TraceError("This is a public folder delivery, OOF history operation skipped."); shouldKeepOofHistory = false; } if (shouldKeepOofHistory && mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion < 1937801494) { base.Context.TraceError("Recipient's mailbox doesn't support OOF history."); shouldKeepOofHistory = false; } if (string.IsNullOrEmpty(base.Context.SenderAddress)) { base.Context.TraceError("Sender address was empty, OOF history operation skipped."); shouldKeepOofHistory = false; } if (shouldKeepOofHistory) { RuleUtil.RunMapiCode(ServerStrings.UpdateOOFHistoryOperation, delegate(object[] param0) { MapiStore mapiStore = this.Context.StoreSession.Mailbox.MapiStore; byte[] globalRuleId = mapiStore.GlobalIdFromId(this.Rule.ID); byte[] bytes = Encoding.ASCII.GetBytes(this.Context.SenderAddress); oofHistory = new OofHistory(bytes, globalRuleId, this.Context); if (!oofHistory.TryInitialize()) { shouldKeepOofHistory = false; return; } if (mailboxSession.IsMailboxOof()) { shouldSendOofReply = oofHistory.ShouldSendOofReply(); this.Context.TraceDebug <bool>("Should send automatic reply: {0}.", shouldSendOofReply); return; } this.Context.TraceDebug("Mailbox is not OOF, not sending oof reply"); }, new object[0]); } if (!shouldSendOofReply) { if (!ObjectClass.IsOfClass(base.Context.Message.ClassName, "IPM.Note.Microsoft.Approval.Request")) { base.Context.TraceDebug("Automatic reply will not be sent."); return; } base.Context.TraceDebug("Sending automatic reply anyway - the incoming message is an approval request."); } if (!base.Context.LimitChecker.DoesExceedAutoReplyLimit()) { using (MessageItem messageItem = base.OpenMessage(this.messageTemplateEntryId)) { using (MessageItem messageItem2 = RuleMessageUtils.CreateOofReply(base.Context.Message, messageItem, base.Context.StoreSession.PreferedCulture, new InboundConversionOptions(base.Context.StoreSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid), base.Context.DefaultDomainName), base.Context.XLoopValue)) { messageItem2[ItemSchema.SpamConfidenceLevel] = -1; messageItem2.AutoResponseSuppress = AutoResponseSuppress.All; base.Context.SetMailboxOwnerAsSender(messageItem2); base.SetRecipientsResponsibility(messageItem2); base.SubmitMessage(messageItem2); } } if (shouldKeepOofHistory && oofHistory != null) { RuleUtil.RunMapiCode(ServerStrings.AppendOOFHistoryEntry, delegate(object[] param0) { oofHistory.AppendEntry(); }, new object[0]); } } } finally { if (oofHistory != null) { RuleUtil.RunMapiCode(ServerStrings.UnlockOOFHistory, delegate(object[] param0) { oofHistory.Dispose(); }, new object[0]); } if (oofHistoryFolder != null) { RuleUtil.RunMapiCode(ServerStrings.DisposeOOFHistoryFolder, delegate(object[] param0) { oofHistoryFolder.Dispose(); }, new object[0]); } if (nonIpmSubtreeFolder != null) { RuleUtil.RunMapiCode(ServerStrings.DisposeNonIPMFolder, delegate(object[] param0) { nonIpmSubtreeFolder.Dispose(); }, new object[0]); } } }
internal static void RemoveOofHistoryEntriesWithProperty(MailboxSession itemStore, bool oofEnabled, OofHistory.PropId propId, byte[] propValue) { MapiFolder mapiFolder = null; MapiFolder mapiFolder2 = null; MapiStream mapiStream = null; bool flag = false; byte[] initialBytes = oofEnabled ? OofHistory.InitialBytesOofStateOn : OofHistory.InitialBytesOofStateOff; try { if (OofHistory.TryOpenFolder(itemStore, out mapiFolder, out mapiFolder2)) { long hashCode = (long)itemStore.GetHashCode(); bool flag2; mapiStream = OofHistory.OpenAndLockStream(mapiFolder2, initialBytes, hashCode, out flag2); flag = true; if (!flag2) { int num; if (OofHistory.TryGetStreamLengthForEntryRemoval(hashCode, mapiStream, out num)) { byte[] buffer; if (OofHistory.TryReadAllFromStream(hashCode, mapiStream, num, out buffer)) { int num2 = OofHistory.RemoveEntriesWithProperty(num, buffer, propId, propValue, hashCode); if (num2 < num) { mapiStream.Seek(0L, SeekOrigin.Begin); mapiStream.Write(buffer, 0, num2); mapiStream.SetLength((long)num2); } } } } } } finally { if (mapiStream != null) { try { if (flag) { mapiStream.UnlockRegion(0L, 1L, 1); } } finally { mapiStream.Dispose(); } } if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } if (mapiFolder2 != null) { mapiFolder2.Dispose(); mapiFolder2 = null; } } }
internal static void ClearOofHistory(MailboxSession itemStore, bool oofEnabled) { MapiFolder mapiFolder = null; MapiFolder mapiFolder2 = null; MapiStream mapiStream = null; bool flag = false; byte[] initialBytes = oofEnabled ? OofHistory.InitialBytesOofStateOn : OofHistory.InitialBytesOofStateOff; try { if (OofHistory.TryOpenFolder(itemStore, out mapiFolder, out mapiFolder2)) { long num = (long)itemStore.GetHashCode(); bool flag2; mapiStream = OofHistory.OpenAndLockStream(mapiFolder2, initialBytes, num, out flag2); flag = true; if (!flag2) { byte[] array = new byte[2]; if (2 != mapiStream.Read(array, 0, 2)) { OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, num); } else { bool flag3 = 0 != array[1]; if (flag3 == oofEnabled) { OofHistory.Tracer.TraceDebug <bool>(num, "Current OOF state {0} matches in OOF history and mailbox properties, clear is not executed.", oofEnabled); } else { OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, num); } } } } } finally { if (mapiStream != null) { try { if (flag) { mapiStream.UnlockRegion(0L, 1L, 1); } } finally { mapiStream.Dispose(); } } if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } if (mapiFolder2 != null) { mapiFolder2.Dispose(); mapiFolder2 = null; } } }
internal override void Save(bool keepUnmanagedResources) { if (ObjectState.Unchanged == base.ObjectState) { return; } if (ObjectState.Deleted == base.ObjectState) { throw new MapiInvalidOperationException(Strings.ExceptionObjectStateInvalid(base.ObjectState.ToString())); } base.EnableDisposeTracking(); using (MapiStore messageStore = this.GetMessageStore()) { MapiFolder mapiFolder = null; MapiFolder parentFolder = null; bool isFolderRetrieved = false; try { MapiSession mapiSession = base.MapiSession; Folder.CheckRequirementsOnSessionToContinue(base.MapiSession); bool creating = false; if (base.ObjectState == ObjectState.New) { creating = true; string text = null; if (this.newFolderIdentity == null) { if (null == this.Identity) { throw new MapiInvalidOperationException(Strings.ExceptionIdentityNull); } if (null == this.Identity.MapiFolderPath) { throw new MapiInvalidOperationException(Strings.ExceptionIdentityInvalid); } MapiFolder mapiFolder2 = null; try { parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder2); } finally { if (mapiFolder2 != null) { mapiFolder2.Dispose(); } } if (parentFolder != null && !parentFolder.AllowWarnings) { parentFolder.AllowWarnings = true; } text = this.Identity.MapiFolderPath.Name; } else { this.Identity = this.ConstructIdentity(null, MapiFolderPath.GenerateFolderPath(this.newFolderIdentity.ParentIdentity.MapiFolderPath, this.newFolderIdentity.FolderName, false), null); parentFolder = Folder.RetrieveMapiFolder(messageStore, this.newFolderIdentity.ParentIdentity); if (parentFolder != null && !parentFolder.AllowWarnings) { parentFolder.AllowWarnings = true; } text = this.newFolderIdentity.FolderName; } ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Create Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); try { mapiFolder = parentFolder.CreateFolder(text, string.Empty, false); if (mapiFolder != null && !mapiFolder.AllowWarnings) { mapiFolder.AllowWarnings = true; } isFolderRetrieved = true; } catch (MapiExceptionCollision innerException) { this.DetectFolderExistence(messageStore, parentFolder, text, innerException); throw; } this.UpdateIdentity(this.UpdateIdentityFlagsForCreating); } if (creating || ObjectState.Changed == base.ObjectState) { Folder.CheckRequirementsOnIdentityToContinue(this.Identity); this.DetectDisallowedModification(messageStore); if (ObjectState.Changed == base.ObjectState && base.IsChanged(MapiPropertyDefinitions.Name)) { string name = (string)this[MapiPropertyDefinitions.Name]; if (parentFolder == null) { MapiFolder mapiFolder3 = null; try { parentFolder = Folder.RetrieveParentMapiFolder(messageStore, this.Identity, ref mapiFolder3); } finally { if (mapiFolder3 != null) { mapiFolder3.Dispose(); } } } this.DetectFolderExistence(messageStore, parentFolder, name, null); } PropProblem[] array = null; PropProblem[] array2 = null; FolderId folderId = null; if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } mapiFolder = Folder.RetrieveMapiFolder(messageStore, this.Identity, ref parentFolder, new Folder.IdentityConstructor(this.ConstructIdentity), out folderId); ParameterlessReturnlessDelegate parameterlessReturnlessDelegate = delegate() { if (creating && isFolderRetrieved) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Remove Folder '{0}' for rolling back creating on server '{1}'.", this.Identity, this.MapiSession.ServerName); try { parentFolder.DeleteFolder((byte[])this.Identity.MapiEntryId); } catch (MapiRetryableException ex) { ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex.Message); } catch (MapiPermanentException ex2) { ExTraceGlobals.FolderTracer.TraceError <FolderId, string, string>((long)this.GetHashCode(), "Removing Folder '{0}' for rolling back caughting an exception on server '{1}': {2}", this.Identity, this.MapiSession.ServerName, ex2.Message); } } }; try { PropValue[] propertyValuesToUpdate = base.GetPropertyValuesToUpdate(); if (0 < propertyValuesToUpdate.Length) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Set PropValues against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); array = mapiFolder.SetProps(propertyValuesToUpdate); } PropTag[] propertyTagsToDelete = base.GetPropertyTagsToDelete(); if (0 < propertyTagsToDelete.Length) { ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string>((long)this.GetHashCode(), "To Delete PropTags against Folder '{0}' on server '{1}'.", this.Identity, base.MapiSession.ServerName); array2 = mapiFolder.DeleteProps(propertyTagsToDelete); } } catch (DataValidationException) { parameterlessReturnlessDelegate(); throw; } catch (MapiRetryableException) { parameterlessReturnlessDelegate(); throw; } catch (MapiPermanentException) { parameterlessReturnlessDelegate(); throw; } base.ResetChangeTrackingAndObjectState(); StringBuilder stringBuilder = new StringBuilder(); if (array != null && 0 < array.Length) { stringBuilder.AppendLine(Strings.ErrorSetPropsProblem(this.Identity.ToString(), array.Length.ToString())); foreach (PropProblem propProblem in array) { stringBuilder.Append('\t'); stringBuilder.AppendLine(Strings.ErrorPropProblem(propProblem.PropTag.ToString(), propProblem.PropType.ToString(), propProblem.Scode.ToString())); } stringBuilder.AppendLine(); } if (array2 != null && 0 < array2.Length) { stringBuilder.AppendLine(Strings.ErrorDeletePropsProblem(this.Identity.ToString(), array2.Length.ToString())); foreach (PropProblem propProblem2 in array2) { stringBuilder.Append('\t'); stringBuilder.Append(Strings.ErrorPropProblem(propProblem2.PropTag.ToString(), propProblem2.PropType.ToString(), propProblem2.Scode.ToString())); stringBuilder.AppendLine(); } stringBuilder.AppendLine(); } if (0 < stringBuilder.Length) { string text2 = stringBuilder.ToString(); ExTraceGlobals.FolderTracer.TraceDebug <FolderId, string, string>((long)this.GetHashCode(), "Setting Folder '{0}' on server '{1}' returns error '{2}'.", this.Identity, base.MapiSession.ServerName, text2); parameterlessReturnlessDelegate(); throw new MapiInvalidOperationException(new LocalizedString(text2)); } } } finally { if (mapiFolder != null) { mapiFolder.Dispose(); } if (parentFolder != null) { parentFolder.Dispose(); } base.Dispose(); } } }
internal static MapiFolder GetFolderByPath(MapiStore mapiStore, MapiFolderPath folderPath, out MapiFolder parent) { if (mapiStore == null) { throw new ArgumentNullException("mapiStore"); } if (null == folderPath) { throw new ArgumentNullException("folderPath"); } parent = null; MapiFolder mapiFolder = null; bool flag = false; MapiFolder result; try { mapiFolder = (folderPath.IsIpmPath ? mapiStore.GetIpmSubtreeFolder() : mapiStore.GetNonIpmSubtreeFolder()); int num = 0; while (folderPath.Depth - 1 > num) { MapiFolder mapiFolder2; parent = (mapiFolder2 = mapiFolder); using (mapiFolder2) { mapiFolder = parent.OpenSubFolderByName(folderPath[num]); } num++; } if (folderPath.Depth - 1 == num) { if (parent != null) { parent.Dispose(); parent = null; } parent = mapiFolder; mapiFolder = parent.OpenSubFolderByName(folderPath[num]); } if (parent == null) { parent = mapiStore.GetRootFolder(); } flag = true; result = mapiFolder; } finally { if (!flag) { if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } if (parent != null) { parent.Dispose(); parent = null; } } } return(result); }
private static MapiFolder RetrieveParentMapiFolder(MapiStore store, FolderId identity, ref MapiFolder folder) { if (store == null) { throw new ArgumentNullException("store"); } Folder.CheckRequirementsOnIdentityToContinue(identity); MapiFolder mapiFolder = null; bool flag = false; bool flag2 = false; MapiFolder result; try { byte[] array = null; if (null == identity.MapiEntryId) { if (identity.LegacyDistinguishedName != null) { array = store.GetFolderEntryId(identity.LegacyDistinguishedName); } } else { array = (byte[])identity.MapiEntryId; } if (array != null) { if (folder == null) { folder = (MapiFolder)store.OpenEntry(array); flag = true; } mapiFolder = (MapiFolder)store.OpenEntry(folder.GetProp(PropTag.ParentEntryId).GetBytes()); } else if (null != identity.MapiFolderPath) { MapiFolderPath parent = identity.MapiFolderPath.Parent; if (null == parent) { mapiFolder = store.GetRootFolder(); } else { mapiFolder = Folder.GetFolderByPath(store, parent); } } flag2 = true; result = mapiFolder; } finally { if (!flag2) { if (flag && folder != null) { folder.Dispose(); folder = null; } if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } } } return(result); }
internal static MapiFolder RetrieveMapiFolder(MapiStore store, FolderId identity, ref MapiFolder parent, Folder.IdentityConstructor idCtor, out FolderId realId) { realId = null; if (store == null) { throw new ArgumentNullException("store"); } Folder.CheckRequirementsOnIdentityToContinue(identity); MapiFolder mapiFolder = null; bool flag = false; bool flag2 = false; MapiFolder result; try { byte[] array = null; MapiEntryId entryId = null; MapiFolderPath folderPath = null; string legacyDn = null; if (null == identity.MapiEntryId) { if (identity.LegacyDistinguishedName != null) { legacyDn = identity.LegacyDistinguishedName; array = store.GetFolderEntryId(identity.LegacyDistinguishedName); } } else { array = (byte[])identity.MapiEntryId; } if (array != null) { entryId = new MapiEntryId(array); mapiFolder = (MapiFolder)store.OpenEntry(array); if (parent == null) { parent = (MapiFolder)store.OpenEntry(mapiFolder.GetProp(PropTag.ParentEntryId).GetBytes()); flag = true; } } else if (null != identity.MapiFolderPath) { folderPath = identity.MapiFolderPath; if (parent == null) { mapiFolder = Folder.GetFolderByPath(store, identity.MapiFolderPath, out parent); flag = true; } else { mapiFolder = Folder.GetFolderByPath(store, parent, identity.MapiFolderPath); } } if (idCtor != null) { realId = idCtor(entryId, folderPath, legacyDn); } flag2 = true; result = mapiFolder; } finally { if (!flag2) { if (mapiFolder != null) { mapiFolder.Dispose(); mapiFolder = null; } if (flag && parent != null) { parent.Dispose(); parent = null; } } } return(result); }