TF-825 Download email as EML file (#2854)
This commit is contained in:
@@ -44,8 +44,8 @@ class Attachment with EquatableMixin {
|
||||
final downloadUri = downloadUriTemplate.expand({
|
||||
'accountId' : accountId.id.value,
|
||||
'blobId' : '${blobId?.value}',
|
||||
'name' : '$name',
|
||||
'type' : '${type?.mimeType}',
|
||||
'name' : name ?? '',
|
||||
'type' : type?.mimeType ?? '',
|
||||
});
|
||||
return Uri.decodeFull(downloadUri);
|
||||
}
|
||||
|
||||
@@ -27,5 +27,6 @@ enum EmailActionType {
|
||||
unsubscribe,
|
||||
composeFromUnsubscribeMailtoLink,
|
||||
archiveMessage,
|
||||
printAll
|
||||
printAll,
|
||||
downloadMessageAsEML
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
class EmailProperty {
|
||||
static const String id = 'id';
|
||||
static const String blobId = 'blobId';
|
||||
static const String keywords = 'keywords';
|
||||
static const String size = 'size';
|
||||
static const String receivedAt = 'receivedAt';
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
import 'package:model/email/attachment.dart';
|
||||
|
||||
class EMLAttachment extends Attachment {
|
||||
|
||||
EMLAttachment({
|
||||
super.partId,
|
||||
super.blobId,
|
||||
super.size,
|
||||
super.name,
|
||||
super.type,
|
||||
super.cid,
|
||||
super.disposition,
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:core/presentation/extensions/string_extension.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
@@ -21,6 +22,7 @@ import 'package:model/mailbox/select_mode.dart';
|
||||
class PresentationEmail with EquatableMixin {
|
||||
|
||||
final EmailId? id;
|
||||
final Id? blobId;
|
||||
final Map<KeyWordIdentifier, bool>? keywords;
|
||||
final UnsignedInt? size;
|
||||
final UTCDate? receivedAt;
|
||||
@@ -44,6 +46,7 @@ class PresentationEmail with EquatableMixin {
|
||||
|
||||
PresentationEmail({
|
||||
this.id,
|
||||
this.blobId,
|
||||
this.keywords,
|
||||
this.size,
|
||||
this.receivedAt,
|
||||
@@ -142,6 +145,7 @@ class PresentationEmail with EquatableMixin {
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
blobId,
|
||||
keywords,
|
||||
size,
|
||||
receivedAt,
|
||||
|
||||
@@ -67,6 +67,7 @@ extension EmailExtension on Email {
|
||||
Email updatedEmail({Map<KeyWordIdentifier, bool>? newKeywords, Map<MailboxId, bool>? newMailboxIds}) {
|
||||
return Email(
|
||||
id: id,
|
||||
blobId: blobId,
|
||||
keywords: newKeywords ?? keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -91,6 +92,7 @@ extension EmailExtension on Email {
|
||||
PresentationEmail toPresentationEmail({SelectMode selectMode = SelectMode.INACTIVE}) {
|
||||
return PresentationEmail(
|
||||
id: id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -113,6 +115,7 @@ extension EmailExtension on Email {
|
||||
Email combineEmail(Email newEmail, Properties updatedProperties) {
|
||||
return Email(
|
||||
id: newEmail.id,
|
||||
blobId: updatedProperties.contain(EmailProperty.blobId) ? newEmail.blobId : blobId,
|
||||
keywords: updatedProperties.contain(EmailProperty.keywords) ? newEmail.keywords : keywords,
|
||||
size: updatedProperties.contain(EmailProperty.size) ? newEmail.size : size,
|
||||
receivedAt: updatedProperties.contain(EmailProperty.receivedAt) ? newEmail.receivedAt : receivedAt,
|
||||
@@ -171,6 +174,7 @@ extension EmailExtension on Email {
|
||||
) {
|
||||
return PresentationEmail(
|
||||
id: emailId ?? id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/domain/extensions/datetime_extension.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/email/eml_attachment.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:model/extensions/email_address_extension.dart';
|
||||
import 'package:model/extensions/list_email_address_extension.dart';
|
||||
@@ -44,6 +47,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
PresentationEmail toggleSelect() {
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -67,6 +71,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
PresentationEmail toSelectedEmail({required SelectMode selectMode}) {
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -90,6 +95,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
Email toEmail() {
|
||||
return Email(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -146,6 +152,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -182,6 +189,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
PresentationEmail withRouteWeb(Uri routeWeb) {
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -205,6 +213,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
PresentationEmail updateKeywords(Map<KeyWordIdentifier, bool>? newKeywords) {
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: newKeywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -228,6 +237,7 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
PresentationEmail syncPresentationEmail({PresentationMailbox? mailboxContain, Uri? routeWeb}) {
|
||||
return PresentationEmail(
|
||||
id: this.id,
|
||||
blobId: blobId,
|
||||
keywords: keywords,
|
||||
size: size,
|
||||
receivedAt: receivedAt,
|
||||
@@ -262,4 +272,12 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
EMLAttachment createEMLAttachment() {
|
||||
return EMLAttachment(
|
||||
blobId: blobId,
|
||||
name: getEmailTitle().isEmpty ? '${blobId?.value}.eml' : '${getEmailTitle()}.eml',
|
||||
type: MediaType.parse(Constant.octetStreamMimeType)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user