-
Notifications
You must be signed in to change notification settings - Fork 0
/
imapSearchInboxExmple.js
36 lines (33 loc) · 1.11 KB
/
imapSearchInboxExmple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { ImapFlow } = require("imapflow");
const { serverdetails } = require("./base.js");
const main = async () => {
const client = new ImapFlow(serverdetails);
await client.connect();
let lock = await client.getMailboxLock("INBOX");
try {
// do something in the mailbox
let mailbox = await client.mailboxOpen("INBOX");
// find all unseen messages
let list1 = await client.search({ seen: true });
// use OR modifier (array of 2 or more search queries)
let list2 = await client.search({
seen: false,
or: [
{ flagged: false },
{ from: "test@talk2fast.nl" },
{ from: "user@gmail.com" },
{ subject: "this is test message from cyu" },
],
});
console.log(list1);
console.log(" size of list 1 => " + list1.length);
console.log("###############################################");
console.log(list2);
console.log(" size of list 2 => " + list2.length);
} finally {
// use finally{} to make sure lock is released even if exception occurs
lock.release();
}
await client.logout();
};
main().catch((err) => console.error(err));