private void WaitAndProcessProbeResponses(MapiFolder folder, string fromAddress, Dictionary <string, string> subjectTargets, ExDateTime probeSentTime)
        {
            List <byte[]> list  = new List <byte[]>();
            List <string> list2 = new List <string>();

            for (int i = 0; i < base.Task.ExecutionTimeout; i++)
            {
                foreach (KeyValuePair <string, string> keyValuePair in subjectTargets)
                {
                    if (!string.IsNullOrEmpty(keyValuePair.Value))
                    {
                        using (MapiMessage deliveryReceipt = TestMailFlowHelper.GetDeliveryReceipt(folder, keyValuePair.Key, false))
                        {
                            if (deliveryReceipt != null)
                            {
                                PropValue prop  = deliveryReceipt.GetProp(PropTag.MessageDeliveryTime);
                                PropValue prop2 = deliveryReceipt.GetProp(PropTag.EntryId);
                                PropValue prop3 = deliveryReceipt.GetProp(PropTag.Subject);
                                if (!prop.IsError() && prop.Value != null && prop3.Value != null)
                                {
                                    string text = prop3.Value.ToString();
                                    if (text.StartsWith("RSP: CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase))
                                    {
                                        EnhancedTimeSpan latency = ((ExDateTime)prop.GetDateTime() > probeSentTime) ? ((ExDateTime)prop.GetDateTime() - probeSentTime) : EnhancedTimeSpan.Zero;
                                        base.OutputResult(Strings.TestMailflowSucceeded(fromAddress, keyValuePair.Value), latency, base.IsRemoteTest);
                                    }
                                    else if (text.StartsWith("Undeliverable: CrossPremiseMailFlowMonitoring-", StringComparison.OrdinalIgnoreCase))
                                    {
                                        EnhancedTimeSpan latency2 = EnhancedTimeSpan.FromSeconds(0.0);
                                        string           info     = (string)deliveryReceipt.GetProp(PropTag.Body).Value;
                                        base.OutputResult(Strings.CrossPremiseProbeNdred(fromAddress, keyValuePair.Value, info), latency2, base.IsRemoteTest);
                                    }
                                    list2.Add(keyValuePair.Key);
                                    list.Add(prop2.GetBytes());
                                }
                            }
                        }
                    }
                }
                foreach (string key in list2)
                {
                    subjectTargets.Remove(key);
                }
                list2.Clear();
                if (subjectTargets.Count == 0)
                {
                    break;
                }
                Thread.Sleep(1000);
            }
            foreach (KeyValuePair <string, string> keyValuePair2 in subjectTargets)
            {
                if (!string.IsNullOrEmpty(keyValuePair2.Value))
                {
                    EnhancedTimeSpan latency3 = EnhancedTimeSpan.FromSeconds(0.0);
                    base.OutputResult(Strings.MapiTransactionResultFailure, latency3, base.IsRemoteTest);
                }
            }
            folder.DeleteMessages(DeleteMessagesFlags.ForceHardDelete, list.ToArray());
        }
        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();
                }
            }
        }
Exemple #3
0
        public void CommitChanges(MailboxSession itemStore, MapiFolder folder)
        {
            Exception ex = null;

            try
            {
                if (this.toRemove != null)
                {
                    folder.DeleteRules(this.toRemove.ToArray());
                    List <byte[]> list = new List <byte[]>();
                    foreach (Rule rule in this.toRemove)
                    {
                        RuleManager.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Deleted rule '{1}'", itemStore.MailboxOwner, rule.Name);
                        RuleManager.TracerPfd.TracePfd <int, IExchangePrincipal, string>((long)this.GetHashCode(), "PFD IWO {0} Mailbox:{1}: Deleted rule '{2}'", 29591, itemStore.MailboxOwner, rule.Name);
                        if (((RuleAction.OOFReply)rule.Actions[0]).ReplyTemplateMessageEntryID != null)
                        {
                            list.Add(((RuleAction.OOFReply)rule.Actions[0]).ReplyTemplateMessageEntryID);
                        }
                    }
                    if (list.Count > 0)
                    {
                        folder.DeleteMessages(DeleteMessagesFlags.None, list.ToArray());
                        foreach (byte[] bytes in list)
                        {
                            RuleManager.Tracer.TraceDebug <IExchangePrincipal, ByteArray>((long)this.GetHashCode(), "Mailbox:{0}: Deleted reply template '{1}'", itemStore.MailboxOwner, new ByteArray(bytes));
                            RuleManager.TracerPfd.TracePfd <int, IExchangePrincipal, ByteArray>((long)this.GetHashCode(), "PFD IWO {0} Mailbox:{1}: Deleted reply template '{2}'", 19607, itemStore.MailboxOwner, new ByteArray(bytes));
                        }
                    }
                    this.toRemove = null;
                }
                if (this.toUpdate != null)
                {
                    folder.ModifyRules(this.toUpdate.ToArray());
                    foreach (Rule rule2 in this.toUpdate)
                    {
                        RuleManager.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated rule '{1}'", itemStore.MailboxOwner, rule2.Name);
                        RuleManager.TracerPfd.TracePfd <int, IExchangePrincipal, string>((long)this.GetHashCode(), "PFD IWO {0} Mailbox:{1}: Updated rule '{2}'", 27799, itemStore.MailboxOwner, rule2.Name);
                    }
                    this.toUpdate = null;
                }
                if (this.toAdd != null)
                {
                    folder.AddRules(this.toAdd.ToArray());
                    foreach (Rule rule3 in this.toAdd)
                    {
                        RuleManager.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Created new rule '{1}'", itemStore.MailboxOwner, rule3.Name);
                        RuleManager.TracerPfd.TracePfd <int, IExchangePrincipal, string>((long)this.GetHashCode(), "PFD IWO {0} Mailbox:{1}: Created new rule '{2}'", 23703, itemStore.MailboxOwner, rule3.Name);
                    }
                    this.toAdd = null;
                }
            }
            catch (MapiExceptionInvalidParameter mapiExceptionInvalidParameter)
            {
                ex = mapiExceptionInvalidParameter;
            }
            catch (MapiExceptionNotFound mapiExceptionNotFound)
            {
                ex = mapiExceptionNotFound;
            }
            catch (MapiExceptionQuotaExceeded mapiExceptionQuotaExceeded)
            {
                ex = mapiExceptionQuotaExceeded;
            }
            catch (MapiExceptionShutoffQuotaExceeded mapiExceptionShutoffQuotaExceeded)
            {
                ex = mapiExceptionShutoffQuotaExceeded;
            }
            catch (MapiExceptionNotEnoughMemory mapiExceptionNotEnoughMemory)
            {
                ex = mapiExceptionNotEnoughMemory;
            }
            if (ex is MapiExceptionQuotaExceeded || ex is MapiExceptionShutoffQuotaExceeded || ex is MapiExceptionNotEnoughMemory)
            {
                RuleManager.Tracer.TraceError <IExchangePrincipal, Exception>((long)this.GetHashCode(), "Mailbox:{0}: cannot commit rule changes because exceeded rule quota. Exception {1}", itemStore.MailboxOwner, ex);
                Globals.OOFLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_OOFRulesQuotaExceeded, itemStore.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(), new object[]
                {
                    itemStore.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()
                });
            }
            if (ex != null)
            {
                RuleManager.Tracer.TraceError <IExchangePrincipal, Exception>((long)this.GetHashCode(), "Mailbox:{0}: An OOF rule could not be saved. Exception: {1}", itemStore.MailboxOwner, ex);
                throw new OofRulesSaveException(ex);
            }
        }
 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());
             }
         }
     }
 }