Windows: Fix Outlook drop, add DroppedFile class
This commit is contained in:
@@ -3,9 +3,9 @@ Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language.Utils
|
||||
Imports Microsoft.Office.Interop
|
||||
Imports System.Windows
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Public Class FileDrop
|
||||
Partial Public Class FileDrop
|
||||
Inherits BaseClass
|
||||
|
||||
Public Enum FileFormat
|
||||
@@ -24,51 +24,35 @@ Public Class FileDrop
|
||||
Attachment
|
||||
End Enum
|
||||
|
||||
Public Class DroppedFile
|
||||
Public ReadOnly Property FilePath As String
|
||||
Public Property FileFormat As FileFormat
|
||||
Public Property FileSource As FileSource = FileSource.DragDrop
|
||||
Public ReadOnly Property TempFileSubDirectory
|
||||
Get
|
||||
Return _TempFileSubDirectory
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub New(pFilePath As String)
|
||||
FilePath = pFilePath
|
||||
End Sub
|
||||
|
||||
Public Sub New(pFilePath As String, pDropType As String)
|
||||
MyClass.New(pFilePath)
|
||||
|
||||
Select Case pDropType
|
||||
Case "LOCAL_FILE" ' "|DROPFROMFSYSTEM|"
|
||||
FileFormat = FileFormat.LocalFile
|
||||
|
||||
Case "OUTLOOK_ATTACHMENT" ' "|OUTLOOK_ATTACHMENT|"
|
||||
FileFormat = FileFormat.OutlookAttachment
|
||||
|
||||
Case "OUTLOOK_MAIL" ' "|OUTLOOK_MESSAGE|"
|
||||
FileFormat = FileFormat.OutlookMail
|
||||
|
||||
Case "|MSGONLY|"
|
||||
FileFormat = FileFormat.MailWithoutAttachments
|
||||
|
||||
Case "|FW_OUTLOOK_MESSAGE|"
|
||||
FileFormat = FileFormat.OutlookMail
|
||||
FileSource = FileSource.FolderWatch
|
||||
|
||||
Case "|FW_SIMPLEINDEXER|"
|
||||
FileFormat = FileFormat.LocalFile
|
||||
FileSource = FileSource.FolderWatch
|
||||
|
||||
Case "|ATTMNTEXTRACTED|"
|
||||
FileFormat = FileFormat.LocalFile
|
||||
FileSource = FileSource.Attachment
|
||||
|
||||
End Select
|
||||
End Sub
|
||||
End Class
|
||||
Private _TempFileSubDirectory As String = "FileDrop"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pTempFileSubDirectory As String)
|
||||
MyClass.New(pLogConfig)
|
||||
_TempFileSubDirectory = pTempFileSubDirectory
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Public Function GetFileFormats(pEvent As DragEventArgs) As List(Of String)
|
||||
Dim oFormats As New List(Of String)
|
||||
|
||||
For Each oFormat As String In pEvent.Data.GetFormats(False)
|
||||
oFormats.Add(oFormat)
|
||||
Next
|
||||
|
||||
Return oFormats
|
||||
End Function
|
||||
|
||||
Public Function GetFileFormat(pEvent As DragEventArgs) As FileFormat
|
||||
If IsThunderbird(pEvent) Then
|
||||
If IsThunderbirdAttachment(pEvent) Then
|
||||
@@ -102,7 +86,7 @@ Public Class FileDrop
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function GetFilePaths(pEvent As DragEventArgs) As List(Of DroppedFile)
|
||||
Public Function GetFiles(pEvent As DragEventArgs) As List(Of DroppedFile)
|
||||
Try
|
||||
Dim oFormat = GetFileFormat(pEvent)
|
||||
Dim oFiles As New List(Of DroppedFile)
|
||||
@@ -119,6 +103,7 @@ Public Class FileDrop
|
||||
|
||||
Case Else
|
||||
Dim oDroppedFiles As String() = GetFormat(pEvent, "FileDrop")
|
||||
Dim oTempPath As String = GetTempPathWithSubdirectory()
|
||||
|
||||
If oDroppedFiles IsNot Nothing Then
|
||||
For Each oPath In oDroppedFiles
|
||||
@@ -140,7 +125,7 @@ Public Class FileDrop
|
||||
End Function
|
||||
|
||||
Private Function GetOutlookFilePath(pEvent As DragEventArgs) As List(Of String)
|
||||
Dim oTempPath As String = IO.Path.GetTempPath()
|
||||
Dim oTempPath As String = GetTempPathWithSubdirectory()
|
||||
Dim oFileName As String = GetOutlookFileName(pEvent)
|
||||
Dim oFilePath As String = IO.Path.Combine(oTempPath, oFileName)
|
||||
Dim oContentsList As List(Of Byte()) = GetOutlookFileContents_FromInterop(pEvent)
|
||||
@@ -221,7 +206,7 @@ Public Class FileDrop
|
||||
Logger.Info("Subject Slug: [{0}]", oSubject)
|
||||
|
||||
Dim oFileName As String = $"{oSubject}.msg"
|
||||
Dim oTempPath As String = IO.Path.GetTempPath()
|
||||
Dim oTempPath As String = GetTempPathWithSubdirectory()
|
||||
Dim oFilePath As String = IO.Path.Combine(oTempPath, oFileName)
|
||||
|
||||
oMailItem.SaveAs(oFilePath)
|
||||
@@ -262,7 +247,12 @@ Public Class FileDrop
|
||||
End Function
|
||||
|
||||
Public Function CheckFor(pEvent As DragEventArgs, pFormat As String, pAutoConvert As Boolean) As Boolean
|
||||
Dim oFormatExists = pEvent.Data.GetDataPresent(pFormat)
|
||||
Dim oFormats = pEvent.Data.GetFormats(pAutoConvert).ToList()
|
||||
Dim oFormatExists = oFormats.Any(Function(format) format = pFormat)
|
||||
|
||||
' This does not work with locally created outlook mails
|
||||
'Dim oFormatExists = pEvent.Data.GetDataPresent(pFormat)
|
||||
|
||||
Logger.Debug("Format exists: [{0}]/[{1}]", pFormat, oFormatExists)
|
||||
Return oFormatExists
|
||||
End Function
|
||||
@@ -276,12 +266,41 @@ Public Class FileDrop
|
||||
End Function
|
||||
|
||||
Public Function IsOutlook(e As DragEventArgs) As Boolean
|
||||
Return CheckFor(e, "FileGroupDescriptor") AndAlso CheckFor(e, "FileDrop")
|
||||
Return CheckFor(e, "FileGroupDescriptor") AndAlso CheckFor(e, "FileContents")
|
||||
End Function
|
||||
Public Function IsThunderbird(e As DragEventArgs) As Boolean
|
||||
Return CheckFor(e, "text/x-moz-url") AndAlso CheckFor(e, "FileDrop")
|
||||
End Function
|
||||
|
||||
Public Sub RemoveTempDirectory()
|
||||
Dim oTempPath As String = IO.Path.Combine(IO.Path.GetTempPath(), _TempFileSubDirectory)
|
||||
|
||||
If IO.Directory.Exists(oTempPath) Then
|
||||
Try
|
||||
IO.Directory.Delete(oTempPath, recursive:=True)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not delete Temp Subdirectory [{0}].", oTempPath)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function GetTempPathWithSubdirectory() As String
|
||||
Dim oTempPath As String = IO.Path.Combine(IO.Path.GetTempPath(), _TempFileSubDirectory)
|
||||
|
||||
If IO.Directory.Exists(oTempPath) = False Then
|
||||
Try
|
||||
IO.Directory.CreateDirectory(oTempPath)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Could not create Temp Subdirectory [{0}]. Returning default Temp Path.", oTempPath)
|
||||
Logger.Error(ex)
|
||||
Return IO.Path.GetTempPath()
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return oTempPath
|
||||
End Function
|
||||
|
||||
|
||||
#Region "Thunderbird"
|
||||
Private Function IsOutlookMail(e As DragEventArgs) As Boolean
|
||||
|
||||
Reference in New Issue
Block a user