Add MessageId to Embedded Attachments

This commit is contained in:
Jonathan Jenne
2020-03-10 12:29:40 +01:00
parent 73c5255bd5
commit 1e02757b22
2 changed files with 75 additions and 46 deletions

View File

@@ -5,17 +5,20 @@ Imports GdPicture14
Public Class PDFAttachments
Private Logger As Logger
Private Filesystem As Filesystem.File
Private Const ZUGFERD_XML_FILENAME = "ZUGFeRD-invoice.xml"
Public Class AttachmentResult
Public FileName As String
Public FileContents As Byte()
End Class
Public Sub New(LogConfig As LogConfig, GdPictureKey As String)
Logger = LogConfig.GetLogger
Filesystem = New Filesystem.File(LogConfig)
End Sub
Public Function Extract(FileName As String, AllowedExtensions As List(Of String)) As List(Of FileInfo)
Dim oResults As New List(Of FileInfo)
Public Function Extract(FileName As String, AllowedExtensions As List(Of String)) As List(Of AttachmentResult)
Dim oResults As New List(Of AttachmentResult)
Dim oExtensions = AllowedExtensions.ConvertAll(Of String)(New Converter(Of String, String)(Function(ext) ext.ToUpper))
Try
@@ -34,21 +37,31 @@ Public Class PDFAttachments
Dim FileSize As Integer = oGDPicturePDF.GetEmbeddedFileSize(index)
If oGDPicturePDF.GetStat() = GdPictureStatus.OK Then
Dim FileData As Byte() = New Byte(FileSize) {}
Dim status As GdPictureStatus = oGDPicturePDF.ExtractEmbeddedFile(index, FileData)
Dim oFileData As Byte() = New Byte(FileSize) {}
Dim status As GdPictureStatus = oGDPicturePDF.ExtractEmbeddedFile(index, oFileData)
If status = GdPictureStatus.OK Then
Dim oVersionedName = Filesystem.GetVersionedFilename(oFileName)
Dim oTempName As String = Path.Combine(Path.GetTempPath(), oVersionedName)
Using oFileStream As New FileStream(oTempName, FileMode.OpenOrCreate)
oFileStream.Write(FileData, 0, FileData.Length)
End Using
oResults.Add(New FileInfo(oTempName))
oResults.Add(New AttachmentResult() With {
.FileContents = oFileData,
.FileName = oFileName
})
Else
Logger.Error("The embedded file [{0}] has failed to extract. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
Continue For
End If
'If status = GdPictureStatus.OK Then
' Dim oVersionedName = Filesystem.GetVersionedFilename(oFileName)
' Dim oTempName As String = Path.Combine(Path.GetTempPath(), oVersionedName)
' Using oFileStream As New FileStream(oTempName, FileMode.OpenOrCreate)
' oFileStream.Write(oFileData, 0, oFileData.Length)
' End Using
' oResults.Add(New FileInfo(oTempName))
'Else
' Logger.Error("The embedded file [{0}] has failed to extract. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
' Continue For
'End If
Else
Logger.Error("An error occurred getting the file size for [{0}]. Status: {1}", oFileName, oGDPicturePDF.GetStat().ToString())
Continue For