-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 719c49a
Showing
7 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Bjarke Walling <bwp@bwp.dk> (https://bjarkewalling.com) | ||
Khalid Rehioui <rehioui@gmail.com> (https://github.com/javascipt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2018 Bjarke WALLING, Khalid REHIOUI | ||
|
||
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 above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
# is-autoreply | ||
|
||
Returns `true` if email is an autoreply according to the email headers. | ||
|
||
Please [open an issue](https://github.com/walling/is-autoreply/issues) if an email isn't properly detected as autoreply :) | ||
|
||
|
||
## Installation | ||
|
||
npm install --save is-autoreply | ||
|
||
|
||
## Programmatic usage | ||
|
||
```js | ||
const isAutoreply = require('is-autoreply'); | ||
const emailHeaders = { 'X-Auto-Response-Suppress': 'OOF' }; | ||
|
||
if (isAutoreply(emailHeaders)) { | ||
console.log('The email is an autoreply'); | ||
} | ||
``` | ||
|
||
## License | ||
|
||
[MIT](LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
/** | ||
* Convert header names to lower case and normalize value to string. | ||
* @param {Object} headers - Key/value object of headers | ||
* @return {Object} - Normalized headers | ||
*/ | ||
const normalizedHeaders = (headers) => { | ||
var normalized = {}; | ||
Object.keys(headers).forEach((key) => { | ||
normalized[key.toLowerCase()] = "" + [headers[key]]; | ||
}); | ||
return normalized; | ||
} | ||
|
||
/** | ||
* Check if email is autoreply according to headers. | ||
* @param {Object} headers - Email headers as key/value object | ||
* @return {boolean} - True if autoreply, false otherwise | ||
*/ | ||
module.exports = (headers) => { | ||
// TODO: maybe if headers is a string, we can parse it as email headers using a NPM module | ||
|
||
headers = normalizedHeaders(headers); | ||
|
||
// Detections according to <https://github.com/jpmckinney/multi_mail/wiki/Detecting-autoresponders> | ||
if ('auto-submitted' in headers && headers['auto-submitted'].toLowerCase() !== 'no') { | ||
return true; | ||
} | ||
// TODO: add more here | ||
|
||
// Detecting MS Exchange/Outlook according to <https://msdn.microsoft.com/en-us/library/ee219609(v=exchg.80).aspx> | ||
if ('x-auto-response-suppress' in headers && headers['x-auto-response-suppress'].toLowerCase() !== 'none') { | ||
return true; | ||
} | ||
|
||
// By default email is not autoreply | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "is-autoreply", | ||
"version": "0.1.0", | ||
"description": "Detect if email is an autoreply according to the email headers.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/walling/is-autoreply.git" | ||
}, | ||
"keywords": [ | ||
"email", | ||
"autoreply", | ||
"auto-reply", | ||
"headers", | ||
"autoresponse", | ||
"auto-reponse", | ||
"autoresponder", | ||
"auto-reponder" | ||
], | ||
"author": "Bjarke Walling <bwp@bwp.dk> (https://bjarkewalling.com)", | ||
"contributors": [ | ||
"Bjarke Walling <bwp@bwp.dk> (https://bjarkewalling.com)", | ||
"Khalid Rehioui <rehioui@gmail.com> (https://github.com/javascipt)" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/walling/is-autoreply/issues" | ||
}, | ||
"homepage": "https://github.com/walling/is-autoreply#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
const isAutoreply = require('.'); | ||
const assert = require('assert'); | ||
|
||
// Generally email is not autoreply | ||
assert.ok(!isAutoreply({})); | ||
|
||
// Test Auto-Submitted header | ||
assert.ok(!isAutoreply({ 'Auto-Submitted': 'No' })); | ||
assert.ok(!isAutoreply({ 'auto-submitted': 'no' })); | ||
assert.ok(isAutoreply({ 'Auto-Submitted': 'Yes' })); | ||
assert.ok(isAutoreply({ 'auto-submitted': 'yes' })); | ||
assert.ok(isAutoreply({ 'auto-submitted': '' })); | ||
|
||
// Test X-Auto-Response-Suppress header | ||
assert.ok(!isAutoreply({ 'X-Auto-Response-Suppress': 'None' })); | ||
assert.ok(!isAutoreply({ 'x-auto-response-suppress': 'none' })); | ||
assert.ok(isAutoreply({ 'X-Auto-Response-Suppress': 'OOF' })); | ||
assert.ok(isAutoreply({ 'x-auto-response-suppress': 'oof' })); | ||
assert.ok(isAutoreply({ 'x-auto-response-suppress': 'RN, NRN' })); | ||
assert.ok(isAutoreply({ 'x-auto-response-suppress': '' })); |