Start extension implementatiopn

This commit is contained in:
Fabian Stamm 2016-11-30 21:09:45 +01:00
parent 68e0ac2ef0
commit df48102215
4 changed files with 35 additions and 7 deletions

View File

@ -7,6 +7,7 @@ namespace MailServer
public class Configuration public class Configuration
{ {
public const string Hostname = "localhost"; public const string Hostname = "localhost";
public bool STARTTLS_Active = false; public const bool STARTTLS_Active = true;
public const int MaxMessageSizeInKb = 500000;
} }
} }

View File

@ -69,6 +69,13 @@ namespace MailServer.SMTPServer
AUTH_LOGIN AUTH_LOGIN
} }
public enum Extensions
{
PIPELINING,
SIZE,
STARTTLS,
}
public enum ResponseCodes public enum ResponseCodes
{ {
C211 = 211, C211 = 211,

View File

@ -79,7 +79,7 @@ namespace MailServer.SMTPServer
var res3 = context.Accounts.Where(x => x.Domain.Equals(domain) && x.CatchAll == true); var res3 = context.Accounts.Where(x => x.Domain.Equals(domain) && x.CatchAll == true);
if (res3.Count() < 1) if (res3.Count() < 1)
{ {
//ToDo unmöglich machen!! accountId = 0;
} }
else else
{ {
@ -145,6 +145,22 @@ namespace MailServer.SMTPServer
switch (command.Command.ToUpper()) switch (command.Command.ToUpper())
{ {
case "EHLO": case "EHLO":
if (command.Parameters.Length < 1)
{
SendResponse(ResponseCodes.C501, "Hostname Required");
return;
}
SenderHostname = command.Parameters[0];
Initialized = true;
SendExtensionResponse(Extensions.PIPELINING);
if (Configuration.STARTTLS_Active)
{
SendExtensionResponse(Extensions.STARTTLS);
}
SendResponse(ResponseCodes.C250, "SIZE " + (Configuration.MaxMessageSizeInKb * 1000).ToString());
return;
case "HELO": case "HELO":
if (command.Parameters.Length < 1) if (command.Parameters.Length < 1)
{ {

View File

@ -36,14 +36,18 @@ namespace MailServer.SMTPServer
Worker.Start(); Worker.Start();
} }
public void SendExtensionResponse(Extensions extension) => SendResponse("250-" + extension.ToString());
public void SendResponse(ResponseCodes responseCode) => SendResponse(responseCode, ""); public void SendResponse(ResponseCodes responseCode) => SendResponse(responseCode, "");
public void SendResponse(ResponseCodes responseCode, string args) public void SendResponse(ResponseCodes responseCode, string args) => SendResponse(((int)responseCode).ToString() + " " + args);
public void SendResponse(string response)
{ {
var text = ((int)responseCode).ToString(); Logging.AddLogMessage(Logging.LoggingType.INFO, response);
Logging.AddLogMessage(Logging.LoggingType.DEBUG, "Send back: " + text + " " + args); response += '\r' + '\n';
text += " " + args +'\r' + '\n'; var bytes = Encoding.UTF8.GetBytes(response);
var bytes = Encoding.UTF8.GetBytes(text);
Stream.Write(bytes, 0, bytes.Length); Stream.Write(bytes, 0, bytes.Length);
} }