Difference between revisions of "TPop3Cli.List"

From Overbyte
Jump to navigation Jump to search
(→‎Delphi Example: Translated the C++ example to Delphi ~~~~)
 
(3 intermediate revisions by 3 users not shown)
Line 9: Line 9:
 
== Description ==
 
== 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 [[TPop3Cli.MsgNum | MsgNum]] property to 0 before calling this method. To issue it in single mode set [[TPop3Cli.MsgNum | MsgNum]] property to index of the message you want to get LIST for.
+
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 [[TPop3Cli.MsgNum | MsgNum]] property to 0 before calling this method. To issue it in single mode set [[TPop3Cli.MsgNum | MsgNum]] property to index of the message you want to get LIST for.  
  
 
<syntaxhighlight lang="delphi">
 
<syntaxhighlight lang="delphi">
Line 16: Line 16:
 
Pop3Cli.List;
 
Pop3Cli.List;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
<syntaxhighlight lang="delphi">
 
<syntaxhighlight lang="delphi">
Line 32: Line 31:
 
<syntaxhighlight lang="delphi">
 
<syntaxhighlight lang="delphi">
 
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------
Procedure TForm1.Button1Click(Sender: TObject)
+
procedure TForm1.Button1Click(Sender: TObject);
Begin
+
begin
  // Clear the memo for clean output
+
    // Clear the memo for clean output
  Memo1.Lines.Clear();
+
    Memo1.Lines.Clear;
 +
    // Fill the following with your actual server details
 +
    Pop3Cli1.Host    := 'pop3.yourserver.com';
 +
    Pop3Cli1.UserName := 'username';
 +
    Pop3Cli1.PassWord := 'password';
 +
    Pop3Cli1.Connect;
 +
end;
  
  // Fill the following with your actual server details
+
// ---------------------------------------------------------------------------
  Pop3Cli1.Host    := "pop3.yourserver.com";
+
procedure TForm1.Pop3Cli1RequestDone(Sender: TObject; RqType: TPop3Request; Error: WORD);
  Pop3Cli1.UserName := "username";
+
var
  Pop3Cli1.PassWord := "password";
+
    ListAll : Boolean;
  Pop3Cli1.Connect();
+
begin
End;
+
    // Toggle this to change the behaviour of LIST command from single to list and back
 +
    ListAll := True;
  
//---------------------------------------------------------------------------
+
    if Error = 0 then begin
Procedure TForm1.Pop3Cli1RequestDone(Sender: TObject; RqType: TPop3Request; Error: WORD)
+
        if Pop3Cli1.LastResponse <> '' then
Var
+
            Memo1.Lines.Add(Pop3Cli1.LastResponse);
  ListAll: Boolean;
 
Begin
 
  // Toggle this to change the behaviour of LIST command from single to list and back
 
  ListAll := true;
 
  
  If (Error = 0) Then Begin
+
        case RqType of
    If (Pop3Cli1.LastResponse <> '') Then
+
            Pop3Connect : Pop3Cli1.User;
      Memo1.Lines.Add(Pop3Cli1.LastResponse);
+
            Pop3User    : Pop3Cli1.Pass;
 +
            Pop3Pass    : Pop3Cli1.Stat;
 +
            Pop3Quit    : ; // Nothing
 +
            Pop3Stat:
 +
                begin
 +
                    if ListAll then begin
 +
                        Pop3Cli1.MsgNum := 0;
 +
                        Pop3Cli1.List;
 +
                    end
 +
                    else begin
 +
                        Pop3Cli1.MsgNum := 1;
 +
                        Pop3Cli1.List;
 +
                    end;
 +
                end;
 +
            Pop3List: // Do not list if it's in "list" mode
 +
                begin
 +
                    if not ListAll then
 +
                        Memo1.Lines.Add('Message=' + IntToStr(Pop3Cli1.MsgNum) +
 +
                                    ', Size=' + IntToStr(Pop3Cli1.MsgSize));
  
    Case (RqType) Of
+
                    Pop3Cli1.Quit;
      Case pop3Connect: Pop3Cli1.User();
+
                 end;
      Case pop3User:    Pop3Cli1.Pass();
+
        end;
      Case pop3Pass:    Pop3Cli1.Stat();
