internal static string GetExceptionDiagnosticInfo(Exception exception)
        {
            StringBuilder stringBuilder = new StringBuilder((exception.InnerException == null) ? 1000 : 2000);

            stringBuilder.Append(exception.Message);
            Exception ex = (exception.InnerException == null) ? exception : exception.InnerException;
            MapiPermanentException ex2 = ex as MapiPermanentException;

            if (ex2 != null)
            {
                stringBuilder.AppendFormat(" {0}", StorageExceptionHandler.GetDiagnosticInfo(ex2));
            }
            else
            {
                MapiRetryableException ex3 = ex as MapiRetryableException;
                if (ex3 != null)
                {
                    stringBuilder.AppendFormat(" {0}", StorageExceptionHandler.GetDiagnosticInfo(ex3));
                }
                else
                {
                    stringBuilder.AppendFormat(" {0}: {1}", ex.GetType().Name, ex.Message);
                }
            }
            return(stringBuilder.ToString());
        }
        private static MessageStatus GetMessageStatus(IMessageConverter converter, DataValidationException invalidDataException)
        {
            StorageExceptionHandler.LogException(converter, invalidDataException);
            SmtpResponse exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, invalidDataException, true, converter.IsOutbound ? AckReason.OutboundInvalidDirectoryData : AckReason.InboundInvalidDirectoryData);

            return(new MessageStatus(MessageAction.NDR, exceptionSmtpResponse, invalidDataException));
        }
Exemplo n.º 3
0
        public MessageStatus CreateStatus(Exception exception, Exception exceptionAssociatedWithHandler, IMessageConverter converter, TimeSpan fastRetryInterval, TimeSpan quarantineRetryInterval)
        {
            SmtpResponse  exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, exception, this.Category == Category.Permanent, this.GetEffectiveStatusCode(), this.GetEffectiveEnhancedStatusCode(exceptionAssociatedWithHandler), this.GetEffectivePrimaryStatusText(exceptionAssociatedWithHandler), this.IncludeDiagnosticStatusText);
            MessageStatus messageStatus         = new MessageStatus(this.Action, exceptionSmtpResponse, exception, this.AppliesToAllRecipients);

            if (this.SpecifiedRetryInterval != null)
            {
                messageStatus.RetryInterval = new TimeSpan?(this.SpecifiedRetryInterval.Value);
            }
            else if (this.RetryInterval != RetryInterval.None)
            {
                if (this.RetryInterval == RetryInterval.QuarantinedRetry)
                {
                    messageStatus.RetryInterval = new TimeSpan?(quarantineRetryInterval);
                }
                else
                {
                    messageStatus.RetryInterval = new TimeSpan?(fastRetryInterval);
                }
            }
            if (this.CustomizeStatusCallback != null)
            {
                this.CustomizeStatusCallback(exceptionAssociatedWithHandler, converter, messageStatus);
            }
            return(messageStatus);
        }
        internal static SmtpResponse GetExceptionSmtpResponse(IMessageConverter converter, Exception exception, bool isPermanent, string statusCode, string enhancedStatusCode, string primaryStatusText, bool includeDiagnostic = true)
        {
            string source = string.Format(CultureInfo.InvariantCulture, "STOREDRV.{0}.Exception:{1}; Failed to process message due to a {2} exception with message {3}", new object[]
            {
                converter.Description,
                StorageExceptionHandler.GetExceptionTypeString(exception),
                isPermanent ? "permanent" : "transient",
                StorageExceptionHandler.GetExceptionDiagnosticInfo(exception)
            });

            if (string.IsNullOrEmpty(statusCode))
            {
                statusCode = (isPermanent ? "554" : "432");
            }
            if (string.IsNullOrEmpty(enhancedStatusCode))
            {
                if (isPermanent)
                {
                    enhancedStatusCode = (converter.IsOutbound ? "5.6.0" : "5.2.0");
                }
                else
                {
                    enhancedStatusCode = "4.2.0";
                }
            }
            return(new SmtpResponse(statusCode, enhancedStatusCode, new string[]
            {
                primaryStatusText,
                includeDiagnostic ? StorageExceptionHandler.StripNonAscii(source) : string.Empty
            }));
        }
        private static SmtpResponse GetExceptionSmtpResponse(IMessageConverter converter, Exception exception, string exceptionName, bool isPermanent)
        {
            SmtpResponse smtpResponse = SmtpResponse.Empty;

            if (exceptionName != null)
            {
                if (!(exceptionName == "MapiExceptionRpcServerTooBusy"))
                {
                    if (!(exceptionName == "MapiExceptionSessionLimit"))
                    {
                        if (exceptionName == "MapiExceptionNotEnoughMemory")
                        {
                            smtpResponse = AckReason.MailboxServerNotEnoughMemory;
                        }
                    }
                    else
                    {
                        smtpResponse = AckReason.MailboxMapiSessionLimit;
                    }
                }
                else
                {
                    smtpResponse = AckReason.MailboxServerTooBusy;
                }
            }
            return(StorageExceptionHandler.GetExceptionSmtpResponse(converter, exception, isPermanent, smtpResponse.StatusCode, smtpResponse.EnhancedStatusCode, smtpResponse.StatusText[0], true));
        }
        private static MessageStatus GetMessageStatus(IMessageConverter converter, ADTransientException unavailableException)
        {
            StorageExceptionHandler.LogException(converter, unavailableException);
            SmtpResponse exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, unavailableException, false);

            return(new MessageStatus(MessageAction.Retry, exceptionSmtpResponse, unavailableException));
        }
        private static MessageStatus GetMessageStatus(IMessageConverter converter, ConversionFailedException exception)
        {
            StorageExceptionHandler.LogException(converter, exception);
            SmtpResponse exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, exception, true, "554", (ConversionFailureReason.ExceedsLimit == exception.ConversionFailureReason) ? "5.3.4" : "5.6.0", StorageExceptionHandler.GetReasonDescription(exception.ConversionFailureReason), true);

            return(new MessageStatus(MessageAction.NDR, exceptionSmtpResponse, exception, true));
        }
 public static MessageStatus RunUnderExceptionHandler(IMessageConverter converter, StoreDriverDelegate workerFunction)
 {
     if (StorageExceptionHandler.MailboxTransportTableBasedExceptionHandlerEnabled)
     {
         return(StorageExceptionHandler.RunUnderTableBasedExceptionHandler(converter, workerFunction));
     }
     return(StorageExceptionHandler.RunUnderExplicitExceptionHandler(converter, workerFunction));
 }
        private static MessageStatus ProcessExchangeDataException(ExchangeDataException exchangeDataException, IMessageConverter converter)
        {
            MessageStatus messageStatus = StorageExceptionHandler.GetMessageStatus(converter, exchangeDataException);

            if (messageStatus.Action == MessageAction.NDR)
            {
                converter.LogMessage(exchangeDataException);
            }
            return(messageStatus);
        }
 private static MessageStatus GetMessageStatus(IMessageConverter converter, DataSourceOperationException dataSourceOperationException)
 {
     if (dataSourceOperationException is ADInvalidCredentialException)
     {
         ADTransientException unavailableException = new ADTransientException(dataSourceOperationException.LocalizedString, dataSourceOperationException);
         return(StorageExceptionHandler.GetMessageStatus(converter, unavailableException));
     }
     StorageExceptionHandler.LogException(converter, dataSourceOperationException);
     return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, dataSourceOperationException, true), dataSourceOperationException));
 }
        private static MessageStatus GetMessageStatus(IMessageConverter converter, IOException e)
        {
            StorageExceptionHandler.LogException(converter, e);
            SmtpResponse exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, e, true, AckReason.DiskFull);

            if (ExceptionHelper.IsDiskFullException(e))
            {
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, exceptionSmtpResponse, e));
            }
            return(new MessageStatus(MessageAction.Throw, exceptionSmtpResponse, e));
        }
