Exemple #1
0
        private SmtpResponse Read()
        {
            byte [] buffer   = new byte [512];
            int     position = 0;
            bool    lastLine = false;

            do
            {
                CheckCancellation();

                int readLength = stream.Read(buffer, position, buffer.Length - position);
                if (readLength > 0)
                {
                    int available = position + readLength - 1;
                    if (available > 4 && (buffer [available] == '\n' || buffer [available] == '\r'))
                    {
                        for (int index = available - 3; ; index--)
                        {
                            if (index < 0 || buffer [index] == '\n' || buffer [index] == '\r')
                            {
                                lastLine = buffer [index + 4] == ' ';
                                break;
                            }
                        }
                    }

                    // move position
                    position += readLength;

                    // check if buffer is full
                    if (position == buffer.Length)
                    {
                        byte [] newBuffer = new byte [buffer.Length * 2];
                        Array.Copy(buffer, 0, newBuffer, 0, buffer.Length);
                        buffer = newBuffer;
                    }
                }
                else
                {
                    break;
                }
            } while (!lastLine);

            if (position > 0)
            {
                Encoding encoding = new ASCIIEncoding();

                string line = encoding.GetString(buffer, 0, position - 1);

                // parse the line to the lastResponse object
                SmtpResponse response = SmtpResponse.Parse(line);

                return(response);
            }
            else
            {
                throw new System.IO.IOException("Connection closed");
            }
        }
Exemple #2
0
        public static SmtpResponse GenerateResponse(MessageAction messageLevelAction, IReadOnlyMailRecipientCollection recipients, SmtpResponse smtpResponse, TimeSpan?retryInterval)
        {
            if (recipients == null)
            {
                throw new ArgumentNullException("recipients", "Required argument is not provided");
            }
            bool flag = SmtpResponseGenerator.ShouldGenerateAllRecipients(recipients);

            if (!flag && retryInterval == null && messageLevelAction != MessageAction.RetryQueue)
            {
                return(smtpResponse);
            }
            StringBuilder stringBuilder = new StringBuilder();

            SmtpResponseGenerator.GenerateBanner(stringBuilder, smtpResponse.StatusCode, smtpResponse.EnhancedStatusCode);
            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}{2} {3} {4}{5}{6}", new object[]
            {
                smtpResponse.StatusCode,
                flag ? "-" : " ",
                flag ? smtpResponse.StatusCode : string.Empty,
                smtpResponse.EnhancedStatusCode,
                SmtpResponseGenerator.FlattenStatusText(smtpResponse),
                SmtpResponseGenerator.GenerateAdditionalContextForMessage(messageLevelAction, retryInterval),
                "\r\n"
            });
            if (flag)
            {
                IEnumerator <MailRecipient> enumerator = recipients.GetEnumerator();
                bool flag2 = enumerator.MoveNext();
                while (flag2)
                {
                    MailRecipient mailRecipient = enumerator.Current;
                    flag2 = enumerator.MoveNext();
                    bool value = mailRecipient.ExtendedProperties.GetValue <bool>("Microsoft.Exchange.Transport.MailboxTransport.RetryOnDuplicateDelivery ", false);
                    mailRecipient.ExtendedProperties.Remove("Microsoft.Exchange.Transport.MailboxTransport.RetryOnDuplicateDelivery ");
                    SmtpResponse responseForRecipient = SmtpResponseGenerator.GetResponseForRecipient(mailRecipient, value);
                    stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}{2} {3} {4}{5}{6}", new object[]
                    {
                        smtpResponse.StatusCode,
                        flag2 ? "-" : " ",
                        responseForRecipient.StatusCode,
                        responseForRecipient.EnhancedStatusCode,
                        SmtpResponseGenerator.FlattenStatusText(responseForRecipient),
                        SmtpResponseGenerator.GenerateAdditionalContextForRecipient(mailRecipient, value),
                        "\r\n"
                    });
                }
            }
            return(SmtpResponse.Parse(stringBuilder.ToString()));
        }
Exemple #3
0
        private static SmtpResponse CreateStoreDriverRetireResponse()
        {
            StringBuilder stringBuilder = new StringBuilder();

            SmtpResponseGenerator.GenerateBanner(stringBuilder, "432", "4.3.2");
            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}{2} {3} {4}{5}{6}", new object[]
            {
                "432",
                " ",
                "432",
                "4.3.2",
                "STOREDRV.Deliver; Component has been retired",
                string.Format(CultureInfo.InvariantCulture, "[{0}={1}]", new object[]
                {
                    "resubmit",
                    true
                }),
                "\r\n"
            });
            return(SmtpResponse.Parse(stringBuilder.ToString()));
        }