Move processed emails to imap folder Verarbeitet, if they are not deleted

This commit is contained in:
Jonathan Jenne
2023-11-21 16:28:25 +01:00
parent b4cf442c89
commit 1c07b9b507
4 changed files with 203 additions and 131 deletions

View File

@@ -5,6 +5,7 @@ Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Messaging.Mail
Imports Limilabs.Mail
Imports Limilabs.Mail.Headers
Imports System.Reflection.Emit
Public Class clsWorker
Private ReadOnly Logger As Logger
@@ -19,6 +20,8 @@ Public Class clsWorker
Private ReadOnly EmailLimitationSender As String = ""
Private ReadOnly EmailLimitationEnabled As Boolean = False
Private Const SUCCESS_IMAP_FOLDER = "Verarbeitet"
Private ReadOnly LocalEmlFile As String = ""
Sub New(pLogConfig As LogConfig, pConnectionString As String, pWindreamConnectionString As String, pPollProfileId As Integer, pUseWindream As Boolean, pEmailAccountID As Integer, pEmailPrefix As String, pEmailLimitationSender As String, Optional pLocalEML As String = "")
@@ -215,7 +218,7 @@ Public Class clsWorker
End If
If ClassWorkMail.WorkEmailMessage(oEmail, oMailId, oValidationSql) = True Then
If LocalEmlFile = "" Then
DeleteEmailFile(oMailId)
DeleteOrMoveEmailFile(oMailId)
End If
End If
@@ -308,22 +311,45 @@ Public Class clsWorker
End Try
End Function
Private Sub DeleteEmailFile(pMailId As Integer)
Private Sub DeleteOrMoveEmailFile(pMailId As Integer)
Try
If DeleteMail = True And MESSAGE_ERROR = False Then
If IsNothing(Fetcher.Client) Then
Logger.Warn("EMAIL_DELETE - CURRENT_ImapObject is nothing")
End If
If MESSAGE_ERROR = True Then
Logger.Warn("Did not delete or move Message with UID [{0}] as there was an MessageError!", pMailId)
Return
End If
If IsNothing(Fetcher.Client) Then
Logger.Warn("Did not delete or move Message with UID [{0}] as ImapClient is null", pMailId)
Return
End If
If DeleteMail = True Then
Fetcher.Client.DeleteMessageByUID(pMailId)
Logger.Info("Email with Id [{0}] was deleted.", pMailId)
Else
If MESSAGE_ERROR = True Then
Logger.Warn("Did not delete Message with UID [{0}] as there was an MessageError!", pMailId)
If TestImapFolderExists(SUCCESS_IMAP_FOLDER) Then
If Fetcher.Client.MoveByUID(pMailId, SUCCESS_IMAP_FOLDER) IsNot Nothing Then
Logger.Info("Email with UID [{0}] was moved", pMailId)
End If
Else
Logger.Warn("IMAP Folder [{0}] does not exist. Emails could not be moved!", SUCCESS_IMAP_FOLDER)
End If
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
Private Function TestImapFolderExists(pFolderName As String) As Boolean
Try
Return Fetcher.Client.
GetFolders().
Where(Function(f) f.Name = pFolderName).
Any()
Catch ex As Exception
Logger.Warn("Could not get IMAP folders. Returning False.")
Logger.Error(ex)
Return False
End Try
End Function
End Class