X-Git-Url: http://git.megabrutal.com/?p=mgsmtp.git;a=blobdiff_plain;f=Common.pas;h=2280c2b5358f968ba6d8f0c5c070e445088be0d3;hp=fadccc59f8b17f0ca294d84740c7af03e946d546;hb=973fc2e5ed9372c813ce98f65ad4496c0935185b;hpb=461ab8aed63976eed05ba159c4dbfa4baa06d33b diff --git a/Common.pas b/Common.pas index fadccc5..2280c2b 100644 --- a/Common.pas +++ b/Common.pas @@ -26,7 +26,7 @@ unit Common; interface -uses Windows, SysUtils, DateUtils, Classes, INIFiles; +uses Windows, SysUtils, DateUtils, Classes, INIFiles, RFCSMTP; type @@ -73,10 +73,11 @@ type {FTimeCorrection: integer;} FTimeOffset: integer; FTimeOffsetStr: string; - FListenAddresses: TStrings; + FListenAddresses, FListenAddresses6: TStrings; public function GetVersionStr: string; property ListenAddresses: TStrings read FListenAddresses; + property ListenAddresses6: TStrings read FListenAddresses6; property Databytes: longint read FDatabytes; {property TimeCorrection: integer read FTimeCorrection;} property TimeOffset: integer read FTimeOffset; @@ -165,6 +166,7 @@ type function IsPrintableString(S: string): boolean; function UnixTimeStamp(DateTime: TDateTime): TUnixTimeStamp; function CmdlineToStringArray: TStringArray; + procedure ParseIPv6Address(S: string; var Address: string; var Port: word); procedure SplitParameters(S: string; var FirstPrm, Remainder: string; Separator: char = #32); function ReadLineFromStream(Stream: TStream): string; @@ -385,6 +387,54 @@ begin end; end; +procedure ParseIPv6Address(S: string; var Address: string; var Port: word); +{ IPv6 addresses can be supplied in the following formats: + []: e.g. [::1]:25 + or + : e.g. mail.example.com:25 } +var SPort: string; c: integer; +begin + if S[1] = '[' then begin + { Guess format is "[]:". } + c:= pos(']', S); + if c > 1 then begin + Address:= Copy(S, 2, c - 2); + if c = Length(S) then begin + { There is no port to extract. } + Port:= STANDARD_SMTP_PORT; + end + else begin + { The closing bracket should be followed by a colon. } + if S[c+1] = ':' then + { Extract port number. } + Port:= StrToIntDef(Copy(S, c+2, Length(S) - (c+1)), 0) + else + { Invalid format. } + Port:= 0; + end; + end + else begin + { Format is incorrect, return invalid data. } + Address:= ''; + Port:= 0; + end; + end + else begin + { Guess format is ":". } + SplitParameters(S, Address, SPort, ':'); + if (pos(':', Address) = 0) and (pos(':', SPort) = 0) then begin + { Format seems correct. } + if SPort = '' then Port:= STANDARD_SMTP_PORT + else Port:= StrToIntDef(SPort, 0); + end + else begin + { Format is incorrect, return invalid data. } + Address:= ''; + Port:= 0; + end; + end; +end; + procedure SplitParameters(S: string; var FirstPrm, Remainder: string; Separator: char = #32); var i: integer; begin @@ -483,6 +533,10 @@ begin portlist.Free; end; + FListenAddresses6:= TStringList.Create; + FListenAddresses6.Delimiter:= ','; + FListenAddresses6.DelimitedText:= Config.ReadString('Server', 'ListenAddress6', ''); + FDatabytes:= Config.ReadInteger('Server', 'Databytes', 1024 * 1024 * 1024); FTimeOffset:= Config.ReadInteger('Server', 'TimeOffset', Config.ReadInteger('Server', 'TimeCorrection', 0) * 100); FTimeOffsetStr:= MakeTimeOffsetStr(FTimeOffset);