Gummy Guest
|
Posted: Thu Sep 08, 2005 1:42 pm Post subject: XPAT search in TIdNNTP |
|
|
Hello guys,
In need of XPAT search for my nntp client, I quickly wrote the following
method to add to IdNntp; probably contains a couple bugs, doesn't
respect rules, bla bla bla, but if it can save you 5 minutes or so :)
You will notice it is heavily based on XHDR method, and it calls
OnXhdrEntry, as the results returned are in the same format.
Hope it can help
Gummy
----------------------------------------------------------------------
procedure TIdNNTP.XPAT(AHeader : string; startArticle,endArticle :
integer;AParam: String);
var LLine : String;
LMsg, LHeaderData : String;
LCanContinue : Boolean;
SearchPattern : string;
c:char;
i:integer;
begin
if Assigned(FOnXHDREntry) then
begin
// make the search pattern
SearchPattern := 'subject '+inttostr(startArticle)+'-';
// searching the whole group is done by specifying 0 both for
startArticle and endArticle
if endArticle>0 then SearchPattern :=
SearchPattern+inttostr(endArticle);
if AParam<>'' then begin
SearchPattern := SearchPattern+' *';
// make the search pattern case insensitive
// for case sensitive search, just do SearchPattern := SearchPattern +
AParam instead of the for loop.
for i:=1 to length(AParam) do
begin
c:=AParam[i];
SearchPattern := SearchPattern +
'['+uppercase(c)+LowerCase(c)+']';
end;
SearchPattern := SearchPattern+'*';
end;
SendCmd('XPAT ' + SearchPattern, 221);
// code taken from XHDR
BeginWork(wmRead, 0);
try
LLine := IOHandler.ReadLn;
LCanContinue := True;
while (LLine <> '.') and LCanContinue do
begin
ParseXHDRLine(LLine,LMsg,LHeaderData);
FOnXHDREntry(AHeader,LMsg,LHeaderData,LCanContinue);
LLine := IOHandler.ReadLn;
end;
finally
EndWork(wmRead);
end;
end
else
begin
raise EIdNNTPNoOnXHDREntry.Create(RSNNTPNoOnXHDREntry);
end;
end;
----------------------------------------------------------------------
|
|