private MailSubmissionResult SubmitMessageImpl(MapiSubmissionInfo submissionInfo, SubmissionPoisonHandler submissionPoisonHandler, QuarantineHandler quarantineHandler)
        {
            MailSubmissionResult mailSubmissionResult = new MailSubmissionResult();

            if (this.Retired)
            {
                mailSubmissionResult.ErrorCode = 2214592514U;
                return(mailSubmissionResult);
            }
            string mailboxFqdn = submissionInfo.MailboxFqdn;
            string database    = submissionInfo.MdbGuid.ToString();
            MailSubmissionResult result;

            using (submissionInfo.GetTraceFilter())
            {
                using (SubmissionConnectionWrapper connection = SubmissionConnectionPool.GetConnection(mailboxFqdn, database))
                {
                    using (SubmissionThreadLimiter submissionThreadLimiter = new SubmissionThreadLimiter())
                    {
                        SubmissionPoisonContext submissionPoisonContext = null;
                        try
                        {
                            submissionThreadLimiter.BeginSubmission(connection.Id, mailboxFqdn, database);
                            if (this.Retired)
                            {
                                mailSubmissionResult.ErrorCode = 2214592514U;
                                connection.SubmissionAborted("Retiring.");
                                result = mailSubmissionResult;
                            }
                            else
                            {
                                this.storeDriverTracer.StoreDriverSubmissionTracer.TracePfdPass <int, MapiSubmissionInfo>(this.storeDriverTracer.MessageProbeActivityId, 0L, "PFD ESD {0} Processing SubmitMessage for {1}", 27547, submissionInfo);
                                submissionPoisonContext = submissionInfo.GetPoisonContext();
                                MailItemSubmitter mailItemSubmitter2;
                                MailItemSubmitter mailItemSubmitter = mailItemSubmitter2 = new MailItemSubmitter(connection.Id, submissionInfo, this.sendAsManager, submissionPoisonHandler, submissionPoisonContext, this);
                                try
                                {
                                    QuarantineInfoContext quarantineInfoContext;
                                    TimeSpan timeSpan;
                                    if (SubmissionConfiguration.Instance.App.EnableMailboxQuarantine && quarantineHandler.IsResourceQuarantined(submissionPoisonContext.ResourceGuid, out quarantineInfoContext, out timeSpan))
                                    {
                                        mailSubmissionResult.ErrorCode          = 1140850696U;
                                        mailSubmissionResult.QuarantineTimeSpan = timeSpan;
                                        mailSubmissionResult.DiagnosticInfo     = string.Format("{0}:{1}, QuarantineRemainingTimeSpan:{2}", "QuarantineStart", quarantineInfoContext.QuarantineStartTime, timeSpan);
                                        connection.SubmissionFailed(string.Format("Resource {0} is in quarantined state", submissionPoisonContext.ResourceGuid));
                                        return(mailSubmissionResult);
                                    }
                                    if (this.PoisonMessageDectionEnabled && submissionPoisonHandler.VerifyPoisonMessage(submissionPoisonContext))
                                    {
                                        this.LogPoisonMessageMTL(submissionInfo, submissionPoisonContext);
                                        if (SubmissionConfiguration.Instance.App.EnableSendNdrForPoisonMessage)
                                        {
                                            if (!submissionPoisonHandler.VerifyPoisonNdrSent(submissionPoisonContext))
                                            {
                                                mailItemSubmitter.HandlePoisonMessageNdrSubmission();
                                                mailSubmissionResult.ErrorCode = StoreDriverSubmissionUtils.MapSubmissionStatusErrorCodeToPoisonErrorCode(mailItemSubmitter.Result.ErrorCode);
                                            }
                                        }
                                        else
                                        {
                                            mailSubmissionResult.ErrorCode = 3U;
                                        }
                                        connection.SubmissionAborted(string.Format("Poison Context Info: Resource = {0};EventCounter = {1}.", submissionPoisonContext.ResourceGuid, submissionPoisonContext.MapiEventCounter));
                                        return(mailSubmissionResult);
                                    }
                                    Thread currentThread = Thread.CurrentThread;
                                    try
                                    {
                                        this.SubmissionsInProgress[currentThread] = mailItemSubmitter;
                                        mailItemSubmitter.Submit();
                                        mailSubmissionResult.RemoteHostName = mailItemSubmitter.Result.RemoteHostName;
                                    }
                                    finally
                                    {
                                        this.SubmissionsInProgress.Remove(currentThread);
                                    }
                                }
                                finally
                                {
                                    if (mailItemSubmitter2 != null)
                                    {
                                        ((IDisposable)mailItemSubmitter2).Dispose();
                                    }
                                }
                                if (mailItemSubmitter.Result.ErrorCode == 0U)
                                {
                                    connection.SubmissionSuccessful(mailItemSubmitter.MessageSize, mailItemSubmitter.RecipientCount);
                                }
                                else
                                {
                                    StringBuilder stringBuilder = new StringBuilder();
                                    stringBuilder.Append("HResult: ");
                                    stringBuilder.Append(mailItemSubmitter.Result.ErrorCode.ToString());
                                    stringBuilder.Append("; DiagnosticInfo: ");
                                    stringBuilder.Append(mailItemSubmitter.Result.DiagnosticInfo);
                                    connection.SubmissionFailed(stringBuilder.ToString());
                                }
                                if (mailItemSubmitter.Result.ErrorCode == 3U)
                                {
                                    submissionInfo.LogEvent(SubmissionInfo.Event.StoreDriverSubmissionPoisonMessageInSubmission);
                                }
                                result = mailItemSubmitter.Result;
                            }
                        }
                        catch (ThreadLimitExceededException ex)
                        {
                            connection.SubmissionAborted(ex.Message);
                            mailSubmissionResult.ErrorCode      = 1090519042U;
                            mailSubmissionResult.DiagnosticInfo = ex.Message;
                            result = mailSubmissionResult;
                        }
                        catch (Exception exception)
                        {
                            try
                            {
                                submissionPoisonHandler.SavePoisonContext(submissionPoisonContext);
                                string exceptionDiagnosticInfo = StorageExceptionHandler.GetExceptionDiagnosticInfo(exception);
                                connection.SubmissionFailed("Exception: " + exceptionDiagnosticInfo);
                                submissionInfo.LogEvent(SubmissionInfo.Event.StoreDriverSubmissionPoisonMessage, exception);
                                FailFast.Fail(exception);
                            }
                            catch (Exception ex2)
                            {
                                StoreDriverSubmission.LogEvent(MSExchangeStoreDriverSubmissionEventLogConstants.Tuple_StoreDriverSubmissionFailFastFailure, null, new object[]
                                {
                                    ex2
                                });
                            }
                            result = mailSubmissionResult;
                        }
                    }
                }
            }
            return(result);
        }
        public MailSubmissionResult SubmitMessage(string serverDN, Guid mailboxGuid, Guid mdbGuid, string databaseName, long eventCounter, byte[] entryId, byte[] parentEntryId, string serverFqdn, IPAddress networkAddressBytes, DateTime originalCreateTime, bool isPublicFolder, TenantPartitionHint tenantHint, string mailboxHopLatency, QuarantineHandler quarantineHandler, SubmissionPoisonHandler submissionPoisonHandler, LatencyTracker latencyTracker)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("serverDN", serverDN);
            ArgumentValidator.ThrowIfEmpty("mailboxGuid", mailboxGuid);
            ArgumentValidator.ThrowIfEmpty("mdbGuid", mdbGuid);
            ArgumentValidator.ThrowIfNullOrEmpty("databaseName", databaseName);
            ArgumentValidator.ThrowIfNull("entryId", entryId);
            ArgumentValidator.ThrowIfInvalidValue <int>("entryId", entryId.Length, (int value) => value > 0);
            ArgumentValidator.ThrowIfNull("parentEntryId", parentEntryId);
            ArgumentValidator.ThrowIfInvalidValue <int>("parentEntryId", parentEntryId.Length, (int value) => value > 0);
            ArgumentValidator.ThrowIfNullOrEmpty("serverFqdn", serverFqdn);
            ArgumentValidator.ThrowIfNull("networkAddressBytes", networkAddressBytes);
            ArgumentValidator.ThrowIfNullOrEmpty("mailboxHopLatency", mailboxHopLatency);
            ArgumentValidator.ThrowIfNull("quarantineHandler", quarantineHandler);
            ArgumentValidator.ThrowIfNull("submissionPoisonHandler", submissionPoisonHandler);
            bool shouldDeprioritize = false;

            if (SubmissionConfiguration.Instance.App.SenderRateDeprioritizationEnabled)
            {
                long num = this.rateTrackerForDeprioritization.IncrementSenderRate(mailboxGuid, originalCreateTime);
                if (num > (long)SubmissionConfiguration.Instance.App.SenderRateDeprioritizationThreshold)
                {
                    shouldDeprioritize = true;
                }
            }
            bool shouldThrottle = false;

            if (SubmissionConfiguration.Instance.App.SenderRateThrottlingEnabled)
            {
                long num2 = this.rateTrackerForThrottling.IncrementSenderRate(mailboxGuid, originalCreateTime);
                if (num2 > (long)SubmissionConfiguration.Instance.App.SenderRateThrottlingThreshold)
                {
                    shouldThrottle = true;
                    this.rateTrackerForThrottling.ResetSenderRate(mailboxGuid, originalCreateTime);
                }
            }
            MapiSubmissionInfo submissionInfo = new MapiSubmissionInfo(serverDN, mailboxGuid, entryId, parentEntryId, eventCounter, serverFqdn, networkAddressBytes, mdbGuid, databaseName, originalCreateTime, isPublicFolder, tenantHint, mailboxHopLatency, latencyTracker, shouldDeprioritize, shouldThrottle, this.storeDriverTracer);

            return(this.SubmitMessageImpl(submissionInfo, submissionPoisonHandler, quarantineHandler));
        }