Renamed FetchEmailsError to FetchEmailError

This commit is contained in:
dankito 2024-11-28 03:41:14 +01:00
parent 9480bc0282
commit 54a5227fb7
7 changed files with 17 additions and 17 deletions

View File

@ -62,7 +62,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" }
options.onError?.invoke(FetchEmailsError(FetchEmailsErrorType.ListenForNewEmails, null, e)) options.onError?.invoke(FetchEmailError(FetchEmailErrorType.ListenForNewEmails, null, e))
} }
} }
@ -206,7 +206,7 @@ open class EmailsFetcher(
} }
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not check attachment '${messagePart.part.fileName}' (${messagePart.mediaType}) for eInvoice" } log.error(e) { "Could not check attachment '${messagePart.part.fileName}' (${messagePart.mediaType}) for eInvoice" }
status.addError(FetchEmailsErrorType.GetAttachment, messagePart.part, e) status.addError(FetchEmailErrorType.GetAttachment, messagePart.part, e)
} }
return null return null
@ -307,7 +307,7 @@ open class EmailsFetcher(
} }
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not get message body for media type '$mediaType'" } log.error(e) { "Could not get message body for media type '$mediaType'" }
status.addError(FetchEmailsErrorType.GetMesssageBody, parts.map { it.part }, e) status.addError(FetchEmailErrorType.GetMesssageBody, parts.map { it.part }, e)
null null
} }

View File

@ -1,7 +1,7 @@
package net.codinux.invoicing.email package net.codinux.invoicing.email
data class FetchEmailsError( data class FetchEmailError(
val type: FetchEmailsErrorType, val type: FetchEmailErrorType,
val messageNumber: Int?, val messageNumber: Int?,
val error: Throwable val error: Throwable
) )

View File

@ -1,6 +1,6 @@
package net.codinux.invoicing.email package net.codinux.invoicing.email
enum class FetchEmailsErrorType { enum class FetchEmailErrorType {
GetEmail, GetEmail,
GetMesssageBody, GetMesssageBody,

View File

@ -25,7 +25,7 @@ open class FetchEmailsOptions(
val emailFolderName: String = "INBOX", val emailFolderName: String = "INBOX",
val connectTimeoutSeconds: Int = 5, val connectTimeoutSeconds: Int = 5,
val onError: ((FetchEmailsError) -> Unit)? = null, val onError: ((FetchEmailError) -> Unit)? = null,
val onEmailReceived: ((Email) -> Unit)? = null val onEmailReceived: ((Email) -> Unit)? = null
) { ) {
companion object { companion object {

View File

@ -5,5 +5,5 @@ import net.codinux.invoicing.email.model.Email
data class FetchEmailsResult( data class FetchEmailsResult(
val emails: List<Email>, val emails: List<Email>,
val overallError: Throwable?, val overallError: Throwable?,
val messageSpecificErrors: List<FetchEmailsError> = emptyList() val messageSpecificErrors: List<FetchEmailError> = emptyList()
) )

View File

@ -12,7 +12,7 @@ data class FetchEmailsStatus(
val account: EmailAccount, val account: EmailAccount,
val folder: IMAPFolder, val folder: IMAPFolder,
val options: FetchEmailsOptions, val options: FetchEmailsOptions,
val messageSpecificErrors: MutableList<FetchEmailsError> = mutableListOf() val messageSpecificErrors: MutableList<FetchEmailError> = mutableListOf()
) { ) {
val userAttachmentsDownloadDirectory: File by lazy { val userAttachmentsDownloadDirectory: File by lazy {
@ -22,16 +22,16 @@ data class FetchEmailsStatus(
} }
fun addError(type: FetchEmailsErrorType, parts: Collection<Part>, error: Throwable) = fun addError(type: FetchEmailErrorType, parts: Collection<Part>, error: Throwable) =
addError(FetchEmailsError(type, parts.firstNotNullOfOrNull { getMessage(it) }?.messageNumber, error)) addError(FetchEmailError(type, parts.firstNotNullOfOrNull { getMessage(it) }?.messageNumber, error))
fun addError(type: FetchEmailsErrorType, part: Part, error: Throwable) = fun addError(type: FetchEmailErrorType, part: Part, error: Throwable) =
addError(FetchEmailsError(type, getMessage(part)?.messageNumber, error)) addError(FetchEmailError(type, getMessage(part)?.messageNumber, error))
fun addError(type: FetchEmailsErrorType, messageNumber: Int?, error: Throwable) = fun addError(type: FetchEmailErrorType, messageNumber: Int?, error: Throwable) =
addError(FetchEmailsError(type, messageNumber, error)) addError(FetchEmailError(type, messageNumber, error))
fun addError(error: FetchEmailsError) { fun addError(error: FetchEmailError) {
messageSpecificErrors.add(error) messageSpecificErrors.add(error)
options.onError?.invoke(error) options.onError?.invoke(error)

View File

@ -16,7 +16,7 @@ open class ListenForNewMailsOptions(
emailFolderName: String = "INBOX", emailFolderName: String = "INBOX",
connectTimeoutSeconds: Int = 5, connectTimeoutSeconds: Int = 5,
onError: ((FetchEmailsError) -> Unit)? = null, onError: ((FetchEmailError) -> Unit)? = null,
onEmailReceived: (Email) -> Unit onEmailReceived: (Email) -> Unit
) : FetchEmailsOptions( ) : FetchEmailsOptions(
null, null,