Exemplo n.º 12
0
        public MessageStatus Handle(string handlerName, Exception exception, IMessageConverter converter, TimeSpan fastRetryInterval, TimeSpan quarantineRetryInterval)
        {
            StorageExceptionHandler.LogException(converter, exception);
            exception.GetType();
            Exception exception2 = null;
            Exception exceptionAssociatedWithHandler                = null;
            ConcurrentDictionary <Type, Handler> handlerMap         = this.registeredHandlers[handlerName];
            ConcurrentDictionary <Type, Handler> overrideHandlerMap = this.overrideHandlers.ContainsKey(handlerName) ? this.overrideHandlers[handlerName] : null;
            Handler handler = ExceptionHandler.FindHandler(handlerMap, overrideHandlerMap, exception, out exception2, out exceptionAssociatedWithHandler);

            if (handler == null)
            {
                handler = ExceptionHandler.ThrowHandler;
            }
            return(handler.CreateStatus(exception2, exceptionAssociatedWithHandler, converter, fastRetryInterval, quarantineRetryInterval));
        }
 private static MessageStatus GetMessageStatus(IMessageConverter converter, StorageTransientException storageException)
 {
     StorageExceptionHandler.LogException(converter, storageException);
     if (storageException is MailboxInSiteFailoverException)
     {
         return(new MessageStatus(converter.IsOutbound ? MessageAction.Skip : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));
     }
     if (storageException.InnerException != null)
     {
         MapiPermanentException ex = storageException.InnerException as MapiPermanentException;
         if (ex != null)
         {
             return(StorageExceptionHandler.GetMessageStatus <StorageTransientException>(converter, ex, storageException));
         }
         MapiRetryableException ex2 = storageException.InnerException as MapiRetryableException;
         if (ex2 != null)
         {
             return(StorageExceptionHandler.GetMessageStatus <StorageTransientException>(converter, ex2, storageException));
         }
     }
     return(new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));
 }
        private static MessageStatus GetMessageStatus(IMessageConverter converter, StoragePermanentException storageException)
        {
            StorageExceptionHandler.LogException(converter, storageException);
            ConversionFailedException ex = storageException as ConversionFailedException;

            if (ex != null)
            {
                return(StorageExceptionHandler.GetMessageStatus(converter, ex));
            }
            if (storageException is MailboxCrossSiteFailoverException || storageException is MailboxInfoStaleException)
            {
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Skip : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));
            }
            if (storageException is UnableToFindServerForDatabaseException || storageException is IllegalCrossServerConnectionException)
            {
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Skip : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));
            }
            if (storageException.InnerException is CannotGetSiteInfoException)
            {
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException.InnerException, true), storageException));
            }
            if (storageException.InnerException != null)
            {
                MapiPermanentException ex2 = storageException.InnerException as MapiPermanentException;
                if (ex2 != null)
                {
                    return(StorageExceptionHandler.GetMessageStatus <StoragePermanentException>(converter, ex2, storageException));
                }
                MapiRetryableException ex3 = storageException.InnerException as MapiRetryableException;
                if (ex3 != null)
                {
                    return(StorageExceptionHandler.GetMessageStatus <StoragePermanentException>(converter, ex3, storageException));
                }
            }
            return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));
        }
        private static MessageStatus GetMessageStatus <T>(IMessageConverter converter, MapiRetryableException mapiException, T storageException) where T : Exception
        {
            string        name = mapiException.GetType().Name;
            string        key;
            MessageStatus messageStatus;

            switch (key = name)
            {
            case "MapiExceptionMailboxInTransit":
            case "MapiExceptionServerPaused":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Skip : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));

            case "MapiExceptionDismountInProgress":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryQueue : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));

            case "MapiExceptionLogonFailed":
                return(new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.LogonFailure), storageException));

            case "MapiExceptionJetErrorLogWriteFail":
            case "MapiExceptionJetErrorDiskIO":
            case "MapiExceptionJetErrorCheckpointDepthTooDeep":
                return(new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxIOError), storageException));

            case "MapiExceptionJetErrorInstanceUnavailable":
                return(new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxIOError), storageException));

            case "MapiExceptionNetworkError":
                messageStatus = new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxServerOffline), storageException);
                messageStatus.RetryInterval = new TimeSpan?(StorageExceptionHandler.MailboxDeliveryFastQueueRetryInterval);
                return(messageStatus);

            case "MapiExceptionRpcServerTooBusy":
            case "MapiExceptionSessionLimit":
            case "MapiExceptionNotEnoughMemory":
                messageStatus = new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, name, false), storageException);
                messageStatus.RetryInterval = new TimeSpan?(StorageExceptionHandler.MailboxDeliveryFastQueueRetryInterval);
                return(messageStatus);

            case "MapiExceptionMaxThreadsPerMdbExceeded":
                messageStatus = new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxServerMaxThreadsPerMdbExceeded), storageException);
                messageStatus.RetryInterval = new TimeSpan?(StorageExceptionHandler.MailboxDeliveryFastQueueRetryInterval);
                return(messageStatus);

            case "MapiExceptionMaxThreadsPerSCTExceeded":
                messageStatus = new MessageStatus(converter.IsOutbound ? MessageAction.Retry : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MapiExceptionMaxThreadsPerSCTExceeded), storageException);
                messageStatus.RetryInterval = new TimeSpan?(StorageExceptionHandler.MailboxDeliveryFastQueueRetryInterval);
                return(messageStatus);

            case "MapiExceptionRpcOutOfMemory":
            case "MapiExceptionRpcOutOfResources":
            case "MapiExceptionRpcServerOutOfMemory":
            case "MapiExceptionVersionStoreBusy":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Retry : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));

            case "MapiExceptionSubsystemStopping":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));

            case "MapiExceptionLowDatabaseDiskSpace":
            case "MapiExceptionLowDatabaseLogDiskSpace":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Retry : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxDiskFull), storageException));

            case "MapiExceptionADNotFound":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MailboxDiskFull), storageException));

            case "MapiExceptionMailboxQuarantined":
                if (converter.IsOutbound)
                {
                    return(new MessageStatus(MessageAction.Skip, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));
                }
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, AckReason.RecipientMailboxQuarantined), storageException));

            case "MapiExceptionRetryableImportFailure":
            case "MapiExceptionBusy":
            case "MapiExceptionDiskError":
            case "MapiExceptionJetErrorOutOfBuffers":
            case "MapiExceptionJetErrorOutOfCursors":
            case "MapiExceptionJetErrorOutOfMemory":
            case "MapiExceptionJetErrorOutOfSessions":
            case "MapiExceptionJetErrorTooManyOpenTables":
            case "MapiExceptionJetErrorTooManyOpenTablesAndCleanupTimedOut":
            case "MapiExceptionJetErrorVersionStoreOutOfMemory":
            case "MapiExceptionJetErrorVersionStoreOutOfMemoryAndCleanupTimedOut":
            case "MapiExceptionNoFreeJses":
            case "MapiExceptionNotEnoughDisk":
            case "MapiExceptionTimeout":
            case "MapiExceptionWait":
            case "MapiExceptionCollision":
                return(new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));
            }
            messageStatus = new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException);
            return(messageStatus);
        }
        private static MessageStatus GetMessageStatus <T>(IMessageConverter converter, MapiPermanentException mapiException, T storageException) where T : Exception
        {
            string        name = mapiException.GetType().Name;
            string        key;
            MessageStatus messageStatus;

            switch (key = name)
            {
            case "MapiExceptionJetErrorLogDiskFull":
                return(new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, AckReason.MailboxDiskFull), storageException));

            case "MapiExceptionADDuplicateEntry":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, "Duplicated AD entries found"), storageException));

            case "MapiExceptionNoMoreConnections":
                messageStatus = new MessageStatus(converter.IsOutbound ? MessageAction.RetryMailboxServer : MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, SmtpResponse.TooManyConnectionsPerSource), storageException);
                messageStatus.RetryInterval = new TimeSpan?(StorageExceptionHandler.MailboxDeliveryFastQueueRetryInterval);
                return(messageStatus);

            case "MapiExceptionUnknownUser":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Retry : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));

            case "MapiExceptionNoReplicaHere":
            case "MapiExceptionWrongServer":
            case "MapiExceptionWrongMailbox":
                return(new MessageStatus(converter.IsOutbound ? MessageAction.Skip : MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));

            case "MapiExceptionClientVersionDisallowed":
                return(new MessageStatus(MessageAction.Reroute, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));

            case "MapiExceptionDuplicateDelivery":
                return(new MessageStatus(MessageAction.LogDuplicate, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));

            case "MapiExceptionMaxTimeExpired":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "4.4.1", "connection timed out", true), storageException));

            case "MapiExceptionUnableToComplete":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "4.4.1", "connection timed out", true), storageException));

            case "MapiExceptionMessageTooBig":
            case "MapiExceptionTooComplex":
            case "MapiExceptionTooBig":
            case "MapiExceptionMaxAttachmentExceeded":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "5.3.4", "message exceeds fixed system limits", true), storageException));

            case "MapiExceptionTooManyRecips":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "5.3.3", "too many recipients", true), storageException));

            case "MapiExceptionQuotaExceeded":
            case "MapiExceptionShutoffQuotaExceeded":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "5.2.2", "mailbox full", true), storageException));

            case "MapiExceptionNoReplicaAvailable":
            case "MapiExceptionFolderDisabled":
            case "MapiExceptionMailboxDisabled":
            case "MapiExceptionAccountDisabled":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "5.2.1", "mailbox disabled", true), storageException));

            case "MapiExceptionMdbOffline":
                return(new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, AckReason.MDBOffline), storageException));

            case "MapiExceptionMaxObjsExceeded":
            case "MapiExceptionRpcBufferTooSmall":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, null, "4.3.2", "mailbox busy", true), storageException));

            case "MapiExceptionNoAccess":
                return(new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false, AckReason.MapiNoAccessFailure), storageException));

            case "MapiExceptionJetErrorPageNotInitialized":
                return(new MessageStatus(MessageAction.RetryQueue, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true, "Database page not initialized"), storageException));

            case "MapiExceptionOutOfMemory":
            case "MapiExceptionTooManyMountedDatabases":
                return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException));

            case "MapiExceptionUnconfigured":
                return(new MessageStatus(MessageAction.Retry, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, false), storageException));
            }
            messageStatus = new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, storageException, true), storageException);
            return(messageStatus);
        }
        private static MessageStatus RunUnderExplicitExceptionHandler(IMessageConverter converter, StoreDriverDelegate workerFunction)
        {
            MessageStatus messageStatus = MessageStatus.Success;

            StorageExceptionHandler.diag = converter.Tracer;
            try
            {
                workerFunction();
            }
            catch (StoreDriverAgentRaisedException ex)
            {
                if (ex.InnerException == null)
                {
                    TraceHelper.TraceFail(StorageExceptionHandler.diag, 0L, "StoreDriverAgentRaisedException's InnerException is null. It is expected to contain the actual exception that the agent has thrown. StoreDriverAgentRaisedException.Message: {0}; StoreDriverAgentRaisedException.StackTrace: {1}.", new object[]
                    {
                        ex.Message,
                        ex.StackTrace
                    });
                    throw;
                }
                if (ex.InnerException is StoreDriverAgentTransientException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (StoreDriverAgentTransientException)ex.InnerException);
                }
                else if (ex.InnerException is SmtpResponseException)
                {
                    messageStatus = StorageExceptionHandler.ProcessSmtpResponseException((SmtpResponseException)ex.InnerException, converter);
                }
                else if (ex.InnerException is ADTransientException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (ADTransientException)ex.InnerException);
                }
                else if (ex.InnerException is DataValidationException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (DataValidationException)ex.InnerException);
                }
                else if (ex.InnerException is DataSourceOperationException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (DataSourceOperationException)ex.InnerException);
                }
                else if (ex.InnerException is StorageTransientException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (StorageTransientException)ex.InnerException);
                }
                else if (ex.InnerException is StoragePermanentException)
                {
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (StoragePermanentException)ex.InnerException);
                }
                else if (ex.InnerException is ExchangeDataException)
                {
                    messageStatus = StorageExceptionHandler.ProcessExchangeDataException((ExchangeDataException)ex.InnerException, converter);
                }
                else
                {
                    if (!(ex.InnerException is IOException))
                    {
                        throw;
                    }
                    messageStatus = StorageExceptionHandler.GetMessageStatus(converter, (IOException)ex.InnerException);
                }
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (StoreDriverAgentTransientException storeDriverAgentTransientException)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, storeDriverAgentTransientException);
            }
            catch (SmtpResponseException smtpResponseException)
            {
                messageStatus = StorageExceptionHandler.ProcessSmtpResponseException(smtpResponseException, converter);
            }
            catch (ADTransientException unavailableException)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, unavailableException);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (DataValidationException invalidDataException)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, invalidDataException);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (DataSourceOperationException dataSourceOperationException)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, dataSourceOperationException);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (StorageTransientException storageException)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, storageException);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (StoragePermanentException storageException2)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, storageException2);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (ExchangeDataException exchangeDataException)
            {
                messageStatus = StorageExceptionHandler.ProcessExchangeDataException(exchangeDataException, converter);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            catch (IOException e)
            {
                messageStatus = StorageExceptionHandler.GetMessageStatus(converter, e);
                if (messageStatus.Action == MessageAction.Throw)
                {
                    throw;
                }
            }
            return(messageStatus);
        }
 internal static SmtpResponse GetExceptionSmtpResponse(IMessageConverter converter, Exception exception, bool isPermanent, string primaryStatusText)
 {
     return(StorageExceptionHandler.GetExceptionSmtpResponse(converter, exception, isPermanent, null, null, primaryStatusText, true));
 }
 private static MessageStatus GetMessageStatus(IMessageConverter converter, ExchangeDataException dataException)
 {
     StorageExceptionHandler.LogException(converter, dataException);
     return(new MessageStatus(MessageAction.NDR, StorageExceptionHandler.GetExceptionSmtpResponse(converter, dataException, true), dataException));
 }
        // Note: this type is marked as 'beforefieldinit'.
        static MailboxTransportExceptionMapping()
        {
            Dictionary <Type, Handler> dictionary  = new Dictionary <Type, Handler>();
            Dictionary <Type, Handler> dictionary2 = dictionary;
            Type    typeFromHandle = typeof(ConversionFailedException);
            Handler handler        = new Handler();

            handler.Action   = MessageAction.NDR;
            handler.Category = Category.Permanent;
            handler.AppliesToAllRecipients     = true;
            handler.PrimaryStatusTextCallback  = ((Exception e) => StorageExceptionHandler.GetReasonDescription(((ConversionFailedException)e).ConversionFailureReason));
            handler.EnhancedStatusCodeCallback = delegate(Exception e)
            {
                if (ConversionFailureReason.ExceedsLimit != ((ConversionFailedException)e).ConversionFailureReason)
                {
                    return("5.6.0");
                }
                return("5.3.4");
            };
            dictionary2.Add(typeFromHandle, handler);
            Dictionary <Type, Handler> dictionary3 = dictionary;
            Type    typeFromHandle2 = typeof(IOException);
            Handler handler2        = new Handler();

            handler2.Action   = MessageAction.Throw;
            handler2.Category = Category.Transient;
            handler2.Response = AckReason.DiskFull;
            handler2.CustomizeStatusCallback = delegate(Exception e, IMessageConverter mb, MessageStatus ms)
            {
                if (ExceptionHelper.IsDiskFullException((IOException)e))
                {
                    ms.Action = MessageAction.RetryQueue;
                }
            };
            dictionary3.Add(typeFromHandle2, handler2);
            dictionary.Add(typeof(ExchangeDataException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary.Add(typeof(DataSourceOperationException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary.Add(typeof(ADInvalidCredentialException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(ADTransientException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(DataValidationException), new Handler
            {
                Action   = MessageAction.NDR,
                Category = Category.Permanent,
                Response = AckReason.InboundInvalidDirectoryData
            });
            dictionary.Add(typeof(MailboxInSiteFailoverException), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MailboxCrossSiteFailoverException), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MailboxInfoStaleException), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(UnableToFindServerForDatabaseException), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(IllegalCrossServerConnectionException), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(CannotGetSiteInfoException), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                ProcessInnerException = true
            });
            dictionary.Add(typeof(MapiExceptionJetErrorLogDiskFull), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary.Add(typeof(MapiExceptionADDuplicateEntry), new Handler
            {
                Action            = MessageAction.RetryQueue,
                Category          = Category.Transient,
                PrimaryStatusText = "Duplicated AD entries found"
            });
            dictionary.Add(typeof(MapiExceptionNoMoreConnections), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = SmtpResponse.TooManyConnectionsPerSource,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionUnknownUser), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionNoReplicaHere), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionWrongServer), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionWrongMailbox), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionClientVersionDisallowed), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionDuplicateDelivery), new Handler
            {
                Action   = MessageAction.LogDuplicate,
                Category = Category.Permanent
            });
            dictionary.Add(typeof(MapiExceptionMaxTimeExpired), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.4.1",
                PrimaryStatusText  = "connection timed out"
            });
            dictionary.Add(typeof(MapiExceptionUnableToComplete), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.4.1",
                PrimaryStatusText  = "connection timed out"
            });
            dictionary.Add(typeof(MapiExceptionMessageTooBig), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary.Add(typeof(MapiExceptionTooComplex), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary.Add(typeof(MapiExceptionTooBig), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary.Add(typeof(MapiExceptionMaxAttachmentExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary.Add(typeof(MapiExceptionTooManyRecips), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.3",
                PrimaryStatusText  = "too many recipients"
            });
            dictionary.Add(typeof(MapiExceptionQuotaExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.2",
                PrimaryStatusText  = "mailbox full"
            });
            dictionary.Add(typeof(MapiExceptionShutoffQuotaExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.2",
                PrimaryStatusText  = "mailbox full"
            });
            dictionary.Add(typeof(MapiExceptionNoReplicaAvailable), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary.Add(typeof(MapiExceptionFolderDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary.Add(typeof(MapiExceptionMailboxDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary.Add(typeof(MapiExceptionAccountDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary.Add(typeof(MapiExceptionMdbOffline), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MDBOffline
            });
            dictionary.Add(typeof(MapiExceptionMaxObjsExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.3.2",
                PrimaryStatusText  = "mailbox busy"
            });
            dictionary.Add(typeof(MapiExceptionRpcBufferTooSmall), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.3.2",
                PrimaryStatusText  = "mailbox busy"
            });
            dictionary.Add(typeof(MapiExceptionNoAccess), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.MapiNoAccessFailure
            });
            dictionary.Add(typeof(MapiExceptionJetErrorPageNotInitialized), new Handler
            {
                Action            = MessageAction.RetryQueue,
                Category          = Category.Transient,
                PrimaryStatusText = "Database page not initialized"
            });
            dictionary.Add(typeof(MapiExceptionOutOfMemory), MailboxTransportExceptionMapping.NdrHandler);
            dictionary.Add(typeof(MapiExceptionUnconfigured), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionMailboxInTransit), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionServerPaused), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionDismountInProgress), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary.Add(typeof(MapiExceptionLogonFailed), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.LogonFailure
            });
            dictionary.Add(typeof(MapiExceptionJetErrorLogWriteFail), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary.Add(typeof(MapiExceptionJetErrorDiskIO), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary.Add(typeof(MapiExceptionJetErrorCheckpointDepthTooDeep), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary.Add(typeof(MapiExceptionJetErrorInstanceUnavailable), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary.Add(typeof(MapiExceptionNetworkError), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerOffline,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionRpcServerTooBusy), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerTooBusy,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionSessionLimit), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxMapiSessionLimit,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionNotEnoughMemory), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerNotEnoughMemory,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionMaxThreadsPerMdbExceeded), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerMaxThreadsPerMdbExceeded,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionMaxThreadsPerSCTExceeded), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MapiExceptionMaxThreadsPerSCTExceeded,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary.Add(typeof(MapiExceptionRpcOutOfMemory), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(MapiExceptionRpcOutOfResources), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(MapiExceptionRpcServerOutOfMemory), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(MapiExceptionVersionStoreBusy), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(MapiExceptionSubsystemStopping), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary.Add(typeof(MapiExceptionLowDatabaseDiskSpace), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary.Add(typeof(MapiExceptionLowDatabaseLogDiskSpace), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary.Add(typeof(MapiExceptionADNotFound), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary.Add(typeof(MapiExceptionMailboxQuarantined), new Handler
            {
                Action   = MessageAction.NDR,
                Category = Category.Permanent,
                Response = AckReason.RecipientMailboxQuarantined
            });
            dictionary.Add(typeof(MapiExceptionRetryableImportFailure), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionBusy), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionDiskError), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorOutOfBuffers), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorOutOfCursors), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorOutOfSessions), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorTooManyOpenTables), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorVersionStoreOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionNoFreeJses), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionNotEnoughDisk), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionTimeout), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionWait), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionCollision), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(StoreDriverAgentTransientException), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.DeliverAgentTransientFailure,
                IncludeDiagnosticStatusText = false
            });
            dictionary.Add(typeof(MapiPermanentException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary.Add(typeof(StoragePermanentException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary.Add(typeof(StorageTransientException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiRetryableException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorTooManyOpenTablesAndCleanupTimedOut), MailboxTransportExceptionMapping.RetryHandler);
            dictionary.Add(typeof(MapiExceptionJetErrorVersionStoreOutOfMemoryAndCleanupTimedOut), MailboxTransportExceptionMapping.RetryHandler);
            MailboxTransportExceptionMapping.delivery = dictionary;
            Dictionary <Type, Handler> dictionary4 = new Dictionary <Type, Handler>();
            Dictionary <Type, Handler> dictionary5 = dictionary4;
            Type    typeFromHandle3 = typeof(ConversionFailedException);
            Handler handler3        = new Handler();

            handler3.Action   = MessageAction.NDR;
            handler3.Category = Category.Permanent;
            handler3.AppliesToAllRecipients     = true;
            handler3.PrimaryStatusTextCallback  = ((Exception e) => StorageExceptionHandler.GetReasonDescription(((ConversionFailedException)e).ConversionFailureReason));
            handler3.EnhancedStatusCodeCallback = delegate(Exception e)
            {
                if (ConversionFailureReason.ExceedsLimit != ((ConversionFailedException)e).ConversionFailureReason)
                {
                    return("5.6.0");
                }
                return("5.3.4");
            };
            dictionary5.Add(typeFromHandle3, handler3);
            dictionary4.Add(typeof(NonNdrItemToTransportItemCopyException), new Handler
            {
                Action   = MessageAction.NDR,
                Category = Category.Permanent,
                AppliesToAllRecipients      = true,
                EnhancedStatusCode          = "5.6.0",
                PrimaryStatusText           = "Permanent error while processing message",
                IncludeDiagnosticStatusText = false
            });
            dictionary4.Add(typeof(NdrItemToTransportItemCopyException), new Handler
            {
                Action   = MessageAction.Skip,
                Category = Category.Permanent,
                AppliesToAllRecipients = true
            });
            dictionary4.Add(typeof(PoisonHandlerNdrGenerationErrorException), new Handler
            {
                Action   = MessageAction.Skip,
                Category = Category.Permanent,
                AppliesToAllRecipients = true
            });
            Dictionary <Type, Handler> dictionary6 = dictionary4;
            Type    typeFromHandle4 = typeof(IOException);
            Handler handler4        = new Handler();

            handler4.Action   = MessageAction.Throw;
            handler4.Category = Category.Transient;
            handler4.Response = AckReason.DiskFull;
            handler4.CustomizeStatusCallback = delegate(Exception e, IMessageConverter mb, MessageStatus ms)
            {
                if (ExceptionHelper.IsDiskFullException((IOException)e))
                {
                    ms.Action = MessageAction.RetryMailboxServer;
                }
            };
            dictionary6.Add(typeFromHandle4, handler4);
            dictionary4.Add(typeof(ExchangeDataException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary4.Add(typeof(DataSourceOperationException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary4.Add(typeof(ADInvalidCredentialException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(ADTransientException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(DataValidationException), new Handler
            {
                Action   = MessageAction.NDR,
                Category = Category.Permanent,
                Response = AckReason.OutboundInvalidDirectoryData
            });
            dictionary4.Add(typeof(MailboxInSiteFailoverException), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MailboxCrossSiteFailoverException), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MailboxInfoStaleException), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(UnableToFindServerForDatabaseException), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(IllegalCrossServerConnectionException), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(CannotGetSiteInfoException), new Handler
            {
                Action   = MessageAction.RetryMailboxServer,
                Category = Category.Transient,
                ProcessInnerException = true
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorLogDiskFull), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary4.Add(typeof(MapiExceptionADDuplicateEntry), new Handler
            {
                Action            = MessageAction.RetryMailboxServer,
                Category          = Category.Transient,
                PrimaryStatusText = "Duplicated AD entries found"
            });
            dictionary4.Add(typeof(MapiExceptionNoMoreConnections), new Handler
            {
                Action        = MessageAction.RetryMailboxServer,
                Category      = Category.Transient,
                Response      = SmtpResponse.TooManyConnectionsPerSource,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionUnknownUser), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionNoReplicaHere), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionWrongServer), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionWrongMailbox), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionClientVersionDisallowed), MailboxTransportExceptionMapping.RerouteHandler);
            dictionary4.Add(typeof(MapiExceptionDuplicateDelivery), new Handler
            {
                Action   = MessageAction.LogDuplicate,
                Category = Category.Permanent
            });
            dictionary4.Add(typeof(MapiExceptionMaxTimeExpired), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.4.1",
                PrimaryStatusText  = "connection timed out"
            });
            dictionary4.Add(typeof(MapiExceptionUnableToComplete), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.4.1",
                PrimaryStatusText  = "connection timed out"
            });
            dictionary4.Add(typeof(MapiExceptionMessageTooBig), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary4.Add(typeof(MapiExceptionTooComplex), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary4.Add(typeof(MapiExceptionTooBig), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary4.Add(typeof(MapiExceptionMaxAttachmentExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.4",
                PrimaryStatusText  = "message exceeds fixed system limits"
            });
            dictionary4.Add(typeof(MapiExceptionTooManyRecips), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.3.3",
                PrimaryStatusText  = "too many recipients"
            });
            dictionary4.Add(typeof(MapiExceptionQuotaExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.2",
                PrimaryStatusText  = "mailbox full"
            });
            dictionary4.Add(typeof(MapiExceptionShutoffQuotaExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.2",
                PrimaryStatusText  = "mailbox full"
            });
            dictionary4.Add(typeof(MapiExceptionNoReplicaAvailable), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary4.Add(typeof(MapiExceptionFolderDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary4.Add(typeof(MapiExceptionMailboxDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary4.Add(typeof(MapiExceptionAccountDisabled), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "5.2.1",
                PrimaryStatusText  = "mailbox disabled"
            });
            dictionary4.Add(typeof(MapiExceptionMdbOffline), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MDBOffline
            });
            dictionary4.Add(typeof(MapiExceptionMaxObjsExceeded), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.3.2",
                PrimaryStatusText  = "mailbox busy"
            });
            dictionary4.Add(typeof(MapiExceptionRpcBufferTooSmall), new Handler
            {
                Action             = MessageAction.NDR,
                Category           = Category.Permanent,
                EnhancedStatusCode = "4.3.2",
                PrimaryStatusText  = "mailbox busy"
            });
            dictionary4.Add(typeof(MapiExceptionNoAccess), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.MapiNoAccessFailure
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorPageNotInitialized), new Handler
            {
                Action            = MessageAction.RetryQueue,
                Category          = Category.Transient,
                PrimaryStatusText = "Database page not initialized"
            });
            dictionary4.Add(typeof(MapiExceptionOutOfMemory), MailboxTransportExceptionMapping.NdrHandler);
            dictionary4.Add(typeof(MapiExceptionUnconfigured), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionMailboxInTransit), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionServerPaused), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionDismountInProgress), MailboxTransportExceptionMapping.RetryQueueHandler);
            dictionary4.Add(typeof(MapiExceptionLogonFailed), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.LogonFailure
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorLogWriteFail), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorDiskIO), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorCheckpointDepthTooDeep), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary4.Add(typeof(MapiExceptionJetErrorInstanceUnavailable), new Handler
            {
                Action   = MessageAction.RetryQueue,
                Category = Category.Transient,
                Response = AckReason.MailboxIOError
            });
            dictionary4.Add(typeof(MapiExceptionNetworkError), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerOffline,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionRpcServerTooBusy), new Handler
            {
                Action        = MessageAction.RetryMailboxServer,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerTooBusy,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionSessionLimit), new Handler
            {
                Action        = MessageAction.RetryMailboxServer,
                Category      = Category.Transient,
                Response      = AckReason.MailboxMapiSessionLimit,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionNotEnoughMemory), new Handler
            {
                Action        = MessageAction.RetryMailboxServer,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerNotEnoughMemory,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionMaxThreadsPerMdbExceeded), new Handler
            {
                Action        = MessageAction.RetryQueue,
                Category      = Category.Transient,
                Response      = AckReason.MailboxServerMaxThreadsPerMdbExceeded,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionMaxThreadsPerSCTExceeded), new Handler
            {
                Action        = MessageAction.Retry,
                Category      = Category.Transient,
                Response      = AckReason.MapiExceptionMaxThreadsPerSCTExceeded,
                RetryInterval = RetryInterval.FastRetry
            });
            dictionary4.Add(typeof(MapiExceptionRpcOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionRpcOutOfResources), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionRpcServerOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionVersionStoreBusy), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionSubsystemStopping), new Handler
            {
                Action   = MessageAction.RetryMailboxServer,
                Category = Category.Transient
            });
            dictionary4.Add(typeof(MapiExceptionLowDatabaseDiskSpace), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary4.Add(typeof(MapiExceptionLowDatabaseLogDiskSpace), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary4.Add(typeof(MapiExceptionADNotFound), new Handler
            {
                Action   = MessageAction.RetryMailboxServer,
                Category = Category.Transient,
                Response = AckReason.MailboxDiskFull
            });
            dictionary4.Add(typeof(MapiExceptionMailboxQuarantined), MailboxTransportExceptionMapping.SkipHandler);
            dictionary4.Add(typeof(MapiExceptionRetryableImportFailure), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionBusy), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionDiskError), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorOutOfBuffers), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorOutOfCursors), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorOutOfSessions), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorTooManyOpenTables), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorVersionStoreOutOfMemory), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionNoFreeJses), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionNotEnoughDisk), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionTimeout), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionWait), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionCollision), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(StoreDriverAgentTransientException), new Handler
            {
                Action   = MessageAction.Retry,
                Category = Category.Transient,
                Response = AckReason.DeliverAgentTransientFailure,
                IncludeDiagnosticStatusText = false
            });
            dictionary4.Add(typeof(MapiPermanentException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary4.Add(typeof(StoragePermanentException), MailboxTransportExceptionMapping.NdrHandler);
            dictionary4.Add(typeof(StorageTransientException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiRetryableException), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorTooManyOpenTablesAndCleanupTimedOut), MailboxTransportExceptionMapping.RetryHandler);
            dictionary4.Add(typeof(MapiExceptionJetErrorVersionStoreOutOfMemoryAndCleanupTimedOut), MailboxTransportExceptionMapping.RetryHandler);
            MailboxTransportExceptionMapping.submission = dictionary4;
        }
 internal static SmtpResponse GetExceptionSmtpResponse(IMessageConverter converter, Exception exception, bool isPermanent, SmtpResponse smtpResponse)
 {
     return(StorageExceptionHandler.GetExceptionSmtpResponse(converter, exception, isPermanent, smtpResponse.StatusCode, smtpResponse.EnhancedStatusCode, smtpResponse.StatusText[0], true));
 }