⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idreplyimap4.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{ $HDR$}
{**********************************************************************}
{ Unit archived using Team Coherence                                   }
{ Team Coherence is Copyright 2002 by Quality Software Components      }
{                                                                      }
{ For further information / comments, visit our WEB site at            }
{ http://www.TeamCoherence.com                                         }
{**********************************************************************}
{}
{ $Log:  19404: IdReplyIMAP4.pas
{
{   Rev 1.23    10/26/2004 10:39:54 PM  JPMugaas
{ Updated refs.
}
{
    Rev 1.22    6/11/2004 9:38:30 AM  DSiders
  Added "Do not Localize" comments.
}
{
{   Rev 1.21    5/17/04 9:53:00 AM  RLebeau
{ Changed TIdRepliesIMAP4 constructor to use 'reintroduce' instead
}
{
{   Rev 1.20    5/16/04 5:31:24 PM  RLebeau
{ Added constructor to TIdRepliesIMAP4 class
}
{
{   Rev 1.19    03/03/2004 01:16:56  CCostelloe
{ Yet another check-in as part of continuing development
}
{
{   Rev 1.18    26/02/2004 02:02:22  CCostelloe
{ A few updates to support IdIMAP4Server development
}
{
{   Rev 1.17    05/02/2004 00:26:06  CCostelloe
{ Changes to support TIdIMAP4Server
}
{
{   Rev 1.16    2/3/2004 4:12:34 PM  JPMugaas
{ Fixed up units so they should compile.
}
{
{   Rev 1.15    2004.01.29 12:07:52 AM  czhower
{ .Net constructor problem fix.
}
{
{   Rev 1.14    1/3/2004 8:05:48 PM  JPMugaas
{ Bug fix:  Sometimes, replies will appear twice due to the way functionality
{ was enherited.
}
{
{   Rev 1.13    22/12/2003 00:45:40  CCostelloe
{ .NET fixes
}
{
{   Rev 1.12    03/12/2003 09:48:34  CCostelloe
{ IsItANumber and IsItAValidSequenceNumber made public for use by TIdIMAP4.
}
{
{   Rev 1.11    28/11/2003 21:02:46  CCostelloe
{ Fixes for Courier IMAP
}
{
{   Rev 1.10    22/10/2003 12:18:06  CCostelloe
{ Split out DoesLineHaveExpectedResponse for use by other functions in IdIMAP4.
}
{
    Rev 1.9    10/19/2003 5:57:12 PM  DSiders
  Added localization comments.
}
{
{   Rev 1.8    18/10/2003 22:33:00  CCostelloe
{ RemoveUnsolicitedResponses added.
}
{
{   Rev 1.7    20/09/2003 19:36:42  CCostelloe
{ Multiple changes to clear up older issues
}
{
{   Rev 1.6    2003.09.20 10:38:40 AM  czhower
{ Bug fix to allow clearing code field (Return to default value)
}
{
{   Rev 1.5    18/06/2003 21:57:00  CCostelloe
{ Rewrote SetFormattedReply.  Compiles and works.  Needs tidying up, as does
{ IdIMAP4.
}
{
{   Rev 1.4    17/06/2003 01:38:12  CCostelloe
{ Updated to suit LoginSASL changes.  Compiles OK.
}
{
{   Rev 1.3    15/06/2003 08:41:48  CCostelloe
{ Bug fix: i was undefined in SetFormattedReply in posted version, changed to LN
}
{
{   Rev 1.2    12/06/2003 10:26:14  CCostelloe
{ Unfinished but compiles.  Checked in to show problem with Get/SetNumericCode.
}
{
{   Rev 1.1    6/5/2003 04:54:26 AM  JPMugaas
{ Reworkings and minor changes for new Reply exception framework.
}
{
{   Rev 1.0    5/27/2003 03:03:54 AM  JPMugaas
}
unit IdReplyIMAP4;

{
  2003-Sep-26: CC2: Added Extra property.
  2003-Oct-18: CC3: Added RemoveUnsolicitedResponses function.
  2003-Nov-28: CC4: Fixes for Courier IMAP server.
}

interface
uses
  Classes,
  IdReply,
  IdReplyRFC,
  IdTStrings;

const
  IMAP_OK      = 'OK';      {Do not Localize}
  IMAP_NO      = 'NO';      {Do not Localize}
  IMAP_BAD     = 'BAD';     {Do not Localize}
  IMAP_PREAUTH = 'PREAUTH'; {Do not Localize}
  IMAP_BYE     = 'BYE';     {Do not Localize}
  IMAP_CONT    = '+';       {Do not Localize}

  VALID_TAGGEDREPLIES : array [0..5] of string =
    (IMAP_OK, IMAP_NO, IMAP_BAD, IMAP_PREAUTH, IMAP_BYE, IMAP_CONT);

type
  TIdReplyIMAP4 = class(TIdReply)
  protected
    {CC: A tagged IMAP response is 'C41 OK Completed', where C41 is the
    command sequence number identifying the command you sent to get that
    response.  An untagged one is '* OK Bad parameter'.  The codes are
    the same, some just start with *.
    FSequenceNumber is either a *, C41 or '' (if the response line starts with
    a valid response code like OK)...}
    FSequenceNumber: string;
    {IMAP servers can send extra info after a command like "BAD Bad parameter".
    Keep these for error messages (may be more than one).}
    FExtra: TIdStrings;
    function GetExtra: TIdStrings;  //Added to get over .NET not calling TIdReplyIMAP4's constructor
    {You would think that we need to override IdReply's Get/SetNumericCode
    because they assume the code is like '32' whereas IMAP codes are text like
    'OK' (when IdReply's StrToIntDef always returns 0), but Indy 10 has switched
    from numeric codes to string codes (i.e. we use 'OK' and never a
    numeric equivalent like 4).}
    {function GetNumericCode: Integer;
    procedure SetNumericCode(const AValue: Integer);}
    {Get/SetFormattedReply need to be overriden for IMAP4}
    function GetFormattedReply: TIdStrings; override;
    procedure SetFormattedReply(const AValue: TIdStrings); override;
    {CC: Need this also, otherwise the virtual one in IdReply uses
    TIdReplyRFC.CheckIfCodeIsValid which will only convert numeric
    codes like '22' to integer 22.}
    function CheckIfCodeIsValid(const ACode: string): Boolean; override;
    {The Indy10 version that hopefully deals with all TIdIMAP's possibilities...}
    { Moved back to IdIMAP4...
    function GetResponse: string;
    }
  public
    constructor Create(
      ACollection: TCollection = nil;
      AReplyTexts: TIdReplies = nil
      ); override;
    procedure Clear; override;
    //
    //CLIENT-SIDE (TIdIMAP4) FUNCTIONS...
    //procedure RaiseReplyError(ADescription: string; AnOffendingLine: string = ''); reintroduce;
    procedure RaiseReplyError; override;
    procedure DoReplyError(ADescription: string; AnOffendingLine: string = ''); reintroduce;
    procedure RemoveUnsolicitedResponses(AExpectedResponses: array of String);
    function DoesLineHaveExpectedResponse(ALine: string; AExpectedResponses: array of string): Boolean;
    {CC: The following decides if AThing is a valid command sequence number
    like C41...}
    function IsItAValidSequenceNumber(const AThing: string): Boolean;
    {CC2: The following determines if AText consists only of digits...}
    function IsItANumber(const AThing: string): Boolean;
    //
    //SERVER-SIDE (TIdIMAP4Server) FUNCTIONS...
    function ParseRequest(ARequest: string): Boolean;
    //
    property NumericCode: Integer read GetNumericCode write SetNumericCode;
    //property Extra: TIdStrings read FExtra;
    property Extra: TIdStrings read GetExtra;
    property SequenceNumber: string read FSequenceNumber;
    //
    //Added to stop constructor giving run-time error
    procedure SetReply(const ACode: Integer; const AText: string); override;
  end;

  TIdRepliesIMAP4 = class(TIdReplies)
  public
    constructor Create(AOwner: TPersistent); reintroduce;
  end;

  //This error method came from the POP3 Protocol reply exceptions
  // SendCmd / GetResponse
  EIdReplyIMAP4Error = class(EIdReplyError)
  {protected
    FErrorCode : String;}
  public
    {constructor CreateError(const AErrorCode: String; const AReplyMessage: string); reintroduce; virtual;}
    constructor CreateError(const AReplyMessage: string); {reintroduce; virtual;}
    {property ErrorCode : String read FErrorCode;}
  end;

implementation
uses IdGlobal, IdGlobalProtocols, SysUtils;

{ TIdReplyIMAP4 }
{
function TIdReplyIMAP4.GetNumericCode: Integer;
begin
  {Result := StrToIntDef(Code, 0);}
{  Result := PosInStrArray(Code,VALID_TAGGEDREPLIES) + 1;
end;
}
{
procedure TIdReplyIMAP4.SetNumericCode(const AValue: Integer);
begin
  {FCode := IntToStr(AValue);}
{  FCode := VALID_TAGGEDREPLIES[AValue-1];
end;
}

function TIdReplyIMAP4.ParseRequest(ARequest: string): Boolean;
begin
  FSequenceNumber := Fetch(ARequest, #32);
  Result := False;
  if IsItAValidSequenceNumber(FSequenceNumber) then begin
    Result := True;
  end;
end;

function TIdReplyIMAP4.GetExtra: TIdStrings;
begin
  if not assigned(FExtra) then begin
    FExtra := TIdStringList.Create;
  end;
  Result := FExtra;
end;

constructor TIdReplyIMAP4.Create(
      ACollection: TCollection = nil;
      AReplyTexts: TIdReplies = nil
      );
begin
  inherited;
  FExtra := TIdStringList.Create;
  Clear;
end;

procedure TIdReplyIMAP4.Clear;
begin
  inherited Clear;
  FSequenceNumber := '';
  //FExtra.Clear;
  Extra.Clear;
end;

procedure TIdReplyIMAP4.RaiseReplyError;
begin
  raise EIdReplyIMAP4Error.CreateError('Default RaiseReply error'); {do not localize}
end;

function TIdReplyIMAP4.IsItANumber(const AThing: string): Boolean;
var
    LN: integer;
begin
    Result := False;
    for LN := 1 to Length(AThing) do begin
        if ( (Ord(AThing[LN]) < Ord('0')) or (Ord(AThing[LN]) > Ord('9')) ) then begin  {Do not Localize}
            Exit;
        end;
    end;
    Result := True;
end;

function TIdReplyIMAP4.IsItAValidSequenceNumber(const AThing: string): Boolean;
    {CC: The following decides if AThing is a valid command sequence number
    like C41...}
begin
    Result := False;
    {CC: Cannot be a C or a digit on its own...}
    if Length(AThing) < 2 then begin
        Exit;
    end;
    {CC: Must start with a C...}
    if AThing[1] <> 'C' then begin  {Do not Localize}
        Exit;
    end;
    {CC: Check if other characters are digits...}
    Result := IsItANumber(Copy(AThing, 2, MAXINT));
end;

function TIdReplyIMAP4.CheckIfCodeIsValid(const ACode: string): Boolean;
var
  LOrd : Integer;
begin
  LOrd := {IdGlobal.}PosInStrArray(ACode, VALID_TAGGEDREPLIES, False);
  Result := (LOrd <> -1) or (Trim(ACode) = '');
end;

function TIdReplyIMAP4.GetFormattedReply: TIdStrings;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -