Block more HTTP request methods
[mgsmtp.git] / Common.pas
index 8e0b7fb443ffa93db0871a7522e42a007bbc40f6..8677ead2930bae7372d9145358cc90233f6cc6d0 100644 (file)
@@ -1,5 +1,5 @@
 {
-   Copyright (C) 2010-2015 MegaBrutal
+   Copyright (C) 2010-2018 MegaBrutal
 
    This unit is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -73,10 +73,12 @@ type
       {FTimeCorrection: integer;}
       FTimeOffset: integer;
       FTimeOffsetStr: string;
-      FListenPorts: TStrings;
+      FListenAddresses: TStrings;
+      FBindAddress: string;
    public
       function GetVersionStr: string;
-      property ListenPorts: TStrings read FListenPorts;
+      property ListenAddresses: TStrings read FListenAddresses;
+      property BindAddress: string read FBindAddress;
       property Databytes: longint read FDatabytes;
       {property TimeCorrection: integer read FTimeCorrection;}
       property TimeOffset: integer read FTimeOffset;
@@ -138,6 +140,7 @@ type
       procedure AddRecipient(Recipient: TRecipient); overload;
       procedure SetReturnPath(Address: string);
       procedure SetRecipientData(Index, Data: integer; RMsg: string = '');
+      procedure SetAllRecipientData(Data: integer; RMsg: string = '');
       procedure SetRelayHost(HostName: string);
       property ReturnPath: string read FReturnPath write SetReturnPath;
       property RelayHost: string read FRelayHost write SetRelayHost;
@@ -154,7 +157,7 @@ type
    function EMailTimeStamp(DateTime: TDateTime): string;
    function EMailTimeStampCorrected(DateTime: TDateTime): string;
    function StatusToStr(Status: integer): string;
-   procedure AssignDeliveryStatusToSMTPCodes(Envelope: TEnvelope);
+   procedure AssignDeliveryStatusToSMTPCodes(Envelope: TEnvelope; TransactionComplete: boolean);
 
    function CleanEOLN(S: string): string;
    function GenerateRandomString(Length: integer): string;
@@ -303,7 +306,7 @@ begin
       + '+' + IntToStr(Status and DS_SMTPREPLYMASK);
 end;
 
-procedure AssignDeliveryStatusToSMTPCodes(Envelope: TEnvelope);
+procedure AssignDeliveryStatusToSMTPCodes(Envelope: TEnvelope; TransactionComplete: boolean);
 var i, code, cond, status: integer; Recipient: TRecipient;
 begin
    for i:= 0 to Envelope.GetNumberOfRecipients - 1 do begin
@@ -312,7 +315,8 @@ begin
       cond:= code div 100;
       case cond of
          0: status:= DS_DELAYED or DS_UNEXPECTEDFAIL;
-         2: status:= DS_DELIVERED;
+         2: if TransactionComplete then status:= DS_DELIVERED
+            else status:= DS_DELAYED or DS_UNEXPECTEDFAIL;
          4: status:= DS_DELAYED;
          5: status:= DS_PERMANENT;
          else status:= DS_PERMANENT or DS_UNEXPECTEDFAIL;
@@ -463,14 +467,27 @@ begin
 end;
 
 constructor TMainServerConfig.Create(Config: TINIFile);
+var i: integer; rawaddresslist: string; portlist: TStringList;
 begin
    inherited Create(Config.ReadString('Server', 'Name', ''), Config, 'Server');
-   FListenPorts:= TStringList.Create;
-   FListenPorts.Delimiter:= ',';
-   FListenPorts.DelimitedText:= Config.ReadString('Server', 'ListenPort', '25');
+   FListenAddresses:= TStringList.Create;
+   FListenAddresses.Delimiter:= ',';
+
+   rawaddresslist:= Config.ReadString('Server', 'ListenAddress', '');
+   if rawaddresslist <> '' then
+      FListenAddresses.DelimitedText:= rawaddresslist
+   else begin
+      portlist:= TStringList.Create;
+      portlist.Delimiter:= ',';
+      portlist.DelimitedText:= Config.ReadString('Server', 'ListenPort', '25');
+      for i:= 0 to portlist.Count - 1 do
+         FListenAddresses.Add('0.0.0.0:' + portlist.Strings[i]);
+      portlist.Free;
+   end;
+
+   FBindAddress:=    Config.ReadString('Server', 'BindAddress', '0.0.0.0');
 
    FDatabytes:=      Config.ReadInteger('Server', 'Databytes', 1024 * 1024 * 1024);
-   {FTimeCorrection:= Config.ReadInteger('Server', 'TimeCorrection', 0);}
    FTimeOffset:=     Config.ReadInteger('Server', 'TimeOffset', Config.ReadInteger('Server', 'TimeCorrection', 0) * 100);
    FTimeOffsetStr:=  MakeTimeOffsetStr(FTimeOffset);
 
@@ -658,6 +675,13 @@ begin
    FRecipients[Index].Data:= Data;
 end;
 
+procedure TEnvelope.SetAllRecipientData(Data: integer; RMsg: string = '');
+var i: integer;
+begin
+   for i:= 0 to Length(FRecipients) - 1 do
+      SetRecipientData(i, Data, RMsg);
+end;
+
 procedure TEnvelope.SetReturnPath(Address: string);
 begin
    FReturnPath:= Address;