TF-3416 Handle download attachment in EML previewer on mobile
This commit is contained in:
@@ -2059,6 +2059,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
emlPreviewer: emlPreviewer,
|
||||
onMailtoDelegateAction: openMailToLink,
|
||||
onPreviewEMLDelegateAction: (uri) => _openEMLPreviewer(context, uri),
|
||||
onDownloadAttachmentDelegateAction: (uri) =>
|
||||
_downloadAttachmentInEMLPreview(context, uri),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -2069,13 +2071,23 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
log('SingleEmailController::_openEMLPreviewer:uri = $uri');
|
||||
if (uri == null) return;
|
||||
|
||||
final blobId = uri.authority;
|
||||
final blobId = uri.path;
|
||||
log('SingleEmailController::_openEMLPreviewer:blobId = $blobId');
|
||||
if (blobId.isEmpty) return;
|
||||
|
||||
previewEMLFileAction(Id(blobId), AppLocalizations.of(context));
|
||||
}
|
||||
|
||||
Future<void> _downloadAttachmentInEMLPreview(BuildContext context, Uri? uri) async {
|
||||
log('SingleEmailController::_downloadAttachmentInEMLPreview:uri = $uri');
|
||||
if (uri == null) return;
|
||||
|
||||
final attachment = EmailUtils.parsingAttachmentByUri(uri);
|
||||
if (attachment == null) return;
|
||||
|
||||
handleDownloadAttachmentAction(context, attachment);
|
||||
}
|
||||
|
||||
void handleMailToAttendees(CalendarOrganizer? organizer, List<CalendarAttendee>? attendees) {
|
||||
final listEmailAddressAttendees = attendees
|
||||
?.map((attendee) => EmailAddress(attendee.name?.name, attendee.mailto?.mailAddress.value))
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/presentation/extensions/media_type_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
||||
|
||||
extension AttachmentExtension on Attachment {
|
||||
String getIcon(ImagePaths imagePaths) => type?.getIcon(imagePaths, fileName: name) ?? imagePaths.icFileEPup;
|
||||
@@ -8,4 +12,27 @@ extension AttachmentExtension on Attachment {
|
||||
bool get isPDFFile => type?.isPDFFile(fileName: name) ?? false;
|
||||
|
||||
bool get isEMLFile => type?.isEMLFile ?? false;
|
||||
|
||||
String get hyperLink => isEMLFile ? emlLink : attachmentLink;
|
||||
|
||||
String get emlLink {
|
||||
if (blobId == null) return '';
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
return RouteUtils.createUrlWebLocationBar(
|
||||
AppRoutes.emailEMLPreviewer,
|
||||
previewId: blobId!.value,
|
||||
).toString();
|
||||
} else if (PlatformInfo.isMobile) {
|
||||
return '${Constant.emlPreviewerScheme}:${blobId!.value}';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
String get attachmentLink {
|
||||
if (blobId == null) return '';
|
||||
|
||||
return '${Constant.attachmentScheme}:${blobId!.value}?name=${name ?? ''}&size=${size?.value ?? ''}&type=${type?.mimeType ?? ''}';
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,15 @@ import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/mail/mail_address.dart';
|
||||
import 'package:get/get_utils/src/get_utils/get_utils.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/email_unsubscribe.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart';
|
||||
@@ -190,4 +194,24 @@ class EmailUtils {
|
||||
final mailtoLinks = extractMailtoLinksFromListPost(listPost);
|
||||
return extractRecipientsFromListMailtoLink(mailtoLinks);
|
||||
}
|
||||
|
||||
static Attachment? parsingAttachmentByUri(Uri uri) {
|
||||
try {
|
||||
final blobId = uri.path;
|
||||
final queryParams = uri.queryParameters;
|
||||
final name = queryParams['name'];
|
||||
final size = queryParams['size'];
|
||||
final type = queryParams['type'];
|
||||
log('EmailUtils::parsingAttachmentByUri:blobId = $blobId | name = $name | size = $size | type = $type');
|
||||
return Attachment(
|
||||
blobId: Id(blobId),
|
||||
name: name,
|
||||
size: size?.isNotEmpty == true ? UnsignedInt(int.parse(size!)) : null,
|
||||
type: type?.isNotEmpty == true ? MediaType.parse(type!) : null,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('EmailUtils::parsingAttachmentByUri:Exception = $e:');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user