From 7e112404a0330aa4e126167ea070c250ddafe82c Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 21 Nov 2024 19:30:46 +0100 Subject: [PATCH] Extracted findEInvoice(Message) --- .../kotlin/net/codinux/invoicing/mail/MailReader.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt index 835beb0..2f9958f 100644 --- a/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt +++ b/e-invoicing-domain/src/main/kotlin/net/codinux/invoicing/mail/MailReader.kt @@ -91,6 +91,10 @@ class MailReader( // tried to parallelize reading messages by reading them on multiple thread but that had no effect on process duration (don't know why) private fun listAllMessagesWithEInvoiceInFolder(folder: Folder): List = folder.messages.mapNotNull { message -> + findEInvoice(message) + } + + private fun findEInvoice(message: Message): MailWithInvoice? { try { val parts = getAllMessageParts(message) @@ -99,17 +103,17 @@ class MailReader( } if (attachmentsWithEInvoice.isNotEmpty()) { - return@mapNotNull MailWithInvoice( + return MailWithInvoice( message.from.joinToString(), message.subject, message.sentDate?.let { map(it) }, map(message.receivedDate), message.messageNumber, attachmentsWithEInvoice ) } } catch (e: Throwable) { - log.error(e) { "Could not read mail $message" } + log.error(e) { "Could not read message $message" } } - null + return null } private fun getAllMessageParts(part: Part): List {