Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 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
                 });
             }
         }
     }
 }
Ejemplo n.º 3
0
 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;
     }
 }