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

📄 conpop3.dpr

📁 BaiduMp3 search baidu mp3
💻 DPR
📖 第 1 页 / 共 3 页
字号:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Author:       Fran鏾is PIETTE (original)
              Marco van de Voort (ugly hack to console)
Object:       Show how to use TPop3Prot (POP3 protocol, RFC-1225)
              Written with a service that checks a pop3box for
              commands/input in mind.
Credit:       Marco van de Voort <marco@freepascal.org> ported my GUI code
              (MailRcv demo) to console mode.
Creation:     Sep 2003 (From GUI version created 03 october 1997)
Version:      1.01
EMail:        http://www.overbyte.be        http://www.rtfm.be/fpiette
              francois.piette@overbyte.be   francois.piette@rtfm.be
                                            francois.piette@pophost.eunet.be
Support:      Use the mailing list twsocket@elists.org
              Follow "support" link at http://www.overbyte.be for subscription.
Legal issues: Copyright (C) 1997-2005 by Fran鏾is PIETTE
              Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
              <francois.piette@overbyte.be>

              This software is provided 'as-is', without any express or
              implied warranty.  In no event will the author be held liable
              for any  damages arising from the use of this software.

              Permission is granted to anyone to use this software for any
              purpose, including commercial applications, and to alter it
              and redistribute it freely, subject to the following
              restrictions:

              1. The origin of this software must not be misrepresented,
                 you must not claim that you wrote the original software.
                 If you use this software in a product, an acknowledgment
                 in the product documentation would be appreciated but is
                 not required.

              2. Altered source versions must be plainly marked as such, and
                 must not be misrepresented as being the original software.

              3. This notice may not be removed or altered from any source
                 distribution.

              4. You must register this software by sending a picture postcard
                 to the author. Use a nice stamp and mention your name, street
                 address, EMail address and any comment you like to say.

