PowerTCP Mail for .NET
Mailboxes Property (Mailbox)
Example 




Gets a collection containing all sub-mailboxes in the mailbox.
Syntax
Public ReadOnly Property Mailboxes As MailboxCollection
Dim instance As Mailbox
Dim value As MailboxCollection
 
value = instance.Mailboxes
public MailboxCollection Mailboxes {get;}
public: __property MailboxCollection* get_Mailboxes();
public:
property MailboxCollection^ Mailboxes {
   MailboxCollection^ get();
}

Property Value

A MailboxCollection which contains all child mailboxes in the mailbox.
Remarks

Returns a MailboxCollection containing mailboxes falling directly below this mailbox in the hierarchy. MailboxCollection.Refresh must be used to populate this collection before it can be accessed if ImapSession.PopulateMailboxTree is false, or if the desired mailbox was added/renamed by another client since the contents were last updated.

Example
The following example demonstrates navigating into/selecting the specified subfolder/sub-mailbox.
/// <summary>
/// Navigates into the subfolder/sub-mailbox specified by 'subfolderPath'.
/// </summary>
/// <param name="myImap">A connected and authenticated Imap instance</param>
/// <param name="subfolderPath">Path to the subfolder from root, delimited by '/' in this snippet.</param>
/// <remarks>
/// Imap.Select() may be used to access the path directly, but it will not populate the surrounding mailbox tree.
/// </remarks>
public void NavigateToSubfolder(Imap myImap, string subfolderPath)
{
    //Separate provided path into each subfolder name
    string[] subfolderNameArray = subfolderPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

    //myImap.Mailboxes will already be populated by myImap.Authenticate(), so set to the first subfolder
    Mailbox currentMailbox = myImap.Mailboxes[subfolderNameArray[0]];

    //Subfolders (currentMailbox.Mailboxes) will not be populated, so start drilling down
    for (int i = 1; i <= subfolderNameArray.Length - 1; i++)
    {
        //If the entire mailbox structure was not populated upon login, refresh it now
        if(!myImap.Session.PopulateMailboxTree)
            currentMailbox.Mailboxes.Refresh();
        currentMailbox = currentMailbox.Mailboxes[subfolderNameArray[i]];
    }

    //Now that the end of the specified path has been reached, select that mailbox
    myImap.SelectedMailbox = currentMailbox;
}
''' <summary>
''' Navigates into the subfolder/sub-mailbox specified by 'subfolderPath'.
''' </summary>
''' <param name="myImap">A connected and authenticated Imap instance</param>
''' <param name="subfolderPath">Path to the subfolder from root, delimited by '/' in this snippet.</param>
''' <remarks>
''' Imap.Select() may be used to access the path directly, but it will not populate the surrounding mailbox tree.
''' </remarks>
Public Sub NavigateToSubfolder(ByVal myImap As Imap, ByVal subfolderPath As String)
    'Separate provided path into each subfolder name
    Dim subfolderNameArray() As String = subfolderPath.Split(New String() { "/" }, StringSplitOptions.RemoveEmptyEntries)

    'myImap.Mailboxes will already be populated by myImap.Authenticate(), so set to the first subfolder
    Dim currentMailbox As Mailbox = myImap.Mailboxes(subfolderNameArray(0))

    'Subfolders (currentMailbox.Mailboxes) will not be populated, so start drilling down
    For i As Integer = 1 To subfolderNameArray.Length - 1
        'If the entire mailbox structure was not populated upon login, refresh it now
        If Not myImap.Session.PopulateMailboxTree Then
            currentMailbox.Mailboxes.Refresh()
        End If
        currentMailbox = currentMailbox.Mailboxes(subfolderNameArray(i))
    Next i

    'Now that the end of the specified path has been reached, select that mailbox
    myImap.SelectedMailbox = currentMailbox
End Sub
See Also

Reference

Mailbox Class
Mailbox Members


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