Version 2.4.2.2 - Remove Independentsoft Email, Replace with Limilabs.Mail, Remove manual Email Data Exctraction, Support Eml Files

This commit is contained in:
Jonathan Jenne
2021-08-23 10:47:04 +02:00
parent 3da7e37c91
commit 0704b07de7
11 changed files with 604 additions and 580 deletions

View File

@@ -2,18 +2,16 @@
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)
Try
If pFilename.EndsWith(".msg") Then
If pFilename.ToUpper.EndsWith(".MSG") Or pFilename.ToUpper.EndsWith(".EML") Then
CURRENT_MESSAGEID = ""
Dim oMsg As New Msg.Message(pFilename)
If oMsg.Attachments.Count > 0 Then
Dim oMail As IMail = EMAIL.Load_Email(pFilename)
If oMail.Attachments.Count > 0 Then
Dim oTitle As String
Dim oMessage As String
@@ -67,8 +65,7 @@ Public Class ClassFilehandle
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)
Dim oEmail As IMail = EMAIL.Load_Email(pEmailFilePath)
If oEmail.MessageID IsNot Nothing Then
CURRENT_MESSAGEID = oEmail.MessageID
@@ -77,13 +74,13 @@ Public Class ClassFilehandle
CURRENT_MESSAGEID = NewGuid.ToString()
End If
Dim oEmailFilePathWithoutAttachments = EMAIL.Remove_AttachmentsFromEmail(oEmailFilePath, "_excl_attachments")
Dim oEmailFilePathWithoutAttachments = EMAIL.Remove_AttachmentsFromEmail(pEmailFilePath, "_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)
Dim oAttachments As List(Of String) = EMAIL.Save_AttachmentsToDisk(pEmailFilePath)
LOGGER.Debug("Saved [{0}] attachments to disk.", oAttachments.Count)
@@ -108,91 +105,91 @@ Public Class ClassFilehandle
End Try
End Function
Private Shared Function Email_Decay(msgname As String, Optional FW As Boolean = False)
Try
Dim msgonly As String = "|MSGONLY|"
Dim ATT_EXTR As String = "|ATTMNTEXTRACTED|"
If FW = True Then
msgonly = "|FW_MSGONLY|"
ATT_EXTR = "|FW_ATTMNTEXTRACTED|"
End If
Dim erfolgreich As Boolean = False
Dim msg As New Msg.Message(msgname)
'Private Shared Function Email_Decay(msgname As String, Optional FW As Boolean = False)
' Try
' Dim msgonly As String = "|MSGONLY|"
' Dim ATT_EXTR As String = "|ATTMNTEXTRACTED|"
' If FW = True Then
' msgonly = "|FW_MSGONLY|"
' ATT_EXTR = "|FW_ATTMNTEXTRACTED|"
' End If
' Dim erfolgreich As Boolean = False
' Dim msg As New MSG.Message(msgname)
If msg.InternetMessageId IsNot Nothing Then
CURRENT_MESSAGEID = msg.InternetMessageId
Else
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
End If
' If msg.InternetMessageId IsNot Nothing Then
' CURRENT_MESSAGEID = msg.InternetMessageId
' Else
' 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
' End If
'Nur die MSGDatei ablegen
Dim tempfile As String = Path.Combine(Path.GetTempPath, Path.GetFileNameWithoutExtension(msgname) & "_excl_att.msg")
' 'Nur die MSGDatei ablegen
' Dim tempfile As String = Path.Combine(Path.GetTempPath, Path.GetFileNameWithoutExtension(msgname) & "_excl_att.msg")
If File.Exists(tempfile) Then
File.Delete(tempfile)
End If
Dim _msgEXAtt As New Msg.Message(msgname)
_msgEXAtt.Attachments.Clear()
_msgEXAtt.Save(tempfile)
'Datei in Array zum Templöschen speichern
TEMP_FILES.Add(tempfile)
' If File.Exists(tempfile) Then
' File.Delete(tempfile)
' End If
' Dim _msgEXAtt As New Msg.Message(msgname)
' _msgEXAtt.Attachments.Clear()
' _msgEXAtt.Save(tempfile)
' 'Datei in Array zum Templöschen speichern
' TEMP_FILES.Add(tempfile)
If Insert_GI_File(tempfile, msgonly) = True Then
erfolgreich = True
'Hier nun die Anhänge herauslösen
Dim _msg As New Msg.Message(msgname)
Dim i1 As Integer = 1
' If Insert_GI_File(tempfile, msgonly) = True Then
' erfolgreich = True
' 'Hier nun die Anhänge herauslösen
' Dim _msg As New Msg.Message(msgname)
' Dim i1 As Integer = 1
LOGGER.Info(">> Anzahl der Attachments: " & _msg.Attachments.Count)
For Each attachment As Independentsoft.Msg.Attachment In _msg.Attachments
If erfolgreich = False Then
Exit For
End If
Dim attachment_name As String
If attachment.LongFileName Is Nothing Then
attachment_name = attachment.DisplayName
Else
attachment_name = attachment.LongFileName
End If
If attachment.EmbeddedMessage IsNot Nothing Then
attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
tempfile = Path.Combine(Path.GetTempPath, attachment_name & ".msg")
tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
' LOGGER.Info(">> Anzahl der Attachments: " & _msg.Attachments.Count)
' For Each attachment As Independentsoft.Msg.Attachment In _msg.Attachments
' If erfolgreich = False Then
' Exit For
' End If
' Dim attachment_name As String
' If attachment.LongFileName Is Nothing Then
' attachment_name = attachment.DisplayName
' Else
' attachment_name = attachment.LongFileName
' End If
' If attachment.EmbeddedMessage IsNot Nothing Then
' attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
' tempfile = Path.Combine(Path.GetTempPath, attachment_name & ".msg")
' tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
If tempfile <> String.Empty Then
Dim oMessage = attachment.EmbeddedMessage
oMessage.IsEmbedded = False
oMessage.Save(tempfile)
TEMP_FILES.Add(tempfile)
LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
i1 += 1
End If
ElseIf Not attachment_name.Contains("inline") Then
'Sonderzeichen entfernen
attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
tempfile = Path.Combine(Path.GetTempPath, attachment_name)
tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
If tempfile <> "" Then
attachment.Save(tempfile)
'Datei in Array zum Templöschen speichern
TEMP_FILES.Add(tempfile)
LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
'nun der Insert des Anhanges
erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
i1 += 1
End If
End If
Next
End If
Return erfolgreich
Catch ex As Exception
MsgBox("Error in Email_Decay: " & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
' If tempfile <> String.Empty Then
' Dim oMessage = attachment.EmbeddedMessage
' oMessage.IsEmbedded = False
' oMessage.Save(tempfile)
' TEMP_FILES.Add(tempfile)
' LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
' erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
' i1 += 1
' End If
' ElseIf Not attachment_name.Contains("inline") Then
' 'Sonderzeichen entfernen
' attachment_name = Utils.RemoveInvalidCharacters(attachment_name)
' tempfile = Path.Combine(Path.GetTempPath, attachment_name)
' tempfile = ClassFilehandle.Versionierung_Datei(tempfile)
' If tempfile <> "" Then
' attachment.Save(tempfile)
' 'Datei in Array zum Templöschen speichern
' TEMP_FILES.Add(tempfile)
' LOGGER.Info(">> Attachment (" & i1 & "):" & tempfile)
' 'nun der Insert des Anhanges
' erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
' i1 += 1
' End If
' End If
' Next
' End If
' Return erfolgreich
' Catch ex As Exception
' MsgBox("Error in Email_Decay: " & ex.Message, MsgBoxStyle.Critical)
' End Try
'End Function
Private Shared Function Insert_GI_File(filename As String, handleType As String)
Try
@@ -201,7 +198,7 @@ Public Class ClassFilehandle
Dim oHash As String = String.Empty
If File.Exists(filename) Then
If filename.ToUpper.EndsWith(".MSG") And (handleType = "|OUTLOOK_MESSAGE|" Or handleType = "|MSGONLY|") Then
If (filename.ToUpper.EndsWith(".MSG") Or filename.ToUpper.EndsWith(".EML")) And (handleType = "|OUTLOOK_MESSAGE|" Or handleType = "|MSGONLY|") Then
oHash = FILESYSTEM.GetChecksumFromString(filename)
Else
oHash = FILESYSTEM.GetChecksum(filename)