mirror of
https://github.com/dadada/inbox2matrix.git
synced 2025-06-07 17:43:57 +02:00
Add callback for new mail in mailbox
This commit is contained in:
parent
c2578160b2
commit
9d3f9477bf
1 changed files with 7 additions and 31 deletions
|
@ -14,45 +14,21 @@ function openInbox(cb) {
|
|||
imap.once('ready', function() {
|
||||
openInbox(function(err, box) {
|
||||
if (err) throw err;
|
||||
var f = imap.seq.fetch('*', {
|
||||
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();
|
||||
});
|
||||
console.log('ready');
|
||||
});
|
||||
});
|
||||
|
||||
imap.once('mail', (numNewMsgs : number) => {
|
||||
console.log(numNewMsgs);
|
||||
console.log(`You have ${numNewMsgs} mail`);
|
||||
});
|
||||
|
||||
imap.once('update', (seqno : number, info : object) => {
|
||||
console.log(info);
|
||||
});
|
||||
|
||||
imap.once('error', function(err) {
|
||||
console.log(err);
|
||||
imap.end();
|
||||
});
|
||||
|
||||
imap.once('end', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue