当前位置: 首页>>代码示例>>C#>>正文


C# IConnection.WriteResponse方法代码示例

本文整理汇总了C#中IConnection.WriteResponse方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.WriteResponse方法的具体用法?C# IConnection.WriteResponse怎么用?C# IConnection.WriteResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnection的用法示例。


在下文中一共展示了IConnection.WriteResponse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public virtual void Process(IConnection connection, SmtpCommand command)
        {
            if (connection.CurrentMessage == null)
            {
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "Bad sequence of commands"));
                return;
            }

            connection.CurrentMessage.SecureConnection = connection.Session.SecureConnection;
            connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.StartMailInputEndWithDot,
                                                               "End message with period"));

            using (StreamWriter writer = new StreamWriter(connection.CurrentMessage.GetData(DataAccessMode.ForWriting), connection.ReaderEncoding))
            {
                bool firstLine = true;

                do
                {
                    string line = connection.ReadLine();

                    if (line != ".")
                    {
                        line = ProcessLine(line);

                        if (!firstLine)
                            writer.Write(Environment.NewLine);

                        writer.Write(line);
                    }
                    else
                    {
                        break;
                    }

                    firstLine = false;

                } while (true);

                writer.Flush();
                long? maxMessageSize =
                    connection.Server.Behaviour.GetMaximumMessageSize(connection);

                if (maxMessageSize.HasValue && writer.BaseStream.Length > maxMessageSize.Value)
                {
                    connection.WriteResponse(
                        new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation,
                                         "Message exceeds fixed size limit"));
                }
                else
                {
                    writer.Close();
                    connection.Server.Behaviour.OnMessageCompleted(connection);
                    connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Mail accepted"));
                    connection.CommitMessage();
                }

            }
        }
开发者ID:enbiso,项目名称:dummy-smtp-server,代码行数:59,代码来源:DataVerb.cs

示例2: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            if (!string.IsNullOrEmpty(connection.Session.ClientName))
            {
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "You already said HELO"));
                return;
            }

            connection.Session.ClientName = command.Arguments[0];
            connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Nice to meet you"));
        }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:12,代码来源:HeloVerb.cs

示例3: Process

 public void Process(IConnection connection, SmtpCommand command)
 {
     connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.ClosingTransmissionChannel,
                                                        "See you later aligator"));
     connection.CloseConnection();
     connection.Session.CompletedNormally = true;
 }
开发者ID:enbiso,项目名称:dummy-smtp-server,代码行数:7,代码来源:QuitVerb.cs

示例4: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            if (!string.IsNullOrEmpty(connection.Session.ClientName))
            {
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "You already said HELO"));
                return;
            }

            StringBuilder text = new StringBuilder();
            text.AppendLine("Nice to meet you.");

            foreach (string extnName in connection.ExtensionProcessors.SelectMany(extn => extn.EHLOKeywords))
            {
                text.AppendLine(extnName);
            }

            connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, text.ToString().TrimEnd()));
        }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:19,代码来源:EhloVerb.cs

示例5: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            if (connection.CurrentMessage != null)
            {
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "You already told me who the message was from"));
                return;
            }

            if (command.ArgumentsText.Length == 0)
            {
                connection.WriteResponse(
                    new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments,
                                     "Must specify from address or <>"));
                return;
            }

            string from = command.Arguments.First();
            if (from.StartsWith("<"))
                from = from.Remove(0, 1);

            if (from.EndsWith(">"))
                from = from.Remove(from.Length - 1, 1);

            connection.Server.Behaviour.OnMessageStart(connection, from);
            connection.NewMessage();
            connection.CurrentMessage.From = from;


            try
            {
                ParameterProcessorMap.Process(command.Arguments.Skip(1).ToArray(), true);
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Okey dokey"));
            }
            catch
            {
                connection.AbortMessage();
                throw;
            }
        }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:40,代码来源:MailFromVerb.cs

示例6: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            if (connection.CurrentMessage == null)
            {
                connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "No current message"));
                return;
            }

            if (command.ArgumentsText == "<>" || !command.ArgumentsText.StartsWith("<") ||
                !command.ArgumentsText.EndsWith(">") || command.ArgumentsText.Count(c => c == '<') != command.ArgumentsText.Count(c => c == '>'))
            {
                connection.WriteResponse(
                    new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments,
                                     "Must specify to address <address>"));
                return;
            }

            string address = command.ArgumentsText.Remove(0, 1).Remove(command.ArgumentsText.Length - 2);
            connection.Server.Behaviour.OnMessageRecipientAdding(connection, connection.CurrentMessage, address);
            connection.CurrentMessage.ToList.Add(address);
            connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Recipient accepted"));
        }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:23,代码来源:RcptToVerb.cs

