📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NMPOP31->AttachFilePath=".";
NMPOP31->Host=Edit1->Text;
NMPOP31->Port=StrToInt(Edit2->Text);
NMPOP31->UserID=Edit3->Text;
NMPOP31->Password=Edit4->Text;
NMPOP31->Connect();
Label5->Caption="总邮件数: "+IntToStr(NMPOP31->MailCount);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
NMPOP31->Disconnect();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
NMPOP31->List();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Memo1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
NMPOP31->DeleteMailMessage(StrToInt(Edit5->Text));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
NMPOP31->GetMailMessage(StrToInt(Edit5->Text));
Edit6->Text=NMPOP31->MailMessage->From;
Edit7->Text=NMPOP31->MailMessage->Subject;
Edit8->Text=IntToStr(NMPOP31->Summary->Bytes);
Edit9->Text=NMPOP31->MailMessage->MessageId;
Memo2->Lines->Assign(NMPOP31->MailMessage->Head);
Memo3->Lines->Assign(NMPOP31->MailMessage->Body);
if(NMPOP31->MailMessage->Attachments->Text!="")
ShowMessage("Attachments\n"+NMPOP31->MailMessage->Attachments->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
NMPOP31->GetSummary(StrToInt(Edit5->Text));
Edit6->Text=NMPOP31->Summary->From;
Edit7->Text=NMPOP31->Summary->Subject;
Edit8->Text=IntToStr(NMPOP31->Summary->Bytes);
Edit9->Text=NMPOP31->Summary->MessageId;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Connect(TObject *Sender)
{
StatusBar1->SimpleText="Connected";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31ConnectionFailed(TObject *Sender)
{
StatusBar1->SimpleText="Connect failed";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31ConnectionRequired(bool &handled)
{
AnsiString BoxMsg;
AnsiString BoxCaption;
BoxMsg="Connect Required.Connect?";
BoxCaption="Connect Required";
if(MessageBox(0,&BoxCaption[1],&BoxMsg[1],MB_YESNO+MB_ICONEXCLAMATION)==IDYES)
{
handled=true;
Form1->Button1Click(this);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Disconnect(TObject *Sender)
{
if(StatusBar1!=0)
StatusBar1->SimpleText="Disconnect";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Failure(TObject *Sender)
{
ShowMessage("Operation failed.");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31HostResolved(TComponent *Sender)
{
StatusBar1->SimpleText="Host Resolved.";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31InvalidHost(bool &handled)
{
AnsiString NewHost;
if(InputQuery("Invalid host","Please input another host",NewHost))
{
NMPOP31->Host=NewHost;
handled=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31List(int Msg, int Size)
{
if(Msg<2)
{
Memo1->Clear();
Memo1->Lines->Add("Message Number / Message size");
}
Memo1->Lines->Add(IntToStr(Msg)+" / "+ IntToStr(Size));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31PacketRecvd(TObject *Sender)
{
StatusBar1->SimpleText=IntToStr(NMPOP31->BytesRecvd)+" Bytes of "+ IntToStr(NMPOP31->BytesTotal);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Reset(TObject *Sender)
{
ShowMessage("Deleted flags reset.");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31RetriveEnd(TObject *Sender)
{
Form1->Cursor=crDefault;
StatusBar1->SimpleText="Retrieve complished.";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31RetriveStart(TObject *Sender)
{
Form1->Cursor=crHourGlass;
StatusBar1->SimpleText="Beginning message retrieve...";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Status(TComponent *Sender,
AnsiString Status)
{
if(StatusBar1!=0)
StatusBar1->SimpleText=Status;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31Success(TObject *Sender)
{
StatusBar1->SimpleText="Operation success.";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31AuthenticationNeeded(bool &Handled)
{
AnsiString NewPass, NewID;
NewPass = NMPOP31->Password;
NewID = NMPOP31->UserID;
InputQuery("Authorization Needed", "Input User ID", NewID);
InputQuery("Authorization Needed", "Input Password", NewPass);
NMPOP31->UserID = NewID;
NMPOP31->Password = NewPass;
Handled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31AuthenticationFailed(bool &Handled)
{
AnsiString NewPass, NewID;
if (MessageDlg("Authentication Failed. Retry?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
NewPass = NMPOP31->Password;
NewID = NMPOP31->UserID;
InputQuery("Authentication Failed", "Input User ID", NewID);
InputQuery("Authentication Failed", "Input Password", NewPass);
NMPOP31->Password = NewPass;
NMPOP31->UserID = NewID;
Handled = true;
}
else
Handled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31RetrieveStart(TObject *Sender)
{
StatusBar2->SimpleText="Start retrieve message...";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMPOP31RetrieveEnd(TObject *Sender)
{
StatusBar2->SimpleText="End retrieve message";
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -