EMailprofiler.Common: Auswertung ob Attachments valide sind, oder nicht.
Defekte Embedded Attachments führen zu einer Ablehnung, sonst Info an Absender
This commit is contained in:
parent
01eaf9922b
commit
6b0d247c8e
@ -8,9 +8,9 @@ Public Class EmailAttachment
|
||||
|
||||
Public FileStatus As GdPictureStatus = GdPictureStatus.OK
|
||||
|
||||
Public IsValidExtension As Boolean = True
|
||||
Public SendInfoMailNecessary As Boolean = False
|
||||
Public IsAttachmentValid As Boolean = True
|
||||
Public ErrorCodeValue As ErrorCode = ErrorCode.Unknown
|
||||
Public ErrorCodeComment As String = ""
|
||||
|
||||
Public EmbeddedFiles As List(Of EmailAttachment) = New List(Of EmailAttachment)
|
||||
|
||||
|
||||
@ -50,22 +50,22 @@
|
||||
<HintPath>..\packages\AE.Net.Mail.1.7.10.0\lib\net45\AE.Net.Mail.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Base">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Base\bin\Debug\DigitalData.Modules.Base.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Base\bin\Debug\DigitalData.Modules.Base.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Database">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Language">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Language\bin\Debug\DigitalData.Modules.Language.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Language\bin\Debug\DigitalData.Modules.Language.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Logging">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Messaging">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Messaging\bin\Debug\DigitalData.Modules.Messaging.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Messaging\bin\Debug\DigitalData.Modules.Messaging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Patterns">
|
||||
<HintPath>..\..\..\2_DLL Projekte\DDModules\Patterns\bin\Debug\DigitalData.Modules.Patterns.dll</HintPath>
|
||||
<HintPath>..\..\..\DDModules\Patterns\bin\Debug\DigitalData.Modules.Patterns.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="GdPicture.NET.14, Version=14.2.90.0, Culture=neutral, PublicKeyToken=f52a2e60ad468dbb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\GdPicture.14.2.90\lib\net462\GdPicture.NET.14.dll</HintPath>
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
Unknown = 0
|
||||
NoAttachments = 10001
|
||||
SenderValidationFailed = 10002
|
||||
PDFStructureCorrupt = 10003
|
||||
FileExtensionNotValid = 10004
|
||||
EmbeddedFileAttachmentCorrupt = 10003
|
||||
NormalFileAttachmentCorrupt = 10004 ' Info Mail
|
||||
End Enum
|
||||
|
||||
@ -227,12 +227,29 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
|
||||
' Jetzt werden die ggf gefundenen Attachment-Fehler überprüft und verarbeitet
|
||||
SendMailToSenderIfAttachmentsAreNotValid()
|
||||
Dim oNormalAttachmentsNotValid As Boolean = False
|
||||
Dim oEmbeddedAttachmentsNotValid As Boolean = False
|
||||
|
||||
oEmbeddedAttachmentsNotValid = EmailAttachments.
|
||||
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
|
||||
SendRejectionMailToSenderIfEmbeddedAttachmentsAreNotValid()
|
||||
ElseIf oNormalAttachmentsNotValid = True Then
|
||||
SendInfoMailToSenderIfNormalAttachmentsAreNotValid()
|
||||
End If
|
||||
|
||||
Return True
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
' Wenn er bis hierin kommt, wird es schon gepasst haben
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return False
|
||||
@ -241,16 +258,32 @@ Public Class clsWorkEmail
|
||||
|
||||
''' <summary>
|
||||
''' Wenn beim Herauslösen der Attachments festgestellt wurde,
|
||||
''' das ein Teil der Attachments fehlerhaft war, wird der Absender hier
|
||||
''' das ein Teil der _normalen_ Attachments fehlerhaft war, wird der Absender hier
|
||||
''' darüber informiert.
|
||||
''' </summary>
|
||||
Private Sub SendMailToSenderIfAttachmentsAreNotValid()
|
||||
Private Sub SendInfoMailToSenderIfNormalAttachmentsAreNotValid()
|
||||
|
||||
Dim oHtmlFilenameList As String = GetHtmlFilenameList()
|
||||
|
||||
If oHtmlFilenameList.IsNotNullOrEmpty() Then
|
||||
|
||||
AddToEmailQueueMSSQL(CurrentMail.MessageId, "", "Attachment invalid", _EmailAccountID, _InfoTemplateId, ErrorCode.PDFStructureCorrupt, oHtmlFilenameList, "")
|
||||
AddToEmailQueueMSSQL(CurrentMail.MessageId, "", "Attachment invalid", _EmailAccountID, _InfoTemplateId, ErrorCode.NormalFileAttachmentCorrupt, oHtmlFilenameList, "")
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Wenn beim Herauslösen der Attachments festgestellt wurde,
|
||||
''' das ein Teil der _normalen_ Attachments fehlerhaft war, wird der Absender hier
|
||||
''' darüber informiert.
|
||||
''' </summary>
|
||||
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
|
||||
@ -261,14 +294,15 @@ Public Class clsWorkEmail
|
||||
''' </summary>
|
||||
Private Function GetHtmlFilenameList() As String
|
||||
Dim filenameHtmlString As String = String.Empty
|
||||
Dim oComment As String = String.Empty
|
||||
|
||||
For Each attachmentItem In EmailAttachments
|
||||
|
||||
If attachmentItem.SendInfoMailNecessary = True Then
|
||||
Dim oEmbeddedAttachmentsInvalid As Boolean = False
|
||||
oEmbeddedAttachmentsInvalid = attachmentItem.EmbeddedFiles.Any(Function(emb) emb.IsAttachmentValid = False)
|
||||
|
||||
oComment = GetErrorCodeComment(attachmentItem.ErrorCodeValue)
|
||||
AddTrackingStatusMSSQL(CurrentMail.MessageId, attachmentItem.OrgFileName, "FILE CONSISTENCY NOT OK", oComment, "EMail Profiler")
|
||||
If attachmentItem.IsAttachmentValid = False Or oEmbeddedAttachmentsInvalid = True Then
|
||||
|
||||
AddTrackingStatusMSSQL(CurrentMail.MessageId, attachmentItem.OrgFileName, "FILE CONSISTENCY NOT OK", attachmentItem.ErrorCodeComment, "EMail Profiler")
|
||||
|
||||
filenameHtmlString += "<li>" + attachmentItem.OrgFileName + "</li>"
|
||||
End If
|
||||
@ -278,10 +312,9 @@ Public Class clsWorkEmail
|
||||
If attachmentItem.EmbeddedFiles.Count > 0 Then
|
||||
|
||||
For Each embeddedItem In attachmentItem.EmbeddedFiles
|
||||
If embeddedItem.SendInfoMailNecessary = True Then
|
||||
If embeddedItem.IsAttachmentValid = False Then
|
||||
|
||||
oComment = GetErrorCodeComment(embeddedItem.ErrorCodeValue)
|
||||
AddTrackingStatusMSSQL(CurrentMail.MessageId, embeddedItem.OrgFileName, "EMBEDDED FILE CONSISTENCY NOT OK", oComment, "EMail Profiler")
|
||||
AddTrackingStatusMSSQL(CurrentMail.MessageId, embeddedItem.OrgFileName, "EMBEDDED FILE CONSISTENCY NOT OK", embeddedItem.ErrorCodeComment, "EMail Profiler")
|
||||
|
||||
embeddedFilenamesHtmlString += "<li>" + embeddedItem.OrgFileName + "</li>"
|
||||
End If
|
||||
@ -305,19 +338,6 @@ Public Class clsWorkEmail
|
||||
Return filenameHtmlString
|
||||
End Function
|
||||
|
||||
Private Function GetErrorCodeComment(errorCodeValue As ErrorCode) As String
|
||||
|
||||
Dim retValue As String = String.Empty
|
||||
|
||||
If errorCodeValue = ErrorCode.FileExtensionNotValid Then
|
||||
retValue = "File Extension not valid"
|
||||
ElseIf errorCodeValue = ErrorCode.PDFStructureCorrupt Then
|
||||
retValue = "PDF Structure corrupt"
|
||||
End If
|
||||
|
||||
Return retValue
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Method to decide wether we use the old or the new
|
||||
''' Rejection E-mail method.
|
||||
@ -927,6 +947,7 @@ Public Class clsWorkEmail
|
||||
EmailAttachments.Add(oEmailAttachment)
|
||||
|
||||
If ValidateFileExtension(oEmailAttachment) = False Then
|
||||
oEmailAttachment.ErrorCodeValue = ErrorCode.NormalFileAttachmentCorrupt
|
||||
Continue For
|
||||
End If
|
||||
|
||||
@ -969,8 +990,9 @@ Public Class clsWorkEmail
|
||||
oAttachmentCount -= 1
|
||||
CleanUpFilePath(oEmailAttachment.DestFilePath)
|
||||
oEmailAttachment.FileStatus = oStatus
|
||||
oEmailAttachment.ErrorCodeValue = ErrorCode.PDFStructureCorrupt
|
||||
oEmailAttachment.SendInfoMailNecessary = True
|
||||
oEmailAttachment.ErrorCodeValue = ErrorCode.NormalFileAttachmentCorrupt
|
||||
oEmailAttachment.ErrorCodeComment = "PDF Structure corrupt"
|
||||
oEmailAttachment.IsAttachmentValid = False
|
||||
|
||||
MESSAGE_ERROR = True
|
||||
Continue For
|
||||
@ -1014,6 +1036,7 @@ Public Class clsWorkEmail
|
||||
oEmbeddedFile.FileStatus = pGDPicturePDF.GetStat()
|
||||
If oEmbeddedFile.FileStatus = GdPictureStatus.OK Then
|
||||
If ValidateFileExtension(oEmbeddedFile) = False Then
|
||||
oEmbeddedFile.ErrorCodeValue = ErrorCode.EmbeddedFileAttachmentCorrupt
|
||||
Continue For
|
||||
End If
|
||||
|
||||
@ -1024,8 +1047,9 @@ Public Class clsWorkEmail
|
||||
|
||||
oEmbeddedFile.FileStatus = status
|
||||
If status <> GdPictureStatus.OK Or FileSize = 0 Then
|
||||
oEmbeddedFile.ErrorCodeValue = ErrorCode.PDFStructureCorrupt
|
||||
oEmbeddedFile.SendInfoMailNecessary = True
|
||||
oEmbeddedFile.ErrorCodeValue = ErrorCode.EmbeddedFileAttachmentCorrupt
|
||||
oEmbeddedFile.ErrorCodeComment = "PDF Structure corrupt"
|
||||
oEmbeddedFile.IsAttachmentValid = False
|
||||
Continue For
|
||||
End If
|
||||
End If
|
||||
@ -1094,11 +1118,10 @@ Public Class clsWorkEmail
|
||||
Dim oIsGraphicExtension = _GraphicExtensions.Any(Function(ext) lowerFilename.EndsWith(ext))
|
||||
|
||||
If oIsValidExtension = False Then
|
||||
pAttachmentData.IsValidExtension = False
|
||||
If oIsGraphicExtension = False Then
|
||||
_Logger.Warn("File has no valid extension, and it has no graphic extension. In this case we have to inform the sender!")
|
||||
pAttachmentData.SendInfoMailNecessary = True
|
||||
pAttachmentData.ErrorCodeValue = ErrorCode.FileExtensionNotValid
|
||||
pAttachmentData.IsAttachmentValid = False
|
||||
pAttachmentData.ErrorCodeComment = "File Extension not valid"
|
||||
End If
|
||||
|
||||
Return False
|
||||
@ -1107,6 +1130,9 @@ Public Class clsWorkEmail
|
||||
Return True
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Diese Funktion wird nicht mehr verwendet!!!!
|
||||
''' </summary>
|
||||
Private Function EXTRACT_ATTACHMENTS(pCurrentMail As MailContainer, pExtractPath As String, pErrorPath As String)
|
||||
_Logger.Debug("In EXTRACT_ATTACHMENTS...")
|
||||
|
||||
@ -1133,7 +1159,7 @@ Public Class clsWorkEmail
|
||||
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, "")
|
||||
_InfoTemplateId, ErrorCode.NormalFileAttachmentCorrupt, oATTFilename, "")
|
||||
|
||||
End If
|
||||
Continue For
|
||||
@ -1185,7 +1211,7 @@ Public Class clsWorkEmail
|
||||
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,
|
||||
_InfoTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
|
||||
_InfoTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oATTFilename, "")
|
||||
File.Delete(oAttachmentFilePath)
|
||||
Continue For
|
||||
Else
|
||||
@ -1206,7 +1232,7 @@ Public Class clsWorkEmail
|
||||
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, "")
|
||||
_InfoTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oEmbAttName, "")
|
||||
End If
|
||||
Continue For
|
||||
End If
|
||||
@ -1219,7 +1245,7 @@ Public Class clsWorkEmail
|
||||
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, "")
|
||||
_InfoTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oEmbAttName, "")
|
||||
Continue For
|
||||
End If
|
||||
End If
|
||||
@ -1242,7 +1268,7 @@ Public Class clsWorkEmail
|
||||
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, "")
|
||||
_InfoTemplateId, ErrorCode.EmbeddedFileAttachmentCorrupt, oAttachment.SafeFileName, "")
|
||||
Try
|
||||
File.Delete(oAttachmentFilePath)
|
||||
Catch ex As Exception
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user