Many thanks, this solve the issue.
Unfortunately I did not write the procedure, I downloaded somewhere years ago this library in order to code/uncode in base64.
I had already applied your suggestion to another procedure but I am not able to translate this part:
Pointer(Cardinal(Result) + InputSize)^
The function declaration is
function MimeDecodePartialEnd(out OutputBuffer; const ByteBuffer: Cardinal; const ByteBufferSpace: Cardinal): Cardinal;
I really appreciate your help.
function MimeDecodeString(const s: AnsiString): AnsiString;
var
ByteBuffer, ByteBufferSpace: Cardinal;
l: Cardinal;
InputSize, OutputSize: SizeInt;
begin
if S <> '' then
begin
InputSize := Length(S);
SetString(Result, nil, MimeDecodedSize(InputSize));
ByteBuffer := 0;
ByteBufferSpace := 4;
InputSize := MimeDecodePartial(Pointer(s)^, InputSize, Pointer(Result)^, ByteBuffer, ByteBufferSpace);
Inc(InputSize, MimeDecodePartialEnd(Pointer(Cardinal(Result) + InputSize)^, ByteBuffer, ByteBufferSpace));
SetLength(Result, InputSize);
end
else
Result := '';
end;