Implemented configuring attachments download folder
This commit is contained in:
parent
b3f6f2dbc3
commit
4dc9b43189
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue