diff options
Diffstat (limited to 'app/imap.js')
-rw-r--r-- | app/imap.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/imap.js b/app/imap.js new file mode 100644 index 0000000..1ac76a4 --- /dev/null +++ b/app/imap.js @@ -0,0 +1,34 @@ +const { ipcMain } = require('electron'); +const { ImapFlow } = require('imapflow'); + +ipcMain.on('imap:listTree:from', listTreeFrom); +ipcMain.on('imap:listTree:to', listTreeTo); + +async function connect (options) { + const client = new ImapFlow({ + host: options.server, + port: options.port, + auth: { + user: options.username, + pass: options.password, + }, + }); + + await client.connect(); + + return client; +} + +async function listTreeFrom (event, options) { + const client = await connect(options); + + event.reply('imap:listTree:from:reply', await client.listTree()); + await client.logout(); +} + +async function listTreeTo (event, options) { + const client = await connect(options); + + event.reply('imap:listTree:to:reply', await client.listTree()); + await client.logout(); +} |