+
    end;
      Case pop3Quit:    ; // Nothing
+
end;
      Case pop3Stat:
 
            Begin
 
              If (ListAll) Then Begin
 
                 Pop3Cli1.MsgNum := 0;
 
                Pop3Cli1.List();
 
              End Else Begin
 
                Pop3Cli1.MsgNum := 1;
 
                Pop3Cli1.List();
 
              End;
 
            End;
 
      Case pop3List:      // Do not list if it's in "list" mode
 
            Begin
 
                If (NOT ListAll)
 
                  Memo1.Lines.Add('Message='+ IntToStr(Pop3Cli1.MsgNum) +', Size='+ IntToStr(Pop3Cli1.MsgSize));
 
  
                Pop3Cli1.Quit();
+
// ---------------------------------------------------------------------------
            End;
+
procedure TForm1.Pop3Cli1ListBegin(Sender: TObject);
     End;
+
begin
  End;
+
     Memo1.Lines.Add('List Begin');
End;
+
end;
  
//---------------------------------------------------------------------------
+
// ---------------------------------------------------------------------------
Procedure TForm1.Pop3Cli1ListBegin(Sender: TObject)
+
procedure TForm1.Pop3Cli1ListLine(Sender: TObject);
Begin
+
begin
  Memo1.Lines.Add('List Begin');
+
    Memo1.Lines.Add('List line=' + Pop3Cli1.LastResponse);
End;
+
    Memo1.Lines.Add('Message=' + IntToStr(Pop3Cli1.MsgNum) + ', Size=' +
 +
                    IntToStr(Pop3Cli1.MsgSize));
 +
end;
  
//---------------------------------------------------------------------------
+
// ---------------------------------------------------------------------------
Procedure TForm1.Pop3Cli1ListLine(Sender: TObject)
+
procedure TForm1.Pop3Cli1ListEnd(Sender: TObject);
Begin
+
begin
  Memo1.Lines.Add('List line='+ Pop3Cli1.LastResponse);
+
    Memo1.Lines.Add('List End');
  Memo1.Lines.Add('Message='+ IntToStr(Pop3Cli1.MsgNum) +', Size='+ IntToStr(Pop3Cli1.MsgSize));
+
end;
End;
 
  
//---------------------------------------------------------------------------
+
// ---------------------------------------------------------------------------
Procedure TForm1.Pop3Cli1ListEnd(Sender: TObject)
 
Begin
 
  Memo1.Lines.Add('List End');
 
End;
 
//---------------------------------------------------------------------------
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== C++ Example ==
 
== C++ Example ==
Line 115: Line 118:
  
 
// Fill the following with your actual server details
 
// Fill the following with your actual server details
Pop3Cli1->Host   = "pop3.yourserver.com";
+
Pop3Cli1->Host     = "pop3.yourserver.com";
 
Pop3Cli1->UserName = "username";
 
Pop3Cli1->UserName = "username";
 
Pop3Cli1->PassWord = "password";
 
Pop3Cli1->PassWord = "password";
Line 126: Line 129:
 
bool ListAll = true;
 
bool ListAll = true;
  
if (Error == 0)
+
if (Error == 0) {
{
+
    if (Pop3Cli1->LastResponse != "") Memo1->Lines->Add(Pop3Cli1->LastResponse);
if (Pop3Cli1->LastResponse != "") Memo1->Lines->Add(Pop3Cli1->LastResponse);
 
  
switch (RqType)
+
    switch (RqType) {
{
+
        case pop3Connect: Pop3Cli1->User(); break;
case pop3Connect: Pop3Cli1->User(); break;
+
        case pop3User:   Pop3Cli1->Pass(); break;
case pop3User: Pop3Cli1->Pass(); break;
+
        case pop3Pass:   Pop3Cli1->Stat(); break;
case pop3Pass: Pop3Cli1->Stat(); break;
+
        case pop3Quit:   break;
case pop3Quit: break;
+
        case pop3Stat:   if (ListAll) {
case pop3Stat:     if (ListAll)
+
                              Pop3Cli1->MsgNum = 0;
{
+
                              Pop3Cli1->List();
Pop3Cli1->MsgNum = 0;
+
                              }
Pop3Cli1->List();
+
                          else {
}
+
                              Pop3Cli1->MsgNum = 1;
else
+
                              Pop3Cli1->List();
{
+
                              }
                                Pop3Cli1->MsgNum = 1;
+
                          break;
Pop3Cli1->List();
+
        case pop3List:   // Do not list if it's in "list" mode
}
+
                          if (!ListAll) {
break;
+
                              Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size=" + IntToStr(Pop3Cli1->MsgSize));
case pop3List:     // Do not list if it's in "list" mode
+
                              }
if (!ListAll)
+
                          Pop3Cli1->Quit();
{
+
                          break;
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize));
+
        default:         break;
}
+
        }
Pop3Cli1->Quit();
+
    }
