I want to return subjects
from this function, but I always get undefined
.
getNewItems() {
imap.connect(this.config).then((imapCon) => {
imapCon.openBox("INBOX").then(() => {
let searchCriteria = [
'UNSEEN'
];
let fetchOptions = {
bodies: ['HEADER', 'TEXT'],
markSeen: false
};
imapCon.search(searchCriteria, fetchOptions).then((result) => {
let subjects = result.map((res) => {
return res.parts.filter((part) => {
return part.which === 'HEADER';
})[0].body.subject[0];
});
return subjects;
})
})
})
I tried using awaits but this only resulted in getting a promise from the function