Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebeau committed Apr 30, 2023
1 parent 82aed7c commit 6f109e3
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions Lib/Protocols/IdReplyPOP3.pas
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class function TIdReplyPOP3.FindCodeTextDelim(const AText: String): Integer;
//we do things this way because a line can start with a minus as in
//-ERR [IN-USE] Mail box in use
LBuf := AText;
// TODO: use PosEx() instead, then we can just skip
// past the '-' without physically removing it...
if TextStartsWith(LBuf, '-') then begin
Delete(LBuf, 1, 1);
LAddBackFlag := True;
Expand Down Expand Up @@ -323,7 +325,7 @@ class function TIdReplyPOP3.IsValidEnhancedCode(const AText : String; const AStr
if AStrict then begin
Result := PosInStrArray(LBuf, VALID_ENH_CODES) > -1;
end else begin
{We don't use PosInStrArray because we only want the fist
{We don't use PosInStrArray because we only want the first
charactors in our string to match. This is necessary because
the POP3 enhanced codes will be hierarchical as time goes on.
}
Expand Down Expand Up @@ -372,10 +374,19 @@ procedure TIdReplyPOP3.SetFormattedReply(const AValue: TStrings);
i: Integer;
idx : Integer;
LOrd : Integer;
LBuf : String;
LBuf, LEnh : String;
LText : TStringList;
begin
Clear;
if AValue.Count > 0 then begin
// RLebeau: what is the purpose of this ExtractTextPosArray() shenanigans? Why
// are we allowing the status code to appear outside of the 1st line? That does
// not conform to the POP3 protocol spec. Are any servers actually doing this
// in practice? None of the other TIdReply classes handle this possibility...
//
// Note: Microsoft's Outlook365 POP3 server DOES send a greeting WITHOUT a
// status code if a client connects using implicit TLS 1.0 or 1.1! That was
// apparently allowed by RFC 1725, but not anymore by RFC 1939!
LOrd := ExtractTextPosArray(AValue[0]);
if LOrd > -1 then begin
Code := VALID_POP3_STR[LOrd];
Expand All @@ -395,7 +406,20 @@ procedure TIdReplyPOP3.SetFormattedReply(const AValue: TStrings);
Text.Add(LBuf);
end;
if LOrd = -1 then begin
Code := ST_ERR;
// RLebeau 4/30/2023: warning - TIdReply.SetCode() calls Clear(),
// which will LOSE any EnhancedCode and Text values already assigned
// above! We need to preserve them here. This wouldn't be an issue
// anymore if we get rid of the ExtractTextPosArray() nonsense above...
LText := TStringList.Create;
try
LText.Assign(Text);
LEnh := FEnhancedCode;
Code := ST_ERR;
Text.Assign(LText);
FEnhancedCode := LEnh;
finally
LText.Free;
end;
end;
end;
end;
Expand Down

0 comments on commit 6f109e3

Please sign in to comment.