From 84b3177e299737fe5ba27ae7a138729cb5fe30da Mon Sep 17 00:00:00 2001 From: pitzm Date: Fri, 2 Feb 2024 11:06:22 +0100 Subject: [PATCH] Common: oHistoryID is not always numeric, but we need the Rejection Mail --- App/EmailProfiler.Common/clsWorkEmail.vb | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/App/EmailProfiler.Common/clsWorkEmail.vb b/App/EmailProfiler.Common/clsWorkEmail.vb index 48677f1..67c37fc 100644 --- a/App/EmailProfiler.Common/clsWorkEmail.vb +++ b/App/EmailProfiler.Common/clsWorkEmail.vb @@ -119,7 +119,7 @@ Public Class clsWorkEmail Dim oHistoryID = _DB_MSSQL.GetScalarValue(oSql) If oHistoryID > 0 Then - _Logger.Info($"Messsage with subject [{CURRENT_MAIL_SUBJECT}] from [{CURRENT_MAIL_FROM}] has already been worked!") + _Logger.Info($"Message with subject [{CURRENT_MAIL_SUBJECT}] from [{CURRENT_MAIL_FROM}] has already been worked!") Return True End If @@ -142,7 +142,7 @@ Public Class clsWorkEmail End Try If oTempMailAccessible = False Then - _Logger.Warn("Could not process email [{0}], file does is not accessible!", CurrentMail.MessageId) + _Logger.Warn("Could not process email [{0}], file is not accessible!", CurrentMail.MessageId) Return False End If @@ -162,7 +162,7 @@ Public Class clsWorkEmail 'insert history und exit InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oResult) - AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "Email validation failed", _EmailAccountID) + AddEmailToQueueMSSQL(CurrentMail.MessageId, oResult, "Email validation failed", _EmailAccountID) ' Return early from processing eml Return True @@ -186,7 +186,7 @@ Public Class clsWorkEmail If CURRENT_ATTMT_COUNT = 0 Then _Logger.Info("### Mail contained no Attachments!! ###") Dim oBody = EmailStrings.EMAIL_NO_FERDS - If AddToEmailQueueMSSQL(CurrentMail.MessageId, oBody, "No Attachments", _EmailAccountID) = True Then + If AddEmailToQueueMSSQL(CurrentMail.MessageId, oBody, "No Attachments", _EmailAccountID) = True Then CURRENT_ImapObject.DeleteMessageByUID(poUID) End If InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", "No Attachments") @@ -204,7 +204,7 @@ Public Class clsWorkEmail End Try End Function - Public Function AddToEmailQueueMSSQL(MessageId As String, BodyText As String, Comment As String, pEmailAccountId As Integer) As Boolean + Public Function AddEmailToQueueMSSQL(MessageId As String, BodyText As String, Comment As String, pEmailAccountId As Integer) As Boolean Try Dim oReference = MessageId @@ -232,11 +232,10 @@ Public Class clsWorkEmail _Logger.Debug("To: {0}", oEmailTo) _Logger.Debug("Subject: {0}", oSubject) _Logger.Debug("Body {0}", oFinalBodyText) - Dim osql = $"Select MAX(GUID) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{MessageId}'" - Dim oHistoryID = _DB_MSSQL.GetScalarValue(osql) + Dim osql = $"Select COALESCE(MAX(GUID), 0) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{MessageId}'" + Dim oHistoryID As Integer = _DB_MSSQL.GetScalarValue(osql) - If IsNumeric(oHistoryID) Then - Dim oInsert = $"INSERT INTO [dbo].[TBEMLP_EMAIL_OUT] ( + Dim oInsert = $"INSERT INTO [dbo].[TBEMLP_EMAIL_OUT] ( [REMINDER_TYPE_ID] ,[SENDING_PROFILE] ,[REFERENCE_ID] @@ -259,13 +258,13 @@ Public Class clsWorkEmail ,'{Comment}' ,'{oCreatedWho}')" Return _DB_MSSQL.ExecuteNonQuery(oInsert) - Else - _Logger.Warn($"!! Could not get oHistoryID in AddToEmailQueueMSSQL [{osql}]") - End If + Catch ex As Exception _Logger.Error(ex) Return False End Try + + Return True End Function Private Function PROCESS_MANAGER_IN(pCurrentMail As MailContainer) As Boolean Try @@ -448,7 +447,7 @@ Public Class clsWorkEmail End Function Private Function SAVE2TEMP(pCurrentMail As MailContainer) As Boolean - Dim oTempFilename As String + Dim oTempFilename As String = "" Try Dim oTempPath As String = Path.Combine(Path.GetTempPath, "DD_EmailProfiler")