?? poptst1.pas
字號(hào):
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+-------------------------------------------------------------------+
| THIS IS AN OUTDATED APPLICATION USING AN OUTDATED COMPONENT. |
| NEW COMPONENT IS IN POP3PROT.PAS FILE. NEW DEMO IS MAILRCV.DPR. |
+-------------------------------------------------------------------+
Author: Fran鏾is PIETTE
Object: Show how to use TPop3Cli (POP3 protocol, RFC-1225)
Creation: 03 october 1997
Version: 1.02
EMail: francois.piette@pophost.eunet.be
francois.piette@rtfm.be http://www.rtfm.be/fpiette
Support: Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1997, 1998 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@pophost.eunet.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:
Nov 12, 1997 V1.01 Added a GetAll button to get all messages waiting in the
POP3 server, copying them to a file using the UIDL to build
the file name (sorry, wont work with D1 because of long file
name). The message is *NOT* deleted from the POP3 server.
Jan 10, 1998 V1.02 Added port selection
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit PopTst1;
interface
uses
WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, WSocket, pop3cli, StdCtrls, Wait, IniFiles, ExtCtrls;
const
PopTstVersion = 102;
type
TPOP3ExcercizerForm = class(TForm)
Pop3Client: TPop3Client;
DisplayMemo: TMemo;
Panel1: TPanel;
InfoLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
ConnectButton: TButton;
Wait1: TWait;
DisconnectButton: TButton;
UserButton: TButton;
HostEdit: TEdit;
UserNameEdit: TEdit;
PassWordEdit: TEdit;
PassButton: TButton;
MsgNumEdit: TEdit;
RetrButton: TButton;
StatButton: TButton;
ListAllButton: TButton;
ListButton: TButton;
DeleteButton: TButton;
NoopButton: TButton;
LastButton: TButton;
ResetButton: TButton;
TopButton: TButton;
MsgLinesEdit: TEdit;
RpopButton: TButton;
UidlButton: TButton;
ApopButton: TButton;
NextButton: TButton;
GetAllButton: TButton;
PortEdit: TEdit;
Label6: TLabel;
procedure ConnectButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DisconnectButtonClick(Sender: TObject);
procedure UserButtonClick(Sender: TObject);
procedure PassButtonClick(Sender: TObject);
procedure Pop3ClientMessageBegin(Sender: TObject);
procedure Pop3ClientMessageEnd(Sender: TObject);
procedure Pop3ClientMessageLine(Sender: TObject);
procedure RetrButtonClick(Sender: TObject);
procedure StatButtonClick(Sender: TObject);
procedure ListAllButtonClick(Sender: TObject);
procedure ListButtonClick(Sender: TObject);
procedure Pop3ClientListBegin(Sender: TObject);
procedure Pop3ClientListEnd(Sender: TObject);
procedure Pop3ClientListLine(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
procedure NoopButtonClick(Sender: TObject);
procedure LastButtonClick(Sender: TObject);
procedure ResetButtonClick(Sender: TObject);
procedure TopButtonClick(Sender: TObject);
procedure RpopButtonClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Pop3ClientDisplay(Sender: TObject; Msg: String);
procedure UidlButtonClick(Sender: TObject);
procedure Pop3ClientUidlBegin(Sender: TObject);
procedure Pop3ClientUidlEnd(Sender: TObject);
procedure Pop3ClientUidlLine(Sender: TObject);
procedure ApopButtonClick(Sender: TObject);
procedure NextButtonClick(Sender: TObject);
procedure GetAllButtonClick(Sender: TObject);
private
FFile : TextFile;
FFileName : String;
function DoTheJob(MethodPtr : TPop3Method; MethodName : String) : Boolean;
procedure MessageBegin(Sender: TObject);
procedure MessageLine(Sender: TObject);
procedure GetAllMessageLine(Sender: TObject);
public
{ D閏larations publiques }
end;
var
POP3ExcercizerForm: TPOP3ExcercizerForm;
implementation
{$R *.DFM}
uses
PopTst2;
const
IniFileName = 'POPTST.INI';
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Restore some data from the INI file }
procedure TPOP3ExcercizerForm.FormCreate(Sender: TObject);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(IniFileName);
HostEdit.Text := IniFile.ReadString('Data', 'Host', '');
PortEdit.Text := IniFile.ReadString('Data', 'Port', '');
UserNameEdit.Text := IniFile.ReadString('Data', 'UserName', '');
PassWordEdit.Text := IniFile.ReadString('Data', 'Password', '');
IniFile.Free;
InfoLabel.Caption := '';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Save data to INI file }
procedure TPOP3ExcercizerForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
var
IniFile : TIniFile;
begin
IniFile := TIniFile.Create(IniFileName);
IniFile.WriteString('Data', 'Host', HostEdit.Text);
IniFile.WriteString('Data', 'Port', PortEdit.Text);
IniFile.WriteString('Data', 'UserName', UserNameEdit.Text);
IniFile.WriteString('Data', 'Password', PassWordEdit.Text);
IniFile.Free;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called when the TPop3Client object wants to display }
{ some information such as connection progress or errors. }
procedure TPOP3ExcercizerForm.Pop3ClientDisplay(Sender: TObject;
Msg: String);
begin
DisplayMemo.Lines.Add(Msg);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ All the TPop3Client method are of the same type. To simplify this demo }
{ application, DoTheJob transfert the parameters form the various EditBoxes }
{ to the Pop3Client instance and then call the appropriate method, showing }
{ the result in the InfoLabel.Caption. }
function TPOP3ExcercizerForm.DoTheJob(
MethodPtr : TPop3Method;
MethodName : String) : Boolean;
begin
Pop3Client.Host := HostEdit.Text;
Pop3Client.Port := PortEdit.Text;
Pop3Client.UserName := UserNameEdit.Text;
Pop3Client.PassWord := PassWordEdit.Text;
Pop3Client.MsgNum := StrToInt(MsgNumEdit.Text);
Pop3Client.MsgLines := StrToInt(MsgLinesEdit.Text);
InfoLabel.Caption := MethodName + ' started';
Result := MethodPtr;
if Result then
InfoLabel.Caption := MethodName + ' ok'
else
InfoLabel.Caption := MethodName + ' failed';
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ConnectButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.Connect, 'Connect');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.DisconnectButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.Quit, 'Quit');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.UserButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.User, 'User');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.PassButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.Pass, 'Pass');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.RetrButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.Retr, 'Retr');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.StatButtonClick(Sender: TObject);
begin
if DoTheJob(Pop3Client.Stat, 'Stat') then
InfoLabel.Caption := 'Stat ok, ' +
IntToStr(Pop3Client.MsgCount) + ' messages ' +
IntToStr(Pop3Client.MsgSize) + ' bytes'
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ListAllButtonClick(Sender: TObject);
begin
MsgNumEdit.Text := '0';
DoTheJob(Pop3Client.List, 'List All');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ListButtonClick(Sender: TObject);
begin
DoTheJob(Pop3Client.List, 'List');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -