New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rfc2047

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rfc2047 - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

19

lib/rfc2047.js
/*jshint regexp:false*/
/*global escape, unescape*/
/*global unescape*/
var isUtf8RegExp = /^utf-?8$/i,
isLatin1RegExp = /^(?:iso-8859-1|latin1)$/i,
canBeLatin1EncodedRegExp = /^[\u0000-\u00ff]*$/,
iconvLite = require('iconv-lite'),

@@ -217,15 +216,5 @@ rfc2047 = module.exports = {};

var charset,
encodedWordBody;
// First see if the text can be represented in iso-8859-1, which takes up less space and
// enjoys more whitespread support than utf-8 (old email clients).
if (canBeLatin1EncodedRegExp.test(token)) {
charset = 'iso-8859-1';
// More than twice as fast as bufferToQuotedPrintableString(new iconv.Iconv("utf-8", "iso-8859-1").convert(token)):
encodedWordBody = escape(token.replace(/ /g, "_")).replace(/%21/g, '!').replace(/%3D/g, '=').replace(/%/g, "=");
} else {
charset = 'utf-8';
// Around 25% faster than encodeURIComponent(token.replace(/ /g, "_")).replace(/%/g, "="):
encodedWordBody = bufferToQuotedPrintableString(new Buffer(token, 'utf-8'));
}
var charset = 'utf-8';
// Around 25% faster than encodeURIComponent(token.replace(/ /g, "_")).replace(/%/g, "="):
var encodedWordBody = bufferToQuotedPrintableString(new Buffer(token, 'utf-8'));
if (previousTokenWasEncodedWord) {

@@ -232,0 +221,0 @@ result += ' ';

{
"name": "rfc2047",
"version": "1.0.2",
"version": "2.0.0",
"description": "Encode and decode rfc2047 (MIME encoded words)",

@@ -5,0 +5,0 @@ "main": "lib/rfc2047.js",

@@ -10,3 +10,3 @@ rfc2047

console.log(rfc2047.encode('Foo bar æøå ☺'));
// Foo bar =?iso-8859-1?Q?=E6=F8=E5?= =?utf-8?Q?_=E2=98=BA?=
// Foo bar =?utf-8?Q?=C3=A6=C3=B8=C3=A5?= =?utf-8?Q?_=E2=98=BA?=

@@ -13,0 +13,0 @@ console.log(rfc2047.decode('=?iso-8859-1?Q?=A1?=Hola, se=?iso-8859-1?Q?=F1?=or!'));

@@ -33,3 +33,3 @@ /*global describe, it*/

it('should handle a multi-word string where the middle word has to be encoded', function () {
expect('Andreas Lindø <andreas@one.com>', 'to encode back and forth to', 'Andreas =?iso-8859-1?Q?Lind=F8?= <andreas@one.com>');
expect('Andreas Lindø <andreas@one.com>', 'to encode back and forth to', 'Andreas =?utf-8?Q?Lind=C3=B8?= <andreas@one.com>');
});

@@ -42,4 +42,4 @@

it('should handle two neighbouring words that have to be encoded', function () {
expect('¡Hola, señor!', 'to encode back and forth to', '=?iso-8859-1?Q?=A1Hola=2C?= =?iso-8859-1?Q?_se=F1or!?=');
expect('På lördag', 'to encode back and forth to', '=?iso-8859-1?Q?P=E5?= =?iso-8859-1?Q?_l=F6rdag?=');
expect('¡Hola, señor!', 'to encode back and forth to', '=?utf-8?Q?=C2=A1Hola=2C?= =?utf-8?Q?_se=C3=B1or!?=');
expect('På lördag', 'to encode back and forth to', '=?utf-8?Q?P=C3=A5?= =?utf-8?Q?_l=C3=B6rdag?=');
});

@@ -52,15 +52,15 @@

it('should handle some dreamed up edge cases', function () {
expect('lördag', 'to encode back and forth to', '=?iso-8859-1?Q?l=F6rdag?=');
expect('lördag', 'to encode back and forth to', '=?utf-8?Q?l=C3=B6rdag?=');
});
it('should handle a multi-word string where the middle word has to be left unencoded', function () {
expect('Så er fødselen i gang', 'to encode back and forth to', '=?iso-8859-1?Q?S=E5?= er =?iso-8859-1?Q?f=F8dselen?= i gang');
expect('Så er fødselen i gang', 'to encode back and forth to', '=?utf-8?Q?S=C3=A5?= er =?utf-8?Q?f=C3=B8dselen?= i gang');
});
it('should place leading quotes correctly', function () {
expect('"ÅÄÖ" <sss@example.com>', 'to encode back and forth to', '"=?iso-8859-1?Q?=C5=C4=D6?=" <sss@example.com>');
expect('"ÅÄÖ" <sss@example.com>', 'to encode back and forth to', '"=?utf-8?Q?=C3=85=C3=84=C3=96?=" <sss@example.com>');
});
it('should place trailing quotes correctly', function () {
expect('"TEST ÅÄÖ" <sss@example.com>', 'to encode back and forth to', '"TEST =?iso-8859-1?Q?=C5=C4=D6?=" <sss@example.com>');
expect('"TEST ÅÄÖ" <sss@example.com>', 'to encode back and forth to', '"TEST =?utf-8?Q?=C3=85=C3=84=C3=96?=" <sss@example.com>');
});

@@ -88,3 +88,3 @@ });

'to encode to',
'=?iso-8859-1?Q?=00=01=02=03=04=05=06=07?= =?iso-8859-1?Q?=08?= =?iso-8859-1?Q?_=0E=0F=10=11=12=13=14=15?= =?iso-8859-1?Q?=16=17=18=19=1A=1B=1C=1D?= =?iso-8859-1?Q?=1E=1F?='
'=?utf-8?Q?=00=01=02=03=04=05=06=07?= =?utf-8?Q?=08?= =?utf-8?Q?_=0E=0F=10=11=12=13=14=15?= =?utf-8?Q?=16=17=18=19=1A=1B=1C=1D?= =?utf-8?Q?=1E=1F?='
);

@@ -102,3 +102,3 @@ });

it('should not split a backslash from the doublequote it is escaping', function () {
expect('"Öland\\""', 'to encode to', '"=?iso-8859-1?Q?=D6land?=\\""');
expect('"Öland\\""', 'to encode to', '"=?utf-8?Q?=C3=96land?=\\""');
});

@@ -105,0 +105,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc