?? mailrcv1.pas
字號:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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.
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 MailRcv1;
interface
uses
WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, IniFiles, Pop3Prot;
const
PopTstVersion = 102;
type
TPOP3ExcercizerForm = class(TForm)
DisplayMemo: TMemo;
Panel1: TPanel;
InfoLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
ConnectButton: TButton;
QuittButton: 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;
Pop3Client: TPop3Cli;
OpenButton: TButton;
procedure ConnectButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure QuittButtonClick(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);
procedure Pop3ClientRequestDone(Sender: TObject; RqType: TPop3Request;
Error: Word);
procedure OpenButtonClick(Sender: TObject);
private
FFile : TextFile;
FFileName : String;
FFileOpened : Boolean;
FGetAllState : Integer;
FMsgPath : String;
procedure Exec(MethodPtr : TPop3NextProc;
MethodName : String);
procedure MessageBegin(Sender: TObject);
procedure MessageLine(Sender: TObject);
procedure GetAllMessageLine(Sender: TObject);
procedure GetAllRequestDone(Sender: TObject;
RqType: TPop3Request; Error: Word);
procedure NextMessageRequestDone(Sender: TObject;
RqType: TPop3Request; Error: Word);
public
{ D閏larations publiques }
end;
var
POP3ExcercizerForm: TPOP3ExcercizerForm;
implementation
{$R *.DFM}
uses
MailRcv2;
const
IniFileName = 'MAILRCV.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, 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 TPOP3ExcercizerForm.Exec(
MethodPtr : TPop3NextProc;
MethodName : String);
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);
{ 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;
InfoLabel.Caption := MethodName + ' started';
try
MethodPtr;
InfoLabel.Caption := MethodName + ' ok';
except
on E:Exception do begin
InfoLabel.Caption := MethodName + ' failed (' + E.Message + ')';
end;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ConnectButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Connect, 'Connect');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.OpenButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Open, 'Open');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.UserButtonClick(Sender: TObject);
begin
Exec(Pop3Client.User, 'User');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.PassButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Pass, 'Pass');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.QuittButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Quit, 'Quit');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.RetrButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Retr, 'Retr');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.StatButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Stat, 'Stat');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ListAllButtonClick(Sender: TObject);
begin
MsgNumEdit.Text := '0';
Exec(Pop3Client.List, 'List All');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.ListButtonClick(Sender: TObject);
begin
Exec(Pop3Client.List, 'List');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.DeleteButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Dele, 'Delete');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.NoopButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Noop, 'Noop');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TPOP3ExcercizerForm.LastButtonClick(Sender: TObject);
begin
Exec(Pop3Client.Last, 'Last');
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -