MS attachmentsHandling

This commit is contained in:
SchreiberM 2024-05-08 15:21:30 +02:00
parent e0bb1d84e2
commit 92b5a72537
4 changed files with 71 additions and 29 deletions

View File

@ -45,10 +45,11 @@ Public Class clsWorkEmail
Private ReadOnly _EmailAccountID As Integer = 1
Private ReadOnly _RejectionTemplateId As Integer = 0
Private ReadOnly _InfoTemplateId As Integer = 0
Private _worked_email As Boolean = False
Sub New(LogConf As LogConfig, ConStr As String, WmConStr As String, pUseWindream As Boolean, EmailAccountID As Integer, EmlProfPraefix As String, pRejectionTemplateId As Integer)
Sub New(LogConf As LogConfig, ConStr As String, WmConStr As String, pUseWindream As Boolean, EmailAccountID As Integer, EmlProfPraefix As String, pRejectionTemplateId As Integer, pInfoTemplateId As Integer)
Try
_Logger = LogConf.GetLogger
_LogConfig = LogConf
@ -57,8 +58,10 @@ Public Class clsWorkEmail
_UseWindream = pUseWindream
_Patterns = New Patterns2(LogConf)
_RejectionTemplateId = pRejectionTemplateId
_InfoTemplateId = pInfoTemplateId
_Logger.Debug($"_RejectionTemplateId: {_RejectionTemplateId}")
If pUseWindream Then
_windream = New clsWindream_allgemein(LogConf)
_windream_index = New clsWindream_Index(LogConf)
@ -217,7 +220,32 @@ Public Class clsWorkEmail
Return False
End Try
End Function
''' <summary>
''' Method to decide wether we use the old or the new
''' Rejection E-mail method.
'''
''' TODO we have no information about the language of the receiver at the moment
''' </summary>
''' <param name="pMessageId">E-Mail Message ID</param>
''' <param name="pSTATE_TITLE">Comment</param>
''' <param name="pSTATE_TITLE1">Name oder Reason</param>
Public Function AddTrackingStatusMSSQL(pMessageId As String, pSTATE_TITLE As String, pSTATE_TITLE1 As String, pCOMMENT As String, pADDEDWHO As String) As Boolean
Dim oInsert = $"INSERT INTO [dbo].[TBEMLP_HISTORY_STATE]
([MESSAGE_ID]
,[STATE_TITLE]
,[STATE_TITLE1]
,[COMMENT]
,ADDED_WHO)
VALUES
('{pMessageId}'
,'{pSTATE_TITLE}'
,'{pSTATE_TITLE1}'
,'{pCOMMENT}'
,'{pADDEDWHO}')"
Return _DB_MSSQL.ExecuteNonQuery(oInsert)
End Function
''' <summary>
''' Method to decide wether we use the old or the new
''' Rejection E-mail method.
@ -810,11 +838,21 @@ Public Class clsWorkEmail
oATTFilename = oAttachment.SafeFileName.ToString.ToLower
Dim oValidExtensions = New List(Of String) From {"pdf", "xls", "xlsx", "doc", "docx", "ppt", "pptx"}
Dim oGraphicExtensions = New List(Of String) From {"jpg", "bmp", "jpg", "gif", "xml"}
Dim oValidExt = oValidExtensions.Any(Function(ext) oATTFilename.EndsWith(ext))
If oValidExt = False Then
_Logger.Info("Invalid FileExtension [{0}]", oATTFilename)
Dim GraphicExt = oGraphicExtensions.Any(Function(ext) oATTFilename.EndsWith(ext))
If GraphicExt = False Then
Dim oInfo = $"Consistency or extension of attached file {oATTFilename} is not ok."
AddTrackingStatusMSSQL(CurrentMail.MessageId, oInfo, "PDF CONSISTENCY NOT OK", "Info GUI", "EML_PROF_EXTR_ATT1")
AddToEmailQueueMSSQL(CurrentMail.MessageId, oInfo, "PDF CONSISTENCY NOT OK", _EmailAccountID,
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
End If
Continue For
End If
Dim oAttachmentFilePath = ""
@ -850,16 +888,12 @@ Public Class clsWorkEmail
Dim oStatus As GdPictureStatus = oGdPicturePDF.LoadFromFile(oAttachmentFilePath, True)
If oStatus <> GdPictureStatus.OK Then
oPDFConsistent = False
'ABLEHNUNG da PDF ungültig
MESSAGE_ERROR = True
System.IO.File.Delete(oAttachmentFilePath)
Dim oResult = $"PDF CONSISTENCY of File {oATTFilename} IS NOT OK "
'insert history und exit
InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oResult)
Dim oResult = $"PDF-Consistency of attached file {oATTFilename} is not ok. ({oStatus.ToString})"
AddTrackingStatusMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY NOT OK", "Info GUI", "EML_PROF_EXTR_ATT2")
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY NOT OK", _EmailAccountID,
_RejectionTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
Exit For
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
System.IO.File.Delete(oAttachmentFilePath)
Continue For
Else
Dim embeddedFileCount As Integer = oGdPicturePDF.GetEmbeddedFileCount()
If embeddedFileCount > 0 Then
@ -872,7 +906,14 @@ Public Class clsWorkEmail
oValidExt = oValidExtensions.Any(Function(ext) oEmbAttName.EndsWith(ext))
If oValidExt = False Then
_Logger.Debug("Invalid FileExtension [{0}]", oEmbAttName)
_Logger.Info("Invalid FileExtension of embedded file [{0}]", oEmbAttName)
Dim GraphicExt = oGraphicExtensions.Any(Function(ext) oEmbAttName.EndsWith(ext))
If GraphicExt = False Then
Dim oInfo = $"Consistency or extension of attached file [{oEmbAttName}] is not ok."
AddTrackingStatusMSSQL(CurrentMail.MessageId, oInfo, "Extension invalid", "Info GUI", "EML_PROF_EXTR_ATT3")
AddToEmailQueueMSSQL(CurrentMail.MessageId, oInfo, "Extension invalid", _EmailAccountID,
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oEmbAttName, "")
End If
Continue For
End If
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
@ -880,15 +921,12 @@ Public Class clsWorkEmail
Dim status As GdPictureStatus = oGdPicturePDF.ExtractEmbeddedFile(0, FileData)
If status <> GdPictureStatus.OK Or FileSize = 0 Then
oPDFConsistent = False
'ABLEHNUNG da PDF ungültig
MESSAGE_ERROR = True
System.IO.File.Delete(oAttachmentFilePath)
Dim oResult = $"Consistency or PDF-State of embedded file [{oEmbAttName}] IS NOT OK "
'insert history und exit
InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oResult)
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "Consistency or PDF-State Embedded file NOT OK", _EmailAccountID,
_RejectionTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
Exit For
Dim oResult = $"Consistency or PDF-State of embedded file [{oEmbAttName}] is not ok."
AddTrackingStatusMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY EMBEDDED FILE NOT OK", "Info GUI", "EML_PROF_EXTR_ATT4")
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY EMBEDDED FILE NOT OK", _EmailAccountID,
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oEmbAttName, "")
Continue For
End If
End If
End If
@ -900,19 +938,22 @@ Public Class clsWorkEmail
End If
Dim oFileLenth As Long = oFileInfo1.Length
If oFileLenth > 2 Then
Dim oFileLength As Long = oFileInfo1.Length
If oFileLength > 2 Then
_Logger.Info(String.Format("Attachment saved to [{0}]", oAttachmentFilePath))
InsertAttachmentHistoryEntry(pCurrentMail, oAttachment.SafeFileName, oAttachmentFileName)
oAttachmentCount += 1
Else
_Logger.Warn($"##!! oFileLenth for AttachmentObjects is <2 !!##")
_Logger.Warn($"##!! oFileLength for AttachmentObjects is <2 !!##")
Dim oResult = $"Consistency of attached file [{oAttachment.SafeFileName}] is not ok."
AddTrackingStatusMSSQL(CurrentMail.MessageId, oResult, "CONSISTENCY ATTACHED FILE NOT OK", "Info GUI", "EML_PROF_EXTR_ATT5")
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "CONSISTENCY ATTACHED FILE NOT OK", _EmailAccountID,
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oAttachment.SafeFileName, "")
Try
System.IO.File.Delete(oAttachmentFilePath)
Catch ex As Exception
_Logger.Error(ex)
End Try
MESSAGE_ERROR = True
End If
Catch ex As Exception
@ -963,7 +1004,7 @@ Public Class clsWorkEmail
_Logger.Error(ex)
_Logger.Warn("Could not delete the tempworkfile : [{0}]", _file)
End Try
ElseIf pACT = "Move" Then
ElseIf pACT = "move" Then
IO.File.Move(_file, _file.Replace("\Temp", ""))
End If