Updates:
Sep 08, 2004 V1.01 A little bit of cleaning. Still need more :-(
                   Updated for NOFORMS use.


 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
program ConPop3;

{$I ICSDEFS.INC}
{$IFDEF VER80}
    Bomb('Sorry, Delphi 1 does not support console mode programs');
{$ENDIF}
{$IFNDEF NOFORMS}
    Bomb('Please add NOFORMS to your project defines to reduce exe size');
{$ENDIF}
{$APPTYPE CONSOLE}
{$DEFINE DOHEADERS}     // true: find subject with "RUN SCRIPT"
                        // false: list all subjects
{$DEFINE DEBUG}         // debug output.

uses
  {$ifdef UseWindows}Windows, {$else} WinTypes, WinProcs, {$endif}
  Messages, SysUtils, Classes, ConApp, IniFiles, Pop3Prot;

const
    ConPop3Version = 101;
    CopyRight : String = ' ConPOP3 (c) 1997-2005 F. Piette V1.01 ';

type
  TPOP3ExercizerApp = class(TConApplication)
    Msg       : TStringList;
    Pop3Client: TSyncPop3Cli;
    procedure ReadDataFromIni(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Connectevent     (Sender: TObject);
    procedure Quittevent       (Sender: TObject);
    procedure Userevent        (Sender: TObject);
    procedure Passevent        (Sender: TObject);
    procedure Retrevent        (Sender: TObject);
    procedure Statevent        (Sender: TObject);
    procedure ListAllevent     (Sender: TObject);
    procedure Listevent        (Sender: TObject);
    procedure Deleteevent      (Sender: TObject);
    procedure Noopevent        (Sender: TObject);
    procedure Lastevent        (Sender: TObject);
    procedure Resetevent       (Sender: TObject);
    procedure Topevent         (Sender: TObject);
    procedure Rpopevent        (Sender: TObject);
    procedure Apopevent        (Sender: TObject);
    procedure Nextevent        (Sender: TObject);
    procedure GetAllevent      (Sender: TObject);

    procedure Pop3ClientDisplay(Sender: TObject; Msg: String);
    procedure Uidlevent(Sender: TObject);
    procedure Pop3ClientUidlBegin(Sender: TObject);
    procedure Pop3ClientUidlEnd(Sender: TObject);
    procedure Pop3ClientUidlLine(Sender: TObject);
    procedure Pop3ClientMessageBegin(Sender: TObject);
    procedure Pop3ClientMessageEnd(Sender: TObject);
    procedure Pop3ClientMessageLine(Sender: TObject);
    procedure Pop3ClientListBegin(Sender: TObject);
    procedure Pop3ClientListEnd(Sender: TObject);
    procedure Pop3ClientListLine(Sender: TObject);

    function  ConnectSyncEvent (sender: TObject):boolean;
    function  OpenSyncEvent    (sender: TObject):boolean;
    function  UserSyncEvent    (sender: TObject):boolean;
    function  PassSyncEvent    (sender: TObject):boolean;
    function  QuittSyncEvent   (sender: TObject):boolean;
    function  AbortSyncEvent   (sender: TObject):boolean;
    function  RetrSyncEvent    (sender: TObject):boolean;
    function  StatSyncEvent    (sender: TObject):boolean;
    function  ListAllSyncEvent (sender: TObject):boolean;
    function  ListSyncEvent    (sender: TObject):boolean;
    function  DeleteSyncEvent  (sender: TObject):boolean;
    function  NoopSyncEvent    (sender: TObject):boolean;
    function  LastSyncEvent    (sender: TObject):boolean;
    function  ResetSyncEvent   (sender: TObject):boolean;
    function  TopSyncEvent     (sender: TObject):boolean;
    function  RpopSyncEvent    (sender: TObject):boolean;
    function  UidlSyncEvent    (sender: TObject):boolean;
    function  ApopSyncEvent    (sender: TObject):boolean;

    procedure Pop3ClientRequestDone(Sender: TObject; RqType: TPop3Request;
                                    ErrCode: Word);
    procedure Openevent(Sender: TObject);
    procedure Abortevent(Sender: TObject);
    procedure Pop3ClientHeaderEnd(Sender: TObject);
  private
    OkMsgnumber : TList;
    SubjectOk    : Boolean;
    Waitfor      : TPop3Request;
    FFile        : TextFile;
    FFileName    : String;
    FFileOpened  : Boolean;
    FGetAllState : Integer;
    FMsgPath     : String;
    fHost,
    fPort,
    fUser,
    fPasswd      : string;
    MsgCount,
    Lines,
    msgnum       : integer;
    procedure Exec(MethodPtr  : TPop3NextProc;
                   MethodName : String); overload;
    Function Exec(MethodPtr  : TPop3Method;
                   MethodName  : String):Boolean; overload;
    procedure MessageBegin(Sender: TObject);
    procedure MessageLine(Sender: TObject);
    procedure GetAllMessageLine(Sender: TObject);
    procedure GetAllRequestDone(Sender: TObject;
                                RqType: TPop3Request; ErrCode: Word);
    procedure NextMessageRequestDone(Sender: TObject;
                                     RqType: TPop3Request; ErrCode: Word);
   public
     Constructor Create(AOwner:TComponent); override;
     Destructor  Destroy; override;
     procedure   Wait;
     procedure   WaitReady;
     procedure   waitfordone(ev: TPop3Request);
  end;


const
    IniFileName = 'CONPOP3.INI';
    MsgFileName = 'CONPOP3.TXT';

    SectionData = 'Data';
    KeyMsgPath  = 'MsgPath';
    KeyHost     = 'Host';
    KeyPort     = 'Port';
    KeyUserName = 'UserName';
    KeyPassword = 'Password';
    

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
constructor TPOP3ExercizerApp.Create(AOwner: TComponent);
begin
    inherited Create(aowner);
    Pop3Client  := TSyncPop3Cli.create(Self);
    OkMsgNumber := TList.Create;
    Lines       := 0;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
destructor TPOP3ExercizerApp.Destroy;
begin
    OkMsgNumber.Free;
    Pop3Client.Free;
    inherited;
end;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Restore some data from the INI file                                       }
procedure TPOP3ExercizerApp.ReadDataFromIni(Sender: TObject);
var
    IniFile : TIniFile;
begin
    IniFile := TIniFile.Create(IniFileName);
    FHost   := IniFile.ReadString(SectionData, KeyHost,     'pop3.isp.com');
    FPort   := IniFile.ReadString(SectionData, KeyPort,     'pop3');
    FUser   := IniFile.ReadString(SectionData, KeyUserName, 'myname');
    FPasswd := IniFile.ReadString(SectionData, KeyPassword, 'mypassword');
    // Write the values to create the ini file is non exitent
    IniFile.WriteString(SectionData, KeyHost,     FHost);
    IniFile.WriteString(SectionData, KeyPort,     FPort);
    IniFile.WriteString(SectionData, KeyUserName, FUser);
    IniFile.WriteString(SectionData, KeyPassword, FPasswd);
    IniFile.Free;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Save data to INI file   (unused)                                          }
