diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/EmailsFetcher.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/EmailsFetcher.kt index 6484e1e..e1d5621 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/EmailsFetcher.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/EmailsFetcher.kt @@ -154,9 +154,8 @@ open class EmailsFetcher( if (invoice != null || Part.ATTACHMENT.equals(part.description, ignoreCase = true)) { val file = if (extension !in status.options.downloadAttachmentsWithExtensions) null else { - File.createTempFile(filename.nameWithoutExtension, "." + extension).also { file -> + File(status.options.attachmentsDownloadDirectory, part.fileName).also { file -> part.inputStream.use { it.copyTo(file.outputStream()) } - file.deleteOnExit() } } diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/FetchEmailsOptions.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/FetchEmailsOptions.kt index d9bb88e..b0faf91 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/FetchEmailsOptions.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/FetchEmailsOptions.kt @@ -1,6 +1,8 @@ package net.codinux.invoicing.email import net.codinux.invoicing.email.model.Email +import java.io.File +import java.nio.file.Files open class FetchEmailsOptions( val downloadMessageBody: Boolean = false, @@ -8,6 +10,7 @@ open class FetchEmailsOptions( * Set the extension (without the dot) of files that should be downloaded. */ val downloadAttachmentsWithExtensions: List = DefaultDownloadedAttachmentsWithExtensions, + val attachmentsDownloadDirectory: File = DefaultAttachmentsDownloadDirectory, val emailFolderName: String = "INBOX", val onError: ((FetchEmailsError) -> Unit)? = null, @@ -15,6 +18,8 @@ open class FetchEmailsOptions( ) { companion object { val DefaultDownloadedAttachmentsWithExtensions = listOf("pdf", "xml") + + val DefaultAttachmentsDownloadDirectory: File = Files.createTempDirectory("eInvoices").toFile() } fun emailReceived(email: Email) { diff --git a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/ListenForNewMailsOptions.kt b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/ListenForNewMailsOptions.kt index 812e507..60eddd7 100644 --- a/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/ListenForNewMailsOptions.kt +++ b/e-invoice-domain/src/main/kotlin/net/codinux/invoicing/email/ListenForNewMailsOptions.kt @@ -1,6 +1,7 @@ package net.codinux.invoicing.email import net.codinux.invoicing.email.model.Email +import java.io.File import java.util.concurrent.atomic.AtomicBoolean open class ListenForNewMailsOptions( @@ -8,8 +9,9 @@ open class ListenForNewMailsOptions( downloadMessageBody: Boolean = false, downloadAttachmentsWithExtensions: List = DefaultDownloadedAttachmentsWithExtensions, + attachmentsDownloadDirectory: File = DefaultAttachmentsDownloadDirectory, emailFolderName: String = "INBOX", onError: ((FetchEmailsError) -> Unit)? = null, onEmailReceived: (Email) -> Unit -) : FetchEmailsOptions(downloadMessageBody, downloadAttachmentsWithExtensions, emailFolderName, onError, onEmailReceived) \ No newline at end of file +) : FetchEmailsOptions(downloadMessageBody, downloadAttachmentsWithExtensions, attachmentsDownloadDirectory, emailFolderName, onError, onEmailReceived) \ No newline at end of file