Implemented configuring attachments download folder

This commit is contained in:
dankito 2024-11-26 04:06:22 +01:00
parent b3f6f2dbc3
commit 4dc9b43189
3 changed files with 9 additions and 3 deletions

View File

@ -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()
}
}

View File

@ -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<String> = 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) {

View File

@ -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<String> = DefaultDownloadedAttachmentsWithExtensions,
attachmentsDownloadDirectory: File = DefaultAttachmentsDownloadDirectory,
emailFolderName: String = "INBOX",
onError: ((FetchEmailsError) -> Unit)? = null,
onEmailReceived: (Email) -> Unit
) : FetchEmailsOptions(downloadMessageBody, downloadAttachmentsWithExtensions, emailFolderName, onError, onEmailReceived)
) : FetchEmailsOptions(downloadMessageBody, downloadAttachmentsWithExtensions, attachmentsDownloadDirectory, emailFolderName, onError, onEmailReceived)