Messaging: Rework mail fetcher to build client adhoc
This commit is contained in:
parent
b16050cfc6
commit
ddffb9c4f8
@ -7,7 +7,7 @@ Imports Limilabs.Mail
|
|||||||
Namespace Mail
|
Namespace Mail
|
||||||
Public Class MailFetcher
|
Public Class MailFetcher
|
||||||
Inherits BaseClass
|
Inherits BaseClass
|
||||||
Private ReadOnly MailSession As MailSession
|
Private MailSession As MailSession
|
||||||
Private ReadOnly MailBuilder As New MailBuilder
|
Private ReadOnly MailBuilder As New MailBuilder
|
||||||
|
|
||||||
Public ReadOnly Property Connected2Server As Boolean
|
Public ReadOnly Property Connected2Server As Boolean
|
||||||
@ -24,35 +24,50 @@ Namespace Mail
|
|||||||
|
|
||||||
Public Sub New(pLogConfig As LogConfig)
|
Public Sub New(pLogConfig As LogConfig)
|
||||||
MyBase.New(pLogConfig)
|
MyBase.New(pLogConfig)
|
||||||
MailSession = New MailSession(pLogConfig, New Imap)
|
|
||||||
|
|
||||||
Log.Enabled = pLogConfig.Debug
|
Log.Enabled = pLogConfig.Debug
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Function Connect(pServer As String, pPort As Integer, pUser As String, pPassword As String, pAuthType As String) As MailSession.SessionInfo
|
Public Function Connect(pServer As String, pPort As Integer, pUser As String, pPassword As String, pAuthType As String) As MailSession.SessionInfo
|
||||||
|
MailSession = New MailSession(LogConfig, New Imap)
|
||||||
|
|
||||||
Return MailSession.ConnectToServerWithBasicAuth(pServer, pPort, pUser, pPassword, pAuthType, New MailSession.MailSessionOptions)
|
Return MailSession.ConnectToServerWithBasicAuth(pServer, pPort, pUser, pPassword, pAuthType, New MailSession.MailSessionOptions)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function ConnectToO365(pUser As String, pClientId As String, pTenantId As String, pClientSecret As String)
|
Public Function ConnectToO365(pUser As String, pClientId As String, pTenantId As String, pClientSecret As String)
|
||||||
|
MailSession = New MailSession(LogConfig, New Imap)
|
||||||
|
|
||||||
Dim oOptions = New MailSession.MailSessionOptions With {.EnableTls1_2 = True}
|
Dim oOptions = New MailSession.MailSessionOptions With {.EnableTls1_2 = True}
|
||||||
Return MailSession.ConnectToServerWithO365OAuth(pUser, pClientId, pTenantId, pClientSecret, oOptions)
|
Return MailSession.ConnectToServerWithO365OAuth(pUser, pClientId, pTenantId, pClientSecret, oOptions)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function Connect(pServer As String, pPort As Integer, pUser As String, pPassword As String, pAuthType As String, pOptions As MailSession.MailSessionOptions) As MailSession.SessionInfo
|
Public Function Connect(pServer As String, pPort As Integer, pUser As String, pPassword As String, pAuthType As String, pOptions As MailSession.MailSessionOptions) As MailSession.SessionInfo
|
||||||
|
MailSession = New MailSession(LogConfig, New Imap)
|
||||||
|
|
||||||
Return MailSession.ConnectToServerWithBasicAuth(pServer, pPort, pUser, pPassword, pAuthType, pOptions)
|
Return MailSession.ConnectToServerWithBasicAuth(pServer, pPort, pUser, pPassword, pAuthType, pOptions)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function Disconnect() As Boolean
|
Public Function Disconnect() As Boolean
|
||||||
|
If (MailSession.Session.Connected = False) Then
|
||||||
|
Return True
|
||||||
|
End If
|
||||||
|
|
||||||
Return MailSession.DisconnectFromServer()
|
Return MailSession.DisconnectFromServer()
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Async Function FetchAllMails() As Task(Of List(Of IMail))
|
Public Async Function FetchAllMailsAsync() As Task(Of List(Of IMail))
|
||||||
Return Await FetchMailsAsync(Flag.All)
|
Return Await FetchMailsAsync(Flag.All)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Async Function FetchUnreadMails() As Task(Of List(Of IMail))
|
Public Async Function FetchUnreadMailsAsync() As Task(Of List(Of IMail))
|
||||||
Return Await FetchMailsAsync(Flag.Unseen)
|
Return Await FetchMailsAsync(Flag.Unseen)
|
||||||
End Function
|
End Function
|
||||||
|
Public Function FetchAllMails() As List(Of IMail)
|
||||||
|
Return FetchMails(Flag.All)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function FetchUnreadMails() As List(Of IMail)
|
||||||
|
Return FetchMails(Flag.Unseen)
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Function ListAllMails() As List(Of Long)
|
Public Function ListAllMails() As List(Of Long)
|
||||||
Return ListMails(Flag.All)
|
Return ListMails(Flag.All)
|
||||||
@ -62,18 +77,54 @@ Namespace Mail
|
|||||||
Return ListMails(Flag.Unseen)
|
Return ListMails(Flag.Unseen)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Public Function FetchMails(pMailFlag As Flag) As List(Of IMail)
|
||||||
|
Try
|
||||||
|
If MailSession.Session.Connected Then
|
||||||
|
Dim oMailIds = ListMails(pMailFlag)
|
||||||
|
Dim oMails As New List(Of IMail)
|
||||||
|
|
||||||
|
For Each oId In oMailIds
|
||||||
|
|
||||||
|
Dim oMail As IMail = FetchMail(oId)
|
||||||
|
oMails.Add(oMail)
|
||||||
|
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return oMails
|
||||||
|
Else
|
||||||
|
Logger.Error("No connection to Server. Exiting.")
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Async Function FetchMailsAsync(pMailFlag As Flag) As Task(Of List(Of IMail))
|
Public Async Function FetchMailsAsync(pMailFlag As Flag) As Task(Of List(Of IMail))
|
||||||
Dim oMailIds = ListMails(pMailFlag)
|
Try
|
||||||
Dim oMails As New List(Of IMail)
|
If MailSession.Session.Connected Then
|
||||||
|
Dim oMailIds = ListMails(pMailFlag)
|
||||||
|
Dim oMails As New List(Of IMail)
|
||||||
|
|
||||||
For Each oId In oMailIds
|
For Each oId In oMailIds
|
||||||
|
|
||||||
Dim oMail As IMail = Await FetchMailAsync(oId)
|
Dim oMail As IMail = Await FetchMailAsync(oId)
|
||||||
oMails.Add(oMail)
|
oMails.Add(oMail)
|
||||||
|
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
Return oMails
|
||||||
|
Else
|
||||||
|
Logger.Error("No connection to Server. Exiting.")
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
|
||||||
Return oMails
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function ListMails(pMailFlag As Flag) As List(Of Long)
|
Public Function ListMails(pMailFlag As Flag) As List(Of Long)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user