MS Common VS 3.0
This commit is contained in:
@@ -12,6 +12,9 @@ Imports Limilabs.Mail.Headers
|
||||
Imports MailBox = Limilabs.Mail.Headers.MailBox
|
||||
Imports DigitalData.Modules.Patterns
|
||||
Imports System.Data.SqlClient
|
||||
Imports GdPicture14
|
||||
Imports System.Net.WebRequestMethods
|
||||
Imports Limilabs.Client.IMAP
|
||||
|
||||
Public Class clsWorkEmail
|
||||
Private Const SUBJECT_MAX_LENGTH = 25
|
||||
@@ -121,7 +124,7 @@ Public Class clsWorkEmail
|
||||
Dim oSql = $"Select COALESCE(MAX(GUID),0) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{CurrentMail.MessageId}'"
|
||||
Dim oHistoryID = _DB_MSSQL.GetScalarValue(oSql)
|
||||
|
||||
If oHistoryID > 0 Then
|
||||
If oHistoryID > 0 And IS_LOCAL_TEST = False Then
|
||||
_Logger.Info($"Message with subject [{CURRENT_MAIL_SUBJECT}] from [{CURRENT_MAIL_FROM}] has already been worked!")
|
||||
Return True
|
||||
End If
|
||||
@@ -137,7 +140,7 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim oFS As FileStream = File.OpenRead(CurrentTempMailPath)
|
||||
Dim oFS As FileStream = System.IO.File.OpenRead(CurrentTempMailPath)
|
||||
oTempMailAccessible = True
|
||||
oFS.Close()
|
||||
Catch ex As Exception
|
||||
@@ -200,7 +203,9 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
|
||||
Else
|
||||
InsertHistoryEntry(CurrentMail)
|
||||
If IS_LOCAL_TEST = False Then
|
||||
InsertHistoryEntry(CurrentMail)
|
||||
End If
|
||||
End If
|
||||
|
||||
Return True
|
||||
@@ -553,7 +558,7 @@ Public Class clsWorkEmail
|
||||
End Try
|
||||
|
||||
If COPY2HDD(pCurrentMail, oRow("COPY_2_HDD"), oRow("PATH_ORIGINAL"), oRow("PATH_EMAIL_ERRORS"), True) = True Then
|
||||
'ToDo Konsistenz prüfen
|
||||
|
||||
If EXTRACT_ATTACHMENTS(pCurrentMail, oExtractMainPath, oRow("PATH_EMAIL_ERRORS")) = True Then
|
||||
|
||||
Return True
|
||||
@@ -591,7 +596,7 @@ Public Class clsWorkEmail
|
||||
Dim oFileName As String
|
||||
For Each oFileName In oFileEntries
|
||||
Try
|
||||
File.Delete(oFileName)
|
||||
System.IO.File.Delete(oFileName)
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
Next oFileName
|
||||
@@ -613,7 +618,7 @@ Public Class clsWorkEmail
|
||||
|
||||
Dim oCounter As Integer = 1
|
||||
Dim oCancel As Boolean
|
||||
Do While File.Exists(CurrentTempMailPath) = False
|
||||
Do While System.IO.File.Exists(CurrentTempMailPath) = False
|
||||
_Logger.Debug("Trying to read saved mail.. ({0}/{1})", oCounter, 10)
|
||||
Thread.Sleep(1000)
|
||||
oCounter += 1
|
||||
@@ -626,7 +631,7 @@ Public Class clsWorkEmail
|
||||
If oCancel = True Then
|
||||
oResult = False
|
||||
Else
|
||||
If File.Exists(CurrentTempMailPath) Then
|
||||
If System.IO.File.Exists(CurrentTempMailPath) Then
|
||||
oResult = True
|
||||
End If
|
||||
End If
|
||||
@@ -651,7 +656,7 @@ Public Class clsWorkEmail
|
||||
If Directory.Exists(pDestination) Then
|
||||
Dim oTempFilename = Path.Combine(pDestination, $"{pCurrentMail.MessageId}.eml")
|
||||
|
||||
If File.Exists(oTempFilename) = False Then
|
||||
If System.IO.File.Exists(oTempFilename) = False Then
|
||||
|
||||
pCurrentMail.Mail.Save(oTempFilename)
|
||||
|
||||
@@ -664,7 +669,7 @@ Public Class clsWorkEmail
|
||||
Else
|
||||
_Logger.Warn("FileLenth of file [{0}] is 0! File will be deleted.", oTempFilename)
|
||||
Try
|
||||
File.Delete(oTempFilename)
|
||||
System.IO.File.Delete(oTempFilename)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
@@ -795,19 +800,20 @@ Public Class clsWorkEmail
|
||||
_Logger.Debug(String.Format("PATH_TEMP[{0}]", pExtractPath))
|
||||
Dim oAttachmentCount As Integer
|
||||
oAttachmentCount = 0
|
||||
TEMP_WORK_FILES.Clear()
|
||||
|
||||
Try
|
||||
If CurrentTempMailPath <> Nothing Then
|
||||
If File.Exists(CurrentTempMailPath) Then
|
||||
|
||||
If System.IO.File.Exists(CurrentTempMailPath) Then
|
||||
Dim oATTFilename = ""
|
||||
For Each oAttachment As MimeData In pCurrentMail.Mail.Attachments
|
||||
Dim oATTFilename = oAttachment.SafeFileName.ToString.ToLower
|
||||
oATTFilename = oAttachment.SafeFileName.ToString.ToLower
|
||||
|
||||
Dim oValidExtensions = New List(Of String) From {"pdf", "xls", "xlsx", "doc", "docx", "ppt", "pptx"}
|
||||
Dim oValidExt = oValidExtensions.Any(Function(ext) oATTFilename.EndsWith(ext))
|
||||
|
||||
If oValidExt = False Then
|
||||
_Logger.Debug("Invalid FileExtension [{0}]", oATTFilename)
|
||||
_Logger.Info("Invalid FileExtension [{0}]", oATTFilename)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
@@ -815,7 +821,6 @@ Public Class clsWorkEmail
|
||||
_Logger.Info("Working on Attachment [{0}]", oAttachment.SafeFileName)
|
||||
Try
|
||||
|
||||
|
||||
Dim oFileInfo = New FileInfo(oAttachment.SafeFileName)
|
||||
Dim oFilenameWithoutExtension = Path.GetFileNameWithoutExtension(oAttachment.SafeFileName)
|
||||
Dim oFilename = StringEx.ConvertTextToSlug(oFilenameWithoutExtension) & oFileInfo.Extension
|
||||
@@ -825,45 +830,104 @@ Public Class clsWorkEmail
|
||||
|
||||
_Logger.Debug("Final Filename for Attachment: [{0}]", oAttachmentFileName)
|
||||
|
||||
oAttachmentFilePath = Path.Combine(pExtractPath, oAttachmentFileName)
|
||||
oAttachmentFilePath = Path.Combine(pExtractPath, "Temp", oAttachmentFileName)
|
||||
_Logger.Debug("Final Path for Attachment: [{0}]", oAttachmentFilePath)
|
||||
|
||||
If File.Exists(oAttachmentFilePath) = False Then
|
||||
_Logger.Debug(String.Format("Trying to save attachment [{0}]", oAttachmentFilePath))
|
||||
Try
|
||||
oAttachment.Save(oAttachmentFilePath)
|
||||
'oAttachment.Save(oAttachmentFileString)
|
||||
Dim oFileInfo1 As New FileInfo(oAttachmentFilePath)
|
||||
Dim oFileLenth As Long = oFileInfo1.Length
|
||||
If oFileLenth > 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 !!##")
|
||||
Try
|
||||
File.Delete(oAttachmentFilePath)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
If System.IO.File.Exists(oAttachmentFilePath) Then
|
||||
_Logger.Warn("File [{0}] already exists!", oAttachmentFilePath)
|
||||
System.IO.File.Delete(oAttachmentFilePath)
|
||||
End If
|
||||
|
||||
_Logger.Debug(String.Format("Trying to save attachment [{0}]", oAttachmentFilePath))
|
||||
Try
|
||||
oAttachment.Save(oAttachmentFilePath)
|
||||
'oAttachment.Save(oAttachmentFileString)
|
||||
Dim oFileInfo1 As New FileInfo(oAttachmentFilePath)
|
||||
'ToDo Konsistenz prüfen
|
||||
If oFileInfo.Extension.ToLower = ".pdf" Then
|
||||
Dim oPDFConsistent As Boolean = True
|
||||
Dim oGdPicturePDF As New GdPicturePDF()
|
||||
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)
|
||||
AddToEmailQueueMSSQL(CurrentMail.MessageId, oResult, "PDF CONSISTENCY NOT OK", _EmailAccountID,
|
||||
_RejectionTemplateId, ErrorCode.PDFStructureCorrupt, oATTFilename, "")
|
||||
Exit For
|
||||
|
||||
Else
|
||||
Dim embeddedFileCount As Integer = oGdPicturePDF.GetEmbeddedFileCount()
|
||||
If embeddedFileCount > 0 Then
|
||||
For i As Integer = 0 To embeddedFileCount - 1
|
||||
Dim oEmbAttName As String = oGdPicturePDF.GetEmbeddedFileName(i)
|
||||
Dim fileDetail As IO.FileInfo
|
||||
fileDetail = My.Computer.FileSystem.GetFileInfo(oEmbAttName)
|
||||
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
Dim FileSize As Integer = oGdPicturePDF.GetEmbeddedFileSize(i)
|
||||
oValidExt = oValidExtensions.Any(Function(ext) oEmbAttName.EndsWith(ext))
|
||||
|
||||
If oValidExt = False Then
|
||||
_Logger.Debug("Invalid FileExtension [{0}]", oEmbAttName)
|
||||
Continue For
|
||||
End If
|
||||
If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
|
||||
Dim FileData As Byte() = New Byte(FileSize) {}
|
||||
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
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Warn($"Error while saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFilePath}")
|
||||
MESSAGE_ERROR = True
|
||||
|
||||
End Try
|
||||
Else
|
||||
_Logger.Warn("File [{0}] already exists!", oAttachmentFilePath)
|
||||
oAttachmentCount += 1
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Dim oFileLenth As Long = oFileInfo1.Length
|
||||
If oFileLenth > 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 !!##")
|
||||
Try
|
||||
System.IO.File.Delete(oAttachmentFilePath)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
MESSAGE_ERROR = True
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Warn($"Error while saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFilePath}")
|
||||
MESSAGE_ERROR = True
|
||||
|
||||
End Try
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Warn($"Error while creating and saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFilePath}")
|
||||
MESSAGE_ERROR = True
|
||||
|
||||
End Try
|
||||
TEMP_WORK_FILES.Add(oAttachmentFilePath)
|
||||
Next
|
||||
Else
|
||||
_Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CurrentTempMailPath} not existing")
|
||||
@@ -873,9 +937,13 @@ Public Class clsWorkEmail
|
||||
End If
|
||||
CURRENT_ATTMT_COUNT = oAttachmentCount
|
||||
If MESSAGE_ERROR = True Then
|
||||
WorkTempFiles("delete")
|
||||
Return False
|
||||
|
||||
Else
|
||||
WorkTempFiles("move")
|
||||
Return True
|
||||
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
@@ -883,6 +951,26 @@ Public Class clsWorkEmail
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Sub WorkTempFiles(pACT As String)
|
||||
For Each _file In TEMP_WORK_FILES
|
||||
_Logger.Debug("Working on temp work file: [{0}]", _file)
|
||||
|
||||
If IO.File.Exists(_file) Then
|
||||
If pACT = "Delete" Then
|
||||
Try
|
||||
IO.File.Delete(_file)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_Logger.Warn("Could not delete the tempworkfile : [{0}]", _file)
|
||||
End Try
|
||||
ElseIf pACT = "Move" Then
|
||||
IO.File.Move(_file, _file.Replace("\Temp", ""))
|
||||
End If
|
||||
|
||||
End If
|
||||
Next
|
||||
TEMP_WORK_FILES.Clear()
|
||||
End Sub
|
||||
|
||||
Private Function InsertHistoryEntry(pCurrentMail As MailContainer) As Boolean
|
||||
If MESSAGE_ERROR = False Then
|
||||
|
||||
Reference in New Issue
Block a user