Removed message body parts from attachment parts

This commit is contained in:
dankito 2024-11-26 06:05:58 +01:00
parent ccf48f7cb4
commit bb5b89fd5a
1 changed files with 13 additions and 2 deletions

View File

@ -33,6 +33,11 @@ open class EmailsFetcher(
) )
companion object {
private val MessageBodyMediaTypes = listOf("text/plain", "text/html")
}
protected val log by logger() protected val log by logger()
@ -126,8 +131,14 @@ open class EmailsFetcher(
protected open fun getEmail(message: Message, status: FetchEmailsStatus): Email? { protected open fun getEmail(message: Message, status: FetchEmailsStatus): Email? {
val parts = getAllMessageParts(message) val parts = getAllMessageParts(message)
val messageBodyParts = parts.filter { it.part.fileName == null && it.mediaType in MessageBodyMediaTypes }
val attachmentParts = parts.filter { it !in messageBodyParts }
val attachments = parts.mapNotNull { part -> if (attachmentParts.any { it.mediaType in MessageBodyMediaTypes }) {
log.info { "Ups, that does not seem to be a message part" }
}
val attachments = attachmentParts.mapNotNull { part ->
findAttachment(part, status) findAttachment(part, status)
} }
@ -135,7 +146,7 @@ open class EmailsFetcher(
message.from?.joinToString(), message.subject ?: "", message.from?.joinToString(), message.subject ?: "",
message.sentDate?.let { map(it) }, map(message.receivedDate), message.messageNumber, message.sentDate?.let { map(it) }, map(message.receivedDate), message.messageNumber,
parts.any { it.mediaType == "application/pgp-encrypted" }, parts.any { it.mediaType == "application/pgp-encrypted" },
getPlainTextBody(parts, status), getHtmlBody(parts, status), getPlainTextBody(messageBodyParts, status), getHtmlBody(messageBodyParts, status),
attachments attachments
) )