internal void SaveToMailbox(MapiStore mailbox, int maxMoveHistoryLength) { MrsTracer.Common.Function("MoveHistoryEntryInternal.SaveToMailbox(maxHistoryLength={0})", new object[] { maxMoveHistoryLength }); List <byte[]> list = new List <byte[]>(); using (MapiFolder folder = MapiUtils.OpenFolderUnderRoot(mailbox, MoveHistoryEntryInternal.MHEFolderName, true)) { using (MapiTable contentsTable = folder.GetContentsTable(ContentsTableFlags.DeferredErrors)) { contentsTable.SortTable(new SortOrder(PropTag.LastModificationTime, SortFlags.Ascend), SortTableFlags.None); PropValue[][] array = MapiUtils.QueryAllRows(contentsTable, null, new PropTag[] { PropTag.EntryId }); foreach (PropValue[] array3 in array) { list.Add(array3[0].GetBytes()); } } MrsTracer.Common.Debug("Move history contains {0} items.", new object[] { list.Count }); List <byte[]> list2 = new List <byte[]>(); while (list.Count >= maxMoveHistoryLength && list.Count > 0) { list2.Add(list[0]); list.RemoveAt(0); } if (list2.Count > 0) { MrsTracer.Common.Debug("Clearing {0} entries from move history", new object[] { list2.Count }); MapiUtils.ProcessMapiCallInBatches <byte[]>(list2.ToArray(), delegate(byte[][] batch) { folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, batch); }); } } if (maxMoveHistoryLength <= 0) { MrsTracer.Common.Debug("Move history saving is disabled.", new object[0]); return; } DateTime dateTime = this.TimeTracker.GetTimestamp(RequestJobTimestamp.Creation) ?? DateTime.MinValue; string subject = string.Format("MoveHistoryEntry {0}", dateTime.ToString()); byte[] bytes = BitConverter.GetBytes(dateTime.ToBinary()); MoveObjectInfo <MoveHistoryEntryInternal> moveObjectInfo = new MoveObjectInfo <MoveHistoryEntryInternal>(Guid.Empty, mailbox, null, MoveHistoryEntryInternal.MHEFolderName, MoveHistoryEntryInternal.MHEMessageClass, subject, bytes); using (moveObjectInfo) { moveObjectInfo.SaveObject(this); } }
public void DeleteOldMessages() { using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, false)) { if (mapiFolder != null) { for (int i = 0; i < 100; i++) { byte[] array = this.FindMessageId(); if (array == null) { break; } mapiFolder.DeleteMessages(DeleteMessagesFlags.None, new byte[][] { array }); } } } }
public void DeleteMessage() { if (this.MessageId != null) { using (MapiFolder mapiFolder = MapiUtils.OpenFolderUnderRoot(this.store, this.folderName, false)) { if (mapiFolder != null) { mapiFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, new byte[][] { this.MessageId }); } } if (this.message != null) { this.message.Dispose(); this.message = null; } this.MessageId = null; this.FolderId = null; } }