Compare commits
3 Commits
e8974376c5
...
ddffb9c4f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddffb9c4f8 | ||
|
|
b16050cfc6 | ||
|
|
a415f90906 |
@@ -111,7 +111,7 @@ Public Class MSSQLServer
|
||||
|
||||
Private Function MaybeGetTransaction(Connection As SqlConnection, Mode As TransactionMode, Transaction As SqlTransaction) As SqlTransaction
|
||||
If Connection Is Nothing Then
|
||||
Throw New ArgumentNullException("Connection")
|
||||
Throw New ArgumentNullException("Connection", "Could not get transaction because connection is null!")
|
||||
End If
|
||||
|
||||
If Mode = TransactionMode.NoTransaction Then
|
||||
@@ -269,7 +269,7 @@ Public Class MSSQLServer
|
||||
Try
|
||||
If pConnectionString Is Nothing OrElse pConnectionString.Length = 0 Then
|
||||
Logger.Warn("Connection String is empty!")
|
||||
Throw New ArgumentNullException("pConnectionString")
|
||||
Throw New ArgumentNullException("pConnectionString", "Could not mask connection string because connectiong string is empty!")
|
||||
End If
|
||||
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
|
||||
@@ -7,7 +7,7 @@ Imports Limilabs.Mail
|
||||
Namespace Mail
|
||||
Public Class MailFetcher
|
||||
Inherits BaseClass
|
||||
Private ReadOnly MailSession As MailSession
|
||||
Private MailSession As MailSession
|
||||
Private ReadOnly MailBuilder As New MailBuilder
|
||||
|
||||
Public ReadOnly Property Connected2Server As Boolean
|
||||
@@ -24,35 +24,50 @@ Namespace Mail
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
MailSession = New MailSession(pLogConfig, New Imap)
|
||||
|
||||
Log.Enabled = pLogConfig.Debug
|
||||
End Sub
|
||||
|
||||
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)
|
||||
End Function
|
||||
|
||||
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}
|
||||
Return MailSession.ConnectToServerWithO365OAuth(pUser, pClientId, pTenantId, pClientSecret, oOptions)
|
||||
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
|
||||
MailSession = New MailSession(LogConfig, New Imap)
|
||||
|
||||
Return MailSession.ConnectToServerWithBasicAuth(pServer, pPort, pUser, pPassword, pAuthType, pOptions)
|
||||
End Function
|
||||
|
||||
Public Function Disconnect() As Boolean
|
||||
If (MailSession.Session.Connected = False) Then
|
||||
Return True
|
||||
End If
|
||||
|
||||
Return MailSession.DisconnectFromServer()
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
Return ListMails(Flag.All)
|
||||
@@ -62,18 +77,54 @@ Namespace Mail
|
||||
Return ListMails(Flag.Unseen)
|
||||
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))
|
||||
Dim oMailIds = ListMails(pMailFlag)
|
||||
Dim oMails As New 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
|
||||
For Each oId In oMailIds
|
||||
|
||||
Dim oMail As IMail = Await FetchMailAsync(oId)
|
||||
oMails.Add(oMail)
|
||||
Dim oMail As IMail = Await FetchMailAsync(oId)
|
||||
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
|
||||
|
||||
Public Function ListMails(pMailFlag As Flag) As List(Of Long)
|
||||
|
||||
@@ -166,7 +166,7 @@ Namespace Mail
|
||||
|
||||
ElseIf pSession.AuthType = AUTH_SSL Then
|
||||
Try
|
||||
If pSession.Port = 465 Then
|
||||
If pSession.Port = 993 Then
|
||||
Logger.Debug("Connecting with [ConnectSSL] on [{0}/{1}]", pSession.Server, pSession.Port)
|
||||
Client.ConnectSSL(pSession.Server, pSession.Port)
|
||||
Else
|
||||
@@ -186,8 +186,13 @@ Namespace Mail
|
||||
ElseIf Session.AuthType = AUTH_SSLTLS Or Session.AuthType = AUTH_STARTTLS Then
|
||||
|
||||
Try
|
||||
Logger.Debug("Connecting with [Connect] on [{0}/{1}]", pSession.Server, pSession.Port)
|
||||
Client.Connect(pSession.Server, pSession.Port)
|
||||
If pSession.Port = 993 Then
|
||||
Logger.Debug("Connecting with [ConnectSSL] on [{0}/{1}]", pSession.Server, pSession.Port)
|
||||
Client.ConnectSSL(pSession.Server, pSession.Port)
|
||||
Else
|
||||
Logger.Debug("Connecting with [Connect] on [{0}/{1}]", pSession.Server, pSession.Port)
|
||||
Client.Connect(pSession.Server, pSession.Port)
|
||||
End If
|
||||
Logger.Info("Connection Successful!")
|
||||
|
||||
Dim oSupportsSTARTTLS As Boolean = SupportsSTARTTLS(Client)
|
||||
|
||||
Reference in New Issue
Block a user