Add IMAP flow logging configuration and enhance message arrival logging

This commit is contained in:
Krisztián Szabolcsi 2026-01-10 13:56:34 +01:00
parent b92ec64746
commit 30357418b5

View File

@ -6,6 +6,7 @@ const i18n = require('./i18n');
const NTFY_INTERNAL_URL = process.env.NTFY_URL || 'https://ntfy.sh'; const NTFY_INTERNAL_URL = process.env.NTFY_URL || 'https://ntfy.sh';
const CONFIG_PATH = process.env.CONFIG_PATH || './config.json'; const CONFIG_PATH = process.env.CONFIG_PATH || './config.json';
const LOG_LEVEL = process.env.LOG_LEVEL || 'info'; const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
const IMAP_FLOW_LOG = process.env.IMAP_FLOW_LOG || false;
let config; let config;
const fromIcon = "\uD83D\uDC64"; // 👤 const fromIcon = "\uD83D\uDC64"; // 👤
@ -87,18 +88,21 @@ async function watchAccount(acc) {
user: acc.user, user: acc.user,
pass: acc.pass pass: acc.pass
}, },
logger: (LOG_LEVEL === 'debug' ? log.debug : false) logger: IMAP_FLOW_LOG ? log.debug : false
}); });
const run = async () => { const run = async () => {
try { try {
await client.connect(); await client.connect();
let lock = await client.getMailboxLock('INBOX'); let lock = await client.getMailboxLock('INBOX');
log.info(`[${acc.name}] ${i18n.t('watch_started')}`); log.info(`[${acc.name}] ${i18n.t('watch_started')}`);
client.on('exists', async (data) => { client.on('exists', async (data) => {
// Fetch only envelope data (Subject, From) // Fetch only envelope data (Subject, From)
let message = await client.fetchOne(data.count, { envelope: true }); let message = await client.fetchOne(data.count, { envelope: true });
log.debug(`[${acc.name}] New message arrived:`, message);
const subject = message.envelope.subject || i18n.t('no_subject'); const subject = message.envelope.subject || i18n.t('no_subject');
const fromInfo = message.envelope.from[0]; const fromInfo = message.envelope.from[0];