fetch.on("message") event is firing twice, though imap.search result is only one result
See original GitHub issueI am trying to fetch all unseen messages, but some times mail event is triggering twice
var self = this, search = self.options.search || [[ 'UNSEEN', ['SINCE', 'May 20, 2010'] ]];
self.dbg('scanning %s with filter `%s`.', self.options.box, search);
self.imap.search(search, function (err, seachResults) {
if (err) {
self.emit('error', err);
callback();
return;
}
if (!seachResults || seachResults.length === 0) {
self.dbg('no new mail in %s', self.options.box);
callback();
return;
}
self.dbg('found %d new messages', seachResults.length);
var fetch = self.imap.fetch(seachResults, {
markSeen: self.options.markSeen !== false,
bodies: ''
});
//this below event emitting twice
fetch.on('message' function (msg,seqno) {
var uid, flags;
msg.on('attributes', function(attrs) {
uid = attrs.uid;
flags = attrs.flags;
**self.dbg("Message uid", attrs.uid);
});
var mp = new MailParser();
mp.once('end', function (mail) {
mail.uid = uid;
mail.flags = flags;
if(uid>last_seq)
self.emit('mail', mail);
self.dbg('found mail '+mail.headers["message-id"]);
});
msg.once('body', function (stream, info) {
stream.pipe(mp);
});
});
fetch.once('end', function () {
self.dbg('Done fetching all messages!');
callback();
});
``` The logs are showing mail id/uid printed twice but scanned only once and scan result was 1 item
This is not always happening, any solution so that fetch.on message only triggered once for once search result
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Why are these two IMAP Search results different from one ...
One ( SEARCH ) returns message sequence numbers (MSN), which are numbered from 1 to N and change as messages are added and...
Read more >Outlook search - duplicate emails for gmail imap
I'm using a gmail imap account with Outlook for Mac v15.33. ... Outlook for Mac client, it will show duplicated emails in the...
Read more >Common Problems with Google Calendar - Zapier Help
The "New Event Matching Search" trigger is firing too often or on old events. If older events in Google Calendar are updated, this...
Read more >JMAP Mail Specification
If a JMAP Mail server also provides an IMAP interface to the data and supports ... If true , when sorting the query...
Read more >When attempting to copy or move large numbers of local ...
As a result, half the messages never appeared on the IMAP server but did disappear ... I tried to look through it to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as the search criteria goes, I think there is an extra set of brackets that need to be removed, it should be just
[ 'UNSEEN', ['SINCE', formattedDate] ]
that is passed tosearch()
.As far as the error goes, that’s coming from
mailparser
, notimap
, so you’d want to submit an issue with that project instead.