procedure TPOP3ExercizerApp.FormCloseQuery(
    Sender       : TObject;
    var CanClose : Boolean);
var
    IniFile : TIniFile;
begin
    IniFile := TIniFile.Create(IniFileName);
    IniFile.WriteString(SectionData, 'Host',     fHost);
    IniFile.WriteString(SectionData, 'Port',     fPort);
    IniFile.WriteString(SectionData, 'UserName', fUser);
    IniFile.WriteString(SectionData, 'Password', fPassWd);
    IniFile.Free;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called when the TPop3Client object wants to display }
{ some information such as connection progress or errors.                   }
procedure TPOP3ExercizerApp.Pop3ClientDisplay(Sender: TObject;
  Msg: String);
begin
  {$IFDEF DEBUG}
  WriteLn('TPop3Cli: ',Msg);
  {$ENDIF}
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ All the TPop3Client method are of the same type. The "sync" versions      }
{ are a different type from the other (async) methods, so we need two       }
{ execs()                                                                   }
{ To simplify quickly "scripting" together certain POP3 actions, the Exec   }
{ methods stuffs some commonly used handlers and fields in load default     }
{ values a lot of methods that are dispatched application, we al            }
{ Exec transfert the parameters form the various EditBoxes                  }
{ to the Pop3Client instance and then call the appropriate method, showing  }
{ the result in the InfoLabel.Caption.                                      }
procedure TPOP3ExercizerApp.Exec(
    MethodPtr  : TPop3NextProc;
    MethodName : String);

begin
    Pop3Client.Host           := fHost;
    Pop3Client.Port           := fPort;
    Pop3Client.UserName       := fUser;
    Pop3Client.PassWord       := fPassWd;
    Pop3Client.MsgNum         := msgnum; //    MsgNumEdit.Text);
    Pop3Client.MsgLines       := Lines; //Msg.count;
    { We need to reassign event handlers because we may have changed them }
    { doing GetAllMessages for example                                    }
    Pop3Client.OnRequestDone  := Pop3ClientRequestDone;
    Pop3Client.OnMessageBegin := Pop3ClientMessageBegin;
    Pop3Client.OnMessageEnd   := Pop3ClientMessageEnd;
    Pop3Client.OnMessageLine  := Pop3ClientMessageLine;
    Pop3Client.OnListLine     := Pop3ClientListLine;
    {$IFDEF DEBUG}
    WriteLn('status :', MethodName + ' started');
    {$ENDIF}
    try
        MethodPtr;
        {$IFDEF DEBUG}
        WriteLn('status :',MethodName, ' ok');
        {$ENDIF}
    except
        on E:Exception do begin
            {$IFDEF DEBUG}
             WriteLn('status :',MethodName, ' failed ',E.Message, ')');
            {$ENDIF}
        end;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TPOP3ExercizerApp.Exec(
    MethodPtr  : TPop3Method;
    MethodName : String):boolean;
begin
    Pop3Client.Host           := fHost;
    Pop3Client.Port           := fPort;
    Pop3Client.UserName       := fUser;
    Pop3Client.PassWord       := fPassWd;
    Pop3Client.MsgNum         := msgnum; //    MsgNumEdit.Text);
    Pop3Client.MsgLines       := Lines; //Msg.count;
    { We need to reassign event handlers because we may have changed them }
    { doing GetAllMessages for example                                    }
    Pop3Client.OnRequestDone  := Pop3ClientRequestDone;
    Pop3Client.OnMessageBegin := Pop3ClientMessageBegin;
    Pop3Client.OnMessageEnd   := Pop3ClientMessageEnd;
    Pop3Client.OnMessageLine  := Pop3ClientMessageLine;
    Pop3Client.OnListLine     := Pop3ClientListLine;

    {$IFDEF DEBUG}
    WriteLn('status :', MethodName + ' started');
    {$ENDIF}
    try
        Result:=MethodPtr;
        {$IFDEF DEBUG}
        WriteLn('status :',MethodName, ' ok');
        {$ENDIF}
    except
        on E:Exception do begin
            {$IFDEF DEBUG}
            WriteLn('status :',MethodName, ' failed ',E.Message, ')');
            {$ENDIF}
            Result:=false;
        end;
    end;
end;


⌨️ 快捷键说明

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