-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added plugin method to override address fields
- Loading branch information
Showing
5 changed files
with
103 additions
and
28 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
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
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 |
---|---|---|
|
@@ -296,15 +296,20 @@ Where | |
|
||
Return value is an object with the following properties: | ||
|
||
- **addresses** an array of (plain) e-mail addresses found for that key | ||
- **addresses** an array of e-mail addresses found for that key (structured values) | ||
- **set** _(addresses)_ a method that overrides original key with new addresses | ||
|
||
**Example** | ||
|
||
```javascript | ||
// From: Sender Name <[email protected]> | ||
let from = app.validateAddress(envelope.headers, 'from'); | ||
from.addresses // ['[email protected]'] | ||
from.set('[email protected]'); | ||
// From: Sender Name <[email protected]> | ||
from.addresses // [{name:'Sender Name', address: '[email protected]'}] | ||
from.set('My Name <[email protected]>'); | ||
// From: [email protected] | ||
from.set({ | ||
name: 'My Name', | ||
address: '[email protected]' | ||
}); | ||
// From: [email protected] | ||
``` |
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,40 @@ | ||
'use strict'; | ||
|
||
|
||
const crypto = require('crypto'); | ||
|
||
// Set module title | ||
module.exports.title = 'Image Hashes'; | ||
|
||
// Initialize the module | ||
module.exports.init = (app, done) => { | ||
// This example calculates MD5 hash for every image in the message | ||
app.addStreamHook((envelope, node) => /^(image|application)\//i.test(node.contentType), (envelope, node, source, done) => { | ||
let hash = crypto.createHash('md5'); | ||
let filename = node.filename; | ||
let contentType = node.contentType; | ||
let bytes = 0; | ||
|
||
source.on('data', chunk => { | ||
bytes += chunk.length; | ||
hash.update(chunk); | ||
}); | ||
|
||
source.on('end', () => { | ||
if (!envelope.attachments) { | ||
envelope.attachments = []; | ||
} | ||
hash = hash.digest('hex'); | ||
envelope.attachments.push({ | ||
name: filename, | ||
type: contentType, | ||
hash | ||
}); | ||
app.logger.info('ImageHash', '%s ATTACHMENT name="%s" type="%s" size=%s md5=%s', envelope.id, filename || '', contentType, bytes, hash); | ||
done(); | ||
}); | ||
}); | ||
|
||
// all set up regarding this plugin | ||
done(); | ||
}; |
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 |
---|---|---|
|
@@ -70,7 +70,16 @@ module.exports['#validateAddress'] = test => { | |
|
||
let parsed = addressTools.validateAddress(headers, 'from'); | ||
|
||
test.deepEqual(parsed.addresses, ['[email protected]', '[email protected]', '[email protected]']); | ||
test.deepEqual(parsed.addresses, [{ | ||
name: '', | ||
address: '[email protected]' | ||
}, { | ||
name: 'Andris4', | ||
address: '[email protected]' | ||
}, { | ||
name: 'Andris3', | ||
address: '[email protected]' | ||
}]); | ||
|
||
parsed.set('Juhan Liiv <[email protected]>'); | ||
|
||
|
@@ -113,16 +122,28 @@ module.exports['#validateAddress, multiple'] = test => { | |
|
||
let parsed = addressTools.validateAddress(headers, 'to'); | ||
|
||
test.deepEqual(parsed.addresses, ['[email protected]', '[email protected]', '[email protected]']); | ||
test.deepEqual(parsed.addresses, [{ | ||
name: '', | ||
address: '[email protected]' | ||
}, { | ||
name: 'Andris4', | ||
address: '[email protected]' | ||
}, { | ||
name: 'Andris3', | ||
address: '[email protected]' | ||
}]); | ||
|
||
parsed.set('Juhan Liiv <[email protected]>, Jõgeva <[email protected]>, [email protected]'); | ||
parsed.set('Juhan Liiv <[email protected]>, Jõgeva <[email protected]>, [email protected]', { | ||
name: 'Andris3', | ||
address: '[email protected]' | ||
}); | ||
|
||
test.deepEqual(headers.getList(), [{ | ||
key: 'x-prev', | ||
line: 'X-Prev: previous line' | ||
}, { | ||
key: 'to', | ||
line: 'to: Juhan Liiv <[email protected]>, =?UTF-8?Q?J=C3=B5geva?=\r\n <[email protected]>, Andris3 <andris3@kreata.ee>' | ||
line: 'to: Juhan Liiv <[email protected]>, =?UTF-8?Q?J=C3=B5geva?=\r\n <[email protected]>, [email protected], Andris3 <andris4@kreata.ee>' | ||
}, { | ||
key: 'x-mid', | ||
line: 'X-Mid: middle line' | ||
|