S22 TryCatch to continue
This commit is contained in:
parent
d49e627f5d
commit
34368ce760
Binary file not shown.
Binary file not shown.
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.5.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.5.0.0")>
|
||||
<Assembly: AssemblyVersion("2.6.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.6.0.0")>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -23,32 +23,45 @@ Public Class clsEmailIMAP
|
||||
'End Sub
|
||||
|
||||
Public Function FetchIMAPMessages(Server As String, Port As Integer, Username As String, Password As String, pInbox As String, Optional IsTest As Boolean = False, Optional DeleteinTest As Boolean = False, Optional MoveMailTo As String = "") As Boolean
|
||||
Logger.Debug("S22 Connecting to Server {0}:{1} with user {2}", Server, Port, Username)
|
||||
Logger.Debug("S22FetchIMAPMessages - Connecting to Server {0}:{1} with user {2}", Server, Port, Username)
|
||||
Try
|
||||
Logger.Debug("S22 Connecting...")
|
||||
Logger.Debug("S22FetchIMAPMessages - Connecting...")
|
||||
Using oClient As New S22.Imap.ImapClient(Server, Port, Username, Password, S22.Imap.AuthMethod.Login, True)
|
||||
If Not oClient.Authed Then
|
||||
Logger.Warn("S22 Connected to server but authentication failed.")
|
||||
Logger.Warn("S22FetchIMAPMessages - Connected to server but authentication failed.")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Logger.Debug($"S22 Fetching unseen MessageIds from Inbox: {pInbox}")
|
||||
Logger.Debug($"S22FetchIMAPMessages - Fetching unseen MessageIds from Inbox: {pInbox}")
|
||||
Dim oMessageIds As IEnumerable(Of UInteger) = oClient.Search(S22.Imap.SearchCondition.Unseen, pInbox)
|
||||
|
||||
Logger.Debug("S22 Found {0} messages", oMessageIds.Count)
|
||||
Logger.Debug("S22 Fetching messages...")
|
||||
Logger.Debug("S22FetchIMAPMessages - Found {0} messages", oMessageIds.Count)
|
||||
Logger.Debug("S22FetchIMAPMessages - Fetching messages...")
|
||||
Dim oMessageCountRegular As Integer = 0
|
||||
Dim oMessageCountWorked As Integer = 0
|
||||
Dim oLastLog As String
|
||||
For Each oMessageId As UInteger In oMessageIds
|
||||
Logger.Debug($"Checking message")
|
||||
Logger.Debug($"Checking message...")
|
||||
Dim oMessage = oClient.GetMessage(oMessageId, False, pInbox)
|
||||
Logger.Debug($"Checking message Subject: {oMessage.Subject}, From: {oMessage.From}")
|
||||
|
||||
oLastLog = $"Checking message with Subject [{oMessage.Subject}] From [{oMessage.From}]"
|
||||
Logger.Debug(oLastLog)
|
||||
Dim oTempPath = Path.GetTempFileName()
|
||||
Try
|
||||
Dim oResult = WriteMessageToFile(oMessage, oTempPath)
|
||||
oLastLog &= $" # Message written to TempPath [{oTempPath}]"
|
||||
Dim oMessageREFGUID
|
||||
Dim oMsg As Message
|
||||
Try
|
||||
oLastLog &= " # Creating the New Message(oTempPath)"
|
||||
oMsg = New Message(oTempPath)
|
||||
oLastLog &= " # Extracting the MessageID"
|
||||
oMessageREFGUID = oMsg.MessageID
|
||||
Catch ex As Exception
|
||||
Logger.Warn($"S22FetchIMAPMessages - Could not get a MessageID or create a MailObject - Error: {ex.Message} - Last Debug Log: [{oLastLog}]")
|
||||
Continue For
|
||||
End Try
|
||||
|
||||
Dim oMsg As New Message(oTempPath)
|
||||
Dim oMessageREFGUID = oMsg.MessageID
|
||||
oLastLog &= " # Got the MessageID"
|
||||
oMessageREFGUID = oMessageREFGUID.Replace(">", "").Replace("<", "")
|
||||
Dim oCHECKSQL = $"SELECT * FROM TBEMLP_HISTORY WHERE lower(EMAIL_MSGID) = lower('{oMessageREFGUID}')"
|
||||
Dim oCHECKDT As DataTable = _DB_MSSQL.Return_Datatable(oCHECKSQL)
|
||||
@ -56,25 +69,27 @@ Public Class clsEmailIMAP
|
||||
If oCHECKDT.Rows.Count = 0 Then
|
||||
oMessageCountRegular += 1
|
||||
CURRENT_WORKMAIL_LIST.Add(oMsg)
|
||||
oLastLog &= " # Added to CURRENT_WORKMAIL_LIST"
|
||||
Else
|
||||
Logger.Info("S22 Message has already been worked! Skipping!")
|
||||
Logger.Info("S22FetchIMAPMessages - Message has already been worked! Skipping!")
|
||||
Logger.Debug($"Message shall be deleted...")
|
||||
|
||||
oLastLog &= " # Message shall be deleted..."
|
||||
oClient.DeleteMessage(oMessageId,)
|
||||
Logger.Debug($"S22 Message has been deleted!")
|
||||
Logger.Debug($"S22FetchIMAPMessages - Message has been deleted!")
|
||||
oLastLog &= " # S22FetchIMAPMessages - Message has been deleted!"
|
||||
Dim oUpd = $"UPDATE TBEMLP_HISTORY SET DATE_DELETED_INBOX = GETDATE() WHERE lower(EMAIL_MSGID) = lower('{oMessageId}')"
|
||||
_DB_MSSQL.Execute_non_Query(oUpd)
|
||||
oMessageCountWorked += 1
|
||||
End If
|
||||
If IsTest = True Then
|
||||
Logger.Debug($"S22 IMAP-Test Message#: {oMessageCountRegular} - Msgsubject is: {oMsg.Subject} - MsgMessageID is: {oMessageREFGUID}")
|
||||
Logger.Debug($"S22 message correctly fetched. Mail has been downloaded to {oTempPath}")
|
||||
Logger.Debug($"S22FetchIMAPMessages - IMAP-Test Message#: {oMessageCountRegular} - Msgsubject is: {oMsg.Subject} - MsgMessageID is: {oMessageREFGUID}")
|
||||
Logger.Debug($"S22FetchIMAPMessages - message correctly fetched. Mail has been downloaded to {oTempPath}")
|
||||
End If
|
||||
Try
|
||||
If DeleteinTest = True Then
|
||||
Logger.Debug($"Message shall be deleted...")
|
||||
oClient.DeleteMessage(oMessageId,)
|
||||
Logger.Debug($"S22 Message has been deleted!")
|
||||
Logger.Debug($"S22FetchIMAPMessages - Message has been deleted!")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Message could not be deleted: " & ex.Message)
|
||||
@ -83,9 +98,9 @@ Public Class clsEmailIMAP
|
||||
Try
|
||||
Logger.Debug($"Moving to [{MoveMailTo}] is active...")
|
||||
oClient.MoveMessage(oMessageId, MoveMailTo)
|
||||
Logger.Debug($"S22 successfully moved!")
|
||||
Logger.Debug($"S22FetchIMAPMessages - successfully moved!")
|
||||
Catch ex As Exception
|
||||
Logger.Warn($"S22 Could not move message to folder [{MoveMailTo}] - Error: {ex.Message}")
|
||||
Logger.Warn($"S22FetchIMAPMessages - Could not move message to folder [{MoveMailTo}] - Error: {ex.Message}")
|
||||
End Try
|
||||
End If
|
||||
|
||||
@ -98,12 +113,15 @@ Public Class clsEmailIMAP
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("S22 Temp file could not be deleted")
|
||||
|
||||
End Try
|
||||
Catch ex As Exception
|
||||
Logger.Warn($"FetchIMAPMessages - Unexpected Error while working on email: [{ex.Message}] - Last Debug Log: [{oLastLog}]")
|
||||
End Try
|
||||
|
||||
Next
|
||||
oClient.Expunge()
|
||||
Logger.Debug("S22 Finished Message-Fetch")
|
||||
Logger.Debug("S22FetchIMAPMessages - Finished Message-Fetch")
|
||||
If oMessageCountRegular > 0 Or oMessageCountWorked > 0 Then
|
||||
Logger.Info($"###############################################")
|
||||
If oMessageCountRegular > 0 Then
|
||||
|
||||
@ -135,10 +135,10 @@ Public Class clsWorker
|
||||
End If
|
||||
|
||||
If pollresult = False Then
|
||||
Logger.Warn(String.Format("Error while polling emails...Trying S22...."))
|
||||
Logger.Info(String.Format("Error while polling emails...Trying S22...."))
|
||||
pollresult = _emailIMAP.FetchIMAPMessages(MAIL_SERVER, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_INBOX_NAME)
|
||||
If pollresult = False Then
|
||||
Logger.Warn(String.Format("S22 also returned error!"))
|
||||
Logger.Warn(String.Format("S22FetchIMAPMessages - also returned error!"))
|
||||
End If
|
||||
End If
|
||||
If CURRENT_WORKMAIL_LIST.Count() > 0 Then
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user