Mapping sent to Instant; also mapping received and messageNumber

This commit is contained in:
dankito 2024-11-21 17:02:38 +01:00
parent 07fdbec5d7
commit b09b7cf69b
2 changed files with 14 additions and 9 deletions

View File

@ -15,8 +15,7 @@ import net.codinux.invoicing.reader.EInvoiceReader
import net.codinux.log.logger
import org.eclipse.angus.mail.imap.IMAPFolder
import java.io.File
import java.time.LocalDate
import java.time.ZoneId
import java.time.Instant
import java.util.*
import java.util.concurrent.Executors
@ -101,7 +100,11 @@ class MailReader(
}
if (attachmentsWithEInvoice.isNotEmpty()) {
return@mapNotNull MailWithInvoice(message.from.joinToString(), message.subject, map(message.sentDate), attachmentsWithEInvoice)
return@mapNotNull MailWithInvoice(
message.from.joinToString(), message.subject,
map(message.sentDate), map(message.receivedDate), message.messageNumber,
attachmentsWithEInvoice
)
}
}
} catch (e: Throwable) {
@ -153,9 +156,8 @@ class MailReader(
null
}
// TODO: same code as in MustangMapper
private fun map(date: Date): LocalDate =
date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
private fun map(date: Date): Instant =
date.toInstant()
private fun <T> connect(account: MailAccount, connected: (Store) -> T?): T? {

View File

@ -1,12 +1,15 @@
package net.codinux.invoicing.mail
import java.time.LocalDate
import java.time.Instant
import java.time.ZoneId
class MailWithInvoice(
val sender: String,
val subject: String,
val date: LocalDate,
val sent: Instant,
val received: Instant,
val messageNumber: Int,
val attachmentsWithEInvoice: List<MailAttachmentWithEInvoice>
) {
override fun toString() = "$date $sender: $subject, ${attachmentsWithEInvoice.size} invoices"
override fun toString() = "${sent.atZone(ZoneId.systemDefault()).toLocalDate()} $sender: $subject, ${attachmentsWithEInvoice.size} invoice(s)"
}