イベント ハンドラが、このイベントに関連するデータを含む、ImapProgressEventArgs 型の引数を受け取りました。次の ImapProgressEventArgs プロパティには、このイベントの固有の情報が記載されます。
以下のサンプルコードでは、Imapコンポーネントを使用してINBOX内のすべてのメッセージのヘッダを取得し、各メッセージの送信者、件名、および日付をリストに追加します。
private void getMessageHeaders(object sender)
{
// サーバーとアカウントの情報を設定します。
imap1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session));
imap1.Session.Username = myUsername;
imap1.Session.Password = myPassword;
// 接続してアカウントにログインします。
imap1.Connect();
imap1.Authenticate();
// メールボックスを選択します。
imap1.SelectedMailbox = imap1.Mailboxes["INBOX"];
//Get headers for all messages in the box
imap1.SelectedMailbox.Get(imap1.SelectedMailbox.ToArray(), ImapMessageInfo.Header);
// セッションから適切にログアウトします。
imap1.Close();
}
private void imap1_Progress(object sender, ImapProgressEventArgs e)
{
// プログレスバーで進行状況を表示します。
progressBar1.Value = (int)((e.Position/e.Length)*100);
// メッセージヘッダの情報をリストビューに表示します。
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)
' サーバーとアカウントの情報を設定します。
imap1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myServer, Imap.GetDefaultPort(imap1.Session))
imap1.Session.Username = myUsername
imap1.Session.Password = myPassword
' 接続してアカウントにログインします。
imap1.Connect()
imap1.Authenticate()
' メールボックスを選択します。
imap1.SelectedMailbox = imap1.Mailboxes("INBOX")
' メールボックス内のすべてのメッセージのヘッダを取得します。
imap1.SelectedMailbox.Get(imap1.SelectedMailbox.ToArray(), ImapMessageInfo.Header)
' セッションから適切にログアウトします。
imap1.Close()
End Sub
Private Sub imap1_Progress(ByVal sender As Object, ByVal e As ImapProgressEventArgs) Handles imap1.Progress
' プログレスバーで進行状況を表示します。
progressBar1.Value = CInt((e.Position\e.Length)*100)
' メッセージヘッダの情報をリストビューに表示します。
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