Skip to content

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

Fix email attachment open in mobile apps (#1841)

Leendert de Borst0785bd6d0339
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt
index bd69fa9f3..0a6674394 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/webapi/WebApiService.kt
@@ -202,9 +202,22 @@ class WebApiService(private val context: Context) {
// Read response body
val responseBody = try {
+ // Check if response is binary (octet-stream)
+ val contentType = connection.getHeaderField("Content-Type") ?: ""
+ val isBinary = contentType.contains("application/octet-stream", ignoreCase = true)
+
if (statusCode in 200..299) {
- BufferedReader(InputStreamReader(connection.inputStream)).use { reader ->
- reader.readText()
+ if (isBinary) {
+ // Read binary data and encode as base64
+ connection.inputStream.use { inputStream ->
+ val bytes = inputStream.readBytes()
+ android.util.Base64.encodeToString(bytes, android.util.Base64.NO_WRAP)
+ }
+ } else {
+ // Read text data
+ BufferedReader(InputStreamReader(connection.inputStream)).use { reader ->
+ reader.readText()
+ }
}
} else {
BufferedReader(InputStreamReader(connection.errorStream ?: connection.inputStream)).use { reader ->
diff --git a/apps/mobile-app/app/(tabs)/emails/[id].tsx b/apps/mobile-app/app/(tabs)/emails/[id].tsx
index c4d4804f8..a13164a8a 100644
--- a/apps/mobile-app/app/(tabs)/emails/[id].tsx
+++ b/apps/mobile-app/app/(tabs)/emails/[id].tsx
@@ -3,9 +3,10 @@ import { Buffer } from 'buffer';
import { Ionicons } from '@expo/vector-icons';
import * as FileSystem from 'expo-file-system';
import { useLocalSearchParams, useRouter, useNavigation, Stack } from 'expo-router';
+import * as Sharing from 'expo-sharing';
import React, { useEffect, useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
-import { StyleSheet, View, ActivityIndicator, Share, useColorScheme, Linking, Text, TextInput, Platform } from 'react-native';
+import { StyleSheet, View, ActivityIndicator, useColorScheme, Linking, Text, TextInput, Platform } from 'react-native';
import { WebView } from 'react-native-webview';
import ConversionUtility from '@/utils/ConversionUtility';
@@ -170,11 +171,16 @@ export default function EmailDetailsScreen() : React.ReactNode {
encoding: FileSystem.EncodingType.Base64,
});
- await Share.share({
- url: tempFile,
- title: attachment.filename,
- });
+ if (await Sharing.isAvailableAsync()) {
+ await Sharing.shareAsync(tempFile, {
+ mimeType: attachment.mimeType || 'application/octet-stream',
+ dialogTitle: attachment.filename,
+ });
+ } else {
+ setError('Sharing is not available on this device');
+ }
+ // Cleanup after sharing completes
await FileSystem.deleteAsync(tempFile);
} catch (err) {
console.error('handleDownloadAttachment error', err);
diff --git a/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift b/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift
index 033f7f976..24d5086b5 100644
--- a/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/Services/WebApiService.swift
@@ -182,9 +182,6 @@ public class WebApiService {
)
}
- // Parse response body
- let responseBody = String(data: data, encoding: .utf8) ?? ""
-
// Extract headers
var responseHeaders: [String: String] = [:]
for (key, value) in httpResponse.allHeaderFields {
@@ -193,6 +190,20 @@ public class WebApiService {
}
}
+ // Check if response is binary (octet-stream)
+ let contentType = responseHeaders["Content-Type"] ?? ""
+ let isBinary = contentType.lowercased().contains("application/octet-stream")
+
+ // Parse response body
+ let responseBody: String
+ if isBinary && httpResponse.statusCode >= 200 && httpResponse.statusCode < 300 {
+ // Encode binary data as base64
+ responseBody = data.base64EncodedString()
+ } else {
+ // Parse as text
+ responseBody = String(data: data, encoding: .utf8) ?? ""
+ }
+
return WebApiResponse(
statusCode: httpResponse.statusCode,
body: responseBody,
diff --git a/apps/mobile-app/utils/WebApiService.ts b/apps/mobile-app/utils/WebApiService.ts
index cb3326544..7dbc3fea9 100644
--- a/apps/mobile-app/utils/WebApiService.ts
+++ b/apps/mobile-app/utils/WebApiService.ts
@@ -1,3 +1,5 @@
+import { Buffer } from 'buffer';
+
import { AppInfo } from '@/utils/AppInfo';
import type { StatusResponse, VaultResponse, AuthLogModel, RefreshToken } from '@/utils/dist/core/models/webapi';
@@ -198,16 +200,41 @@ export class WebApiService {
*/
public async downloadBlob(endpoint: string): Promise<Uint8Array> {
try {
- const response = await this.authFetch<Response>(endpoint, {
- method: 'GET',
- headers: {
- 'Accept': 'application/octet-stream',
- }
- }, false);
+ const method = 'GET';
+ const headers: Record<string, string> = {
+ 'Accept': 'application/octet-stream',
+ };
+
+ // Execute request through native layer with auth
+ const responseJson = await NativeVaultManager.executeWebApiRequest(
+ method,
+ endpoint,
+ null,
+ JSON.stringify(headers),
+ true // requiresAuth
+ );
+
+ const response: NativeWebApiResponse = JSON.parse(responseJson);
+
+ // Handle auth errors
+ if (response.statusCode === 401) {
+ logoutEventEmitter.emit('auth.errors.sessionExpired');
+ throw new Error(i18n.t('auth.errors.sessionExpired'));
+ }
+
+ if (response.statusCode >= 400) {
+ throw new Error(i18n.t('auth.errors.httpError', { status: response.statusCode }));
+ }
+
+ // Convert base64 response body to Uint8Array
+ // The native layer returns binary data as base64 encoded string
+ if (!response.body) {
+ throw new Error('Empty response body');
+ }
- // Get the response as an ArrayBuffer
- const arrayBuffer = await response.arrayBuffer();
- return new Uint8Array(arrayBuffer);
+ // Decode base64 string to binary data using Buffer (React Native compatible)
+ const buffer = Buffer.from(response.body, 'base64');
+ return new Uint8Array(buffer);
} catch (error) {
console.error('Error downloading blob:', error);
throw error;