From c96bef7839f29e11313cad9d7a3cb15f83034f90 Mon Sep 17 00:00:00 2001 From: Ping Chen Date: Mon, 29 Mar 2021 13:51:30 +0300 Subject: [PATCH] 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 --- mailnews/compose/src/MessageSend.jsm | 15 +++++++++++--- mailnews/compose/src/MimeMessageUtils.jsm | 7 ++++--- mailnews/compose/src/MimePart.jsm | 25 ++++++++++++++--------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/mailnews/compose/src/MessageSend.jsm b/mailnews/compose/src/MessageSend.jsm index 35130df146..47e585b97f 100644 --- a/mailnews/compose/src/MessageSend.jsm +++ b/mailnews/compose/src/MessageSend.jsm @@ -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; } diff --git a/mailnews/compose/src/MimeMessageUtils.jsm b/mailnews/compose/src/MimeMessageUtils.jsm index a6247aa689..27ff172a86 100644 --- a/mailnews/compose/src/MimeMessageUtils.jsm +++ b/mailnews/compose/src/MimeMessageUtils.jsm @@ -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 ); } diff --git a/mailnews/compose/src/MimePart.jsm b/mailnews/compose/src/MimePart.jsm index fb1633e4e8..10e9463191 100644 --- a/mailnews/compose/src/MimePart.jsm +++ b/mailnews/compose/src/MimePart.jsm @@ -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}>`); }