From f332b992a8e654c19b391b9e543246ea3c606ae9 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Mar 2021 16:59:37 +0100 Subject: [PATCH] Extract PackageType constant enum --- .../data/extension/EmailPackage.kt | 9 ++++--- .../core/mailmessage/domain/Constants.kt | 26 +++++++++++++++++++ .../domain/entity/EncryptedPackage.kt | 8 +++--- 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/Constants.kt diff --git a/mail-message/data/src/main/kotlin/me/proton/core/mailmessage/data/extension/EmailPackage.kt b/mail-message/data/src/main/kotlin/me/proton/core/mailmessage/data/extension/EmailPackage.kt index fec66cb76..b0c68136c 100644 --- a/mail-message/data/src/main/kotlin/me/proton/core/mailmessage/data/extension/EmailPackage.kt +++ b/mail-message/data/src/main/kotlin/me/proton/core/mailmessage/data/extension/EmailPackage.kt @@ -20,19 +20,20 @@ package me.proton.core.mailmessage.data.extension import me.proton.core.mailmessage.data.api.request.EmailPackage import me.proton.core.mailmessage.domain.entity.EncryptedPackage +import me.proton.core.util.kotlin.toInt fun EncryptedPackage.toEmailPackage(): EmailPackage = EmailPackage( addresses = addresses.mapValues { entry -> when (val address = entry.value) { is EncryptedPackage.Address.Internal -> EmailPackage.Address( - type = address.type, - signature = address.signature, + type = address.packageType.type, + signature = address.signed.toInt(), bodyKeyPacket = address.bodyKeyPacket, attachmentKeyPackets = address.attachmentKeyPackets ) is EncryptedPackage.Address.External -> EmailPackage.Address( - type = address.type, - signature = address.signature + type = address.packageType.type, + signature = address.signed.toInt() ) } }, diff --git a/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/Constants.kt b/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/Constants.kt new file mode 100644 index 000000000..e54a23d95 --- /dev/null +++ b/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/Constants.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 Proton Technologies AG + * This file is part of Proton Technologies AG and ProtonCore. + * + * ProtonCore is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ProtonCore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ProtonCore. If not, see . + */ + +enum class PackageType(val type: Int) { + ProtonMail(1), + EncryptedOutside(2), + Cleartext(4), + PgpInline(8), + PgpMime(16), + ClearMime(32) +} diff --git a/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/entity/EncryptedPackage.kt b/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/entity/EncryptedPackage.kt index c494c9762..dfed86595 100644 --- a/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/entity/EncryptedPackage.kt +++ b/mail-message/domain/src/main/kotlin/me/proton/core/mailmessage/domain/entity/EncryptedPackage.kt @@ -18,6 +18,8 @@ package me.proton.core.mailmessage.domain.entity +import PackageType + data class EncryptedPackage( val addresses: Map, val mimeType: String, @@ -27,14 +29,14 @@ data class EncryptedPackage( val bodyKey: Key? = null, ) { - sealed class Address(val type: Int, val signature: Int) { + sealed class Address(val packageType: PackageType, val signed: Boolean) { data class Internal( val bodyKeyPacket: String, val attachmentKeyPackets: List - ) : Address(1, 1) // TODO + ) : Address(PackageType.ProtonMail, true) - object External : Address(4, 0) // TODO + object External : Address(PackageType.Cleartext, false) } data class Key(