mirror of
https://github.com/sakaljurgis/nntp-worker.git
synced 2026-07-08 21:27:41 +00:00
initial
This commit is contained in:
@@ -0,0 +1 @@
|
||||
*.js text eol=lf
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
upgrade: true,
|
||||
reject: [
|
||||
// api changes, check and fix
|
||||
'eslint',
|
||||
'grunt-eslint'
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
printWidth: 160,
|
||||
tabWidth: 4,
|
||||
singleQuote: true,
|
||||
endOfLine: 'lf',
|
||||
trailingComma: 'none',
|
||||
arrowParens: 'avoid'
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
# Changelog
|
||||
|
||||
## [3.7.2](https://github.com/nodemailer/mailparser/compare/v3.7.1...v3.7.2) (2024-11-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** Bumped deps to fix issue with missing whitespace ([92884d0](https://github.com/nodemailer/mailparser/commit/92884d0619efa77042ecc35fbc887e93a59e5a93))
|
||||
|
||||
## [3.7.1](https://github.com/nodemailer/mailparser/compare/v3.7.0...v3.7.1) (2024-04-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** Replaced 'punycode' with 'punycode.js' module ([4a15157](https://github.com/nodemailer/mailparser/commit/4a15157dc9a815aa0e756d9e6ae0e8631842c447))
|
||||
|
||||
## [3.7.0](https://github.com/nodemailer/mailparser/compare/v3.6.9...v3.7.0) (2024-04-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **events:** Emit a new headerLines event to gain access the raw headers ([#364](https://github.com/nodemailer/mailparser/issues/364)) ([d33d7ec](https://github.com/nodemailer/mailparser/commit/d33d7ec4b8e32a4eb7a9a664cec5fdb545c274af))
|
||||
|
||||
## [3.6.9](https://github.com/nodemailer/mailparser/compare/v3.6.8...v3.6.9) (2024-02-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** Bumped deps ([db842ad](https://github.com/nodemailer/mailparser/commit/db842addd36e2fe94d0c4b466da80719a36f47ac))
|
||||
|
||||
## [3.6.8](https://github.com/nodemailer/mailparser/compare/v3.6.7...v3.6.8) (2024-02-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **punycode:** Fixes [#355](https://github.com/nodemailer/mailparser/issues/355) Deprecation warning of the punycode module ([#356](https://github.com/nodemailer/mailparser/issues/356)) ([0f35330](https://github.com/nodemailer/mailparser/commit/0f35330c87d715d38e8c853ae6c2f64d098b971d))
|
||||
|
||||
## [3.6.7](https://github.com/nodemailer/mailparser/compare/v3.6.6...v3.6.7) (2024-02-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* :arrow_up: update nodemailer dependency to resolve security issue GHSA-9h6g-pr28-7cqp ([#357](https://github.com/nodemailer/mailparser/issues/357)) ([8bc4225](https://github.com/nodemailer/mailparser/commit/8bc42251fca6f538ece599f0a5bebe09b0aeff4f))
|
||||
|
||||
## [3.6.6](https://github.com/nodemailer/mailparser/compare/v3.6.5...v3.6.6) (2024-01-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deploy:** added auto-deployment ([d6eb56f](https://github.com/nodemailer/mailparser/commit/d6eb56fe09fe8b415e5bbf2e53704f6788ca0fee))
|
||||
* Fix produced text address list string according to rfc 2822 ([#340](https://github.com/nodemailer/mailparser/issues/340)) ([6bae600](https://github.com/nodemailer/mailparser/commit/6bae600a3f4a0452ee7ca43634a11939de7bcc6d))
|
||||
* **test:** updated test matrix (18, 20, 21) ([a2ba9c2](https://github.com/nodemailer/mailparser/commit/a2ba9c236dcd7f990c9d53a386ffaa5b564181b3))
|
||||
@@ -0,0 +1,16 @@
|
||||
Copyright (c) 2020 - 2021 Andris Reinman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,31 @@
|
||||
# mailparser
|
||||
|
||||

|
||||
|
||||
Advanced email parser for Node.js. Everything is handled as a stream which should make it able to parse even very large messages (100MB+) with relatively low overhead.
|
||||
|
||||
## Looking for a front-end solution?
|
||||
|
||||
_mailparser_ is Node.js only library, so you can't use it reliably in the front-end or bundle with WebPack. If you do need a solution to parse emails in the front-end then use [PostalMime](https://www.npmjs.com/package/postal-mime).
|
||||
|
||||
## Installation
|
||||
|
||||
First install the module from npm:
|
||||
|
||||
```
|
||||
$ npm install mailparser
|
||||
```
|
||||
|
||||
next import the `mailparser` object into your script:
|
||||
|
||||
```js
|
||||
const mailparser = require('mailparser');
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
See [mailparser homepage](https://nodemailer.com/extras/mailparser/) for documentation and terms.
|
||||
|
||||
### License
|
||||
|
||||
Licensed under MIT
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const MailParser = require('./lib/mail-parser');
|
||||
const simpleParser = require('./lib/simple-parser');
|
||||
|
||||
module.exports = {
|
||||
MailParser,
|
||||
simpleParser
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
|
||||
const MailParser = require('./mail-parser.js');
|
||||
|
||||
module.exports = (input, options, callback) => {
|
||||
if (input === null || input === undefined) {
|
||||
throw new TypeError('Input cannot be null or undefined.');
|
||||
}
|
||||
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = false;
|
||||
}
|
||||
|
||||
let promise;
|
||||
if (!callback) {
|
||||
promise = new Promise((resolve, reject) => {
|
||||
callback = callbackPromise(resolve, reject);
|
||||
});
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
let keepCidLinks = !!options.keepCidLinks;
|
||||
|
||||
let mail = {
|
||||
attachments: []
|
||||
};
|
||||
|
||||
let parser = new MailParser(options);
|
||||
|
||||
parser.on('error', err => {
|
||||
callback(err);
|
||||
});
|
||||
|
||||
parser.on('headers', headers => {
|
||||
mail.headers = headers;
|
||||
mail.headerLines = parser.headerLines;
|
||||
});
|
||||
|
||||
let reading = false;
|
||||
let reader = () => {
|
||||
reading = true;
|
||||
|
||||
let data = parser.read();
|
||||
|
||||
if (data === null) {
|
||||
reading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.type === 'text') {
|
||||
Object.keys(data).forEach(key => {
|
||||
if (['text', 'html', 'textAsHtml'].includes(key)) {
|
||||
mail[key] = data[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (data.type === 'attachment') {
|
||||
mail.attachments.push(data);
|
||||
|
||||
let chunks = [];
|
||||
let chunklen = 0;
|
||||
data.content.on('readable', () => {
|
||||
let chunk;
|
||||
while ((chunk = data.content.read()) !== null) {
|
||||
chunks.push(chunk);
|
||||
chunklen += chunk.length;
|
||||
}
|
||||
});
|
||||
|
||||
data.content.on('end', () => {
|
||||
data.content = Buffer.concat(chunks, chunklen);
|
||||
data.release();
|
||||
reader();
|
||||
});
|
||||
} else {
|
||||
reader();
|
||||
}
|
||||
};
|
||||
|
||||
parser.on('readable', () => {
|
||||
if (!reading) {
|
||||
reader();
|
||||
}
|
||||
});
|
||||
|
||||
parser.on('end', () => {
|
||||
['subject', 'references', 'date', 'to', 'from', 'to', 'cc', 'bcc', 'message-id', 'in-reply-to', 'reply-to'].forEach(key => {
|
||||
if (mail.headers && mail.headers.has(key)) {
|
||||
mail[key.replace(/-([a-z])/g, (m, c) => c.toUpperCase())] = mail.headers.get(key);
|
||||
}
|
||||
});
|
||||
|
||||
if (keepCidLinks) {
|
||||
return callback(null, mail);
|
||||
}
|
||||
parser.updateImageLinks(
|
||||
(attachment, done) => done(false, 'data:' + attachment.contentType + ';base64,' + attachment.content.toString('base64')),
|
||||
(err, html) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
mail.html = html;
|
||||
|
||||
callback(null, mail);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (typeof input === 'string') {
|
||||
parser.end(Buffer.from(input));
|
||||
} else if (Buffer.isBuffer(input)) {
|
||||
parser.end(input);
|
||||
} else {
|
||||
input
|
||||
.once('error', err => {
|
||||
input.destroy();
|
||||
parser.destroy();
|
||||
callback(err);
|
||||
})
|
||||
.pipe(parser);
|
||||
}
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
function callbackPromise(resolve, reject) {
|
||||
return function (...args) {
|
||||
let err = args.shift();
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(...args);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const crypto = require('crypto');
|
||||
const Transform = require('stream').Transform;
|
||||
|
||||
class StreamHash extends Transform {
|
||||
constructor(attachment, algo) {
|
||||
super();
|
||||
this.attachment = attachment;
|
||||
this.algo = (algo || 'md5').toLowerCase();
|
||||
this.hash = crypto.createHash(algo);
|
||||
this.byteCount = 0;
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, done) {
|
||||
this.hash.update(chunk);
|
||||
this.byteCount += chunk.length;
|
||||
done(null, chunk);
|
||||
}
|
||||
|
||||
_flush(done) {
|
||||
this.attachment.checksum = this.hash.digest('hex');
|
||||
this.attachment.size = this.byteCount;
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StreamHash;
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "mailparser",
|
||||
"version": "3.7.2",
|
||||
"description": "Parse e-mails",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "grunt",
|
||||
"update": "rm -rf node_modules package-lock.json && ncu -u && npm install"
|
||||
},
|
||||
"author": "Andris Reinman",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Peter Salomonsen",
|
||||
"email": "petersalomonsen@runbox.com",
|
||||
"url": "https://github.com/petersalomonsen"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"encoding-japanese": "2.2.0",
|
||||
"he": "1.2.0",
|
||||
"html-to-text": "9.0.5",
|
||||
"iconv-lite": "0.6.3",
|
||||
"libmime": "5.3.6",
|
||||
"linkify-it": "5.0.0",
|
||||
"mailsplit": "5.4.2",
|
||||
"nodemailer": "6.9.16",
|
||||
"punycode.js": "2.3.1",
|
||||
"tlds": "1.255.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "8.17.1",
|
||||
"eslint": "8.57.0",
|
||||
"eslint-config-nodemailer": "1.2.0",
|
||||
"eslint-config-prettier": "9.1.0",
|
||||
"grunt": "1.6.1",
|
||||
"grunt-cli": "1.5.0",
|
||||
"grunt-contrib-nodeunit": "5.0.0",
|
||||
"grunt-eslint": "24.3.0",
|
||||
"iconv": "3.0.1",
|
||||
"random-message": "1.1.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nodemailer/mailparser.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nodemailer/mailparser/issues"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user