Added extension, size, contentType and disposition to EmailAttachment
This commit is contained in:
parent
1d7c07e7d6
commit
b28403025c
|
@ -6,10 +6,7 @@ import jakarta.mail.event.MessageCountEvent
|
|||
import jakarta.mail.internet.InternetAddress
|
||||
import jakarta.mail.internet.MimeUtility
|
||||
import kotlinx.coroutines.*
|
||||
import net.codinux.invoicing.email.model.Email
|
||||
import net.codinux.invoicing.email.model.EmailAccount
|
||||
import net.codinux.invoicing.email.model.EmailAddress
|
||||
import net.codinux.invoicing.email.model.EmailAttachment
|
||||
import net.codinux.invoicing.email.model.*
|
||||
import net.codinux.invoicing.filesystem.FileUtil
|
||||
import net.codinux.invoicing.model.Invoice
|
||||
import net.codinux.invoicing.reader.EInvoiceReader
|
||||
|
@ -198,7 +195,7 @@ open class EmailsFetcher(
|
|||
if (extension !in status.options.downloadAttachmentsWithExtensions) null
|
||||
else downloadAttachment(part, status)
|
||||
|
||||
return EmailAttachment(part.fileName, messagePart.mediaType, invoiceAndFile?.first, file)
|
||||
return EmailAttachment(part.fileName, extension, part.size.takeIf { it > 0 }, mapDisposition(part), messagePart.mediaType, part.contentType, invoiceAndFile?.first, file)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
log.error(e) { "Could not check attachment '${messagePart.part.fileName}' (${messagePart.mediaType}) for eInvoice" }
|
||||
|
@ -208,6 +205,13 @@ open class EmailsFetcher(
|
|||
return null
|
||||
}
|
||||
|
||||
private fun mapDisposition(part: Part) = when (part.disposition?.lowercase()) {
|
||||
"inline" -> ContentDisposition.Inline
|
||||
"attachment" -> ContentDisposition.Attachment
|
||||
null -> ContentDisposition.Body
|
||||
else -> ContentDisposition.Unknown
|
||||
}
|
||||
|
||||
protected open fun tryToReadEInvoice(part: Part, extension: String, mediaType: String?, status: FetchEmailsStatus): Pair<Invoice, File>? = try {
|
||||
if (extension == "pdf" || mediaType == "application/pdf" || mediaType == "application/octet-stream") {
|
||||
val file = downloadAttachment(part, status)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package net.codinux.invoicing.email.model
|
||||
|
||||
enum class ContentDisposition {
|
||||
Body,
|
||||
|
||||
Inline,
|
||||
|
||||
Attachment,
|
||||
|
||||
Unknown
|
||||
}
|
|
@ -4,13 +4,17 @@ import net.codinux.invoicing.model.Invoice
|
|||
import java.io.File
|
||||
|
||||
class EmailAttachment(
|
||||
val filename: String,
|
||||
val filename: String?,
|
||||
val extension: String?,
|
||||
val size: Int?,
|
||||
val disposition: ContentDisposition,
|
||||
/**
|
||||
* Attachment's media type like "application/xml", "application/pdf", ...
|
||||
*
|
||||
* Should always be non-null, but can theoretically be null.
|
||||
*/
|
||||
val mediaType: String?,
|
||||
val contentType: String?,
|
||||
val invoice: Invoice? = null,
|
||||
val file: File? = null
|
||||
) {
|
||||
|
|
Loading…
Reference in New Issue