private static void CleanUpInbox(MapiFolder folder)
        {
            DateTime  t = DateTime.UtcNow.AddMinutes(-20.0);
            MapiTable contentsTable;
            MapiTable mapiTable = contentsTable = folder.GetContentsTable();

            try
            {
                mapiTable.SetColumns(new PropTag[]
                {
                    PropTag.EntryId,
                    PropTag.MessageDeliveryTime,
                    PropTag.NormalizedSubject,
                    PropTag.OriginalSubject
                });
                Restriction restriction = Restriction.Or(new Restriction[]
                {
                    Restriction.Content(PropTag.NormalizedSubject, "66c7004a-6860-44b2-983a-327aa3c9cfec", ContentFlags.SubString | ContentFlags.IgnoreCase),
                    Restriction.Content(PropTag.OriginalSubject, "66c7004a-6860-44b2-983a-327aa3c9cfec", ContentFlags.SubString | ContentFlags.IgnoreCase)
                });
                mapiTable.Restrict(restriction);
                mapiTable.SortTable(new SortOrder(PropTag.MessageDeliveryTime, SortFlags.Ascend), SortTableFlags.None);
                PropValue[][] array = mapiTable.QueryRows(100, QueryRowsFlags.None);
                List <byte[]> list  = new List <byte[]>(100);
                for (int i = 0; i <= array.GetUpperBound(0); i++)
                {
                    if (TestMailFlowHelper.IsValidPropData(array, i, 2))
                    {
                        if (array[i][1].GetDateTime() > t)
                        {
                            break;
                        }
                        list.Add(array[i][0].GetBytes());
                    }
                }
                if (list.Count > 0)
                {
                    folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray());
                }
            }
            finally
            {
                if (contentsTable != null)
                {
                    ((IDisposable)contentsTable).Dispose();
                }
            }
        }
 private void MatchCrossPremiseMessages(MapiFolder responseFolder, MapiFolder probeFolder, SmtpAddress source, List <SmtpAddress> targets)
 {
     using (MapiTable contentsTable = responseFolder.GetContentsTable())
     {
         using (MapiTable contentsTable2 = probeFolder.GetContentsTable())
         {
             contentsTable.SetColumns(new PropTag[]
             {
                 PropTag.EntryId,
                 PropTag.Subject,
                 PropTag.ClientSubmitTime
             });
             contentsTable2.SetColumns(new PropTag[]
             {
                 PropTag.EntryId,
                 PropTag.Subject,
                 PropTag.ClientSubmitTime
             });
             PropValue[][] array  = contentsTable.QueryRows(1000, QueryRowsFlags.None);
             PropValue[][] array2 = contentsTable2.QueryRows(1000, QueryRowsFlags.None);
             List <byte[]> list   = new List <byte[]>();
             List <byte[]> list2  = new List <byte[]>();
             Dictionary <SmtpAddress, CrossPremiseTestMailFlowHelper.HealthData> dictionary = new Dictionary <SmtpAddress, CrossPremiseTestMailFlowHelper.HealthData>(targets.Count);
             for (int i = 0; i <= array2.GetUpperBound(0); i++)
             {
                 if (TestMailFlowHelper.IsValidPropData(array2, i, 3))
                 {
                     string text = (string)array2[i][1].Value;
                     if (text.StartsWith("CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase))
                     {
                         byte[] bytes = array2[i][0].GetBytes();
                         using (MapiMessage mapiMessage = (MapiMessage)probeFolder.OpenEntry(bytes))
                         {
                             SmtpAddress key = SmtpAddress.Parse((string)mapiMessage.GetProp(PropTag.ReceivedByEmailAddress).Value);
                             if (!dictionary.ContainsKey(key))
                             {
                                 dictionary.Add(key, new CrossPremiseTestMailFlowHelper.HealthData(EnhancedTimeSpan.Zero, EnhancedTimeSpan.Zero, 0, 0, 0, 0));
                             }
                             ExDateTime exDateTime = (ExDateTime)array2[i][2].GetDateTime();
                             if (exDateTime.Add(base.Task.CrossPremisesExpirationTimeout) < ExDateTime.UtcNow)
                             {
                                 dictionary[key].ExpiredNumber++;
                                 list.Add(bytes);
                             }
                             else
                             {
                                 for (int j = 0; j <= array.GetUpperBound(0); j++)
                                 {
                                     if (TestMailFlowHelper.IsValidPropData(array, j, 3))
                                     {
                                         string text2 = (string)array[j][1].Value;
                                         if (text2.EndsWith(text, StringComparison.OrdinalIgnoreCase))
                                         {
                                             byte[] bytes2 = array[j][0].GetBytes();
                                             if (((ExDateTime)array[j][2].GetDateTime()).Add(base.Task.CrossPremisesExpirationTimeout) < ExDateTime.UtcNow)
                                             {
                                                 list2.Add(bytes2);
                                             }
                                             else
                                             {
                                                 using (MapiMessage mapiMessage2 = (MapiMessage)responseFolder.OpenEntry(bytes2))
                                                 {
                                                     EnhancedTimeSpan t;
                                                     EnhancedTimeSpan t2;
                                                     if (this.ProcessCrossPremiseMessagePair(mapiMessage, mapiMessage2, source.ToString(), key.ToString(), out t, out t2))
                                                     {
                                                         dictionary[key].ProbeLatency    += t;
                                                         dictionary[key].ResponseLatency += t2;
                                                         dictionary[key].SuccessNumber++;
                                                     }
                                                     else
                                                     {
                                                         dictionary[key].FailedNumber++;
                                                     }
                                                 }
                                                 list2.Add(bytes2);
                                                 list.Add(bytes);
                                             }
                                         }
                                     }
                                 }
                                 if (!list.Contains(bytes) && exDateTime.AddMinutes(10.0) < ExDateTime.UtcNow)
                                 {
                                     dictionary[key].PendingNumber++;
                                 }
                             }
                         }
                     }
                 }
             }
             this.SaveHealthData(source, dictionary);
             if (list2.Count > 0)
             {
                 responseFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list2.ToArray());
             }
             if (list.Count > 0)
             {
                 probeFolder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray());
             }
         }
     }
 }