Files
FEDEO/test/imapflow/index.js
2024-02-19 07:46:28 +01:00

60 lines
2.1 KiB
JavaScript

const { ImapFlow } = require('imapflow');
const client = new ImapFlow({
host: 'imap.strato.de',
port: 993,
secure: true,
auth: {
user: 'info@federspiel.tech',
pass: 'fpGUpbQG34'
},
logger: {}
});
const main = async () => {
// Wait until client connects and authorizes
await client.connect();
// Select and lock a mailbox. Throws if mailbox does not exist
let lock = await client.getMailboxLock('INBOX');
try {
// fetch latest message source
// client.mailbox includes information about currently selected mailbox
// "exists" value is also the largest sequence number available in the mailbox
let message = await client.fetchOne(client.mailbox.exists, { source: true });
//console.log(message.source.toString());
// list subjects for all messages
// uid value is always included in FETCH response, envelope strings are in unicode.
for await (let message of client.fetch('1', { source:true , envelope: true, flags:true, bodyStructure: true, labels:true, bodyParts: true })) {
console.log(`${message.uid}: ${message.envelope.subject}`);
//console.log(`${message.envelope}`);
console.log(message)
console.log(message.bodyStructure.childNodes)
message.bodyStructure.childNodes.forEach(i => console.log(i))
}
let data = await client.download('1','1.1');
console.log(data)
data.content.pipe(process.stdout)
/*let tree = await client.listTree();
console.log(tree)
tree.folders.forEach(mailbox => console.log(mailbox.path))*/
} finally {
// Make sure lock is released, otherwise next `getMailboxLock()` never returns
lock.release();
}
/*let mailbox = await client.mailboxOpen('INBOX');
// fetch UID for the last email in the selected mailbox
let lastMsg = await client.fetchOne('*', {uid: true})
console.log(lastMsg.uid);*/
// log out and close connection
await client.logout();
};
main().catch(err => {}/*console.error(err)*/);