Compare commits

...

3 Commits

Author SHA1 Message Date
3be1605d93 Email profiler Service: Version 3.0.3.0 2024-11-13 13:25:34 +01:00
1cb9a7ac95 EmailProfiler.Common: Version 3.0.6.0 2024-11-13 13:25:01 +01:00
167b7e1210 temp. GDPicture Lizenz-Abfrage
ExtractAttachment-Logik
2024-11-13 10:58:48 +01:00
5 changed files with 80 additions and 31 deletions

View File

@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("")> <Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("DigitalData.EMLProfiler")> <Assembly: AssemblyProduct("DigitalData.EMLProfiler")>
<Assembly: AssemblyCopyright("Copyright © 2024")> <Assembly: AssemblyCopyright("Copyright © 2024")>
<Assembly: AssemblyTrademark("3.0.5.0")> <Assembly: AssemblyTrademark("3.0.6.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("3.0.5.0")> <Assembly: AssemblyVersion("3.0.6.0")>
<Assembly: AssemblyFileVersion("3.0.5.0")> <Assembly: AssemblyFileVersion("3.0.6.0")>

View File

@ -15,6 +15,7 @@ Imports System.Data.SqlClient
Imports GdPicture14 Imports GdPicture14
Imports Limilabs.Client.IMAP Imports Limilabs.Client.IMAP
Imports System.Net.NetworkInformation Imports System.Net.NetworkInformation
Imports System.Collections.Specialized.BitVector32
Public Class clsWorkEmail Public Class clsWorkEmail
Private Const SUBJECT_MAX_LENGTH = 25 Private Const SUBJECT_MAX_LENGTH = 25
@ -222,9 +223,7 @@ Public Class clsWorkEmail
End If End If
Else Else
If IS_LOCAL_TEST = False Then
InsertHistoryEntry(CurrentMail)
End If
' Jetzt werden die ggf gefundenen Attachment-Fehler überprüft und verarbeitet ' Jetzt werden die ggf gefundenen Attachment-Fehler überprüft und verarbeitet
Dim oNormalAttachmentsNotValid As Boolean = False Dim oNormalAttachmentsNotValid As Boolean = False
@ -234,12 +233,25 @@ Public Class clsWorkEmail
Where(Function(att) att.EmbeddedFiles.Count > 0). Where(Function(att) att.EmbeddedFiles.Count > 0).
Any(Function(emb) emb.EmbeddedFiles.Any(Function(ext) ext.IsAttachmentValid = False)) Any(Function(emb) emb.EmbeddedFiles.Any(Function(ext) ext.IsAttachmentValid = False))
oNormalAttachmentsNotValid = EmailAttachments.Any(Function(ext) ext.IsAttachmentValid = False)
If oEmbeddedAttachmentsNotValid = True Then If oEmbeddedAttachmentsNotValid = True Then
Dim oRejectionCodeString = GetRejectionCodeString(CurrentMail.MessageId, ErrorCode.EmbeddedFileAttachmentCorrupt)
InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oRejectionCodeString)
AddTrackingStatusMSSQL(CurrentMail.MessageId, oRejectionCodeString, "Embedded File corrupt", "", "EMailProfiler")
SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid() SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid()
ElseIf oNormalAttachmentsNotValid = True Then
SendInfoMailToSenderIfNormalAttachmentsAreNotValid() DeleteAllCollectedAttachments()
CURRENT_ImapObject.DeleteMessageByUID(poUID)
Else
If IS_LOCAL_TEST = False Then
InsertHistoryEntry(CurrentMail)
End If
oNormalAttachmentsNotValid = EmailAttachments.Any(Function(ext) ext.IsAttachmentValid = False)
If oNormalAttachmentsNotValid = True Then
SendInfoMailToSenderIfNormalAttachmentsAreNotValid()
End If
End If End If
Return True Return True
@ -274,17 +286,14 @@ Public Class clsWorkEmail
''' <summary> ''' <summary>
''' Wenn beim Herauslösen der Attachments festgestellt wurde, ''' Wenn beim Herauslösen der Attachments festgestellt wurde,
''' das ein Teil der _normalen_ Attachments fehlerhaft war, wird der Absender hier ''' das ein PDF-Attachments korrupte Anhänge enthält war, bekommt der Absender hier
''' darüber informiert. ''' die Ablehnung.
''' </summary> ''' </summary>
Private Sub SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid() Private Sub SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid()
Dim oHtmlFilenameList As String = GetHtmlFilenameList() Dim oHtmlFilenameList As String = GetHtmlFilenameList()
If oHtmlFilenameList.IsNotNullOrEmpty() Then If oHtmlFilenameList.IsNotNullOrEmpty() Then
AddToEmailQueueMSSQL(CurrentMail.MessageId, "", "Attachment invalid", _EmailAccountID, _RejectionTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oHtmlFilenameList, "") AddToEmailQueueMSSQL(CurrentMail.MessageId, "", "Attachment invalid", _EmailAccountID, _RejectionTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oHtmlFilenameList, "")
End If End If
End Sub End Sub
@ -964,7 +973,7 @@ Public Class clsWorkEmail
End If End If
' Sichere Datei auf Platte ' Sichere Datei auf Platte
If SaveFileToDisk(oAttachment, oEmailAttachment.DestFilePath) = True Then If SaveFileToDisk(oAttachment, oEmailAttachment) = True Then
_Logger.Info(String.Format("Attachment saved to [{0}]", oEmailAttachment.DestFilePath)) _Logger.Info(String.Format("Attachment saved to [{0}]", oEmailAttachment.DestFilePath))
' Schreibe Satz nach EMLP_HISTORY ' Schreibe Satz nach EMLP_HISTORY
@ -973,7 +982,6 @@ Public Class clsWorkEmail
End If End If
Else Else
_Logger.Warn($"Error while saving AttachmentName: {oEmailAttachment.DestFilePath}") _Logger.Warn($"Error while saving AttachmentName: {oEmailAttachment.DestFilePath}")
MESSAGE_ERROR = True
Continue For Continue For
End If End If
@ -1000,15 +1008,17 @@ Public Class clsWorkEmail
End If End If
If (oEmailAttachment.ErrorCodeValue = ErrorCode.Unknown) Then
TEMP_WORK_FILES.Add(oEmailAttachment.DestFilePath) ' Wenn der Status ok ist, wird das Attachment eingetragen, sonst nicht
TEMP_WORK_FILES.Add(oEmailAttachment.DestFilePath)
End If
Next Next
CURRENT_ATTMT_COUNT = oAttachmentCount CURRENT_ATTMT_COUNT = oAttachmentCount
If MESSAGE_ERROR = True Then If MESSAGE_ERROR = True Then
WorkTempFiles("delete") WorkTempFiles("delete")
Return False Return True
End If End If
WorkTempFiles("move") WorkTempFiles("move")
@ -1050,6 +1060,11 @@ Public Class clsWorkEmail
oEmbeddedFile.ErrorCodeValue = ErrorCode.EmbeddedFileAttachmentCorrupt oEmbeddedFile.ErrorCodeValue = ErrorCode.EmbeddedFileAttachmentCorrupt
oEmbeddedFile.ErrorCodeComment = "PDF Structure corrupt" oEmbeddedFile.ErrorCodeComment = "PDF Structure corrupt"
oEmbeddedFile.IsAttachmentValid = False oEmbeddedFile.IsAttachmentValid = False
' wenn ein eingebettetes attachment defekt ist, ist das Hauptattachment auch defekt
pEmailAttachment.ErrorCodeValue = ErrorCode.NormalFileAttachmentCorrupt
pEmailAttachment.ErrorCodeComment = "PDF Structure corrupt"
pEmailAttachment.IsAttachmentValid = False
Continue For Continue For
End If End If
End If End If
@ -1058,17 +1073,20 @@ Public Class clsWorkEmail
End Sub End Sub
Private Function SaveFileToDisk(pAttachment As MimeData, pAttachmentFilePath As String) As Boolean Private Function SaveFileToDisk(pAttachment As MimeData, pAttachmentData As EmailAttachment) As Boolean
Try Try
_Logger.Debug(String.Format("Trying to save attachment [{0}]", pAttachmentFilePath)) Dim oFilePath = pAttachmentData.DestFilePath
pAttachment.Save(pAttachmentFilePath) _Logger.Debug(String.Format("Trying to save attachment [{0}]", oFilePath))
pAttachment.Save(oFilePath)
Dim oFileInfo As New FileInfo(pAttachmentFilePath) Dim oFileInfo As New FileInfo(oFilePath)
Dim oFileLength As Long = oFileInfo.Length Dim oFileLength As Long = oFileInfo.Length
If oFileLength <= 2 Then If oFileLength <= 2 Then
_Logger.Warn($"##!! oFileLength for AttachmentObjects is <=2 !!##") _Logger.Warn($"##!! oFileLength for AttachmentObjects is <= 2 !!##")
CleanUpFilePath(pAttachmentFilePath) CleanUpFilePath(oFilePath)
pAttachmentData.ErrorCodeValue = ErrorCode.NormalFileAttachmentCorrupt
pAttachmentData.ErrorCodeComment = "Filesize is zero"
Return False Return False
End If End If
@ -1076,10 +1094,14 @@ Public Class clsWorkEmail
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
MESSAGE_ERROR = True
Return False Return False
End Try End Try
End Function End Function
''' <summary>
''' Falls Datei bereits existiert, lösche sie jetzt
''' </summary>
Private Function CleanUpFilePath(pFilePath As String) As Boolean Private Function CleanUpFilePath(pFilePath As String) As Boolean
Try Try
If File.Exists(pFilePath) Then If File.Exists(pFilePath) Then
@ -1335,6 +1357,28 @@ Public Class clsWorkEmail
TEMP_WORK_FILES.Clear() TEMP_WORK_FILES.Clear()
End Sub End Sub
''' <summary>
''' Wenn eingebettete Attachments defekt sind,
''' gilt die ganze E-Mail als defekt und wird abgelehnt.
''' Hier wird noch aufgeräumt.
''' </summary>
Private Sub DeleteAllCollectedAttachments()
For Each attachment In EmailAttachments
_Logger.Debug("Delete from temp work file: [{0}]", attachment.DestFilePath)
Try
If File.Exists(attachment.DestFilePath) Then
File.Delete(attachment.DestFilePath)
End If
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Could not delete the tempworkfile : [{0}]", attachment.DestFilePath)
End Try
Next
EmailAttachments.Clear()
End Sub
Private Function InsertHistoryEntry(pCurrentMail As MailContainer) As Boolean Private Function InsertHistoryEntry(pCurrentMail As MailContainer) As Boolean
If MESSAGE_ERROR = False Then If MESSAGE_ERROR = False Then
Return InsertHistoryEntryWithStatus(pCurrentMail, String.Empty, String.Empty) Return InsertHistoryEntryWithStatus(pCurrentMail, String.Empty, String.Empty)

