Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Make mobile app gracefully degrade for email view with upcoming 0.31 API (#2346)
Leendert de Borst48f0e155b967
diff --git a/apps/mobile-app/app/(tabs)/emails/[id].tsx b/apps/mobile-app/app/(tabs)/emails/[id].tsxindex 96b3c7d26..2e6b425b6 100644--- a/apps/mobile-app/app/(tabs)/emails/[id].tsx+++ b/apps/mobile-app/app/(tabs)/emails/[id].tsx@@ -238,6 +238,12 @@ export default function EmailDetailsScreen() : React.ReactNode {return modes;}, [email]);+ /*+ * Emails stored by newer server versions only contain the raw source. Until this client can+ * render those itself we show the source verbatim plus a notice to update.+ */+ const isSourceOnly = Boolean(email?.messageSource) && !email?.messageHtml && !email?.messagePlain;+const formatLabels = useMemo<Record<'html' | 'plain' | 'source', string>>(() => ({html: t('emails.formatHtml'),plain: t('emails.formatPlain'),@@ -405,6 +411,18 @@ export default function EmailDetailsScreen() : React.ReactNode {flexDirection: 'row',padding: 2,},+ updateNotice: {+ backgroundColor: colors.warningBackground,+ borderColor: colors.warning,+ borderRadius: 6,+ borderWidth: 1,+ margin: 8,+ padding: 10,+ },+ updateNoticeText: {+ color: colors.warning,+ fontSize: 13,+ },webView: {flex: 1,},@@ -599,6 +617,13 @@ export default function EmailDetailsScreen() : React.ReactNode {<ThemedView style={styles.container}><Stack.Screen options={{ title: t('emails.emailDetails') }} />{metadataView}+ {isSourceOnly && (+ <View style={styles.updateNotice}>+ <ThemedText style={styles.updateNoticeText}>+ {t('emails.updateClientForFormattedView')}+ </ThemedText>+ </View>+ )}{emailView}{email.attachments && email.attachments.length > 0 && (<View style={styles.attachments}>diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.jsonindex 3d760ec71..1b794e312 100644--- a/apps/mobile-app/i18n/locales/en.json+++ b/apps/mobile-app/i18n/locales/en.json@@ -606,6 +606,7 @@"formatSwitchTitle": "Switch email format","sizeKB": "KB","offlineMessage": "You are offline. Please connect to the internet to load your emails.",+ "updateClientForFormattedView": "This email requires a newer app version to display properly. Please update your app.","emptyMessage": "You have not received any emails at your private email addresses yet. When you receive a new email, it will appear here.","loadMore": "Load More ({{count}} remaining)","time": {diff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.jsonindex 14c142dff..00de5e51a 100644--- a/apps/mobile-app/package-lock.json+++ b/apps/mobile-app/package-lock.json@@ -33,6 +33,7 @@"expo-symbols": "~56.0.5","expo-web-browser": "~56.0.5","fbemitter": "^3.0.0",+ "fflate": "^0.8.3","i18next": "^26.0.0","lodash": "^4.18.1","react": "19.2.3",@@ -8376,6 +8377,12 @@"integrity": "sha512-m6I8ALe4L4XpdETy7MJZWs6L1IVMbjs99bwbpIKphxX+0CTns4IKDWJY0LWfr4YsFjfg+z1TjzTMU8lKl8rG0w==","license": "MIT"},+ "node_modules/fflate": {+ "version": "0.8.3",+ "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",+ "integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==",+ "license": "MIT"+ },"node_modules/file-entry-cache": {"version": "8.0.0","resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.jsonindex b89135694..7999290a1 100644--- a/apps/mobile-app/package.json+++ b/apps/mobile-app/package.json@@ -49,6 +49,7 @@"expo-symbols": "~56.0.5","expo-web-browser": "~56.0.5","fbemitter": "^3.0.0",+ "fflate": "^0.8.3","i18next": "^26.0.0","lodash": "^4.18.1","react": "19.2.3",@@ -106,8 +107,12 @@},"expo": {"autolinking": {- "exclude": ["@react-native-masked-view/masked-view"],- "buildFromSource": [".*"]+ "exclude": [+ "@react-native-masked-view/masked-view"+ ],+ "buildFromSource": [+ ".*"+ ]}},"private": truediff --git a/apps/mobile-app/utils/EncryptionUtility.ts b/apps/mobile-app/utils/EncryptionUtility.tsindex dc7d05627..0168c3ef2 100644--- a/apps/mobile-app/utils/EncryptionUtility.ts+++ b/apps/mobile-app/utils/EncryptionUtility.ts@@ -1,5 +1,6 @@import { Buffer } from 'buffer';+import { gunzipSync, strFromU8 } from 'fflate';import AesGcmCrypto from 'react-native-aes-gcm-crypto';import NativeVaultManager from '@/specs/NativeVaultManager';@@ -132,6 +133,25 @@ class EncryptionUtility {return new Uint8Array(decrypted);}+ /**+ * Decrypts a base64 AES-GCM payload that may be gzip compressed after decryption.+ */+ public static async symmetricDecryptMaybeCompressed(base64Ciphertext: string, base64Key: string): Promise<string> {+ if (!base64Ciphertext) {+ return base64Ciphertext;+ }++ const encryptedBytes = Uint8Array.from(atob(base64Ciphertext), c => c.charCodeAt(0));+ const decryptedBytes = await EncryptionUtility.symmetricDecryptBytes(encryptedBytes, base64Key);++ // Gzip magic number (0x1f 0x8b); anything else is treated as plain UTF-8.+ if (decryptedBytes.length >= 2 && decryptedBytes[0] === 0x1f && decryptedBytes[1] === 0x8b) {+ return strFromU8(gunzipSync(decryptedBytes));+ }++ return Buffer.from(decryptedBytes).toString('utf8');+ }+/*** Generates a new RSA key pair for asymmetric encryption*/@@ -297,7 +317,8 @@ class EncryptionUtility {decryptedEmail.messagePlain = await EncryptionUtility.symmetricDecrypt(email.messagePlain, symmetricKeyBase64);}if (email.messageSource) {- decryptedEmail.messageSource = await EncryptionUtility.symmetricDecrypt(email.messageSource, symmetricKeyBase64);+ // The raw source is optionally gzip compressed before encryption by 0.31+ API.+ decryptedEmail.messageSource = await EncryptionUtility.symmetricDecryptMaybeCompressed(email.messageSource, symmetricKeyBase64);}return decryptedEmail;