View File

@ -25,7 +25,7 @@ Public Class clsWorker
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, pRejectionTemplateId As Integer, Optional pLocalEML As String = "")
pEmailAccountID As Integer, pEmailPrefix As String, pEmailLimitationSender As String, pRejectionTemplateId As Integer, pInfoTemplateId As Integer, Optional pLocalEML As String = "")
Logger = pLogConfig.GetLogger
'ClassEmailImap = New clsEmailIMAP(pLogConfig)
Fetcher = New MailFetcher(pLogConfig)
@ -43,7 +43,7 @@ Public Class clsWorker
ClassWindreamIndex = New clsWindream_Index(pLogConfig)
End If
ClassWorkMail = New clsWorkEmail(pLogConfig, pConnectionString, pWindreamConnectionString, pUseWindream, pEmailAccountID, pEmailPrefix, pRejectionTemplateId)
ClassWorkMail = New clsWorkEmail(pLogConfig, pConnectionString, pWindreamConnectionString, pUseWindream, pEmailAccountID, pEmailPrefix, pRejectionTemplateId, pInfoTemplateId)
Encryption = New clsEncryption("!35452didalog=", pLogConfig)

View File

@ -15,6 +15,7 @@ Public Class Config
''' Siehe Tabelle DD_ECM.dbo.TBDD_EMAIL_TEMPLATE
''' </summary>
Public Property RejectionTemplateId As Integer = 0
Public Property InfoTemplateId As Integer = 0
Public Property EmailTestReceiver As String = ""
Public Property EmailTestHTML As String = ""

