Bug 1701450 - Prevent error when attachment name is empty in MessageSend.jsm. r=mkmelin

Also fix error msg of NS_MSG_ERROR_ATTACHING_FILE.

Differential Revision: https://phabricator.services.mozilla.com/D110054

--HG--
extra : amend_source : 0b3a54db2a7b7a9fce30c3bf927c4ff3098c484b
This commit is contained in:
Ping Chen 2021-03-29 13:51:30 +03:00
Родитель 9742ff046f
Коммит c96bef7839
3 изменённых файлов: 31 добавлений и 16 удалений

Просмотреть файл

@ -120,7 +120,14 @@ MessageSend.prototype = {
messageFile = await this._message.createMessageFile();
} catch (e) {
MsgUtils.sendLogger.error(e);
this.fail(e.result || Cr.NS_ERROR_FAILURE);
let errorMsg = "";
if (e.result == MsgUtils.NS_MSG_ERROR_ATTACHING_FILE) {
errorMsg = this._composeBundle.formatStringFromName(
"errorAttachingFile",
[e.data.name || e.data.url]
);
}
this.fail(e.result || Cr.NS_ERROR_FAILURE, errorMsg);
this.notifyListenerOnStopSending(null, e.result, null, null);
return null;
}
@ -287,7 +294,9 @@ MessageSend.prototype = {
let prompter = Cc["@mozilla.org/prompter;1"].getService(
Ci.nsIPromptFactory
);
return prompter.getPrompt(this._parentWindow, Ci.nsIPrompt);
try {
return prompter.getPrompt(this._parentWindow, Ci.nsIPrompt);
} catch (e) {}
}
// If we cannot find a prompter, try the mail3Pane window.
let prompt;
@ -378,7 +387,7 @@ MessageSend.prototype = {
let folder = MailUtils.getOrCreateFolder(this._folderUri);
let accountName = folder?.server.prettyName;
if (!this._fcc || !localFoldersAccountName || !accountName) {
this.fail(Cr.NS_OK, null, status);
this.fail(Cr.NS_OK, null);
return;
}

Просмотреть файл

@ -24,9 +24,10 @@ const NS_ERROR_MODULE_MAILNEWS = 16;
*/
function generateNSError(code) {
return (
(1 << 31) |
((NS_ERROR_MODULE_MAILNEWS + NS_ERROR_MODULE_BASE_OFFSET) << 16) |
code
((1 << 31) |
((NS_ERROR_MODULE_MAILNEWS + NS_ERROR_MODULE_BASE_OFFSET) << 16) |
code) >>>
0
);
}

Просмотреть файл

@ -242,11 +242,14 @@ class MimePart {
2
);
// File name can contain non-ASCII chars, encode according to RFC 2231.
let encodedName = MsgUtils.rfc2047EncodeParam(this._bodyAttachment.name);
let encodedFileName = MsgUtils.rfc2231ParamFolding(
"filename",
this._bodyAttachment.name
);
let encodedName, encodedFileName;
if (this._bodyAttachment.name) {
encodedName = MsgUtils.rfc2047EncodeParam(this._bodyAttachment.name);
encodedFileName = MsgUtils.rfc2231ParamFolding(
"filename",
this._bodyAttachment.name
);
}
let buf = await res.arrayBuffer();
let content = jsmime.mimeutils.typedArrayToString(new Uint8Array(buf));
@ -256,14 +259,16 @@ class MimePart {
if (this._charset) {
contentTypeParams += `; charset=${this._charset}`;
}
if (parmFolding != 2) {
if (encodedName && parmFolding != 2) {
contentTypeParams += `; name="${encodedName}"`;
}
this.setHeader("content-type", `${this._contentType}${contentTypeParams}`);
this.setHeader(
"content-disposition",
`${this._contentDisposition}; ${encodedFileName}`
);
if (encodedFileName) {
this.setHeader(
"content-disposition",
`${this._contentDisposition}; ${encodedFileName}`
);
}
if (this._contentId) {
this.setHeader("content-id", `<${this._contentId}>`);
}