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
            }));
        }