MS ZF Init Change TBDDCONNMessaging Limilab
This commit is contained in:
parent
dcf5bbe21c
commit
7064978ecb
@ -71,10 +71,11 @@ Public Class ClassInit
|
|||||||
Throw New InitException("Could not initialize ECM-Database!")
|
Throw New InitException("Could not initialize ECM-Database!")
|
||||||
|
|
||||||
Else
|
Else
|
||||||
Dim oSQl = "SELECT * FROM TBDD_CONNECTION WHERE BEZEICHNUNG = 'IDB'"
|
Dim oSQl = "SELECT * FROM TBDD_CONNECTION WHERE BEZEICHNUNG = 'IDB' AND AKTIV = 1"
|
||||||
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatable(oSQl)
|
Dim oDatatable As DataTable = My.DatabaseECM.GetDatatable(oSQl)
|
||||||
|
|
||||||
If IsNothing(oDatatable) OrElse oDatatable.Rows.Count = 0 Then
|
If IsNothing(oDatatable) OrElse oDatatable.Rows.Count = 0 Then
|
||||||
|
MsgBox("No IDB connection entries in TBDD_CONNECTION found!", MsgBoxStyle.Exclamation)
|
||||||
Logger.Warn("No IDB connection entries in TBDD_CONNECTION found!")
|
Logger.Warn("No IDB connection entries in TBDD_CONNECTION found!")
|
||||||
Throw New InitException("Fehler beim Laden der IDB Verbindungsdaten!")
|
Throw New InitException("Fehler beim Laden der IDB Verbindungsdaten!")
|
||||||
End If
|
End If
|
||||||
|
|||||||
@ -8,6 +8,7 @@ Imports System
|
|||||||
Imports System.Security.Authentication
|
Imports System.Security.Authentication
|
||||||
Imports Limilabs.Mail.Headers
|
Imports Limilabs.Mail.Headers
|
||||||
Imports Limilabs.Mail.MIME
|
Imports Limilabs.Mail.MIME
|
||||||
|
Imports Limilabs
|
||||||
|
|
||||||
Public Class Limilab
|
Public Class Limilab
|
||||||
Private Initialized As Boolean = False
|
Private Initialized As Boolean = False
|
||||||
@ -18,8 +19,9 @@ Public Class Limilab
|
|||||||
Private User As String
|
Private User As String
|
||||||
Private Password As String
|
Private Password As String
|
||||||
Private AuthType As String
|
Private AuthType As String
|
||||||
Private ImapObject As Imap
|
Private LimilabImapObject As Imap
|
||||||
Public ErrorMessage As String
|
Public ErrorMessage As String
|
||||||
|
Private CURR_ListUIDs As List(Of Long)
|
||||||
Public Sub New(LogConfig As LogConfig)
|
Public Sub New(LogConfig As LogConfig)
|
||||||
LogConfig = LogConfig
|
LogConfig = LogConfig
|
||||||
Logger = LogConfig.GetLogger()
|
Logger = LogConfig.GetLogger()
|
||||||
@ -34,7 +36,8 @@ Public Class Limilab
|
|||||||
''' <param name="oPassword">IMAP-Password</param>
|
''' <param name="oPassword">IMAP-Password</param>
|
||||||
''' <param name="oAuthType">Auth-Type</param>
|
''' <param name="oAuthType">Auth-Type</param>
|
||||||
''' <param name="Folder">The folder to fetch messages from. Defaults to `Inbox`</param>
|
''' <param name="Folder">The folder to fetch messages from. Defaults to `Inbox`</param>
|
||||||
Public Sub InitIMAP(oImapServer As String, oPort As Integer, oUser As String, oPassword As String, oAuthType As String, Optional Folder As String = "Inbox")
|
Public Sub InitIMAP(Log_enabled As Boolean, oImapServer As String, oPort As Integer, oUser As String, oPassword As String, oAuthType As String, Optional Folder As String = "Inbox")
|
||||||
|
LOG_Limilab(Log_enabled)
|
||||||
IMAPServer = oImapServer
|
IMAPServer = oImapServer
|
||||||
IMAPPort = oPort
|
IMAPPort = oPort
|
||||||
User = oUser
|
User = oUser
|
||||||
@ -42,12 +45,35 @@ Public Class Limilab
|
|||||||
AuthType = oAuthType
|
AuthType = oAuthType
|
||||||
Initialized = True
|
Initialized = True
|
||||||
End Sub
|
End Sub
|
||||||
|
Public Function CloseImap() As Boolean
|
||||||
|
Try
|
||||||
|
If Initialized = False Then
|
||||||
|
Return True
|
||||||
|
Else
|
||||||
|
LimilabImapObject.Close()
|
||||||
|
Return True
|
||||||
|
End If
|
||||||
|
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
ErrorMessage = ex.Message
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function LOG_Limilab(Log_enabled As Boolean) As Boolean
|
||||||
|
Mail.Log.Enabled = Log_enabled
|
||||||
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Tests connection to a given IMAP Server by connecting and doing a simple message query.
|
''' Tests connection to a given IMAP Server by connecting and doing a simple message query.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
''' <returns>True if connection and query were successful. False otherwise.</returns>
|
''' <returns>True if connection and query were successful. False otherwise.</returns>
|
||||||
Public Function IMAPTestLogin() As Boolean
|
Public Function IMAPTestLogin() As Boolean
|
||||||
Logger.Debug("Testing Login to Server {0}:{1} with user {2}", IMAPServer, IMAPPort, User)
|
Logger.Debug("Starting IMAPTestLogin ...")
|
||||||
|
|
||||||
If Initialized = False Then
|
If Initialized = False Then
|
||||||
Return False
|
Return False
|
||||||
End If
|
End If
|
||||||
@ -55,7 +81,7 @@ Public Class Limilab
|
|||||||
Logger.Debug("Connecting...")
|
Logger.Debug("Connecting...")
|
||||||
Dim oReturn As Boolean = ImapConnect()
|
Dim oReturn As Boolean = ImapConnect()
|
||||||
If oReturn = True Then
|
If oReturn = True Then
|
||||||
ImapObject.Close()
|
LimilabImapObject.Close()
|
||||||
End If
|
End If
|
||||||
Return oReturn
|
Return oReturn
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -64,11 +90,32 @@ Public Class Limilab
|
|||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
Public Function IMAPGetUnseenMessageIDs() As List(Of Long)
|
||||||
|
Dim oListuids As New List(Of Long)
|
||||||
|
Logger.Debug("Starting IMAPGetMessageIDs ...")
|
||||||
|
If Initialized = False Then
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
Try
|
||||||
|
Dim oConnect As Boolean = ImapConnect()
|
||||||
|
|
||||||
|
If oConnect = True Then
|
||||||
|
oListuids = ImapGetMessageIDs_Unseen()
|
||||||
|
CURR_ListUIDs = oListuids
|
||||||
|
End If
|
||||||
|
Return oListuids
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
ErrorMessage = ex.Message
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
Private Function ImapConnect() As Boolean
|
Private Function ImapConnect() As Boolean
|
||||||
Try
|
Try
|
||||||
If Initialized = False Then
|
If Initialized = False Then
|
||||||
Return True
|
Return True
|
||||||
End If
|
End If
|
||||||
|
Logger.Debug("ImapConnect {0}:{1} with user {2}", IMAPServer, IMAPPort, User)
|
||||||
Dim oReturnImap As New Imap()
|
Dim oReturnImap As New Imap()
|
||||||
AddHandler oReturnImap.ServerCertificateValidate, AddressOf Validate
|
AddHandler oReturnImap.ServerCertificateValidate, AddressOf Validate
|
||||||
Logger.Debug($"AUTH_TYPE [{AuthType}]")
|
Logger.Debug($"AUTH_TYPE [{AuthType}]")
|
||||||
@ -106,7 +153,7 @@ Public Class Limilab
|
|||||||
Logger.Debug("Login with User and password...")
|
Logger.Debug("Login with User and password...")
|
||||||
oReturnImap.UseBestLogin(User, Password)
|
oReturnImap.UseBestLogin(User, Password)
|
||||||
Logger.Debug(">> Logged on!")
|
Logger.Debug(">> Logged on!")
|
||||||
ImapObject = oReturnImap
|
LimilabImapObject = oReturnImap
|
||||||
Return True
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
@ -119,6 +166,7 @@ Public Class Limilab
|
|||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub Validate(
|
Private Sub Validate(
|
||||||
ByVal sender As Object,
|
ByVal sender As Object,
|
||||||
ByVal e As ServerCertificateValidateEventArgs)
|
ByVal e As ServerCertificateValidateEventArgs)
|
||||||
@ -135,31 +183,21 @@ Public Class Limilab
|
|||||||
End If
|
End If
|
||||||
e.IsValid = False
|
e.IsValid = False
|
||||||
End Sub
|
End Sub
|
||||||
Public Function ImapGetMessageIDs() As List(Of Long)
|
Private Function ImapGetMessageIDs_Unseen() As List(Of Long)
|
||||||
Dim oListuids As New List(Of Long)
|
Dim oListuids As New List(Of Long)
|
||||||
Try
|
Try
|
||||||
ImapObject.SelectInbox()
|
LimilabImapObject.SelectInbox()
|
||||||
|
|
||||||
oListuids = ImapObject.Search(Flag.Unseen)
|
oListuids = LimilabImapObject.Search(Flag.Unseen)
|
||||||
|
|
||||||
Return oListuids
|
Return oListuids
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
ErrorMessage = ex.Message
|
ErrorMessage = ex.Message
|
||||||
Return oListuids
|
Return Nothing
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
Public Function DeleteMessageByUID(oUID As String) As Boolean
|
|
||||||
Try
|
|
||||||
ImapObject.DeleteMessageByUID(oUID)
|
|
||||||
Return True
|
|
||||||
Catch ex As Exception
|
|
||||||
Logger.Error(ex)
|
|
||||||
ErrorMessage = ex.Message
|
|
||||||
Return False
|
|
||||||
End Try
|
|
||||||
End Function
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Creates a MailObject and sends Mail via smtp.
|
''' Creates a MailObject and sends Mail via smtp.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
@ -262,4 +300,62 @@ Public Class Limilab
|
|||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
|
Public Function GetMailInfo(UID As Long) As Boolean
|
||||||
|
Try
|
||||||
|
Dim eml = LimilabImapObject.GetMessageByUID(UID)
|
||||||
|
Dim email As IMail = New MailBuilder().CreateFromEml(eml)
|
||||||
|
' Subject
|
||||||
|
Console.WriteLine(email.Subject)
|
||||||
|
|
||||||
|
' From
|
||||||
|
For Each m As MailBox In email.From
|
||||||
|
Console.WriteLine(m.Address)
|
||||||
|
Console.WriteLine(m.Name)
|
||||||
|
Next
|
||||||
|
' Date
|
||||||
|
Console.WriteLine(email.[Date])
|
||||||
|
' Text body of the message
|
||||||
|
Console.WriteLine(email.Text)
|
||||||
|
' Html body of the message
|
||||||
|
Console.WriteLine(email.Html)
|
||||||
|
' Custom header
|
||||||
|
Console.WriteLine(email.Document.Root.Headers("x-spam-value"))
|
||||||
|
' Save all attachments to disk
|
||||||
|
For Each mime As MimeData In email.Attachments
|
||||||
|
mime.Save("c:\" + mime.SafeFileName)
|
||||||
|
Next
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
ErrorMessage = ex.Message
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
|
||||||
|
End Function
|
||||||
|
Public Function GetMailObjects() As ArrayList
|
||||||
|
Try
|
||||||
|
Dim WORKMAIL_LIST As New ArrayList()
|
||||||
|
For Each oUID In CURR_ListUIDs
|
||||||
|
Dim oEml = LimilabImapObject.GetMessageByUID(oUID)
|
||||||
|
Dim oEmail As IMail = New MailBuilder().CreateFromEml(oEml)
|
||||||
|
WORKMAIL_LIST.Add(oEmail)
|
||||||
|
Next
|
||||||
|
Return WORKMAIL_LIST
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
ErrorMessage = ex.Message
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
|
||||||
|
End Function
|
||||||
|
Public Function IMAP_DeleteByUID(UID As String) As Boolean
|
||||||
|
Try
|
||||||
|
LimilabImapObject.DeleteMessageByUID(UID)
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
Logger.Error(ex)
|
||||||
|
ErrorMessage = ex.Message
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user