100 lines
4.4 KiB
VB.net
100 lines
4.4 KiB
VB.net
Imports System.IO
|
|
Imports Independentsoft
|
|
|
|
Public Class ClassFilehandle
|
|
Public Shared Function Decide_FileHandle(filename As String, handletype As String)
|
|
Try
|
|
If filename.EndsWith(".msg") Then
|
|
CURRENT_MESSAGEID = ""
|
|
Dim _msg As New Msg.Message(filename)
|
|
If _msg.Attachments.Count > 0 Then
|
|
Dim result As MsgBoxResult
|
|
result = MessageBox.Show("Achtung: Die Email enthält Anhänge!" & vbNewLine & "Wollen Sie die Anhänge separat indexieren und herauslösen?", "Nachfrage zur Indexierung:", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
|
If result = MsgBoxResult.Yes Then
|
|
If handletype.StartsWith("@FW") Then
|
|
Return Email_Decay(filename, True)
|
|
Else
|
|
Return Email_Decay(filename)
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
Return Insert_GI_File(filename, handletype)
|
|
Catch ex As Exception
|
|
MsgBox("Unexpected Error in Decide_FileHandle: " & ex.Message, MsgBoxStyle.Critical)
|
|
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@"
|
|
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 Not msg.InternetMessageId Is Nothing Then
|
|
CURRENT_MESSAGEID = msg.InternetMessageId
|
|
End If
|
|
|
|
'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)
|
|
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 LogErrorsOnly = False Then ClassLogger.Add(">> Anzahl der Attachments: " & _msg.Attachments.Count, False)
|
|
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 Not attachment_name.Contains("inline") Then
|
|
tempfile = Path.Combine(Path.GetTempPath, attachment_name)
|
|
If File.Exists(tempfile) Then
|
|
File.Delete(tempfile)
|
|
End If
|
|
attachment.Save(tempfile)
|
|
If LogErrorsOnly = False Then ClassLogger.Add(">> Attachment (" & i1 & "):" & tempfile, False)
|
|
'nun der Insert des Anhanges
|
|
erfolgreich = Insert_GI_File(tempfile, ATT_EXTR)
|
|
i1 += 1
|
|
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
|
|
Dim filename_only As String = Path.GetFileName(filename)
|
|
|
|
Dim ins As String = "INSERT INTO TBGI_FILES_USER (FILENAME2WORK, USER@WORK,HANDLE_TYPE,FILENAME_ONLY) VALUES ('" & filename & "','" & Environment.UserName & "','" & handleType & "','" & filename_only & "')"
|
|
Return ClassDatabase.Execute_non_Query(ins, True)
|
|
|
|
Catch ex As Exception
|
|
Return False
|
|
End Try
|
|
End Function
|
|
End Class
|