Block more HTTP request methods
[mgsmtp.git] / Relay.pas
index 713db8d8641af8593d6703d4a9999bd6c548efd1..017d943b22463595f184cf51911f176ea112bca5 100644 (file)
--- a/Relay.pas
+++ b/Relay.pas
@@ -1,6 +1,6 @@
 {
    MegaBrutal's SMTP Server (MgSMTP)
-   Copyright (C) 2010-2015 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
@@ -176,6 +176,7 @@ begin
    FTransactionComplete:= false;
    FRoutingTarget:= RoutingTable.GetRouteInfo(Envelope.RelayHost);
    Response:= TRFCReply.Create;
+   TCP:= nil;
    FillChar(SMTPExtensions, SizeOf(TSMTPExtensions), #0);
 end;
 
@@ -183,6 +184,7 @@ destructor TRelayer.Destroy;
 begin
    FRoutingTarget.Free;
    Response.Free;
+   if TCP <> nil then TCP.Free;
    inherited Destroy;
 end;
 
@@ -331,14 +333,16 @@ var MXList: TStrings; i: integer;
 begin
    MXList:= GetCorrectMXRecordList(RelayServerName);
    if MXList.Count >= 1 then begin
-      TCP:= TTCPRFCConnection.Create(MXList.Strings[0], RelayServerPort);
+      TCP:= TTCPRFCConnection.Create;
+      TCP.SetBindAddress(MainServerConfig.BindAddress);
       TCP.SetSockTimeOut(DEF_SOCK_TIMEOUT);
-      i:= 1;
+      i:= 0;
       while (not TCP.Connected) and (i < MXList.Count) do begin
          TCP.Connect(MXList.Strings[i], RelayServerPort);
          Inc(i);
       end;
       Result:= TCP.Connected;
+      if not TCP.Connected then FreeAndNil(TCP);
    end
    else Result:= false;
    MXList.Free;
@@ -441,7 +445,7 @@ var
    procedure ProcessRCPTResponse;
    begin
       TCP.ReadResponse(Response);
-      { If we get an "OK" reply code, we increase the count of sucessful
+      { If we get an "OK" reply code, we increase the count of successful
         recipients. }
       if Response.GetNumericCode = SMTP_R_OK then Inc(c)
       { Response code 0 is non-existent in the SMTP protocol.
@@ -538,7 +542,7 @@ procedure TRelayer.CloseConnection;
 begin
    TCP.SendCommand(SMTP_C_QUIT);
    {TCP.ReadResponse(Response);}
-   TCP.Free;
+   FreeAndNil(TCP);
 end;