Difference between revisions of "TPop3Cli.List"

From Overbyte
Jump to navigation Jump to search
(Created page with ' Main page -> ICS component reference -> TPop3Cli -> List == Definition == '''procedure''' List; virtual;…')
 
Line 25: Line 25:
 
For this example to work, drop a Memo, Pop3Cli and Button components on the form. Then, add OnClick event to the button and [[TPop3Cli.OnListBegin | OnListBegin]], [[TPop3Cli.OnListLine | OnListLine]], [[TPop3Cli.OnListEnd | OnListEnd]] and [[TPop3Cli.OnRequestDone | OnRequestDone]] events to the Pop3Cli component and use the following code.
 
For this example to work, drop a Memo, Pop3Cli and Button components on the form. Then, add OnClick event to the button and [[TPop3Cli.OnListBegin | OnListBegin]], [[TPop3Cli.OnListLine | OnListLine]], [[TPop3Cli.OnListEnd | OnListEnd]] and [[TPop3Cli.OnRequestDone | OnRequestDone]] events to the Pop3Cli component and use the following code.
  
//---------------------------------------------------------------------------
+
<syntaxhighlight lang="cpp">
'''void __fastcall''' TForm1::Button1Click(TObject *Sender)
+
//---------------------------------------------------------------------------
{
+
void __fastcall TForm1::Button1Click(TObject *Sender)
// Clear the memo for clean output
+
{
Memo1->Lines->Clear();
+
// Clear the memo for clean output
+
Memo1->Lines->Clear();
Pop3Cli1->Host   = "pop3.host.com";
+
 
Pop3Cli1->UserName = "username";
+
// Fill the following with your actual server details
Pop3Cli1->PassWord = "password";
+
Pop3Cli1->Host   = "pop3.yourserver.com";
Pop3Cli1->Connect();
+
Pop3Cli1->UserName = "username";
}
+
Pop3Cli1->PassWord = "password";
//---------------------------------------------------------------------------
+
Pop3Cli1->Connect();
'''void __fastcall''' TForm1::Pop3Cli1RequestDone(TObject *Sender, TPop3Request RqType, WORD Error)
+
}
{
+
//---------------------------------------------------------------------------
// Toggle this to change the behaviour of LIST command from single to list and back
+
void __fastcall TForm1::Pop3Cli1RequestDone(TObject *Sender, TPop3Request RqType, WORD Error)
'''bool''' ListAll = '''true''';
+
{
+
// Toggle this to change the behaviour of LIST command from single to list and back
'''if''' (Error == 0)
+
bool ListAll = true;
{
+
 
'''if''' (Pop3Cli1->LastResponse != "") Memo1->Lines->Add(Pop3Cli1->LastResponse);
+
if (Error == 0)
+
{
'''switch''' (RqType)
+
if (Pop3Cli1->LastResponse != "") Memo1->Lines->Add(Pop3Cli1->LastResponse);
{
+
 
'''case''' pop3Connect: Pop3Cli1->User(); '''break''';
+
switch (RqType)
'''case''' pop3User: Pop3Cli1->Pass(); '''break''';
+
{
'''case''' pop3Pass: Pop3Cli1->Stat(); '''break''';
+
case pop3Connect: Pop3Cli1->User(); break;
'''case''' pop3Quit: '''break''';
+
case pop3User: Pop3Cli1->Pass(); break;
'''case''' pop3Stat:   '''if''' (ListAll)
+
case pop3Pass: Pop3Cli1->Stat(); break;
{
+
case pop3Quit: break;
Pop3Cli1->MsgNum = 0;
+
case pop3Stat:     if (ListAll)
Pop3Cli1->List();
+
{
}
+
Pop3Cli1->MsgNum = 0;
'''else'''
+
Pop3Cli1->List();
                            {
+
}
                                Pop3Cli1->MsgNum = 1;
+
else
Pop3Cli1->List();
+
{
}
+
                                Pop3Cli1->MsgNum = 1;
'''break''';
+
Pop3Cli1->List();
'''case''' pop3List: Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum));
+
}
Memo1->Lines->Add("Message size="+IntToStr(Pop3Cli1->MsgSize));
+
break;
Pop3Cli1->Quit();
+
case pop3List:     // Do not list if it's in "list" mode
'''break''';
+
if (!ListAll)
'''default''': '''break''';
+
{
}
+
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize));
}
+
}
}
+
Pop3Cli1->Quit();
//---------------------------------------------------------------------------
+
break;
'''void __fastcall''' TForm1::Pop3Cli1ListBegin(TObject *Sender)
+
default: break;
{
+
}
Memo1->Lines->Add("List Begin");
+
}
}
+
}
//---------------------------------------------------------------------------
+
//---------------------------------------------------------------------------
'''void __fastcall''' TForm1::Pop3Cli1ListLine(TObject *Sender)
+
void __fastcall TForm1::Pop3Cli1ListBegin(TObject *Sender)
{
+
{
Memo1->Lines->Add("List line="+Pop3Cli1->LastResponse);
+
Memo1->Lines->Add("List Begin");
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum));
+
}
Memo1->Lines->Add("Message size="+IntToStr(Pop3Cli1->MsgSize));
+
//---------------------------------------------------------------------------
}
+
void __fastcall TForm1::Pop3Cli1ListLine(TObject *Sender)
//---------------------------------------------------------------------------
+
{
'''void __fastcall''' TForm1::Pop3Cli1ListEnd(TObject *Sender)
+
Memo1->Lines->Add("List line="+Pop3Cli1->LastResponse);
{
+
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize));
Memo1->Lines->Add("List End");
+
}
}
+
//---------------------------------------------------------------------------
 +
void __fastcall TForm1::Pop3Cli1ListEnd(TObject *Sender)
 +
{
 +
Memo1->Lines->Add("List End");
 +
}
 +
//---------------------------------------------------------------------------
 +
</syntaxhighlight>
  
 
== Best practices ==
 
== Best practices ==
  
 
== How to ==
 
== How to ==

Revision as of 16:58, 30 June 2010

Main page -> ICS component reference -> TPop3Cli -> List

Definition

procedure List; virtual;

Description

Sends LIST command to a POP3 server. The command can be issued in 2 modes - list mode and single mode. This command is valid in POP3 TRANSACTION state so you must issue it after you've successfully authenticated. To issue it in list mode set MsgNum property to 0 before calling this method. To issue it in single mode set MsgNum property to index of the message you want to get LIST for.

//This will issue List in list mode (triggers OnList events)
Pop3Cli.MsgNum := 0;
Pop3Cli.List;
//This will issue List in single mode for the message 1 (does not trigger OnList events)
Pop3Cli.MsgNum := 1;
Pop3Cli.List;

If the command is issued in single mode it returns the result from POP3 server in the next LastResponse property. If it is issued in list mode, LastResponse will be empty but it will trigger OnListBegin, OnListLine and OnListEnd events instead which you can use to appropriately handle the output from the LIST. When the events occur, MsgNum and MsgSize contain the value of the currently listed message.

Delphi Example

C++ Example

For this example to work, drop a Memo, Pop3Cli and Button components on the form. Then, add OnClick event to the button and OnListBegin, OnListLine, OnListEnd and OnRequestDone events to the Pop3Cli component and use the following code.

<syntaxhighlight lang="cpp"> //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { // Clear the memo for clean output Memo1->Lines->Clear();

// Fill the following with your actual server details Pop3Cli1->Host = "pop3.yourserver.com"; Pop3Cli1->UserName = "username"; Pop3Cli1->PassWord = "password"; Pop3Cli1->Connect(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Pop3Cli1RequestDone(TObject *Sender, TPop3Request RqType, WORD Error) { // Toggle this to change the behaviour of LIST command from single to list and back bool ListAll = true;

if (Error == 0) { if (Pop3Cli1->LastResponse != "") Memo1->Lines->Add(Pop3Cli1->LastResponse);

switch (RqType) { case pop3Connect: Pop3Cli1->User(); break; case pop3User: Pop3Cli1->Pass(); break; case pop3Pass: Pop3Cli1->Stat(); break; case pop3Quit: break; case pop3Stat: if (ListAll) { Pop3Cli1->MsgNum = 0; Pop3Cli1->List(); } else {

                               Pop3Cli1->MsgNum = 1;

Pop3Cli1->List(); } break; case pop3List: // Do not list if it's in "list" mode if (!ListAll) { Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize)); } Pop3Cli1->Quit(); break; default: break; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::Pop3Cli1ListBegin(TObject *Sender) { Memo1->Lines->Add("List Begin"); } //--------------------------------------------------------------------------- void __fastcall TForm1::Pop3Cli1ListLine(TObject *Sender) { Memo1->Lines->Add("List line="+Pop3Cli1->LastResponse); Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize)); } //--------------------------------------------------------------------------- void __fastcall TForm1::Pop3Cli1ListEnd(TObject *Sender) { Memo1->Lines->Add("List End"); } //--------------------------------------------------------------------------- </syntaxhighlight>

Best practices

How to