Skip to content

Commit

Permalink
allow importing mails only on LEGEND and UNLIMITED plans
Browse files Browse the repository at this point in the history
For the first version of .eml /.mbox import we only want to allow
importing mails on accounts with LEGEND or UNLIMITED plans. On all
other plans the UI allowing to import mails is currently hidden.
  • Loading branch information
jomapp authored and ganthern committed Nov 18, 2024
1 parent 5dd7e11 commit 7697375
Show file tree
Hide file tree
Showing 9 changed files with 3,654 additions and 3,642 deletions.
1 change: 1 addition & 0 deletions src/common/api/common/TutanotaConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export const NewPersonalPlans: AvailablePlanType[] = [PlanType.Free, PlanType.Re

export const LegacyPlans = [PlanType.Premium, PlanType.PremiumBusiness, PlanType.Teams, PlanType.TeamsBusiness, PlanType.Pro]
export const HighlightedPlans: AvailablePlanType[] = [PlanType.Revolutionary, PlanType.Advanced]
export const HighestTierPlans: PlanType[] = [PlanType.Legend, PlanType.Unlimited]

export const PlanTypeToName = reverse(PlanType)

Expand Down
13 changes: 6 additions & 7 deletions src/common/desktop/mailimport/DesktopMailImportFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ export class DesktopMailImportFacade implements MailImportFacade {

async importFromFiles(
apiUrl: string,
unencryptedTutaCredentials: UnencryptedCredentials,
unencTutaCredentials: UnencryptedCredentials,
targetOwnerGroup: string,
targetFolderId: IdTuple,
filePaths: Array<string>,
): Promise<string> {
const tutaCredentials: TutaCredentials = {
accessToken: unencryptedTutaCredentials?.accessToken,
credentialType:
unencryptedTutaCredentials.credentialInfo.type == CredentialType.Internal ? TutaCredentialType.Internal : TutaCredentialType.External,
encryptedPassphraseKey: unencryptedTutaCredentials.encryptedPassphraseKey ? Array.from(unencryptedTutaCredentials.encryptedPassphraseKey) : [],
login: unencryptedTutaCredentials.credentialInfo.login,
userId: unencryptedTutaCredentials.credentialInfo.userId,
accessToken: unencTutaCredentials?.accessToken,
credentialType: unencTutaCredentials.credentialInfo.type == CredentialType.Internal ? TutaCredentialType.Internal : TutaCredentialType.External,
encryptedPassphraseKey: unencTutaCredentials.encryptedPassphraseKey ? Array.from(unencTutaCredentials.encryptedPassphraseKey) : [],
login: unencTutaCredentials.credentialInfo.login,
userId: unencTutaCredentials.credentialInfo.userId,
apiUrl: apiUrl,
clientVersion: env.versionNumber,
}
Expand Down
23 changes: 15 additions & 8 deletions src/common/native/main/WebCommonNativeFacade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonNativeFacade } from "../common/generatedipc/CommonNativeFacade.js"
import { TranslationKey } from "../../misc/LanguageViewModel.js"
import { TranslationKey, TranslationText } from "../../misc/LanguageViewModel.js"
import { decodeBase64, lazyAsync, noOp, ofClass } from "@tutao/tutanota-utils"
import { CancelledError } from "../../api/common/error/CancelledError.js"
import { UserError } from "../../api/main/UserError.js"
Expand All @@ -16,6 +16,7 @@ import { locator } from "../../api/main/CommonLocator.js"
import { AppType } from "../../misc/ClientConstants.js"
import { ContactTypeRef } from "../../api/entities/tutanota/TypeRefs.js"
import { isDesktop } from "../../api/common/Env"
import { HighestTierPlans } from "../../api/common/TutanotaConstants.js"

export class WebCommonNativeFacade implements CommonNativeFacade {
constructor(
Expand Down Expand Up @@ -108,13 +109,19 @@ export class WebCommonNativeFacade implements CommonNativeFacade {
{ text: "attachFiles_action", value: false },
])
} else if (isDesktop() && allFilesAreMail) {
willImport = await Dialog.choice("emlOrMboxInSharingFiles_msg", [
{
text: "import_action",
value: true,
},
{ text: "attachFiles_action", value: false },
])
// importing mails is currently only allowed on plan LEGEND and UNLIMITED
const currentPlanType = await locator.logins.getUserController().getPlanType()
const isHighestTierPlan = HighestTierPlans.includes(currentPlanType)

let importAction: { text: TranslationText; value: boolean } = {
text: "import_action",
value: true,
}
let attachFilesAction: { text: TranslationText; value: boolean } = {
text: "attachFiles_action",
value: false,
}
willImport = isHighestTierPlan && (await Dialog.choice("emlOrMboxInSharingFiles_msg", [importAction, attachFilesAction]))
}

if (willImport) {
Expand Down
30 changes: 16 additions & 14 deletions src/mail-app/mail/view/MailView.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import m, { Children, Vnode } from "mithril"
import { ViewSlider } from "../../../common/gui/nav/ViewSlider.js"
import { ColumnType, ViewColumn } from "../../../common/gui/base/ViewColumn"
import { lang } from "../../../common/misc/LanguageViewModel"
import { lang, TranslationText } from "../../../common/misc/LanguageViewModel"
import { Dialog } from "../../../common/gui/base/Dialog"
import { FeatureType, Keys, MailSetKind } from "../../../common/api/common/TutanotaConstants"
import { FeatureType, HighestTierPlans, Keys, MailSetKind } from "../../../common/api/common/TutanotaConstants"
import { AppHeaderAttrs, Header } from "../../../common/gui/Header.js"
import type { Mail, MailFolder } from "../../../common/api/entities/tutanota/TypeRefs.js"
import { noOp, ofClass } from "@tutao/tutanota-utils"
Expand Down Expand Up @@ -727,18 +727,20 @@ export class MailView extends BaseTopLevelView implements TopLevelView<MailViewA
return files.every((f) => f.name.endsWith(".eml") || f.name.endsWith(".mbox"))
}

// importing mails is currently only allowed on plan LEGEND and UNLIMITED
const currentPlanType = await locator.logins.getUserController().getPlanType()
const isHighestTierPlan = HighestTierPlans.includes(currentPlanType)

let importAction: { text: TranslationText; value: boolean } = {
text: "import_action",
value: true,
}
let attachFilesAction: { text: TranslationText; value: boolean } = {
text: "attachFiles_action",
value: false,
}
const willImport =
droppedOnlyMailFiles(dropData.files) &&
(await Dialog.choice("emlOrMboxInSharingFiles_msg", [
{
text: "import_action",
value: true,
},
{
text: "attachFiles_action",
value: false,
},
]))
isHighestTierPlan && droppedOnlyMailFiles(dropData.files) && (await Dialog.choice("emlOrMboxInSharingFiles_msg", [importAction, attachFilesAction]))

if (!willImport) {
await this.handleFileDrop(dropData)
Expand All @@ -753,7 +755,7 @@ export class MailView extends BaseTopLevelView implements TopLevelView<MailViewA
unencryptedCredentials,
mailFolder._ownerGroup,
mailFolder._id,
dropData.files.map((f) => window.nativeApp.getPathForFile(f)),
dropData.files.map((file) => window.nativeApp.getPathForFile(file)),
)
}
}
Expand Down
Loading

0 comments on commit 7697375

Please sign in to comment.