PowerTCP Mail for .NET
Progress Event (Imap)
Example 




Repeatedly raised while a message or message section is retrieved.
Syntax
Event Data

The event handler receives an argument of type ImapProgressEventArgs containing data related to this event. The following ImapProgressEventArgs properties provide information specific to this event.

PropertyDescription
Final Returns true the last time a Progress event is raised for a given message. (Inherited from Dart.Mail.ProgressEventArgs)
Length The length of the message data. (Inherited from Dart.Mail.ProgressEventArgs)
Message Gets the ImapMessage being transferred.  
Position The position within the message data. (Inherited from Dart.Mail.ProgressEventArgs)
Remarks
Contains data useful for displaying progress to the user.
Example
In this example, the Imap component gets headers for all messages in the INBOX and adds each message's sender, subject and date to a list.
private void getMessageHeaders(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();

    //Select a mailbox
    imap1.SelectedMailbox = imap1.Mailboxes["INBOX"];
    //Get headers for all messages in the box
    imap1.SelectedMailbox.Get(imap1.SelectedMailbox.ToArray(), ImapMessageInfo.Header);

    //Gracefully logout of the session
    imap1.Close();
}

private void imap1_Progress(object sender, ImapProgressEventArgs e)
{
    //Display progress in a progress bar
    progressBar1.Value = (int)((e.Position/e.Length)*100);

    //Display message header info in a listview
    if (e.Final)
    {
        progressBar1.Value = 0;
        string[] header = { e.Message.Message.From, e.Message.Message.Subject, e.Message.Message.Date.ToString() };
        listView1.Items.Add(new ListViewItem(header));
    }
}
Private Sub getMessageHeaders(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()

    'Select a mailbox
    imap1.SelectedMailbox = imap1.Mailboxes("INBOX")
    'Get headers for all messages in the box
    imap1.SelectedMailbox.Get(imap1.SelectedMailbox.ToArray(), ImapMessageInfo.Header)

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

Private Sub imap1_Progress(ByVal sender As Object, ByVal e As ImapProgressEventArgs) Handles imap1.Progress
    'Display progress in a progress bar
    progressBar1.Value = CInt((e.Position\e.Length)*100)

    'Display message header info in a listview
    If e.Final Then
        progressBar1.Value = 0
        Dim header() As String = { e.Message.Message.From, e.Message.Message.Subject, e.Message.Message.Date.ToString() }
        listView1.Items.Add(New ListViewItem(header))
    End If
End Sub
See Also

Reference

Imap Class
Imap Members


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