void client_DownloadImapMessageCompleted(object sender, ExtendedAsyncCompletedEventArgs <ImapMessage> e) { if (e.Error != null) { if (!HandleException(e.Error)) { return; } } if (_state == ConnectionState.Disconnecting) { Disconnect(); return; } MessageListInfo info = (MessageListInfo)e.UserState; if (ShowMessage(e.Result, info) && !_cancelling) { client.DownloadImapMessageAsync(info.List[info.Index].UniqueId, ImapEnvelopeParts.Envelope, info); } else { EnableProgress(false, 0); // Update the state. listView_SelectedIndexChanged(null, null); } }
bool ShowMessage(ImapMessage msg, MessageListInfo info) { info.Index++; if (msg != null) { // If From property is empty then use the Sender property. string from = msg.From.ToString(); if (from.Length == 0 && msg.Sender != null) { from = msg.Sender.ToString(); } string[] arr = new string[] { from, msg.Subject, msg.Date != null?msg.Date.ToString() : "1/1/1900", (msg.Flags & ImapMessageFlags.Deleted) != 0 ? "Delete" : string.Empty, Util.FormatSize(msg.Size) }; ListViewItem item = new ListViewItem(arr); if ((msg.Flags & ImapMessageFlags.Seen) == 0) { // New message. item.Font = new Font(item.Font, item.Font.Style | FontStyle.Bold); item.ImageIndex = 2; } else { // Seen message. item.ImageIndex = 3; } item.Tag = new ListItemTagInfo(msg.MessageInboxIndex, msg.UniqueId, msg.ReceivedDate, msg.Size); // Add to the list. listView.Items.Add(item); // Update the status text. toolStripProgressLabel.Text = string.Format("{0}/{1} message(s) retrieved", info.Index, info.List.Count); } else { toolStripProgressBar.Maximum--; } if (info.Index < toolStripProgressBar.Maximum) { toolStripProgressBar.Value = info.Index; } return(info.Index < info.List.Count); }
void DownloadImapMessage(MessageListInfo info) #endif { Retry: ImapMessage m = info.List[info.Index]; if (_cancelling) { return; } #if Framework4_5 ImapMessage msg = null; try { // Retrieve message information. msg = await client.DownloadImapMessageAsync(m.UniqueId, ImapEnvelopeParts.Envelope); } catch (Exception ex) { if (!HandleException(ex)) { return; } } ShowMessage(msg, info); if (_state == ConnectionState.Disconnecting) { Disconnect(); return; } if (!_cancelling && info.Index < info.List.Count) { goto Retry; } EnableProgress(false, 0); // Update the state. listView_SelectedIndexChanged(null, null); #else client.DownloadImapMessageAsync(m.UniqueId, ImapEnvelopeParts.Envelope, info); #endif }
void ShowMessageList(ImapMessageCollection col) { // Clear the message list. listView.Items.Clear(); // Update the progress bar control. toolStripProgressBar.Maximum = col.Count; toolStripProgressBar.Value = 0; MessageListInfo info = new MessageListInfo(); info.List = col; if (info.List.Count > 0) { DownloadImapMessage(info); } else { EnableProgress(false, 0); // Update the state. listView_SelectedIndexChanged(null, null); } }
async void DownloadImapMessage(MessageListInfo info)