Moved getAllMessageParts() to end
This commit is contained in:
parent
6d206b25f0
commit
a2d34e217f
|
@ -8,7 +8,6 @@ import jakarta.mail.Session
|
|||
import jakarta.mail.Store
|
||||
import jakarta.mail.event.MessageCountAdapter
|
||||
import jakarta.mail.event.MessageCountEvent
|
||||
import jakarta.mail.internet.MimeMultipart
|
||||
import kotlinx.coroutines.*
|
||||
import net.codinux.invoicing.model.Invoice
|
||||
import net.codinux.invoicing.reader.EInvoiceReader
|
||||
|
@ -123,25 +122,6 @@ class MailReader(
|
|||
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? {
|
||||
try {
|
||||
val part = messagePart.part
|
||||
|
@ -178,6 +158,26 @@ class MailReader(
|
|||
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.
|
||||
* - text/html; charset=utf-8
|
||||
|
|
Loading…
Reference in New Issue