mailparser
Advanced tools
Comparing version 2.7.3 to 2.7.4
@@ -16,2 +16,3 @@ 'use strict'; | ||
const tlds = require('tlds'); | ||
const encodingJapanese = require('encoding-japanese'); | ||
@@ -84,2 +85,42 @@ linkify | ||
class JPDecoder extends Transform { | ||
constructor(charset) { | ||
super(); | ||
this.charset = charset; | ||
this.chunks = []; | ||
this.chunklen = 0; | ||
} | ||
_transform(chunk, encoding, done) { | ||
if (typeof chunk === 'string') { | ||
chunk = Buffer.from(chunk, encoding); | ||
} | ||
this.chunks.push(chunk); | ||
this.chunklen += chunk.length; | ||
done(); | ||
} | ||
_flush(done) { | ||
let input = Buffer.concat(this.chunks, this.chunklen); | ||
try { | ||
let output = encodingJapanese.convert(input, { | ||
to: 'UNICODE', // to_encoding | ||
from: this.charset, // from_encoding | ||
type: 'string' | ||
}); | ||
if (typeof output === 'string') { | ||
output = Buffer.from(output); | ||
} | ||
this.push(output); | ||
} catch (err) { | ||
// keep as is on errors | ||
this.push(input); | ||
} | ||
done(); | ||
} | ||
} | ||
class MailParser extends Transform { | ||
@@ -157,3 +198,16 @@ constructor(config) { | ||
} else { | ||
return iconv; | ||
return { | ||
decodeStream(charset) { | ||
charset = (charset || 'ascii') | ||
.toString() | ||
.trim() | ||
.toLowerCase(); | ||
if (/^jis|^iso-?2022-?jp|^EUCJP/i.test(charset)) { | ||
// special case not supported by iconv-lite | ||
return new JPDecoder(charset); | ||
} | ||
return iconv.decodeStream(charset); | ||
} | ||
}; | ||
} | ||
@@ -160,0 +214,0 @@ } |
{ | ||
"name": "mailparser", | ||
"version": "2.7.3", | ||
"version": "2.7.4", | ||
"description": "Parse e-mails", | ||
@@ -19,6 +19,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"encoding-japanese": "1.0.30", | ||
"he": "1.2.0", | ||
"html-to-text": "5.1.1", | ||
"iconv-lite": "0.5.0", | ||
"libmime": "4.1.4", | ||
"libmime": "4.2.1", | ||
"linkify-it": "2.2.0", | ||
@@ -25,0 +26,0 @@ "mailsplit": "4.4.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59816
1138
9
+ Addedencoding-japanese@1.0.30
+ Addedencoding-japanese@1.0.30(transitive)
+ Addedlibmime@4.2.1(transitive)
- Removedlibmime@4.1.4(transitive)
Updatedlibmime@4.2.1