Skip to content

Instantly share code, notes, and snippets.

@jrgm
Created June 7, 2017 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrgm/f830c768a2774e638a575192c74d10b4 to your computer and use it in GitHub Desktop.
Save jrgm/f830c768a2774e638a575192c74d10b4 to your computer and use it in GitHub Desktop.
mailSummary
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