Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add credential link to email details page (#771)

Leendert de Borsta04586c9591a
diff --git a/mobile-app/app/(tabs)/(emails)/[id].tsx b/mobile-app/app/(tabs)/(emails)/[id].tsx
index 292e47792..f35878928 100644
--- a/mobile-app/app/(tabs)/(emails)/[id].tsx
+++ b/mobile-app/app/(tabs)/(emails)/[id].tsx
@@ -1,29 +1,63 @@
import React, { useEffect, useState } from 'react';
-import { StyleSheet, View, ScrollView, TouchableOpacity, ActivityIndicator, Alert, Share } from 'react-native';
-import { useLocalSearchParams, useRouter } from 'expo-router';
+import { StyleSheet, View, TouchableOpacity, ActivityIndicator, Alert, Share, useColorScheme, TextInput, Linking } from 'react-native';
+import { useLocalSearchParams, useRouter, useNavigation } from 'expo-router';
import { Email } from '@/utils/types/webapi/Email';
+import { Credential } from '@/utils/types/Credential';
import { useDb } from '@/context/DbContext';
import { useWebApi } from '@/context/WebApiContext';
import { ThemedText } from '@/components/ThemedText';
-import { IconSymbol } from '@/components/ui/IconSymbol';
import EncryptionUtility from '@/utils/EncryptionUtility';
import WebView from 'react-native-webview';
import * as FileSystem from 'expo-file-system';
-import { EncryptionKey } from '@/utils/types/EncryptionKey';
+import { Ionicons } from '@expo/vector-icons';
+import { useColors } from '@/hooks/useColorScheme';
+import { IconSymbol } from '@/components/ui/IconSymbol';
export default function EmailDetailsScreen() {
const { id } = useLocalSearchParams();
const router = useRouter();
+ const navigation = useNavigation();
const dbContext = useDb();
const webApi = useWebApi();
+ const colors = useColors();
const [error, setError] = useState<string | null>(null);
const [email, setEmail] = useState<Email | null>(null);
const [isLoading, setIsLoading] = useState(true);
+ const [isMetadataMaximized, setMetadataMaximized] = useState(false);
+ const [isHtmlView, setHtmlView] = useState(true);
+ const isDarkMode = useColorScheme() === 'dark';
+ const [associatedCredential, setAssociatedCredential] = useState<Credential | null>(null);
useEffect(() => {
loadEmail();
}, [id]);
+ // Set navigation options
+ useEffect(() => {
+ navigation.setOptions({
+ headerRight: () => (
+ <View style={{ flexDirection: 'row' }}>
+ <TouchableOpacity
+ onPress={() => setHtmlView(!isHtmlView)}
+ style={{ padding: 10, paddingRight: 0 }}
+ >
+ <Ionicons
+ name={isHtmlView ? 'text-outline' : 'document-outline'}
+ size={22}
+ color="#FFA500"
+ />
+ </TouchableOpacity>
+ <TouchableOpacity
+ onPress={handleDelete}
+ style={{ padding: 10, paddingRight: 0 }}
+ >
+ <Ionicons name="trash-outline" size={22} color="#FF0000" />
+ </TouchableOpacity>
+ </View>
+ ),
+ });
+ }, [isHtmlView, navigation]);
+
const loadEmail = async () => {
try {
setIsLoading(true);
@@ -39,6 +73,20 @@ export default function EmailDetailsScreen() {
const encryptionKeys = await dbContext.sqliteClient.getAllEncryptionKeys();
const decryptedEmail = await EncryptionUtility.decryptEmail(response, encryptionKeys);
setEmail(decryptedEmail);
+
+ // Look up associated credential
+ if (decryptedEmail.toLocal && decryptedEmail.toDomain) {
+ const emailAddress = `${decryptedEmail.toLocal}@${decryptedEmail.toDomain}`;
+ const credential = await dbContext.sqliteClient.getCredentialByEmail(emailAddress);
+ setAssociatedCredential(credential);
+ }
+
+ // Set initial view mode based on content
+ if (decryptedEmail.messageHtml && decryptedEmail.messageHtml.length > 0) {
+ setHtmlView(true);
+ } else {
+ setHtmlView(false);
+ }
} catch (err) {
setError(err instanceof Error ? err.message : 'An error occurred');
} finally {
@@ -49,7 +97,7 @@ export default function EmailDetailsScreen() {
const handleDelete = async () => {
Alert.alert(
'Delete Email',
- 'Are you sure you want to delete this email?',
+ 'Are you sure you want to delete this email? This action is permanent and cannot be undone.',
[
{
text: 'Cancel',
@@ -73,7 +121,6 @@ export default function EmailDetailsScreen() {
const handleDownloadAttachment = async (attachment: Email['attachments'][0]) => {
try {
- // Get the encrypted attachment bytes from the API
const base64EncryptedAttachment = await webApi.downloadBlobAndConvertToBase64(
`Email/${id}/attachments/${attachment.id}`
);
@@ -83,10 +130,7 @@ export default function EmailDetailsScreen() {
return;
}
- // Get encryption keys for decryption
const encryptionKeys = await dbContext.sqliteClient.getAllEncryptionKeys();
-
- // Decrypt the attachment
const decryptedBytes = await EncryptionUtility.decryptAttachment(
base64EncryptedAttachment,
email,
@@ -98,19 +142,16 @@ export default function EmailDetailsScreen() {
return;
}
- // Save to temporary file
const tempFile = `${FileSystem.cacheDirectory}${attachment.filename}`;
await FileSystem.writeAsStringAsync(tempFile, decryptedBytes, {
encoding: FileSystem.EncodingType.Base64,
});
- // Share the file using the native share API
await Share.share({
url: tempFile,
title: attachment.filename,
});
- // Clean up temp file
await FileSystem.deleteAsync(tempFile);
} catch (err) {
console.error('handleDownloadAttachment error', err);
@@ -118,9 +159,144 @@ export default function EmailDetailsScreen() {
}
};
+ const handleOpenCredential = () => {
+ if (associatedCredential) {
+ router.push(`/(tabs)/(credentials)/${associatedCredential.Id}`);
+ }
+ };
+
+ const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ },
+ viewLight: {
+ backgroundColor: colors.background,
+ },
+ viewDark: {
+ backgroundColor: colors.background,
+ },
+ centerContainer: {
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ padding: 20,
+ },
+ errorText: {
+ color: colors.errorBackground,
+ textAlign: 'center',
+ },
+ emptyText: {
+ textAlign: 'center',
+ opacity: 0.7,
+ color: colors.textMuted,
+ },
+ topBox: {
+ backgroundColor: colors.background,
+ flexDirection: 'row',
+ alignSelf: 'flex-start',
+ padding: 2,
+ },
+ subjectContainer: {
+ paddingBottom: 8,
+ paddingTop: 8,
+ paddingLeft: 5,
+ width: '90%',
+ },
+ metadataIcon: {
+ width: 30,
+ paddingTop: 6,
+ },
+ metadataContainer: {
+ padding: 2,
+ },
+ metadataRow: {
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ padding: 2,
+ },
+ metadataLabel: {
+ paddingBottom: 4,
+ paddingTop: 4,
+ paddingLeft: 5,
+ width: 60,
+ },
+ metadataValue: {
+ paddingBottom: 4,
+ paddingTop: 4,
+ paddingLeft: 5,
+ flex: 1,
+ },
+ metadataHeading: {
+ fontWeight: 'bold',
+ marginTop: 0,
+ paddingTop: 0,
+ marginBottom: 0,
+ paddingBottom: 0,
+ fontSize: 13,
+ color: colors.text,
+ },
+ metadataText: {
+ marginTop: 0,
+ marginBottom: 0,
+ paddingTop: 0,
+ paddingBottom: 0,
+ fontSize: 13,
+ color: colors.text,
+ },
+ divider: {
+ height: 1,
+ backgroundColor: colors.accentBorder,
+ marginVertical: 2,
+ },
+ subject: {
+ fontSize: 14,
+ fontWeight: 'bold',
+ textAlign: 'center',
+ color: colors.text,
+ },
+ webView: {
+ flex: 1,
+ },
+ plainText: {
+ flex: 1,
+ padding: 16,
+ fontSize: 15,
+ },
+ textDark: {
+ color: colors.text,
+ },
+ textLight: {
+ color: colors.text,
+ },
+ attachments: {
+ padding: 16,
+ borderTopWidth: 1,
+ borderTopColor: colors.accentBorder,
+ },
+ attachmentsTitle: {
+ fontSize: 18,
+ fontWeight: 'bold',
+ marginBottom: 12,
+ color: colors.text,
+ },
+ attachment: {
+ flexDirection: 'row',
+ alignItems: 'center',
+ padding: 12,
+ backgroundColor: colors.accentBackground,
+ borderRadius: 8,
+ marginBottom: 8,
+ },
+ attachmentName: {
+ marginLeft: 8,
+ fontSize: 14,
+ color: colors.textMuted,
+ },
+ });
+
if (isLoading) {
return (
- <View style={styles.centerContainer}>
+ <View style={[styles.centerContainer, isDarkMode ? styles.viewDark : styles.viewLight]}>
<ActivityIndicator size="large" />
</View>
);
@@ -128,7 +304,7 @@ export default function EmailDetailsScreen() {
if (error) {
return (
- <View style={styles.centerContainer}>
+ <View style={[styles.centerContainer, isDarkMode ? styles.viewDark : styles.viewLight]}>
<ThemedText style={styles.errorText}>Error: {error}</ThemedText>
</View>
);
@@ -136,56 +312,124 @@ export default function EmailDetailsScreen() {
if (!email) {
return (
- <View style={styles.centerContainer}>
+ <View style={[styles.centerContainer, isDarkMode ? styles.viewDark : styles.viewLight]}>
<ThemedText style={styles.emptyText}>Email not found</ThemedText>
</View>
);
}
- return (
- <ScrollView style={styles.container}>
- {/* Header */}
- <View style={styles.header}>
- <View style={styles.headerTop}>
- <ThemedText style={styles.subject}>{email.subject}</ThemedText>
- <TouchableOpacity onPress={handleDelete} style={styles.deleteButton}>
- <IconSymbol name="trash" size={24} color="#ef4444" />
- </TouchableOpacity>
+ let metadataView = null;
+ if (!isMetadataMaximized) {
+ metadataView = (
+ <TouchableOpacity onPress={() => setMetadataMaximized(!isMetadataMaximized)}>
+ <View style={styles.topBox}>
+ <View style={styles.subjectContainer}>
+ <ThemedText style={styles.subject}>{email.subject}</ThemedText>
+ </View>
+ <View style={styles.metadataIcon}>
+ <Ionicons name="reorder-four-outline" size={22} color={isDarkMode ? '#eee' : '#000'} />
+ </View>
</View>
- <View style={styles.metadata}>
- <ThemedText style={styles.metadataText}>
- From: {email.fromDisplay} ({email.fromLocal}@{email.fromDomain})
- </ThemedText>
- <ThemedText style={styles.metadataText}>
- To: {email.toLocal}@{email.toDomain}
- </ThemedText>
- <ThemedText style={styles.metadataText}>
- Date: {new Date(email.dateSystem).toLocaleString()}
- </ThemedText>
+ </TouchableOpacity>
+ );
+ } else {
+ metadataView = (
+ <TouchableOpacity onPress={() => setMetadataMaximized(!isMetadataMaximized)}>
+ <View style={styles.metadataContainer}>
+ <View style={styles.metadataRow}>
+ <View style={styles.metadataLabel}>
+ <ThemedText style={styles.metadataHeading}>Subject:</ThemedText>
+ </View>
+ <View style={styles.metadataValue}>
+ <ThemedText style={styles.metadataText}>{email.subject}</ThemedText>
+ {associatedCredential && (
+ <>
+ <TouchableOpacity onPress={handleOpenCredential} style={{ flexDirection: 'row', alignItems: 'center' }}>
+ <IconSymbol size={16} name="key.fill" color={colors.primary} style={{ marginRight: 4 }} />
+ <ThemedText style={[styles.metadataText, { color: colors.primary }]}>
+ {associatedCredential.ServiceName}
+ </ThemedText>
+ </TouchableOpacity>
+ </>
+ )}
+ </View>
+ <View style={styles.metadataIcon}>
+ <Ionicons name="chevron-up-outline" size={22} color={isDarkMode ? '#eee' : '#000'} />
+ </View>
+ </View>
+ <View style={styles.divider} />
+
+ <View style={styles.metadataRow}>
+ <View style={styles.metadataLabel}>
+ <ThemedText style={styles.metadataHeading}>Date:</ThemedText>
+ </View>
+ <View style={styles.metadataValue}>
+ <ThemedText style={styles.metadataText}>
+ {new Date(email.dateSystem).toLocaleString()}
+ </ThemedText>
+ </View>
+ </View>
+ <View style={styles.divider} />
+
+ <View style={styles.metadataRow}>
+ <View style={styles.metadataLabel}>
+ <ThemedText style={styles.metadataHeading}>From:</ThemedText>
+ </View>
+ <View style={styles.metadataValue}>
+ <ThemedText style={styles.metadataText}>
+ {email.fromDisplay} ({email.fromLocal}@{email.fromDomain})
+ </ThemedText>
+ </View>
+ </View>
+ <View style={styles.divider} />
+
+ <View style={styles.metadataRow}>
+ <View style={styles.metadataLabel}>
+ <ThemedText style={styles.metadataHeading}>To:</ThemedText>
+ </View>
+ <View style={styles.metadataValue}>
+ <ThemedText style={styles.metadataText}>
+ {email.toLocal}@{email.toDomain}
+ </ThemedText>
+ </View>
+ </View>
+ <View style={styles.divider} />
</View>
- </View>
+ </TouchableOpacity>
+ );
+ }
- {/* Email Body */}
- <View style={styles.body}>
- {email.messageHtml ? (
- <WebView
- style={styles.webView}
- source={{ html: email.messageHtml }}
- scrollEnabled={false}
- onNavigationStateChange={(event) => {
- if (event.url !== 'about:blank') {
- Share.share({
- url: event.url,
- });
- }
- }}
- />
- ) : (
- <ThemedText style={styles.plainText}>{email.messagePlain}</ThemedText>
- )}
- </View>
+ let emailView = null;
+ if (isHtmlView && email.messageHtml) {
+ emailView = (
+ <WebView
+ style={styles.webView}
+ source={{ html: email.messageHtml }}
+ scrollEnabled={true}
+ onNavigationStateChange={(event) => {
+ if (event.url !== 'about:blank') {
+ Share.share({
+ url: event.url,
+ });
+ }
+ }}
+ />
+ );
+ } else {
+ emailView = (
+ <TextInput
+ style={[styles.plainText, isDarkMode ? styles.textDark : styles.textLight]}
+ value={email.messagePlain || 'This email does not contain any plain-text.'}
+ editable={false}
+ multiline
+ />
+ );
+ }
- {/* Attachments */}
+ return (
+ <View style={[styles.container, isDarkMode ? styles.viewDark : styles.viewLight]}>
+ {metadataView}
+ {emailView}
{email.attachments && email.attachments.length > 0 && (
<View style={styles.attachments}>
<ThemedText style={styles.attachmentsTitle}>Attachments</ThemedText>
@@ -195,7 +439,7 @@ export default function EmailDetailsScreen() {
style={styles.attachment}
onPress={() => handleDownloadAttachment(attachment)}
>
- <IconSymbol name="paperclip" size={20} color="#666" />
+ <Ionicons name="attach" size={20} color="#666" />
<ThemedText style={styles.attachmentName}>
{attachment.filename} ({Math.ceil(attachment.filesize / 1024)} KB)
</ThemedText>
@@ -203,88 +447,6 @@ export default function EmailDetailsScreen() {
))}
</View>
)}
- </ScrollView>
+ </View>
);
-}
-
-const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- },
- centerContainer: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- padding: 20,
- },
- errorText: {
- color: '#ef4444',
- textAlign: 'center',
- },
- emptyText: {
- textAlign: 'center',
- opacity: 0.7,
- },
- header: {
- padding: 16,
- borderBottomWidth: 1,
- borderBottomColor: '#e5e5e5',
- },
- headerTop: {
- flexDirection: 'row',
- justifyContent: 'space-between',
- alignItems: 'flex-start',
- marginBottom: 12,
- },
- subject: {
- fontSize: 20,
- fontWeight: 'bold',
- flex: 1,
- marginRight: 16,
- },
- deleteButton: {
- padding: 8,
- },
- metadata: {
- marginTop: 8,
- },
- metadataText: {
- fontSize: 14,
- color: '#666',
- marginBottom: 4,
- },
- body: {
- padding: 16,
- },
- webView: {
- minHeight: 200,
- },
- plainText: {
- fontSize: 16,
- lineHeight: 24,
- },
- attachments: {
- padding: 16,
- borderTopWidth: 1,
- borderTopColor: '#e5e5e5',
- },
- attachmentsTitle: {
- fontSize: 18,
- fontWeight: 'bold',
- marginBottom: 12,
- },
- attachment: {
- flexDirection: 'row',
- alignItems: 'center',
- padding: 12,
- backgroundColor: '#f5f5f5',
- borderRadius: 8,
- marginBottom: 8,
- },
- attachmentName: {
- marginLeft: 8,
- fontSize: 14,
- color: '#666',
- },
-});
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/mobile-app/utils/SqliteClient.tsx b/mobile-app/utils/SqliteClient.tsx
index 3a28145f5..96c0c075d 100644
--- a/mobile-app/utils/SqliteClient.tsx
+++ b/mobile-app/utils/SqliteClient.tsx
@@ -484,6 +484,63 @@ class SqliteClient {
return false;
}
}
+
+ /**
+ * Get credential by email address
+ * @param email - The email address to look up
+ * @returns Credential object with service details or null if not found
+ */
+ public async getCredentialByEmail(email: string): Promise<Credential | null> {
+ const query = `
+ SELECT DISTINCT
+ c.Id,
+ c.Username,
+ c.Notes,
+ c.ServiceId,
+ s.Name as ServiceName,
+ s.Url as ServiceUrl,
+ s.Logo as Logo,
+ a.FirstName,
+ a.LastName,
+ a.NickName,
+ a.BirthDate,
+ a.Gender,
+ a.Email,
+ p.Value as Password
+ FROM Credentials c
+ LEFT JOIN Services s ON c.ServiceId = s.Id
+ LEFT JOIN Aliases a ON c.AliasId = a.Id
+ LEFT JOIN Passwords p ON p.CredentialId = c.Id
+ WHERE c.IsDeleted = 0
+ AND LOWER(a.Email) = LOWER(?)
+ LIMIT 1`;
+
+ const results = await this.executeQuery(query, [email]);
+
+ if (results.length === 0) {
+ return null;
+ }
+
+ // Convert the first row to a Credential object
+ const row = results[0] as any;
+ return {
+ Id: row.Id,
+ Username: row.Username,
+ Password: row.Password,
+ ServiceName: row.ServiceName,
+ ServiceUrl: row.ServiceUrl,
+ Logo: row.Logo,
+ Notes: row.Notes,
+ Alias: {
+ FirstName: row.FirstName,
+ LastName: row.LastName,
+ NickName: row.NickName,
+ BirthDate: row.BirthDate,
+ Gender: row.Gender,
+ Email: row.Email
+ }
+ };
+ }
}
export default SqliteClient;
\ No newline at end of file