private static MapiStream OpenAndLockStream(MapiFolder oofHistoryFolder, byte[] initialBytes, long hashCode, out bool isNew) { MapiStream mapiStream = null; isNew = false; OpenPropertyFlags openPropertyFlags = OpenPropertyFlags.Modify | OpenPropertyFlags.DeferredErrors; try { mapiStream = oofHistoryFolder.OpenStream(PropTag.OofHistory, openPropertyFlags); OofHistory.LockStreamWithRetry(mapiStream, hashCode); } catch (MapiExceptionNotFound) { if (mapiStream != null) { mapiStream.Dispose(); mapiStream = null; } OofHistory.Tracer.TraceDebug(hashCode, "OOF history property does not exist, trying to open with create flag."); openPropertyFlags |= OpenPropertyFlags.Create; mapiStream = oofHistoryFolder.OpenStream(PropTag.OofHistory, openPropertyFlags); OofHistory.LockStreamWithRetry(mapiStream, hashCode); OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, hashCode); isNew = true; } return(mapiStream); }
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; } } }