Renamed error listener to onError

This commit is contained in:
dankito 2024-11-26 02:44:54 +01:00
parent 8b7bd31cf1
commit 231da572e5
2 changed files with 7 additions and 7 deletions

View File

@ -35,13 +35,13 @@ open class EmailsFetcher(
open fun listenForNewEmails(account: EmailAccount, downloadMessageBody: Boolean = false, emailFolderName: String = "INBOX", open fun listenForNewEmails(account: EmailAccount, downloadMessageBody: Boolean = false, emailFolderName: String = "INBOX",
error: ((FetchEmailsError) -> Unit)? = null, emailReceived: (EmailWithInvoice) -> Unit) = runBlocking { onError: ((FetchEmailsError) -> Unit)? = null, emailReceived: (EmailWithInvoice) -> Unit) = runBlocking {
try { try {
connect(account) { store -> connect(account) { store ->
val folder = store.getFolder(emailFolderName) val folder = store.getFolder(emailFolderName)
folder.open(Folder.READ_ONLY) folder.open(Folder.READ_ONLY)
val status = FetchEmailsStatus(FetchEmailsOptions(downloadMessageBody)) val status = FetchEmailsStatus(FetchEmailsOptions(downloadMessageBody), onError = onError)
folder.addMessageCountListener(object : MessageCountAdapter() { folder.addMessageCountListener(object : MessageCountAdapter() {
override fun messagesAdded(event: MessageCountEvent) { override fun messagesAdded(event: MessageCountEvent) {
@ -59,7 +59,7 @@ open class EmailsFetcher(
} }
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Listening to new emails of '${account.username}' failed" } log.error(e) { "Listening to new emails of '${account.username}' failed" }
error?.invoke(FetchEmailsError(FetchEmailsErrorType.ListenForNewEmails, null, e)) onError?.invoke(FetchEmailsError(FetchEmailsErrorType.ListenForNewEmails, null, e))
} }
log.info { "Stopped listening to new emails of '${account.username}'" } log.info { "Stopped listening to new emails of '${account.username}'" }

View File

@ -7,7 +7,7 @@ import jakarta.mail.Part
data class FetchEmailsStatus( data class FetchEmailsStatus(
val options: FetchEmailsOptions, val options: FetchEmailsOptions,
val messageSpecificErrors: MutableList<FetchEmailsError> = mutableListOf(), val messageSpecificErrors: MutableList<FetchEmailsError> = mutableListOf(),
val error: ((FetchEmailsError) -> Unit)? = null val onError: ((FetchEmailsError) -> Unit)? = null
) { ) {
fun addError(type: FetchEmailsErrorType, parts: Collection<Part>, error: Throwable) = fun addError(type: FetchEmailsErrorType, parts: Collection<Part>, error: Throwable) =
@ -19,10 +19,10 @@ data class FetchEmailsStatus(
fun addError(type: FetchEmailsErrorType, messageNumber: Int?, error: Throwable) = fun addError(type: FetchEmailsErrorType, messageNumber: Int?, error: Throwable) =
addError(FetchEmailsError(type, messageNumber, error)) addError(FetchEmailsError(type, messageNumber, error))
fun addError(mailError: FetchEmailsError) { fun addError(error: FetchEmailsError) {
messageSpecificErrors.add(mailError) messageSpecificErrors.add(error)
error?.invoke(mailError) onError?.invoke(error)
} }
private fun getMessage(part: Part): Message? { private fun getMessage(part: Part): Message? {