View File

@ -341,7 +341,7 @@ Public Class frmMain
LogConfig.Debug = True
Dim _work As New clsWorker(LogConfig, _SQLServerConString, _DBConfig.WindreamConnectionString, GUIDTextBox.Text,
ConfigManager.Config.UseWindream, ToolStripEmailAccountID2.Text, "EmailProfilerTestClient",
ConfigManager.Config.EmailSenderLimitation, ConfigManager.Config.RejectionTemplateId)
ConfigManager.Config.EmailSenderLimitation, ConfigManager.Config.RejectionTemplateId, ConfigManager.Config.InfoTemplateId)
_work.Start_WorkingProfiles()
Else
@ -349,7 +349,7 @@ Public Class frmMain
Logger.Info($"## Manual working on file {ofile} ... ")
Dim _work As New clsWorker(LogConfig, _SQLServerConString, _DBConfig.WindreamConnectionString, GUIDTextBox.Text,
ConfigManager.Config.UseWindream, ToolStripEmailAccountID2.Text, "EmailProfilerTestClient",
ConfigManager.Config.EmailSenderLimitation, ConfigManager.Config.RejectionTemplateId, ofile)
ConfigManager.Config.EmailSenderLimitation, ConfigManager.Config.RejectionTemplateId, ConfigManager.Config.InfoTemplateId, ofile.ToString)
_work.Start_WorkingProfiles(True)
Next