From beb56140ab6f361f6e93c634e1bfb4048981e26d Mon Sep 17 00:00:00 2001 From: Tao Xu Date: Tue, 11 Jul 2017 11:02:25 +0930 Subject: [PATCH] add ability to delete parsed mail --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index e461659..a4e6967 100644 --- a/index.js +++ b/index.js @@ -87,6 +87,22 @@ Notifier.prototype.scan = function () { mp.once('end', function (mail) { self.emit('mail', mail); }); + var uid; + msg.once('end', function () { + if (self.options.markDeleted && uid) { + self.imap.addFlags(uid, ['DELETED'], function (err) { + if (err) { self.emit('error', err); } + }); + } + if (self.options.autoExpunge) { + self.imap.expunge(function (err) { + if (err) { self.emit('error', err); } + }); + } + }); + msg.once('attributes', function (attrs) { + uid = attrs.uid; + }); msg.once('body', function (stream, info) { stream.pipe(mp); });