View File

@ -6,6 +6,7 @@ Imports DigitalData.Modules.Messaging.Mail
Imports Limilabs.Mail Imports Limilabs.Mail
Imports Limilabs.Mail.Headers Imports Limilabs.Mail.Headers
Imports System.Reflection.Emit Imports System.Reflection.Emit
Imports GdPicture14
Public Class clsWorker Public Class clsWorker
Private ReadOnly Logger As Logger Private ReadOnly Logger As Logger
@ -84,7 +85,7 @@ Public Class clsWorker
Return Database.GetDatatable(oSQL) Return Database.GetDatatable(oSQL)
End Function End Function
Public Sub Start_WorkingProfiles(Optional LocalEmail As Boolean = False) Public Sub Start_WorkingProfiles(Optional LocalEmail As Boolean = False, Optional CallFromService As Boolean = False)
Try Try
DeleteTempFiles() DeleteTempFiles()
IS_LOCAL_TEST = LocalEmail IS_LOCAL_TEST = LocalEmail
@ -107,6 +108,10 @@ Public Class clsWorker
Dim PollingProfileTable = LoadPollingProfiles(ProfileId) Dim PollingProfileTable = LoadPollingProfiles(ProfileId)
Dim oSQLGDPicture = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE ACTIVE = 1" Dim oSQLGDPicture = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE ACTIVE = 1"
If CallFromService = True Then
oSQLGDPicture = "SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE EMAIL_PROFILER'"
End If
GDPictureLicense = Database.GetScalarValue(oSQLGDPicture) GDPictureLicense = Database.GetScalarValue(oSQLGDPicture)
If IsNothing(PollingProfileTable) Then If IsNothing(PollingProfileTable) Then

View File

@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("")> <Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("SERV_EMAIL")> <Assembly: AssemblyProduct("SERV_EMAIL")>
<Assembly: AssemblyCopyright("Copyright © 2024")> <Assembly: AssemblyCopyright("Copyright © 2024")>
<Assembly: AssemblyTrademark("3.0.2.0")> <Assembly: AssemblyTrademark("3.0.3.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("3.0.2.0")> <Assembly: AssemblyVersion("3.0.3.0")>
<Assembly: AssemblyFileVersion("3.0.2.0")> <Assembly: AssemblyFileVersion("3.0.3.0")>

View File

@ -106,7 +106,7 @@ Public Class MyService
Config.EmailTitlePrefix, Config.EmailTitlePrefix,
Config.RejectionTemplateId, Config.RejectionTemplateId,
Config.InfoTemplateId) Config.InfoTemplateId)
oWorker.Start_WorkingProfiles() oWorker.Start_WorkingProfiles(False, True)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
End Try End Try