1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Expose rest of email node header fields.

This commit is contained in:
dceejay 2015-04-12 00:46:03 +01:00
parent 269846c587
commit 73d1f3d0e8
2 changed files with 5 additions and 6 deletions

View File

@ -155,7 +155,8 @@
<p>Repeatedly gets a <b>single email</b> from an IMAP server and forwards on as a msg if not already seen.</p>
<p>The subject is loaded into <b>msg.topic</b> and <b>msg.payload</b> is the plain text body.
If there is text/html then that is returned in <b>msg.html</b>. <b>msg.from</b> and <b>msg.date</b> are also set if you need them.</p>
<p>Additionally <b>msg.to</b>, <b>msg.cc</b>, <b>msg.bcc</b> may exist and contain arrays of relevant email addresses.</p>
<p>Additionally <b>msg.header</b> contains the complete header object including
<i>to</i>, <i>cc</i> and other potentially useful properties.</p>
<p>Uses the imap module.</p>
<p><b>Note:</b> this node <i>only</i> gets the most recent single email from the inbox, so set the repeat (polling) time appropriately.</p>
</script>

View File

@ -181,7 +181,8 @@ module.exports = function(RED) {
}
else {
if (box.messages.total > 0) {
var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE TO CC BCC)','TEXT'] });
//var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER.FIELDS (FROM SUBJECT DATE TO CC BCC)','TEXT'] });
var f = imap.seq.fetch(box.messages.total + ':*', { markSeen:true, bodies: ['HEADER','TEXT'] });
f.on('message', function(msg, seqno) {
node.log('message: #'+ seqno);
var prefix = '(#' + seqno + ') ';
@ -193,13 +194,10 @@ module.exports = function(RED) {
stream.on('end', function() {
if (info.which !== 'TEXT') {
var head = Imap.parseHeader(buffer);
if (RED.settings.verbose) { node.log(head); }
pay.from = head.from[0];
pay.topic = head.subject[0];
pay.date = head.date[0];
if (head.hasOwnProperty("to")) { pay.to = head.to; }
if (head.hasOwnProperty("cc")) { pay.cc = head.cc; }
if (head.hasOwnProperty("bcc")) { pay.bcc = head.bcc; }
pay.header = head;
} else {
var parts = buffer.split("Content-Type");
for (var p = 0; p < parts.length; p++) {