{
MegaBrutal's SMTP Server (MgSMTP)
- Copyright (C) 2010-2014 MegaBrutal
+ Copyright (C) 2010-2018 MegaBrutal
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
type
TMgSMTPListener = class(TTCPListener)
- constructor Create(Port: word);
+ constructor Create(const Address: string; Port: word);
protected
procedure HandleClient(Connection: TTCPConnection); override;
procedure ReceiveEMailData(TCP: TTCPRFCConnection; Response: TRFCReply; SpoolObject: TSpoolObjectCreator);
procedure StartListeners;
-var i: integer;
+var i: integer; address, port: string;
begin
- SetLength(MgSMTPListeners, MainServerConfig.ListenPorts.Count);
+ SetLength(MgSMTPListeners, MainServerConfig.ListenAddresses.Count);
for i:= 0 to Length(MgSMTPListeners) - 1 do begin
- MgSMTPListeners[i]:= TMgSMTPListener.Create(StrToIntDef(MainServerConfig.ListenPorts.Strings[i], STANDARD_SMTP_PORT));
+ SplitParameters(MainServerConfig.ListenAddresses.Strings[i], address, port, ':');
+ MgSMTPListeners[i]:= TMgSMTPListener.Create(address, StrToIntDef(port, STANDARD_SMTP_PORT));
MgSMTPListeners[i].StartListen;
end;
end;
end;
-constructor TMgSMTPListener.Create(Port: word);
+constructor TMgSMTPListener.Create(const Address: string; Port: word);
begin
{ Request connection objects with support for RFC-style commands & responses. }
- inherited Create(Port, NET_TCP_RFCSUPPORT);
- Logger.AddLine('Server', 'Listening on port: ' + IntToStr(Port));
+ inherited Create(Address, Port, NET_TCP_RFCSUPPORT);
+ Logger.AddLine('Server', 'Listening on address: ' + Address + ':' + IntToStr(Port));
end;
Done:= false;
repeat
ReadOK:= TCP.ReadLn(Line);
- if Line <> '.' then
- SpoolObject.DeliverMessagePart(Line)
+ if Line <> '.' then begin
+ { If the line starts with a dot, remove it to comply with RFC. }
+ if (Length(Line) > 1) and (Line[1] = '.') then Delete(Line, 1, 1);
+ SpoolObject.DeliverMessagePart(Line);
+ end
else
Done:= true;
until Done or (not ReadOK);