示例7: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            SmtpCommand subrequest = new SmtpCommand(command.ArgumentsText);
            IVerb verbProcessor = SubVerbMap.GetVerbProcessor(subrequest.Verb);

            if (verbProcessor != null)
            {
                verbProcessor.Process(connection, subrequest);
            }
            else
            {
                connection.WriteResponse(
                    new SmtpResponse(StandardSmtpResponseCode.CommandParameterNotImplemented,
                                     "Subcommand {0} not implemented", subrequest.Verb));
            }
        }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:16,代码来源:MailVerb.cs

示例8: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.ServiceReady,
                                                      "Ready to start TLS"));
            connection.ApplyStreamFilter(stream =>
                                                     {
                                                         SslStream sslStream = new SslStream(stream);
                                                         sslStream.AuthenticateAsServer(
                                                             connection.Server.Behaviour.GetSSLCertificate(
                                                                 connection), false,
                                                             SslProtocols.Ssl2 | SslProtocols.Ssl3 | SslProtocols.Tls,
                                                             false);
                                                         return sslStream;
                                                     });

            connection.Session.SecureConnection = true;
        }
开发者ID:enbiso,项目名称:dummy-smtp-server,代码行数:17,代码来源:StartTlsVerb.cs

示例9: Process

        public void Process(IConnection connection, SmtpCommand command)
        {
            if (command.Arguments.Length > 0)
            {
                if (connection.Session.Authenticated)
                {
                    throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.BadSequenceOfCommands,
                                                                   "Already authenticated"));
                }

                string mechanismId = command.Arguments[0];
                IAuthMechanism mechanism = AuthExtensionProcessor.MechanismMap.Get(mechanismId);

                if (mechanism == null)
                {
                    throw new SmtpServerException(
                        new SmtpResponse(StandardSmtpResponseCode.CommandParameterNotImplemented,
                                         "Specified AUTH mechanism not supported"));
                }

                if (!AuthExtensionProcessor.IsMechanismEnabled(mechanism))
                {
                    throw new SmtpServerException(
                        new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                         "Specified AUTH mechanism not allowed right now (might require secure connection etc)"));
                }

                IAuthMechanismProcessor authMechanismProcessor =
                    mechanism.CreateAuthMechanismProcessor(connection);

                string initialData = null;
                if (command.Arguments.Length > 1)
                {
                    initialData = string.Join(" ", command.Arguments.Skip(1).ToArray());
                }

                AuthMechanismProcessorStatus status =
                    authMechanismProcessor.ProcessResponse(initialData);
                while (status == AuthMechanismProcessorStatus.Continue)
                {
                    string response = connection.ReadLine();

                    if (response == "*")
                    {
                        connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments, "Authentication aborted"));
                        return;
                    }

                    status = authMechanismProcessor.ProcessResponse(response);
                }

                if (status == AuthMechanismProcessorStatus.Success)
                {
                    connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationOK,
                                                              "Authenticated OK"));
                    connection.Session.Authenticated = true;
                    connection.Session.AuthenticationCredentials = authMechanismProcessor.Credentials;
                }
                else
                {
                    connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.AuthenticationFailure,
                                                              "Authentication failure"));
                }
            }
            else
            {
                throw new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments,
                                                               "Must specify AUTH mechanism as a parameter"));
            }
        }
开发者ID:enbiso,项目名称:dummy-smtp-server,代码行数:70,代码来源:AuthVerb.cs

示例10: Process

 public void Process(IConnection connection, SmtpCommand command)
 {
     connection.AbortMessage();
     connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Rset completed"));
 }
开发者ID:LiDamon,项目名称:smtp4dev,代码行数:5,代码来源:RsetVerb.cs

示例11: Process

 public void Process(IConnection connection, SmtpCommand command)
 {
     connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Sucessfully did nothing"));
 }
开发者ID:enbiso,项目名称:dummy-smtp-server,代码行数:4,代码来源:NoopVerb.cs


注:本文中的IConnection.WriteResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。