PowerTCP Mail for .NET
Mailbox Class
Members  Example  See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace : Mailbox Class




Represents an IMAP mailbox on the server.

Object Model

Mailbox ClassMailboxCollection ClassMailbox ClassImapMessageCollection ClassImapMessage Class

Syntax

Visual Basic (Declaration) 
Public Class Mailbox 
Visual Basic (Usage)Copy Code
Dim instance As Mailbox
C# 
public class Mailbox 
Managed Extensions for C++ 
public __gc class Mailbox 
C++/CLI 
public ref class Mailbox 

Example

The following example demonstrates logging into an IMAP server, copying read messages to a Deleted mailbox, and deleting them.
Visual BasicCopy Code
Private Sub DoMove()
   ' Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   Try
      ' Do synchronous login with AutoList
      Imap1.Login("myServer", "myAccount", "myPassword")

      ' Create Mailbox objects for easier reference
      Dim InboxBox As Mailbox = Imap1.CurrentMailbox ' After Login with AutoList, this will be "INBOX"
      Dim DeletedBox As Mailbox = Imap1.Mailboxes("Deleted Items")

      ' Update Messages Count in "Deleted Items" box
      DeletedBox.Refresh()

      ' Display Messages Count in both boxes
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      ' Get an array of ImapMessages with just flags
      Dim Messages As ImapMessage() = InboxBox.Get(InboxBox.Messages(0), InboxBox.Messages(InboxBox.Messages.Count-1), ImapMessageSections.Flags)

      ' Copy Read Messages to "Deleted Items" box and Mark them for Deletion
      Dim Msg as ImapMessage
      For Each Msg in Messages
        If Msg.Seen Then 'If Seen flag is set 
           Msg.CopyTo(DeletedBox) ' Copy to "Deleted Items" box
           Msg.Delete = True ' Set deleted flag in "INBOX"
        End If
      Next

      'Permanently Remove Copied Messages from "INBOX"
      InboxBox.Purge()

      'Update Messages Count in "Deleted Items"
      DeletedBox.Refresh()

      'Display new Messages Counts
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      'Logout from server
      Imap1.Logout()
   
   Catch Ex As Exception
       ' Show MessageBox if error occurs
       MessageBox.Show(Ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try
End Sub
C#Copy Code
private void DoMove()
{
   //Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   try
   {
      //Do synchronous login with AutoList
      imap1.Login("myServer", "myAccount", "myPassword");

      //Create Mailbox objects for easier reference
     Mailbox inboxBox = imap1.CurrentMailbox; //After Login with AutoList, this will be "INBOX"
     Mailbox deletedBox = imap1.Mailboxes["Deleted Items"];

     //Update Messages Count in "Deleted Items" box
     deletedBox.Refresh();

     //Display Messages Count in both boxes
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Get an array of ImapMessages with just flags
     ImapMessage[] messages = inboxBox.Get(inboxBox.Messages[0], inboxBox.Messages[inboxBox.Messages.Count-1], ImapMessageSections.Flags);

     //Copy Read Messages to "Deleted Items" box and Mark them for Deletion
     foreach (ImapMessage msg in messages)
     {
       if (msg.Seen) //If Seen flag is set
       {
          msg.CopyTo(deletedBox); //Copy to "Deleted Items" box
          msg.Delete = true; //Set deleted flag in "INBOX"
       }
     }

     //Permanently Remove Copied Messages from "INBOX"
     inboxBox.Purge();

     //Update Messages Count in "Deleted Items"
     deletedBox.Refresh();

     //Display new Messages Counts
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Logout from server
     imap1.Logout();
   }
   catch (Exception ex)
   {
      //Show MessageBox if error occurs
      MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
}

Remarks

Mailbox objects correspond to mailboxes existing on the server. This information is reliably updated when initially entering the Mailbox. All other changes may not be definitive, as other clients can be making changes to the same account. While a mailbox is selected (see Imap.CurrentMailbox), the information will be reliably updated based on notifications from the server (in response to commands or unsolicited updates while in the Idle state).

Since this object is representing a server-side object, using properties or methods of this class may cause an IMAP command to be sent to the server to update the mailbox. For example, setting Mailbox.Name would cause a RENAME command to be sent to the server to rename the mailbox.

Inheritance Hierarchy

System.Object
   Dart.PowerTCP.Mail.Mailbox

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.