break;
 
default: break;
 
}
 
}
 
 
}
 
}
 
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------
Line 167: Line 165:
 
{
 
{
 
Memo1->Lines->Add("List line="+Pop3Cli1->LastResponse);
 
Memo1->Lines->Add("List line="+Pop3Cli1->LastResponse);
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size="+IntToStr(Pop3Cli1->MsgSize));
+
Memo1->Lines->Add("Message="+IntToStr(Pop3Cli1->MsgNum) + ", Size=" + IntToStr(Pop3Cli1->MsgSize));
 
}
 
}
 
//---------------------------------------------------------------------------
 
//---------------------------------------------------------------------------

Latest revision as of 06:42, 1 July 2010

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

Definition

<syntaxhighlight lang="delphi"> procedure List; virtual; </syntaxhighlight>

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.

<syntaxhighlight lang="delphi"> // This will issue List in list mode (triggers OnList events) Pop3Cli.MsgNum := 0; Pop3Cli.List; </syntaxhighlight>

<syntaxhighlight lang="delphi"> // This will issue List in single mode for the message 1 (does not trigger OnList events) Pop3Cli.MsgNum := 1; Pop3Cli.List; </syntaxhighlight>

If the command is issued in single mode it returns the result from POP3 server in the next LastResponse property. Also, MsgSize will hold the size of the message in octets (bytes). 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 appropriate values of the currently listed message that the event is generated for.

Delphi 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="delphi"> //--------------------------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject); begin

   // 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;

end;

// --------------------------------------------------------------------------- procedure TForm1.Pop3Cli1RequestDone(Sender: TObject; RqType: TPop3Request; Error: WORD); var

   ListAll : Boolean;

begin

   // Toggle this to change the behaviour of LIST command from single to list and back
   ListAll := True;
   if Error = 0 then begin
       if Pop3Cli1.LastResponse <>  then
           Memo1.Lines.Add(Pop3Cli1.LastResponse);
       case RqType of
           Pop3Connect : Pop3Cli1.User;
           Pop3User    : Pop3Cli1.Pass;
           Pop3Pass    : Pop3Cli1.Stat;
           Pop3Quit    : ; // Nothing
           Pop3Stat:
               begin
                   if ListAll then begin
                       Pop3Cli1.MsgNum := 0;
                       Pop3Cli1.List;
                   end
                   else begin
                       Pop3Cli1.MsgNum := 1;
                       Pop3Cli1.List;
                   end;
               end;
           Pop3List: // Do not list if it's in "list" mode
               begin
                   if not ListAll then
                       Memo1.Lines.Add('Message=' + IntToStr(Pop3Cli1.MsgNum) +
                                   ', Size=' + IntToStr(Pop3Cli1.MsgSize));
                   Pop3Cli1.Quit;
               end;
       end;
   end;

end;

// --------------------------------------------------------------------------- procedure TForm1.Pop3Cli1ListBegin(Sender: TObject); begin

   Memo1.Lines.Add('List Begin');

end;

// --------------------------------------------------------------------------- procedure TForm1.Pop3Cli1ListLine(Sender: TObject); begin

   Memo1.Lines.Add('List line=' + Pop3Cli1.LastResponse);
   Memo1.Lines.Add('Message=' + IntToStr(Pop3Cli1.MsgNum) + ', Size=' +
                   IntToStr(Pop3Cli1.MsgSize));

end;

// --------------------------------------------------------------------------- procedure TForm1.Pop3Cli1ListEnd(Sender: TObject); begin

   Memo1.Lines.Add('List End');

end;

// --------------------------------------------------------------------------- </syntaxhighlight>


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