Skip to content

Commit

Permalink
Improve illegal 'Content-Transfer-Encoding' error
Browse files Browse the repository at this point in the history
  • Loading branch information
jorangreef committed Jul 22, 2019
1 parent 2d35710 commit 1076b9f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,17 @@ MIME.decodeBody = function(buffer, contentType, contentTransferEncoding) {
// Further, some systems incorrectly apply a content-transfer-encoding to a
// multipart body, causing corruption and/or missing multiparts if the
// encoding is decoded.

// Options:
// 1. Reject content-transfer-encoding on all composite media types.
// 2. Reject content-transfer-encoding on multiparts.
// 3. Reject content-transfer-encoding on multiparts but allow base64.
// 4. Ignore content-transfer-encoding on multiparts.
// 5. Follow content-transfer-encoding on multiparts.
if (
/^(message|multipart)\//.test(contentType.value) &&
contentTransferEncoding !== '7bit' &&
contentTransferEncoding !== '8bit' &&
contentTransferEncoding !== 'binary'
) {
throw new Error(self.Error.ContentTransferEncodingComposite);
if (/^message\//.test(contentType.value)) {
throw new Error(self.Error.ContentTransferEncodingMessage);
}
if (/^multipart\//.test(contentType.value)) {
throw new Error(self.Error.ContentTransferEncodingMultipart);
}
}
if (contentTransferEncoding === 'base64') {
// RFC 2045 6.8 Base64 Content-Transfer-Encoding
Expand Down Expand Up @@ -3390,8 +3387,11 @@ MIME.Error = {
"(see RFC 2045 2.2, RFC 2046 4.1.2, RFC 2047 3 and RFC 2231).\r\n",
CommentUnterminated: "550 Your email had a header with an unterminated " +
"comment (see RFC 5322 3.2.2).\r\n",
ContentTransferEncodingComposite: "550 Your email had an illegal " +
"'Content-Transfer-Encoding' mechanism for a composite or 'multipart' " +
ContentTransferEncodingMessage: "550 Your email had an illegal " +
"'Content-Transfer-Encoding' mechanism on a 'message' composite media " +
"type (see RFC 2045 6.4).\r\n",
ContentTransferEncodingMultipart: "550 Your email had an illegal " +
"'Content-Transfer-Encoding' mechanism on a 'multipart' composite media " +
"type (see RFC 2045 6.4).\r\n",
ContentTransferEncodingUnrecognized: "550 Your email had an unrecognized " +
"'Content-Transfer-Encoding' mechanism (see RFC 2045 6.1 and 6.4).\r\n",
Expand Down

0 comments on commit 1076b9f

Please sign in to comment.