Messaging: Correctly save emails without attachments as eml
This commit is contained in:
parent
847c7575c4
commit
9899f6867d
@ -290,7 +290,7 @@ Public Class Email2
|
|||||||
''' <returns>The path of the new EML without attachments.</returns>
|
''' <returns>The path of the new EML without attachments.</returns>
|
||||||
Public Function Remove_AttachmentsFromEmail(pFileName As String, Optional pSuffix As String = "") As String
|
Public Function Remove_AttachmentsFromEmail(pFileName As String, Optional pSuffix As String = "") As String
|
||||||
Try
|
Try
|
||||||
Dim oTempPath As String = Path.Combine(Path.GetTempPath(), Add_FilenameSuffix(pFileName, pSuffix))
|
Dim oTempPath As String = Path.Combine(Path.GetTempPath(), Add_FilenameSuffix(pFileName, pSuffix, ".eml"))
|
||||||
Dim oCleanedPath As String = FileEx.GetCleanPath(oTempPath)
|
Dim oCleanedPath As String = FileEx.GetCleanPath(oTempPath)
|
||||||
Dim oVersionedPath As String = FileEx.GetVersionedFilename(oCleanedPath)
|
Dim oVersionedPath As String = FileEx.GetVersionedFilename(oCleanedPath)
|
||||||
Dim oEmlPath As String = MaybeConvert_MsgToEml(pFileName)
|
Dim oEmlPath As String = MaybeConvert_MsgToEml(pFileName)
|
||||||
@ -412,20 +412,28 @@ Public Class Email2
|
|||||||
|
|
||||||
Private Function DoConvertMsgToEmlFile(pMsgFile As String) As String
|
Private Function DoConvertMsgToEmlFile(pMsgFile As String) As String
|
||||||
Try
|
Try
|
||||||
|
Logger.Debug("Converting Msg file to Eml: [{0}]", pMsgFile?.ToString)
|
||||||
|
|
||||||
Dim oTempPath As String = IO.Path.GetTempPath()
|
Dim oTempPath As String = IO.Path.GetTempPath()
|
||||||
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(pMsgFile)
|
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(pMsgFile)
|
||||||
Dim oFileNameWithoutInvalidChars = Language.Utils.RemoveInvalidCharacters(oFileNameWithoutExtension)
|
Dim oFileNameWithoutInvalidChars = Language.Utils.RemoveInvalidCharacters(oFileNameWithoutExtension)
|
||||||
Dim oEmlPath As String = IO.Path.Combine(oTempPath, $"{oFileNameWithoutInvalidChars}.eml")
|
Dim oEmlPath As String = IO.Path.Combine(oTempPath, $"{oFileNameWithoutInvalidChars}.eml")
|
||||||
Dim oVersionedPath As String = FileEx.GetVersionedFilename(oEmlPath)
|
Dim oVersionedPath As String = FileEx.GetVersionedFilename(oEmlPath)
|
||||||
|
|
||||||
|
Logger.Debug("New Path for Eml file: [{0}]", oVersionedPath)
|
||||||
|
|
||||||
Using oConverter As New MsgConverter(pMsgFile)
|
Using oConverter As New MsgConverter(pMsgFile)
|
||||||
|
Logger.Debug("Converter created")
|
||||||
Dim oEmail As IMail = oConverter.CreateMessage()
|
Dim oEmail As IMail = oConverter.CreateMessage()
|
||||||
|
Logger.Debug("Message created")
|
||||||
Dim oData As Byte() = oEmail.Render()
|
Dim oData As Byte() = oEmail.Render()
|
||||||
|
Logger.Debug("Message rendered")
|
||||||
|
|
||||||
oEmail.Save(oVersionedPath)
|
oEmail.Save(oVersionedPath)
|
||||||
|
Logger.Debug("Message saved")
|
||||||
End Using
|
End Using
|
||||||
|
|
||||||
|
Logger.Info("Msg File successfully converted to Eml: [{0}]", oVersionedPath)
|
||||||
TempFiles.Add(oVersionedPath)
|
TempFiles.Add(oVersionedPath)
|
||||||
Return oVersionedPath
|
Return oVersionedPath
|
||||||
|
|
||||||
@ -437,16 +445,20 @@ Public Class Email2
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function Add_FilenameSuffix(pFilename As String, pSuffix As String)
|
Private Function Add_FilenameSuffix(pFilename As String, pSuffix As String, Optional pExtension As String = Nothing)
|
||||||
Dim oFileInfo As New FileInfo(pFilename)
|
Dim oFileInfo As New FileInfo(pFilename)
|
||||||
Dim oExtension As String = oFileInfo.Extension
|
Dim oExtension As String = oFileInfo.Extension
|
||||||
|
|
||||||
|
If pExtension IsNot Nothing Then
|
||||||
|
If pExtension.StartsWith(".") = False Then
|
||||||
|
oExtension = $".{pExtension}"
|
||||||
|
Else
|
||||||
|
oExtension = pExtension
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
|
||||||
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(pFilename)
|
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(pFilename)
|
||||||
|
|
||||||
Return $"{oFileNameWithoutExtension}{pSuffix}{oExtension}"
|
Return $"{oFileNameWithoutExtension}{pSuffix}{oExtension}"
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user