From 2b3c3fa5fada75ffa2c9ab8f53ce83ccd441e830 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 21 Nov 2024 18:36:04 +0100 Subject: [PATCH] Fixed setting file extension and deleting file on exit --- .../src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt index eeedc46..cc2c533 100644 --- a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt +++ b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt @@ -122,8 +122,9 @@ class MailReader( if (invoice != null) { val filename = File(part.fileName) - val file = File.createTempFile(filename.nameWithoutExtension, filename.extension).also { file -> + val file = File.createTempFile(filename.nameWithoutExtension, "." + filename.extension).also { file -> part.inputStream.use { it.copyTo(file.outputStream()) } + file.deleteOnExit() } return MailAttachmentWithEInvoice(part.fileName, mediaType, invoice, file)