Skip to content

Commit

Permalink
Initial project
Browse files Browse the repository at this point in the history
  • Loading branch information
walling committed Feb 19, 2018
0 parents commit 719c49a
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
*.log
2 changes: 2 additions & 0 deletions AUTHORS
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)
19 changes: 19 additions & 0 deletions LICENSE
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.
27 changes: 27 additions & 0 deletions README.md
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)
38 changes: 38 additions & 0 deletions index.js
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;
};
33 changes: 33 additions & 0 deletions package.json
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"
}
21 changes: 21 additions & 0 deletions test.js
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': '' }));

0 comments on commit 719c49a

Please sign in to comment.