This commit is contained in:
the-djmaze 2023-05-16 12:20:45 +02:00
parent 0bd5603dd0
commit a504fd9298

View file

@ -320,7 +320,7 @@ export class ComposePopupView extends AbstractViewPopup {
attachmentsCount: () => this.attachments().length, attachmentsCount: () => this.attachments().length,
attachmentsInErrorCount: () => this.attachmentsInError.length, attachmentsInErrorCount: () => this.attachmentsInError.length,
attachmentsInProcessCount: () => this.attachmentsInProcess.length, attachmentsInProcessCount: () => this.attachmentsInProcess.length,
isDraftFolderMessage: () => this.draftsFolder() && this.draftUid(), isDraft: () => this.draftsFolder() && this.draftUid(),
identitiesOptions: () => identitiesOptions: () =>
IdentityUserStore.map(item => ({ IdentityUserStore.map(item => ({
@ -399,7 +399,9 @@ export class ComposePopupView extends AbstractViewPopup {
* The iframe will be injected into the container identified by selector. * The iframe will be injected into the container identified by selector.
* https://mailvelope.github.io/mailvelope/Editor.html * https://mailvelope.github.io/mailvelope/Editor.html
*/ */
let text = this.oEditor.getData(), let armored = oLastMessage && oLastMessage.body.classList.contains('mailvelope'),
text = armored ? oLastMessage.plain() : this.oEditor.getData(),
draft = this.isDraft(),
encrypted = PgpUserStore.isEncrypted(text), encrypted = PgpUserStore.isEncrypted(text),
size = SettingsGet('phpUploadSizes')['post_max_size'], size = SettingsGet('phpUploadSizes')['post_max_size'],
quota = pInt(size); quota = pInt(size);
@ -413,10 +415,10 @@ export class ComposePopupView extends AbstractViewPopup {
mailvelope.createEditorContainer('#mailvelope-editor', PgpUserStore.mailvelopeKeyring, { mailvelope.createEditorContainer('#mailvelope-editor', PgpUserStore.mailvelopeKeyring, {
// https://mailvelope.github.io/mailvelope/global.html#EditorContainerOptions // https://mailvelope.github.io/mailvelope/global.html#EditorContainerOptions
quota: Math.max(2048, (quota / 1024)) - 48, // (text + attachments) limit in kilobytes quota: Math.max(2048, (quota / 1024)) - 48, // (text + attachments) limit in kilobytes
armoredDraft: encrypted ? text : '', // Ascii Armored PGP Text Block armoredDraft: (encrypted && draft) ? text : '', // Ascii Armored PGP Text Block
predefinedText: encrypted ? '' : (this.oEditor.isHtml() ? htmlToPlain(text) : text), predefinedText: encrypted ? '' : (this.oEditor.isHtml() ? htmlToPlain(text) : text),
quotedMail: (encrypted && !draft) ? text : '', // Ascii Armored PGP Text Block mail that should be quoted
/* /*
quotedMail: '', // Ascii Armored PGP Text Block mail that should be quoted
quotedMailIndent: true, // if true the quoted mail will be indented (default: true) quotedMailIndent: true, // if true the quoted mail will be indented (default: true)
quotedMailHeader: '', // header to be added before the quoted mail quotedMailHeader: '', // header to be added before the quoted mail
keepAttachments: false, // add attachments of quotedMail to editor (default: false) keepAttachments: false, // add attachments of quotedMail to editor (default: false)
@ -431,7 +433,7 @@ export class ComposePopupView extends AbstractViewPopup {
decorateKoCommands(this, { decorateKoCommands(this, {
sendCommand: self => self.canBeSentOrSaved(), sendCommand: self => self.canBeSentOrSaved(),
saveCommand: self => self.canBeSentOrSaved(), saveCommand: self => self.canBeSentOrSaved(),
deleteCommand: self => self.isDraftFolderMessage(), deleteCommand: self => self.isDraft(),
skipCommand: self => self.canBeSentOrSaved(), skipCommand: self => self.canBeSentOrSaved(),
contactsCommand: self => self.allowContacts contactsCommand: self => self.allowContacts
}); });
@ -733,14 +735,25 @@ export class ComposePopupView extends AbstractViewPopup {
this.viewModelDom.dataset.wysiwyg = SettingsUserStore.editorDefaultType(); this.viewModelDom.dataset.wysiwyg = SettingsUserStore.editorDefaultType();
let options = {
mode: type || ComposeType.Empty,
to: aToEmails,
cc: aCcEmails,
bcc: aBccEmails,
subject: sCustomSubject,
text: sCustomPlainText
};
if (1 < arrayLength(oMessageOrArray)) {
options.messages = oMessageOrArray;
} else {
options.message = isArray(oMessageOrArray) ? oMessageOrArray[0] : oMessageOrArray;
}
if (ComposePopupView.inEdit()) { if (ComposePopupView.inEdit()) {
type = type || ComposeType.Empty; if (ComposeType.Empty !== options.mode) {
if (ComposeType.Empty !== type) {
showScreenPopup(AskPopupView, [ showScreenPopup(AskPopupView, [
i18n('COMPOSE/DISCARD_UNSAVED_DATA'), i18n('COMPOSE/DISCARD_UNSAVED_DATA'),
() => { () => this.initOnShow(options),
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText);
},
null, null,
false false
]); ]);
@ -754,7 +767,7 @@ export class ComposePopupView extends AbstractViewPopup {
} }
} }
} else { } else {
this.initOnShow(type, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText); this.initOnShow(options);
} }
ComposePopupView.inEdit(false); ComposePopupView.inEdit(false);
@ -764,34 +777,16 @@ export class ComposePopupView extends AbstractViewPopup {
} }
/** /**
* @param {string=} sType = ComposeType.Empty * @param {object} options
* @param {?MessageModel|Array=} oMessageOrArray = null
* @param {Array=} aToEmails = null
* @param {Array=} aCcEmails = null
* @param {Array=} aBccEmails = null
* @param {string=} sCustomSubject = null
* @param {string=} sCustomPlainText = null
*/ */
initOnShow(sType, oMessageOrArray, aToEmails, aCcEmails, aBccEmails, sCustomSubject, sCustomPlainText) { initOnShow(options) {
let sFrom = '',
sTo = '',
sCc = '',
sDate = '',
sSubject = '',
sText = '',
identity = null,
aDraftInfo = null,
message = 1 === arrayLength(oMessageOrArray)
? oMessageOrArray[0]
: (isArray(oMessageOrArray) ? null : oMessageOrArray);
const const
// excludeEmail = new Set(), // excludeEmail = new Set(),
excludeEmail = {}, excludeEmail = {},
mEmail = AccountUserStore.email(), mEmail = AccountUserStore.email();
msgComposeType = sType || ComposeType.Empty;
oLastMessage = message; oLastMessage = options.message;
if (mEmail) { if (mEmail) {
// excludeEmail.add(mEmail); // excludeEmail.add(mEmail);
@ -800,17 +795,18 @@ export class ComposePopupView extends AbstractViewPopup {
this.reset(); this.reset();
if (message) { let identity = null;
switch (msgComposeType) { if (oLastMessage) {
switch (options.mode) {
case ComposeType.Reply: case ComposeType.Reply:
case ComposeType.ReplyAll: case ComposeType.ReplyAll:
case ComposeType.Forward: case ComposeType.Forward:
case ComposeType.ForwardAsAttachment: case ComposeType.ForwardAsAttachment:
identity = findIdentity(message.to.concat(message.cc, message.bcc)) identity = findIdentity(oLastMessage.to.concat(oLastMessage.cc, oLastMessage.bcc))
/* || findIdentity(message.deliveredTo)*/; /* || findIdentity(oLastMessage.deliveredTo)*/;
break; break;
case ComposeType.Draft: case ComposeType.Draft:
identity = findIdentity(message.from.concat(message.replyTo)); identity = findIdentity(oLastMessage.from.concat(oLastMessage.replyTo));
break; break;
// no default // no default
// case ComposeType.Empty: // case ComposeType.Empty:
@ -822,66 +818,69 @@ export class ComposePopupView extends AbstractViewPopup {
excludeEmail[identity.email()] = true; excludeEmail[identity.email()] = true;
} }
if (arrayLength(aToEmails)) { if (arrayLength(options.to)) {
this.to(emailArrayToStringLineHelper(aToEmails)); this.to(emailArrayToStringLineHelper(options.to));
} }
if (arrayLength(aCcEmails)) { if (arrayLength(options.cc)) {
this.cc(emailArrayToStringLineHelper(aCcEmails)); this.cc(emailArrayToStringLineHelper(options.cc));
} }
if (arrayLength(aBccEmails)) { if (arrayLength(options.bcc)) {
this.bcc(emailArrayToStringLineHelper(aBccEmails)); this.bcc(emailArrayToStringLineHelper(options.bcc));
} }
if (msgComposeType && message) { if (options.mode && oLastMessage) {
sDate = timestampToString(message.dateTimestamp(), 'FULL'); let encrypted,
sSubject = message.subject(); sCc = '',
aDraftInfo = message.draftInfo; sDate = timestampToString(oLastMessage.dateTimestamp(), 'FULL'),
sSubject = oLastMessage.subject(),
sText = '',
aDraftInfo = oLastMessage.draftInfo;
switch (msgComposeType) { switch (options.mode) {
case ComposeType.Reply: case ComposeType.Reply:
case ComposeType.ReplyAll: case ComposeType.ReplyAll:
if (ComposeType.Reply === msgComposeType) { if (ComposeType.Reply === options.mode) {
this.to(emailArrayToStringLineHelper(message.replyEmails(excludeEmail))); this.to(emailArrayToStringLineHelper(oLastMessage.replyEmails(excludeEmail)));
} else { } else {
let parts = message.replyAllEmails(excludeEmail); let parts = oLastMessage.replyAllEmails(excludeEmail);
this.to(emailArrayToStringLineHelper(parts[0])); this.to(emailArrayToStringLineHelper(parts[0]));
this.cc(emailArrayToStringLineHelper(parts[1])); this.cc(emailArrayToStringLineHelper(parts[1]));
} }
this.subject(replySubjectAdd('Re', sSubject)); this.subject(replySubjectAdd('Re', sSubject));
this.prepareMessageAttachments(message, msgComposeType); this.prepareMessageAttachments(oLastMessage, options.mode);
this.aDraftInfo = ['reply', message.uid, message.folder]; this.aDraftInfo = ['reply', oLastMessage.uid, oLastMessage.folder];
this.sInReplyTo = message.messageId; this.sInReplyTo = oLastMessage.messageId;
this.sReferences = (message.messageId + ' ' + message.references).trim(); this.sReferences = (oLastMessage.messageId + ' ' + oLastMessage.references).trim();
// OpenPGP “Transferable Public Key” // OpenPGP “Transferable Public Key”
// message.autocrypt?.keydata // oLastMessage.autocrypt?.keydata
break; break;
case ComposeType.Forward: case ComposeType.Forward:
case ComposeType.ForwardAsAttachment: case ComposeType.ForwardAsAttachment:
this.subject(replySubjectAdd('Fwd', sSubject)); this.subject(replySubjectAdd('Fwd', sSubject));
this.prepareMessageAttachments(message, msgComposeType); this.prepareMessageAttachments(oLastMessage, options.mode);
this.aDraftInfo = ['forward', message.uid, message.folder]; this.aDraftInfo = ['forward', oLastMessage.uid, oLastMessage.folder];
this.sInReplyTo = message.messageId; this.sInReplyTo = oLastMessage.messageId;
this.sReferences = (message.messageId + ' ' + message.references).trim(); this.sReferences = (oLastMessage.messageId + ' ' + oLastMessage.references).trim();
break; break;
case ComposeType.Draft: case ComposeType.Draft:
this.bFromDraft = true; this.bFromDraft = true;
this.draftsFolder(message.folder); this.draftsFolder(oLastMessage.folder);
this.draftUid(message.uid); this.draftUid(oLastMessage.uid);
// fallthrough // fallthrough
case ComposeType.EditAsNew: case ComposeType.EditAsNew:
this.to(emailArrayToStringLineHelper(message.to)); this.to(emailArrayToStringLineHelper(oLastMessage.to));
this.cc(emailArrayToStringLineHelper(message.cc)); this.cc(emailArrayToStringLineHelper(oLastMessage.cc));
this.bcc(emailArrayToStringLineHelper(message.bcc)); this.bcc(emailArrayToStringLineHelper(oLastMessage.bcc));
this.replyTo(emailArrayToStringLineHelper(message.replyTo)); this.replyTo(emailArrayToStringLineHelper(oLastMessage.replyTo));
this.subject(sSubject); this.subject(sSubject);
this.prepareMessageAttachments(message, msgComposeType); this.prepareMessageAttachments(oLastMessage, options.mode);
this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null; this.aDraftInfo = 3 === arrayLength(aDraftInfo) ? aDraftInfo : null;
this.sInReplyTo = message.inReplyTo; this.sInReplyTo = oLastMessage.inReplyTo;
this.sReferences = message.references; this.sReferences = oLastMessage.references;
break; break;
// case ComposeType.Empty: // case ComposeType.Empty:
@ -889,33 +888,29 @@ export class ComposePopupView extends AbstractViewPopup {
// no default // no default
} }
let encrypted;
// https://github.com/the-djmaze/snappymail/issues/491 // https://github.com/the-djmaze/snappymail/issues/491
tpl.innerHTML = message.bodyAsHTML(); tpl.innerHTML = oLastMessage.bodyAsHTML();
tpl.content.querySelectorAll('img').forEach(img => { tpl.content.querySelectorAll('img').forEach(img => {
img.src || img.dataset.xSrcCid || img.dataset.xSrc || img.replaceWith(img.alt || img.title) img.src || img.dataset.xSrcCid || img.dataset.xSrc || img.replaceWith(img.alt || img.title)
}); });
sText = tpl.innerHTML.trim(); sText = tpl.innerHTML.trim();
switch (msgComposeType) { switch (options.mode) {
case ComposeType.Reply: case ComposeType.Reply:
case ComposeType.ReplyAll: case ComposeType.ReplyAll:
sFrom = message.from.toString(false, true); sText = '<br><br><p>'
sText = '<br><br><p>' + i18n('COMPOSE/REPLY_MESSAGE_TITLE', { DATETIME: sDate, EMAIL: sFrom }) + i18n('COMPOSE/REPLY_MESSAGE_TITLE', { DATETIME: sDate, EMAIL: oLastMessage.from.toString(false, true) })
+ ':</p><blockquote>' + ':</p><blockquote>'
+ sText.trim() + sText.trim()
+ '</blockquote>'; + '</blockquote>';
break; break;
case ComposeType.Forward: case ComposeType.Forward:
sFrom = message.from.toString(false, true); sCc = oLastMessage.cc.toString(false, true);
sTo = message.to.toString(false, true);
sCc = message.cc.toString(false, true);
sText = '<br><br><p>' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') + '</p><div>' sText = '<br><br><p>' + i18n('COMPOSE/FORWARD_MESSAGE_TOP_TITLE') + '</p><div>'
+ i18n('GLOBAL/FROM') + ': ' + sFrom + i18n('GLOBAL/FROM') + ': ' + oLastMessage.from.toString(false, true)
+ '<br>' + '<br>'
+ i18n('GLOBAL/TO') + ': ' + sTo + i18n('GLOBAL/TO') + ': ' + oLastMessage.to.toString(false, true)
+ (sCc.length ? '<br>' + i18n('GLOBAL/CC') + ': ' + sCc : '') + (sCc.length ? '<br>' + i18n('GLOBAL/CC') + ': ' + sCc : '')
+ '<br>' + '<br>'
+ i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT') + i18n('COMPOSE/FORWARD_MESSAGE_TOP_SENT')
@ -937,7 +932,7 @@ export class ComposePopupView extends AbstractViewPopup {
default: default:
encrypted = PgpUserStore.isEncrypted(sText); encrypted = PgpUserStore.isEncrypted(sText);
if (encrypted) { if (encrypted) {
sText = message.plain(); sText = oLastMessage.plain();
} }
} }
@ -947,22 +942,22 @@ export class ComposePopupView extends AbstractViewPopup {
editor.modePlain(); editor.modePlain();
} }
encrypted && editor.setPlain(sText); encrypted && editor.setPlain(sText);
this.setSignature(identity, msgComposeType); this.setSignature(identity, options.mode);
this.setFocusInPopup(); this.setFocusInPopup();
}); });
} else if (ComposeType.Empty === msgComposeType) { } else if (ComposeType.Empty === options.mode) {
this.subject(null != sCustomSubject ? '' + sCustomSubject : ''); this.subject(null != options.subject ? '' + options.subject : '');
this.editor(editor => { this.editor(editor => {
editor.setHtml(sCustomPlainText ? '' + sCustomPlainText : ''); editor.setHtml(options.text ? '' + options.text : '');
isPlainEditor() && editor.modePlain(); isPlainEditor() && editor.modePlain();
this.setSignature(identity); this.setSignature(identity);
this.setFocusInPopup(); this.setFocusInPopup();
}); });
} else if (arrayLength(oMessageOrArray)) { } else if (options.messages) {
oMessageOrArray.forEach(item => this.addMessageAsAttachment(item)); options.messages.forEach(item => this.addMessageAsAttachment(item));
this.editor(editor => { this.editor(editor => {
isPlainEditor() ? editor.setPlain('') : editor.setHtml(''); isPlainEditor() ? editor.setPlain('') : editor.setHtml('');
this.setSignature(identity, msgComposeType); this.setSignature(identity, options.mode);
this.setFocusInPopup(); this.setFocusInPopup();
}); });
} else { } else {