打印本文 打印本文 关闭窗口 关闭窗口
TCP/IP(七)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1909  更新时间:2009/4/23 18:43:56  文章录入:mintao  责任编辑:mintao
ponse;
  end;
(*@\\\0000000401*)
(*@\\\0000000801*)
(*@/// class t_nntp(t_tcpip) *)
(*@/// function nntpdate(date:TDateTime):string; *)
function nntpdate(date:TDateTime):string;
begin
  result:=formatdatetime(''''yymmdd hhnnss'''',date);
  end;
(*@\\\0000000330*)

(*@/// constructor t_nntp.Create(Aowner:TComponent); *)
constructor t_nntp.Create(Aowner:TComponent);
begin
  inherited create(Aowner);
  f_news:=TStringlist.Create;
  f_newsgroups:=TStringlist.Create;
  f_socket_number:=119;
  end;
(*@\\\0000000401*)
(*@/// destructor t_nntp.Destroy; *)
destructor t_nntp.Destroy;
begin
  f_news.free;
  f_newsgroups.free;
  inherited destroy;
  end;
(*@\\\0000000501*)
(*@/// procedure t_nntp.SetNews(value:TStringlist); *)
procedure t_nntp.SetNews(value:TStringlist);
begin
  if value=NIL then
    f_news.clear
  else
    f_news.assign(value);
  end;
(*@\\\0000000603*)

(*@/// procedure t_nntp.action; *)
procedure t_nntp.action;
begin
  login;
  (* ??? *)
  logout;
  end;
(*@\\\0000000401*)

(*@/// procedure t_nntp.Login; *)
procedure t_nntp.Login;
begin
  inherited login;
  self.response;
  self.SendCommand(''''MODE READER'''');   (* some NNTP servers need this *)
  try
    self.response;
  except
    (* ignore if the server doesn''''t understand this *)
    end;
  end;
(*@\\\0000000508*)
(*@/// procedure t_nntp.Logout;                                          // QUIT *)
procedure t_nntp.Logout;
begin
  if f_logged_in then begin
    self.SendCommand(''''QUIT'''');
    self.response;
    end;
  inherited logout;
  end;
(*@\\\0000000306*)

(*@/// procedure t_nntp.GetArticleID(msgid:string);                      // ARTICLE *)
procedure t_nntp.GetArticleID(const msgid:string);
begin
  if not f_logged_in then login;
  if msgid[1]<>''''<'''' then
    self.SendCommand(''''ARTICLE <''''+msgid+''''>'''')
  else
    self.SendCommand(''''ARTICLE ''''+msgid);
  self.response;
  f_news.clear;
  GetArticleInternally;
  end;
(*@\\\0000000301*)
(*@/// procedure t_nntp.PostArticle;                                     // POST *)
procedure t_nntp.PostArticle;
var
  i:integer;
begin
  if not f_logged_in then login;
  self.SendCommand(''''POST'''');
  self.response;
  for i:=0 to f_news.count-1 do begin
    if f_news.strings[i]=''''.'''' then
      write_s(f_socket,''''..''''+#13#10)
    else
      write_s(f_socket,f_news.strings[i]+#13#10);
    end;
  write_s(f_socket,''''.''''+#13#10);
  self.response;
  end;
(*@\\\0000000601*)
(*@/// procedure t_nntp.GetAllNewsgroups;                                // LIST *)
procedure t_nntp.GetAllNewsgroups;
var
  s: string;
begin
  if not f_logged_in then login;
  f_newsgroups.clear;
  self.SendCommand(''''LIST'''');
  self.response;
  while true do begin
    s:=read_line(f_socket);
    if s<>''''.'''' then
      f_newsgroups.add(copy(s,1,pos('''' '''',s)-1))
    else
      BREAK;
    end;
  end;
(*@\\\0000000601*)
(*@/// procedure t_nntp.GetNewNewsgroups(since:TDateTime);               // NEWGROUPS *)
procedure t_nntp.GetNewNewsgroups(since:TDateTime);
var
  s: string;
begin
  if not f_logged_in then login;
  f_newsgroups.clear;
  self.SendCommand(''''NEWGROUPS ''''+nntpdate(since));
  self.response;
  while true do begin
    s:=read_line(f_socket);
    if s<>''''.'''' then
      f_newsgroups.add(copy(s,1,pos('''' '''',s)-1))
    else
      BREAK;
    end;
  end;
(*@\\\0000000601*)
(*@/// procedure t_nntp.SetGroup(group:string; low,high,count: integer); // GROUP *)
procedure t_nntp.SetGroup(const group:string; var low,high,count: integer);
var
  s1,s2,s3: integer;
begin
  if not f_logged_in then login;
  self.SendCommand(''''GROUP ''''+group);
  self.response;
  s1:=pos('''' '''',f_status_txt);
  s2:=posn('''' '''',f_status_txt,2);
  s3:=posn('''' '''',f_status_txt,3);
  count:=strtoint(copy(f_status_txt,1,s1-1));
  low:=strtoint(copy(f_status_txt,s1+1,s2-s1-1));
  high:=strtoint(copy(f_status_txt,s2+1,s3-s2-1));
  end;

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口