Created
June 7, 2017 22:42
-
-
Save jrgm/f830c768a2774e638a575192c74d10b4 to your computer and use it in GitHub Desktop.
mailSummary
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
diff --git a/emailserver.js b/emailserver.js | |
index e40f738..9a063c2 100755 | |
--- a/emailserver.js | |
+++ b/emailserver.js | |
@@ -24,6 +24,32 @@ function logError(err) { | |
log("ERROR (oh noes!): " + err); | |
} | |
+function mailSummary(mail) { | |
+ const deliveryTime = | |
+ new Date(mail.receivedAt).getTime() - new Date(mail.date).getTime(); | |
+ | |
+ const summary = { | |
+ subject: mail.subject, | |
+ from: mail.from, | |
+ to: mail.to, | |
+ date: mail.date, | |
+ receivedAt: mail.receivedAt, | |
+ deliveryTime: deliveryTime | |
+ }; | |
+ | |
+ if (mail.headers) { | |
+ summary.headers = { | |
+ subject: mail.headers.subject, | |
+ from: mail.headers.from, | |
+ to: mail.headers.to, | |
+ cc: mail.headers.cc, | |
+ date: mail.headers.date | |
+ }; | |
+ } | |
+ | |
+ return JSON.stringify(summary); | |
+} | |
+ | |
var server = smtp.createServer(HOSTNAME, function (req) { | |
log('Handling SMTP request'); | |
@@ -43,7 +69,7 @@ var server = smtp.createServer(HOSTNAME, function (req) { | |
mailparser.on('end', (function(users, mail) { | |
mail.receivedAt = new Date().toISOString(); | |
- log('Received message for', users, mail); | |
+ log('Received message for', users, mailSummary(mail)); | |
users.forEach(function(user) { | |
db.rpush(user, JSON.stringify(mail), function(err) { | |
if (err) return logError(err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment