From 73d1f3d0e839ee5784b4ea0203958b12ee4f16b5 Mon Sep 17 00:00:00 2001 From: dceejay Date: Sun, 12 Apr 2015 00:46:03 +0100 Subject: [PATCH] Expose rest of email node header fields. --- nodes/core/social/61-email.html | 3 ++- nodes/core/social/61-email.js | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/nodes/core/social/61-email.html b/nodes/core/social/61-email.html index f0375baa7..d2e70219c 100644 --- a/nodes/core/social/61-email.html +++ b/nodes/core/social/61-email.html @@ -155,7 +155,8 @@

Repeatedly gets a single email from an IMAP server and forwards on as a msg if not already seen.

The subject is loaded into msg.topic and msg.payload is the plain text body. If there is text/html then that is returned in msg.html. msg.from and msg.date are also set if you need them.

-

Additionally msg.to, msg.cc, msg.bcc may exist and contain arrays of relevant email addresses.

+

Additionally msg.header contains the complete header object including + to, cc and other potentially useful properties.

Uses the imap module.

Note: this node only gets the most recent single email from the inbox, so set the repeat (polling) time appropriately.

diff --git a/nodes/core/social/61-email.js b/nodes/core/social/61-email.js index 0c3223b64..943631d0b 100644 --- a/nodes/core/social/61-email.js +++ b/nodes/core/social/61-email.js @@ -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++) {