Integration of LimiLabs, Init

This commit is contained in:
Jonathan Jenne
2021-08-19 16:31:29 +02:00
parent d7fca23ebc
commit 3da7e37c91
6 changed files with 160 additions and 26 deletions

View File

@@ -1,22 +1,9 @@
Imports Independentsoft
Imports Limilabs.Mail
Imports Limilabs.Mail.MSG
Imports System.Text.RegularExpressions
Public Class ClassEmailHeaderExtractor
''' <summary>
''' Extrahiert die Headerinformationen aus einer .msg Datei mithilfe der MSG.NET Klasse
''' </summary>
''' <param name="path">Der Pfad einer .msg Datei</param>
''' <returns>Headerinformationen als String oder Nothing wenn ein Fehler aufgetreten ist.</returns>
Public Shared Function getMessageHeaders(path As String)
Try
Dim msg As New Msg.Message(path)
Dim headers = msg.TransportMessageHeaders.Replace(vbCrLf, " ")
Return headers
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' Extrahiert die Headerinformationen aus einem msg Objekt mithilfe der MSG.NET Klasse
''' </summary>
@@ -56,7 +43,7 @@ Public Class ClassEmailHeaderExtractor
End Function
Public Shared Function extractFromHeader(messageHeaders As String, Regex As String)
Try
Dim result
Dim result = Nothing
Dim i As Integer = 0
If IsNothing(messageHeaders) Then
Return Nothing
@@ -68,6 +55,8 @@ Public Class ClassEmailHeaderExtractor
' die Vorkommen im String auslesen
For Each myMatch As Match In myRegex.Matches(strTargetString)
If myMatch.Success Then
LOGGER.Debug("Match success. Matched Value: [{0}]", myMatch.Value)
If myMatch.Value <> "" Then
If i = 0 Then
result = myMatch.Value.ToString
@@ -76,14 +65,19 @@ Public Class ClassEmailHeaderExtractor
End If
i += 1
End If
Else
LOGGER.Debug("Match failed!")
End If
Next
LOGGER.Debug("Extracted value: [{0}]", result)
Return result
Catch ex As Exception
LOGGER.Error(ex)
MsgBox("Unexpected Error in extractFromHeader: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return Nothing
End Try
End Function
''' <summary>

View File

@@ -1,8 +1,10 @@
Imports System.IO
Imports System.Guid
Imports System.Text.RegularExpressions
Imports DevExpress.XtraEditors
Imports Independentsoft
Imports DigitalData.Modules.Language
Imports Limilabs.Mail
Public Class ClassFilehandle
Public Shared Function Decide_FileHandle(pFilename As String, pHandletype As String)
@@ -30,9 +32,9 @@ Public Class ClassFilehandle
If oResult = MsgBoxResult.Yes Then
If pHandletype.StartsWith("|FW") Then
Return Email_Decay(pFilename, True)
Return Save_EmailAndAttachmentsToDisk(pFilename, True)
Else
Return Email_Decay(pFilename)
Return Save_EmailAndAttachmentsToDisk(pFilename)
End If
End If
End If
@@ -53,6 +55,59 @@ Public Class ClassFilehandle
Return False
End Try
End Function
Private Shared Function Save_EmailAndAttachmentsToDisk(pEmailFilePath As String, Optional pFolderWatch As Boolean = False) As Boolean
Try
Dim oMessageOnlyMarker As String = "|MSGONLY|"
Dim oExtractedAttachmentMarker As String = "|ATTMNTEXTRACTED|"
If pFolderWatch = True Then
oMessageOnlyMarker = "|FW_MSGONLY|"
oExtractedAttachmentMarker = "|FW_ATTMNTEXTRACTED|"
End If
Dim oSuccess As Boolean = False
LOGGER.Info("Converting file to Eml if needed: [{0}]", pEmailFilePath)
Dim oEmailFilePath = EMAIL.Convert_MsgToEml(pEmailFilePath)
Dim oEmail As IMail = EMAIL.Load_Email(oEmailFilePath)
If oEmail.MessageID IsNot Nothing Then
CURRENT_MESSAGEID = oEmail.MessageID
Else
LOGGER.Info("Es konnte keine Message-ID gelesen werden. Eine GUID wird erzeugt!")
CURRENT_MESSAGEID = NewGuid.ToString()
End If
Dim oEmailFilePathWithoutAttachments = EMAIL.Remove_AttachmentsFromEmail(oEmailFilePath, "_excl_attachments")
TEMP_FILES.Add(oEmailFilePathWithoutAttachments)
If Insert_GI_File(oEmailFilePathWithoutAttachments, oMessageOnlyMarker) = True Then
oSuccess = True
Dim oAttachments As List(Of String) = EMAIL.Save_AttachmentsToDisk(oEmailFilePath)
LOGGER.Debug("Saved [{0}] attachments to disk.", oAttachments.Count)
For Each oAttachment In oAttachments
TEMP_FILES.Add(oAttachment)
LOGGER.Debug("Saved attachment [{0}].", oAttachment)
oSuccess = Insert_GI_File(oAttachment, oExtractedAttachmentMarker)
If oSuccess = False Then
LOGGER.Warn("Saving attachment to disk failed: [{0}]", oAttachment)
Exit For
End If
Next
End If
Return oSuccess
Catch ex As Exception
LOGGER.Warn("Saving email to disk failed (Email_Decay)")
LOGGER.Error(ex)
Return False
End Try
End Function
Private Shared Function Email_Decay(msgname As String, Optional FW As Boolean = False)
Try
Dim msgonly As String = "|MSGONLY|"
@@ -64,10 +119,10 @@ Public Class ClassFilehandle
Dim erfolgreich As Boolean = False
Dim msg As New Msg.Message(msgname)
If Not msg.InternetMessageId Is Nothing Then
If msg.InternetMessageId IsNot Nothing Then
CURRENT_MESSAGEID = msg.InternetMessageId
Else
LOGGER.Info(">> Email_Decay: Es konnte keine Message-ID gelesen werden. Eine GUID wird erzeugt!")
LOGGER.Info("Es konnte keine Message-ID gelesen werden. Eine GUID wird erzeugt!")
Dim sGUID As String
sGUID = System.Guid.NewGuid.ToString()
CURRENT_MESSAGEID = sGUID
@@ -109,6 +164,7 @@ Public Class ClassFilehandle
If tempfile <> String.Empty Then
Dim oMessage = attachment.EmbeddedMessage
oMessage.IsEmbedded = False
oMessage.Save(tempfile)
TEMP_FILES.Add(tempfile)
LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
@@ -190,7 +246,7 @@ Public Class ClassFilehandle
Try
Dim version As Integer = 1
Dim Stammname As String = Path.GetDirectoryName(Dateiname) & "\" & Path.GetFileNameWithoutExtension(Dateiname)
Dim Stammname As String = Path.GetDirectoryName(Dateiname) & "\" & Path.GetFileNameWithoutExtension(Dateiname).Trim()
extension = Path.GetExtension(Dateiname)
Dim _neuername As String = Stammname

View File

@@ -4,6 +4,7 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Messaging
Public Class ClassInit
Public _lizenzManager As ClassLicenseManager
@@ -67,6 +68,7 @@ Public Class ClassInit
configResult = Load_BasicConfig()
FILESYSTEM = New File(LOGCONFIG)
EMAIL = New Email2(LOGCONFIG)
If configResult = False Then
If USER_LANGUAGE = "de-DE" Then

View File

@@ -175,6 +175,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Messaging">
<HintPath>..\..\DDMonorepo\Modules.Messaging\bin\Debug\DigitalData.Modules.Messaging.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Windows">
<HintPath>..\..\DDMonorepo\Windows\bin\Debug\DigitalData.Modules.Windows.dll</HintPath>
</Reference>
@@ -198,6 +201,10 @@
<HintPath>P:\Visual Studio Projekte\Bibliotheken\windream\Interop.WMOTOOLLib.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Mail, Version=3.0.21189.1553, Culture=neutral, PublicKeyToken=6dc438ab78a525b3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>P:\Visual Studio Projekte\Bibliotheken\Limilabs\Mail.dll\Mail.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.10\lib\net45\NLog.dll</HintPath>
@@ -471,6 +478,7 @@
</EmbeddedResource>
<EmbeddedResource Include="frmIndexFileList.en-US.resx">
<DependentUpon>frmIndexFileList.vb</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="frmIndexFileList.en.resx">
<DependentUpon>frmIndexFileList.vb</DependentUpon>

View File

@@ -1,6 +1,7 @@
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Messaging
Module ModuleCURRENT
Public ERROR_STATE As String
@@ -16,6 +17,7 @@ Module ModuleCURRENT
Public LOGCONFIG As LogConfig
Public LOGGER As Logger
Public FILESYSTEM As File
Public EMAIL As Email2
Public CURRENT_DOKART_ID As Integer
Public CURRENT_DOKART_DUPLICATE_HANDLING As String = "Default"

View File

@@ -9,6 +9,8 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Controls.LookupGrid
Imports DigitalData.GUIs.GlobalIndexer
Imports DevExpress.XtraEditors.Controls
Imports Limilabs.Mail
Imports Limilabs.Mail.Headers
Public Class frmIndex
#Region "+++++ Variablen ++++++"
@@ -835,13 +837,13 @@ Public Class frmIndex
Next
End If
If DropType = "|OUTLOOK_MESSAGE|" Or DropType = "|FW_MSGONLY|" Or DropType = "|MSGONLY|" Or CURRENT_NEWFILENAME.EndsWith(".msg") Then
indexierung_erfolgreich = SetEmailIndices()
indexierung_erfolgreich = SetEmailIndicies(pIndexAttachment:=False)
If indexierung_erfolgreich = False Then
MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical)
Return False
End If
ElseIf DropType = "|ATTMNTEXTRACTED|" Or DropType = "|OUTLOOK_ATTACHMENT|" Then
indexierung_erfolgreich = SetAttachmentIndices()
indexierung_erfolgreich = SetEmailIndicies(pIndexAttachment:=True)
If indexierung_erfolgreich = False Then
MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical)
Return False
@@ -866,9 +868,79 @@ Public Class frmIndex
End Function
Private Function SetEmailIndices()
Private Function SetEmailIndicies(pIndexAttachment As Boolean) As Boolean
Try
Dim oMsgFilePath As String = Path.Combine("\\windream\objects", CURRENT_NEWFILENAME)
Dim oEmlFilePath As String = EMAIL.Convert_MsgToEml(oMsgFilePath)
Dim oMail As IMail = EMAIL.Load_Email(oEmlFilePath)
Dim oSQL As String = $"SELECT * FROM TBGI_OBJECTTYPE_EMAIL_INDEX WHERE OBJECTTYPE = '{CURR_DOKART_OBJECTTYPE}'"
Dim oTable As DataTable = ClassDatabase.Return_Datatable(oSQL)
If IsNothing(oTable) Then
_Logger.Info("Could not get Email Indicies for DocType = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE)
Return False
End If
If oTable.Rows.Count = 0 Then
LOGGER.Warn("Could not get Email Indicies for DocType = [{0}]. Exiting.")
Return False
End If
If oTable.Rows.Count > 1 Then
LOGGER.Warn("Got multiple rows for Email Indicies for DocType = [{0}]. Exiting.")
Return False
End If
Dim oMessageId As String = oMail.MessageID
Dim oMessageFrom As String = oMail.From.First?.Address
Dim oMessageTo As String = DirectCast(oMail.To.First, MailBox)?.Address
Dim oSubject As String = oMail.Subject
Dim oDateIn As Date = oMail.Date
Dim oRow As DataRow = oTable.Rows.Item(0)
Dim oIndexNames As New Dictionary(Of String, Object) From {
{"IDX_EMAIL_ID", oMessageId},
{"IDX_EMAIL_FROM", oMessageFrom},
{"IDX_EMAIL_TO", oMessageTo},
{"IDX_EMAIL_SUBJECT", oSubject},
{"IDX_EMAIL_DATE_IN", oDateIn}
}
If pIndexAttachment = True Then
oIndexNames.Add("IDX_CHECK_ATTACHMENT", True)
End If
For Each oIndex In oIndexNames
Try
If oIndex.Value Is Nothing OrElse oIndex.Value = String.Empty Then
Return False
End If
Dim oIndexingSuccessful = WriteIndex2File(oRow.Item(oIndex.Key), oIndex.Value)
'Die aktuelle Message-ID zwischenspeichern
CURRENT_MESSAGEID = oMessageId
If oIndexingSuccessful = False Then
MsgBox("Error in SetEmailIndices-EmailID - See log", MsgBoxStyle.Critical)
Return False
End If
Catch ex As Exception
LOGGER.Error(ex)
Return False
End Try
Next
Return True
Catch ex As Exception
LOGGER.Error(ex)
Return False
End Try
End Function
Private Function SetEmailIndicesOld()
Dim indexierung_erfolgreich As Boolean = False
Dim _step As String = "1"
Try
Dim oTempPath As String = Path.Combine("\\windream\objects", CURRENT_NEWFILENAME)
Dim msg As Msg.Message = New Msg.Message(oTempPath)
@@ -995,7 +1067,6 @@ Public Class frmIndex
_step = "5"
_Logger.Info("emailTo and From Extraction via messageheader.")
emailFrom = ClassEmailHeaderExtractor.extractFromHeader(headers, fromPattern) 'FromRegexList)
emailTo = ClassEmailHeaderExtractor.extractFromHeader(headers, toPattern) ' extractToAddress(headers, ToRegexList)
'Handler für leere emailTo-Adresse
@@ -1037,6 +1108,7 @@ Public Class frmIndex
emailTo = ClassEmailHeaderExtractor.extractFromHeader(emailTo, finalize_pattern)
emailFrom = ClassEmailHeaderExtractor.extractFromHeader(emailFrom, finalize_pattern)
_step = "6.1"
If Not IsNothing(emailFrom) Then
emailFrom = emailFrom.Replace("<", "")
emailFrom = emailFrom.Replace(">", "")