MS Common VS 3.0
This commit is contained in:
@@ -46,10 +46,11 @@ Public Class ClassCurrent
|
||||
Public Shared Property CURRENT_DOC_ID As Integer
|
||||
Public Shared Property CURRENT_DOC_PATH As String
|
||||
Public Shared Property MESSAGE_ERROR As Boolean = False
|
||||
Public Shared Property IS_LOCAL_TEST As Boolean = False
|
||||
|
||||
Public Shared Property TEMP_FILES As List(Of String) = New List(Of String)
|
||||
|
||||
|
||||
Public Shared Property TEMP_WORK_FILES As List(Of String) = New List(Of String)
|
||||
|
||||
|
||||
End Class
|
||||
|
||||
@@ -65,6 +65,9 @@
|
||||
<Reference Include="DigitalData.Modules.Patterns">
|
||||
<HintPath>..\..\..\DDModules\Patterns\bin\Debug\DigitalData.Modules.Patterns.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="GdPicture.NET.14">
|
||||
<HintPath>D:\ProgramFiles\GdPicture.net 14\Redist\GdPicture.NET (.NET Framework 4.5)\GdPicture.NET.14.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Interop.WINDREAMLib">
|
||||
<HintPath>P:\Visual Studio Projekte\Bibliotheken\windream\Interop.WINDREAMLib.dll</HintPath>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.15.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.15.0.0")>
|
||||
<Assembly: AssemblyVersion("3.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("3.0.0.0")>
|
||||
|
||||
9
App/EmailProfiler.Common/UserConfig.xml
Normal file
9
App/EmailProfiler.Common/UserConfig.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<Debug>true</Debug>
|
||||
<EmailAccountId>2</EmailAccountId>
|
||||
<EmailTitlePrefix>EmailProfiler</EmailTitlePrefix>
|
||||
<EmailSenderLimitation />
|
||||
<UseWindream>false</UseWindream>
|
||||
<RejectionTemplateId>1</RejectionTemplateId>
|
||||
</Config>
|
||||
@@ -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
|
||||
|
||||
@@ -67,6 +67,7 @@ Public Class clsWorker
|
||||
TEMP_FILES.Clear()
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function LoadEmailAccounts() As DataTable
|
||||
Return Database.GetDatatable("SELECT * FROM TBDD_EMAIL_ACCOUNT WHERE ACTIVE = 1")
|
||||
End Function
|
||||
@@ -86,7 +87,7 @@ Public Class clsWorker
|
||||
Public Sub Start_WorkingProfiles(Optional LocalEmail As Boolean = False)
|
||||
Try
|
||||
DeleteTempFiles()
|
||||
|
||||
IS_LOCAL_TEST = LocalEmail
|
||||
If Database.DBInitialized = False Then
|
||||
Logger.Warn("Database is not initialized. Exiting.")
|
||||
Exit Sub
|
||||
@@ -197,7 +198,10 @@ Public Class clsWorker
|
||||
If LocalEmail Then
|
||||
Logger.Info("Working with local Mail")
|
||||
Dim oEmail As IMail = New MailBuilder().CreateFromEmlFile(LocalEmlFile)
|
||||
ClassWorkMail.WorkEmailMessage(oEmail, 123456789, oValidationSql)
|
||||
|
||||
|
||||
Dim oUID = String.Concat(Now.Month.ToString, Now.Day, Now.Hour, Now.Minute, Now.Second)
|
||||
ClassWorkMail.WorkEmailMessage(oEmail, oUID, oValidationSql)
|
||||
'CURRENT_MAIL_MESSAGE = Nothing
|
||||
Else
|
||||
Try
|
||||
|
||||
Reference in New Issue
Block a user