I seem to have some trouble understanding connection events
See original GitHub issueI connect to gmail and can open Inbox. It works to fetch emails. But the mail event gets only fired once at start, when i fetch mails, it does not get fired when i send a new mail.
imap.once('mail', function(numNewMsgs) {
l('NEW MESSAGE', numNewMsgs);
});
also subscribing does not seem to have any effect. I have all connection events logging their args to console, but they never get fired. My understanding would have been, that not ending imap would keep the connection open and new mail to a subscribed box would trigger mail or update or any other event. But nothing happens. What am I getting wrong?
This is my whole testcode:
global.l = console.log;
import Imap from 'imap';
import { inspect } from 'util';
const imap = new Imap({
user: 'xxx@gmail.com',
password: 'xxx',
host: 'imap.gmail.com',
port: 993,
tls: true,
tlsOptions: { servername: 'imap.gmail.com' },
debug: console.log
});
imap.once('ready', function() {
imap.getBoxes(function(error, boxes) {
if (error) throw error;
//l('BOXES', boxes);
for (let box in boxes) {
imap.subscribeBox(box);
l('SUBSCRIBED TO', box);
}
});
imap.openBox('INBOX', true, function(error, box) {
if (error) throw error;
var f = imap.seq.fetch('1:50', {
bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
struct: true
});
f.on('message', function(msg, seqno) {
console.log('Message #%d', seqno);
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
var buffer = '';
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
});
stream.once('end', function() {
console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
});
});
msg.once('attributes', function(attrs) {
console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
});
msg.once('end', function() {
console.log(prefix + 'Finished');
});
});
f.once('error', function(err) {
console.log('Fetch error: ' + err);
});
f.once('end', function() {
//console.log('Done fetching all messages!');
//imap.end();
});
});
});
imap.once('mail', function(numNewMsgs) {
l('NEW MESSAGE', numNewMsgs);
});
imap.once('update', function(seqno, info) {
l('UPDATE', seqno, info);
});
imap.once('expunge', function(seqno) {
l('expunge', seqno);
});
imap.once('alert', function(message) {
l('alert', message);
});
imap.once('error', function(err) {
console.log(err);
});
imap.once('end', function() {
console.log('Connection ended');
});
imap.connect();
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Connecting With People - What It Is and Isn't, And Why You ...
Psychological problems that cause difficulty connecting with others. There are several, including: low self-esteem.
Read more >9 most common network issues and how to solve them
Find out how to troubleshoot common network issues, including slow network speeds, weak Wi-Fi signals and IP address problems.
Read more >Aphasia: Types, Causes, Symptoms & Treatment
Aphasia is a brain disorder where a person has trouble speaking or understanding other people speaking. This happens with damage or ...
Read more >Fix sync problems with the Google Calendar app - Android
Use this page if events you created or updated aren't showing on your computer or in the Google Calendar app. First, try these...
Read more >Aphasia
Symptoms of aphasia. People with aphasia often have trouble with the 4 main ways people understand and use language. These are: reading; listening;...
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
Oh I see the issue now, you’re using
imap.once()
instead ofimap.on()
. Change that and you should see the new mail notifications.Actually
subscribeBox()
is a bit of a relic back when the creators of IMAP envisioned some sort of Usenet-like “mailbox” subscription experience.