Moved getAllMessageParts() to end

This commit is contained in:
dankito 2024-11-21 21:48:24 +01:00
parent 6d206b25f0
commit a2d34e217f
1 changed files with 20 additions and 20 deletions

View File

@ -8,7 +8,6 @@ import jakarta.mail.Session
import jakarta.mail.Store import jakarta.mail.Store
import jakarta.mail.event.MessageCountAdapter import jakarta.mail.event.MessageCountAdapter
import jakarta.mail.event.MessageCountEvent import jakarta.mail.event.MessageCountEvent
import jakarta.mail.internet.MimeMultipart
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.codinux.invoicing.model.Invoice import net.codinux.invoicing.model.Invoice
import net.codinux.invoicing.reader.EInvoiceReader import net.codinux.invoicing.reader.EInvoiceReader
@ -123,25 +122,6 @@ class MailReader(
return null return null
} }
private fun getAllMessageParts(part: Part): List<MessagePart> {
return if (part.isMimeType("multipart/*")) {
val multipart = part.content as Multipart
val parts = IntRange(0, multipart.count - 1).map { multipart.getBodyPart(it) }
parts.flatMap { subPart ->
getAllMessageParts(subPart)
}
} else {
val mediaType = getMediaType(part)
if (mediaType == null) {
log.warn { "Could not determine media type of message part $part" }
emptyList()
} else {
listOf(MessagePart(mediaType, part))
}
}
}
private fun findEInvoice(messagePart: MessagePart): MailAttachmentWithEInvoice? { private fun findEInvoice(messagePart: MessagePart): MailAttachmentWithEInvoice? {
try { try {
val part = messagePart.part val part = messagePart.part
@ -178,6 +158,26 @@ class MailReader(
null null
} }
private fun getAllMessageParts(part: Part): List<MessagePart> {
return if (part.isMimeType("multipart/*")) {
val multipart = part.content as Multipart
val parts = IntRange(0, multipart.count - 1).map { multipart.getBodyPart(it) }
parts.flatMap { subPart ->
getAllMessageParts(subPart)
}
} else {
val mediaType = getMediaType(part)
if (mediaType == null) {
log.warn { "Could not determine media type of message part $part" }
emptyList()
} else {
listOf(MessagePart(mediaType, part))
}
}
}
/** /**
* In most cases parameters are added to content-type's media type, e.g. * In most cases parameters are added to content-type's media type, e.g.
* - text/html; charset=utf-8 * - text/html; charset=utf-8