/// <summary> /// Copies messages /// </summary> private void CopyMessage() { // Create a new ImapMessageIdSet that contains information about the messages being copied. _copyInfo = new ImapMessageSet(); // Add selected messages to the message set; foreach (ListViewItem item in listView.SelectedItems) { _copyInfo.Add(((ListItemTagInfo)item.Tag).UniqueId); } // Save the selected folder. _copyFolder = _currentFolder; }
private async Task GetMessageListAsync() { lvItems.Items.Clear(); // connect using Rebex IMAP and retrieve list of messages using (var client = new Imap()) { // communication logging (enable if needed) // client.LogWriter = new FileLogWriter("imap-oauth.log", LogLevel.Debug); // connect to the server statusLabel.Content = "Connecting to IMAP..."; await client.ConnectAsync("outlook.office365.com", Imap.DefaultImplicitSslPort, SslMode.Implicit); // prepare authentication token suitable for IMAP, POP3, or SMTP string userName = _credentials.UserName; string accessToken = _credentials.AccessToken; string pattern = string.Format("user={0}{1}auth=Bearer {2}{1}{1}", userName, '\x1', accessToken); string token = Convert.ToBase64String(Encoding.ASCII.GetBytes(pattern)); // authenticate using the OAuth 2.0 access token statusLabel.Content = "Authenticating to IMAP..."; await client.LoginAsync(token, ImapAuthentication.OAuth20); // list recent messages in the 'Inbox' folder statusLabel.Content = "Listing folder contents..."; await client.SelectFolderAsync("Inbox", readOnly : true); int messageCount = client.CurrentFolder.TotalMessageCount; var messageSet = new ImapMessageSet(); messageSet.AddRange(Math.Max(1, messageCount - 50), messageCount); var list = await client.GetMessageListAsync(messageSet, ImapListFields.Envelope); list.Sort(new ImapMessageInfoComparer(ImapMessageInfoComparerType.SequenceNumber, Rebex.SortingOrder.Descending)); foreach (ImapMessageInfo item in list) { lvItems.Items.Add($"{item.Date.LocalTime:yyyy-MM-dd} {item.From}: {item.Subject}"); } } statusLabel.Content = "Finished successfully!"; }