Bugfix handling attachments MIME type / content-type as it was broken.

This commit is contained in:
the-djmaze 2022-11-16 15:14:00 +01:00
parent ee5fb1a83e
commit f4448635d1
12 changed files with 461 additions and 302 deletions

View file

@ -22,7 +22,8 @@ const
ics: 'text/calendar',
xml: 'text/xml',
json: app+'json',
asc: app+'pgp-signature',
// asc: app+'pgp-signature',
// asc: app+'pgp-keys',
p10: app+'pkcs10',
p7c: app+'pkcs7-mime',
p7m: app+'pkcs7-mime',

View file

@ -27,6 +27,7 @@ export class ComposeAttachmentModel extends AbstractModel {
fileName: fileName,
size: size,
tempName: '',
type: '', // application/octet-stream
progress: 0,
error: '',
@ -54,7 +55,7 @@ export class ComposeAttachmentModel extends AbstractModel {
return null === localSize ? '' : FileInfo.friendlySize(localSize);
},
mimeType: () => FileInfo.getContentType(this.fileName()),
mimeType: () => this.type() || FileInfo.getContentType(this.fileName()),
fileExt: () => FileInfo.getExtension(this.fileName()),
iconClass: () => FileInfo.getIconClass(this.fileExt(), this.mimeType())

View file

@ -11,7 +11,7 @@ import {
SetSystemFoldersNotification
} from 'Common/EnumsUser';
import { pInt, isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
import { pInt, isArray, arrayLength } from 'Common/Utils';
import { encodeHtml, HtmlEditor, htmlToPlain } from 'Common/Html';
import { koArrayWithDestroy, addObservablesTo, addComputablesTo, addSubscribablesTo } from 'External/ko';
@ -973,28 +973,22 @@ export class ComposePopupView extends AbstractViewPopup {
if (arrayLength(downloads)) {
Remote.request('MessageUploadAttachments',
(iError, oData) => {
if (!iError) {
forEachObjectEntry(oData.Result, (tempName, id) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment.tempName(tempName);
attachment
.waiting(false)
.uploading(false)
.complete(true);
const result = oData?.Result;
downloads.forEach((id, index) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment
.waiting(false)
.uploading(false)
.complete(true);
if (iError || !result?.[index]) {
attachment.error(getUploadErrorDescByCode(UploadErrorCode.NoFileUploaded));
} else {
attachment.tempName(result[index].TempName);
attachment.type(result[index].MimeType);
}
});
} else {
this.attachments.forEach(attachment => {
if (attachment?.fromMessage) {
attachment
.waiting(false)
.uploading(false)
.complete(true)
.error(getUploadErrorDescByCode(UploadErrorCode.NoFileUploaded));
}
});
}
}
});
},
{
Attachments: downloads
@ -1123,6 +1117,7 @@ export class ComposePopupView extends AbstractViewPopup {
attachment.size(attachmentJson.Size ? pInt(attachmentJson.Size) : 0);
attachment.tempName(attachmentJson.TempName ? attachmentJson.TempName : '');
attachment.isInline = false;
attachment.type(attachmentJson.MimeType);
}
}
});
@ -1178,20 +1173,6 @@ export class ComposePopupView extends AbstractViewPopup {
return this.attachments.find(item => item && id === item.id);
}
/**
* @returns {Object}
*/
prepareAttachmentsForSendOrSave() {
const result = {};
this.attachments.forEach(item => {
if (item?.complete() && item?.tempName() && item?.enabled()) {
result[item.tempName()] = [item.fileName(), item.isInline ? '1' : '0', item.CID, item.contentLocation];
}
});
return result;
}
/**
* @param {MessageModel} message
*/
@ -1237,6 +1218,7 @@ export class ComposePopupView extends AbstractViewPopup {
if (message) {
let reply = [ComposeType.Reply, ComposeType.ReplyAll].includes(type);
if (reply || [ComposeType.Forward, ComposeType.Draft, ComposeType.EditAsNew].includes(type)) {
// item instanceof AttachmentModel
message.attachments.forEach(item => {
if (!reply || item.isLinked()) {
const attachment = new ComposeAttachmentModel(
@ -1249,6 +1231,7 @@ export class ComposePopupView extends AbstractViewPopup {
item.contentLocation
);
attachment.fromMessage = true;
attachment.type(item.mimeType);
this.addAttachment(attachment);
}
});
@ -1405,6 +1388,20 @@ export class ComposePopupView extends AbstractViewPopup {
async getMessageRequestParams(sSaveFolder, draft)
{
// Prepare ComposeAttachmentModel attachments
const attachments = {};
this.attachments.forEach(item => {
if (item?.complete() && item?.tempName() && item?.enabled()) {
attachments[item.tempName()] = {
name: item.fileName(),
inline: item.isInline,
cid: item.CID,
location: item.contentLocation,
type: item.mimeType()
};
}
});
const
identity = this.currentIdentity(),
params = {
@ -1422,7 +1419,7 @@ export class ComposePopupView extends AbstractViewPopup {
InReplyTo: this.sInReplyTo,
References: this.sReferences,
MarkAsImportant: this.markAsImportant() ? 1 : 0,
Attachments: this.prepareAttachmentsForSendOrSave(),
Attachments: attachments,
// Only used at send, not at save:
Dsn: this.requestDsn() ? 1 : 0,
ReadReceiptRequest: this.requestReadReceipt() ? 1 : 0

View file

@ -69,8 +69,8 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
this.close();
}
onShow() {
this.key('');
onShow(key) {
this.key(key || '');
this.keyError(false);
this.keyErrorMessage('');
}

View file

@ -55,10 +55,17 @@ import { MimeToMessage } from 'Mime/Utils';
import { MessageModel } from 'Model/Message';
import { showScreenPopup } from 'Knoin/Knoin';
import { OpenPgpImportPopupView } from 'View/Popup/OpenPgpImport';
import { GnuPGUserStore } from 'Stores/User/GnuPG';
import { OpenPGPUserStore } from 'Stores/User/OpenPGP';
const
oMessageScrollerDom = () => elementById('messageItem') || {},
currentMessage = MessageUserStore.message;
currentMessage = MessageUserStore.message,
fetchRaw = url => rl.fetch(url).then(response => response.ok && response.text());
export class MailMessageView extends AbstractViewRight {
constructor() {
@ -284,22 +291,23 @@ export class MailMessageView extends AbstractViewRight {
el = eqs(event, '.attachmentsPlace .attachmentName');
if (el) {
const attachment = ko.dataFor(el);
if (attachment?.linkDownload()) {
if ('message/rfc822' == attachment.mimeType) {
const attachment = ko.dataFor(el), url = attachment?.linkDownload();
if (url) {
if ('application/pgp-keys' == attachment.mimeType
&& (OpenPGPUserStore.isSupported() || GnuPGUserStore.isSupported())) {
fetchRaw(url).then(text =>
showScreenPopup(OpenPgpImportPopupView, [text])
);
} else if ('message/rfc822' == attachment.mimeType) {
// TODO
rl.fetch(attachment.linkDownload()).then(response => {
if (response.ok) {
response.text().then(text => {
const oMessage = new MessageModel();
MimeToMessage(text, oMessage);
// cleanHTML
oMessage.viewPopupMessage();
});
}
fetchRaw(url).then(text => {
const oMessage = new MessageModel();
MimeToMessage(text, oMessage);
// cleanHTML
oMessage.viewPopupMessage();
});
} else {
download(attachment.linkDownload(), attachment.fileName);
download(url, attachment.fileName);
}
}
}