mirror of
https://github.com/dadada/inbox2matrix.git
synced 2025-06-08 18:13:57 +02:00
Improve logging and make refresh interval configurable
This commit is contained in:
parent
153c7b29fe
commit
f72f69b0e7
1 changed files with 12 additions and 15 deletions
|
@ -31,7 +31,7 @@ function openInbox(cb) {
|
||||||
imap.once('ready', function() {
|
imap.once('ready', function() {
|
||||||
openInbox(function(err, box) {
|
openInbox(function(err, box) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('ready');
|
console.log('IMAP inbox is ready');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ function fetchAndReport(results) {
|
||||||
buffer += chunk.toString('utf-8').replace(/(\r\n\r\n|\n|\r\n|\r)/g, "\n");
|
buffer += chunk.toString('utf-8').replace(/(\r\n\r\n|\n|\r\n|\r)/g, "\n");
|
||||||
});
|
});
|
||||||
stream.once('end', () => {
|
stream.once('end', () => {
|
||||||
console.log('Buffer: %s', buffer);
|
console.log('Body: %s', buffer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,13 +60,13 @@ function fetchAndReport(results) {
|
||||||
};
|
};
|
||||||
|
|
||||||
client.sendEvent(myRoom, "m.room.message", content, "", (err, res) => {
|
client.sendEvent(myRoom, "m.room.message", content, "", (err, res) => {
|
||||||
console.log(err);
|
if (err) console.log(err.message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fetched.once('error', (err) => {
|
fetched.once('error', (err) => {
|
||||||
console.log(err);
|
if (err) console.log(err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
fetched.once('end', function() {
|
fetched.once('end', function() {
|
||||||
|
@ -75,21 +75,20 @@ function fetchAndReport(results) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function processUnseen() {
|
function processUnseen() {
|
||||||
console.log("processUnseen");
|
|
||||||
imap.search(['UNSEEN'], (err, results) => {
|
imap.search(['UNSEEN'], (err, results) => {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err.message);
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
fetchAndReport(results);
|
fetchAndReport(results);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
imap.once('mail', (numNewMsgs : number) => {
|
imap.once('mail', (numNewMsgs : number) => {
|
||||||
console.log(`You have ${numNewMsgs} mail`);
|
console.log(`Inbox has ${numNewMsgs} mails`);
|
||||||
processUnseen();
|
processUnseen();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,14 +103,12 @@ imap.once('error', function(err) {
|
||||||
});
|
});
|
||||||
|
|
||||||
imap.once('end', function() {
|
imap.once('end', function() {
|
||||||
console.log('Connection ended');
|
console.log('IMAP connection ended');
|
||||||
});
|
});
|
||||||
|
|
||||||
client.once('sync', function(state, prevState, res) {
|
client.once('sync', function(state, prevState, res) {
|
||||||
if (state === 'PREPARED') {
|
if (state === 'PREPARED') {
|
||||||
console.log("prepared");
|
console.log("IMAP " + state);
|
||||||
} else {
|
|
||||||
console.log(state);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -122,9 +119,9 @@ async function startBot() {
|
||||||
await client.initCrypto();
|
await client.initCrypto();
|
||||||
await client.startClient({initialSyncLimit: 200});
|
await client.startClient({initialSyncLimit: 200});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startBot();
|
startBot();
|
||||||
setInterval(processUnseen, 10 * 1000);
|
setInterval(processUnseen, config.get("refresh_interval") * 1000);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue