Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports System.Threading.Tasks Imports ImapX Imports ImapX.Collections Imports System.Windows Namespace ImapPackage Class ImapService Private Shared Property client As ImapClient Public Shared Sub Initialize() client = New ImapClient("imap.gmail.com", True) If Not client.Connect() Then Throw New Exception("Error connecting to the client.") End If End Sub Public Shared Function Login(ByVal u As String, ByVal p As String) As Boolean Return client.Login(u, p) End Function Public Shared Sub Logout() If client.IsAuthenticated Then client.Logout() End If MainWindow.LoggedIn = False End Sub Public Shared Function GetFolders() As List(Of EmailFolder) Dim folders = New List(Of EmailFolder)() For Each folder In client.Folders folders.Add(New EmailFolder With {.Title = folder.Name}) Next client.Folders.Inbox.StartIdling() client.Folders.Inbox.OnNewMessagesArrived += AddressOf Inbox_OnNewMessagesArrived Return folders End Function Private Shared Sub Inbox_OnNewMessagesArrived(ByVal sender As Object, ByVal e As IdleEventArgs) MessageBox.Show($"A new message was downloaded in {e.Folder.Name} folder.") End Sub Public Shared Function GetMessagesForFolder(ByVal name As String) As MessageCollection client.Folders(name).Messages.Download() Return client.Folders(name).Messages End Function End Class End Namespace
+=
AddHandler client.Folders.Inbox.OnNewMessagesArrived, AddressOf Inbox_OnNewMessagesArrived
EmailFolder
class EmailFolder { public string Title { get; set; } }
String
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)