Reputation: 3783
I would like to parse the following String:
{
date: [ 'Thu, 28 Apr 2016 10:56:13 +0200' ],
subject: [ 'Subject' ],
from: [ 'Blob <[email protected]>' ],
to: [ '<[email protected]>' ]
}
In order to access the variable date
, subject
etc ...
But I am not sure how to do it since it
And I don't want to re-invent the wheel if a solution exist which I am not (yet) aware of.
Any ideas?
EDIT
Data are getting using a node-imap module (only relevant part)
f.on('message', function(msg, seqno) {
console.log('Message #%d', seqno);
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
var buffer = '';
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
});
stream.once('end', function() {
var parsedHeader = inspect(Imap.parseHeader(buffer));
console.log('Author: '+parsedHeader);
});
SOLVED
See the comment of @stdob--. Imap.parseHeader() return an object.
Upvotes: 0
Views: 136
Reputation: 29172
Looks like that Imap.parseHeader
already returns an object with keys
Try console.log( Object.keys(parsedHeader)
to see all the keys.
Upvotes: 2