PowerTCP Mail for .NET
List(String,String,Boolean) Method
Example 




The directory in which to execute the command.
Checks against all mailboxes for matches, and may include wildcards.
True to only return Mailboxes the user is subscribed to (use the IMAP LSUB command).
Lists a subset of mailboxes found on the IMAP server.
Syntax
Public Overloads Function List( _
   ByVal directory As String, _
   ByVal searchTerm As String, _
   ByVal subscribedOnly As Boolean _
) As Mailbox()
Dim instance As Imap
Dim directory As String
Dim searchTerm As String
Dim subscribedOnly As Boolean
Dim value() As Mailbox
 
value = instance.List(directory, searchTerm, subscribedOnly)
public Mailbox[] List( 
   string directory,
   string searchTerm,
   bool subscribedOnly
)
public: Mailbox*[]* List( 
   string* directory,
   string* searchTerm,
   bool subscribedOnly
) 

Parameters

directory
The directory in which to execute the command.
searchTerm
Checks against all mailboxes for matches, and may include wildcards.
subscribedOnly
True to only return Mailboxes the user is subscribed to (use the IMAP LSUB command).

Return Value

A Mailbox array.
Remarks

This method does not update Mailboxes; use Imap.Mailboxes.Refresh() to refresh its contents.

If Imap.Session.AutoUtf8 is set to true, and the server advertises UTF8=ACCEPT, UTF8 will be used for encoding and decoding UNICODE strings.

Example
This example demonstrates how to create, rename and delete a mailbox. It also shows how to subscribe and unsubscribe a mailbox.
private void doMailboxFunctions(object sender)
{
    //Configure server and account info
    imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session));
    imap1.Session.Username = myUsername;
    imap1.Session.Password = myPassword;

    //Connect and log into the account
    imap1.Connect();
    imap1.Authenticate();

    //Create a mailbox
    Mailbox newBox = imap1.Mailboxes.Add("My_New_Box");

    //Subscribe the mailbox and check the subscribed list
    newBox.Subscribe();
    //Get all subscribed mailboxes
    List<Mailbox> list = imap1.List("", "%", true).ToList<Mailbox>();
    if (!list.Contains(newBox)) throw new Exception("Server did not subscribe the mailbox.");

    //Unsubscribe the mailbox and check the subscribed list
    newBox.Unsubscribe();
    list = imap1.List("", "%", true).ToList<Mailbox>();
    if (list.Contains(newBox)) throw new Exception("Server did not unsubscribe the mailbox.");

    //Rename the mailbox and then delete it
    newBox.Name = newBox.Name + "_Renamed";
    imap1.Mailboxes.Remove(newBox);

    //Gracefully logout of the session
    imap1.Close();
}
Private Sub doMailboxFunctions(ByVal sender As Object)
    'Configure server and account info
    imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session))
    imap1.Session.Username = myUsername
    imap1.Session.Password = myPassword

    'Connect and log into the account
    imap1.Connect()
    imap1.Authenticate()

    'Create a mailbox
    Dim newBox As Mailbox = imap1.Mailboxes.Add("My_New_Box")

    'Subscribe the mailbox and check the subscribed list
    newBox.Subscribe()
    'Get all subscribed mailboxes
    Dim list As List(Of Mailbox) = imap1.List("", "%", True).ToList()
    If Not list.Contains(newBox) Then
        Throw New Exception("Server did not subscribe the mailbox.")
    End If

    'Unsubscribe the mailbox and check the subscribed list
    newBox.Unsubscribe()
    list = imap1.List("", "%", True).ToList()
    If list.Contains(newBox) Then
        Throw New Exception("Server did not unsubscribe the mailbox.")
    End If

    'Rename the mailbox and then delete it
    newBox.Name = newBox.Name & "_Renamed"
    imap1.Mailboxes.Remove(newBox)

    'Gracefully logout of the session
    imap1.Close()
End Sub
See Also

Reference

Imap Class
Imap Members
Overload List


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic