diff --git a/App/EmailProfiler.Common/clsWorkEmail.vb b/App/EmailProfiler.Common/clsWorkEmail.vb
index 44c391c..6733daa 100644
--- a/App/EmailProfiler.Common/clsWorkEmail.vb
+++ b/App/EmailProfiler.Common/clsWorkEmail.vb
@@ -15,6 +15,7 @@ Imports System.Data.SqlClient
Imports GdPicture14
Imports Limilabs.Client.IMAP
Imports System.Net.NetworkInformation
+Imports System.Collections.Specialized.BitVector32
Public Class clsWorkEmail
Private Const SUBJECT_MAX_LENGTH = 25
@@ -222,9 +223,7 @@ Public Class clsWorkEmail
End If
Else
- If IS_LOCAL_TEST = False Then
- InsertHistoryEntry(CurrentMail)
- End If
+
' Jetzt werden die ggf gefundenen Attachment-Fehler überprüft und verarbeitet
Dim oNormalAttachmentsNotValid As Boolean = False
@@ -234,12 +233,25 @@ Public Class clsWorkEmail
Where(Function(att) att.EmbeddedFiles.Count > 0).
Any(Function(emb) emb.EmbeddedFiles.Any(Function(ext) ext.IsAttachmentValid = False))
- oNormalAttachmentsNotValid = EmailAttachments.Any(Function(ext) ext.IsAttachmentValid = False)
-
If oEmbeddedAttachmentsNotValid = True Then
+ Dim oRejectionCodeString = GetRejectionCodeString(CurrentMail.MessageId, ErrorCode.EmbeddedFileAttachmentCorrupt)
+ InsertHistoryEntryWithStatus(CurrentMail, "REJECTED", oRejectionCodeString)
+ AddTrackingStatusMSSQL(CurrentMail.MessageId, oRejectionCodeString, "Embedded File corrupt", "", "EMailProfiler")
+
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
Return True
@@ -274,17 +286,14 @@ Public Class clsWorkEmail
'''
''' Wenn beim Herauslösen der Attachments festgestellt wurde,
- ''' das ein Teil der _normalen_ Attachments fehlerhaft war, wird der Absender hier
- ''' darüber informiert.
+ ''' das ein PDF-Attachments korrupte Anhänge enthält war, bekommt der Absender hier
+ ''' die Ablehnung.
'''
Private Sub SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid()
Dim oHtmlFilenameList As String = GetHtmlFilenameList()
-
If oHtmlFilenameList.IsNotNullOrEmpty() Then
-
AddToEmailQueueMSSQL(CurrentMail.MessageId, "", "Attachment invalid", _EmailAccountID, _RejectionTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oHtmlFilenameList, "")
-
End If
End Sub
@@ -964,7 +973,7 @@ Public Class clsWorkEmail
End If
' 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))
' Schreibe Satz nach EMLP_HISTORY
@@ -973,7 +982,6 @@ Public Class clsWorkEmail
End If
Else
_Logger.Warn($"Error while saving AttachmentName: {oEmailAttachment.DestFilePath}")
- MESSAGE_ERROR = True
Continue For
End If
@@ -1000,15 +1008,17 @@ Public Class clsWorkEmail
End If
-
- TEMP_WORK_FILES.Add(oEmailAttachment.DestFilePath)
+ If (oEmailAttachment.ErrorCodeValue = ErrorCode.Unknown) Then
+ ' Wenn der Status ok ist, wird das Attachment eingetragen, sonst nicht
+ TEMP_WORK_FILES.Add(oEmailAttachment.DestFilePath)
+ End If
Next
CURRENT_ATTMT_COUNT = oAttachmentCount
If MESSAGE_ERROR = True Then
WorkTempFiles("delete")
- Return False
+ Return True
End If
WorkTempFiles("move")
@@ -1050,6 +1060,11 @@ Public Class clsWorkEmail
oEmbeddedFile.ErrorCodeValue = ErrorCode.EmbeddedFileAttachmentCorrupt
oEmbeddedFile.ErrorCodeComment = "PDF Structure corrupt"
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
End If
End If
@@ -1058,17 +1073,20 @@ Public Class clsWorkEmail
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
- _Logger.Debug(String.Format("Trying to save attachment [{0}]", pAttachmentFilePath))
- pAttachment.Save(pAttachmentFilePath)
+ Dim oFilePath = pAttachmentData.DestFilePath
+ _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
If oFileLength <= 2 Then
- _Logger.Warn($"##!! oFileLength for AttachmentObjects is <=2 !!##")
- CleanUpFilePath(pAttachmentFilePath)
+ _Logger.Warn($"##!! oFileLength for AttachmentObjects is <= 2 !!##")
+ CleanUpFilePath(oFilePath)
+ pAttachmentData.ErrorCodeValue = ErrorCode.NormalFileAttachmentCorrupt
+ pAttachmentData.ErrorCodeComment = "Filesize is zero"
Return False
End If
@@ -1076,10 +1094,14 @@ Public Class clsWorkEmail
Catch ex As Exception
_Logger.Error(ex)
+ MESSAGE_ERROR = True
Return False
End Try
End Function
+ '''
+ ''' Falls Datei bereits existiert, lösche sie jetzt
+ '''
Private Function CleanUpFilePath(pFilePath As String) As Boolean
Try
If File.Exists(pFilePath) Then
@@ -1335,6 +1357,28 @@ Public Class clsWorkEmail
TEMP_WORK_FILES.Clear()
End Sub
+ '''
+ ''' Wenn eingebettete Attachments defekt sind,
+ ''' gilt die ganze E-Mail als defekt und wird abgelehnt.
+ ''' Hier wird noch aufgeräumt.
+ '''
+ 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
If MESSAGE_ERROR = False Then
Return InsertHistoryEntryWithStatus(pCurrentMail, String.Empty, String.Empty)
diff --git a/App/EmailProfiler.Common/clsWorker.vb b/App/EmailProfiler.Common/clsWorker.vb
index a1c1598..70cad43 100644
--- a/App/EmailProfiler.Common/clsWorker.vb
+++ b/App/EmailProfiler.Common/clsWorker.vb
@@ -6,6 +6,7 @@ Imports DigitalData.Modules.Messaging.Mail
Imports Limilabs.Mail
Imports Limilabs.Mail.Headers
Imports System.Reflection.Emit
+Imports GdPicture14
Public Class clsWorker
Private ReadOnly Logger As Logger
@@ -84,7 +85,7 @@ Public Class clsWorker
Return Database.GetDatatable(oSQL)
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
DeleteTempFiles()
IS_LOCAL_TEST = LocalEmail
@@ -107,6 +108,10 @@ Public Class clsWorker
Dim PollingProfileTable = LoadPollingProfiles(ProfileId)
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)
If IsNothing(PollingProfileTable) Then
diff --git a/App/EmailProfiler.Service/MyService.vb b/App/EmailProfiler.Service/MyService.vb
index 373c4f4..2bec176 100644
--- a/App/EmailProfiler.Service/MyService.vb
+++ b/App/EmailProfiler.Service/MyService.vb
@@ -106,7 +106,7 @@ Public Class MyService
Config.EmailTitlePrefix,
Config.RejectionTemplateId,
Config.InfoTemplateId)
- oWorker.Start_WorkingProfiles()
+ oWorker.Start_WorkingProfiles(False, True)
Catch ex As Exception
Logger.Error(ex)
End Try