Ad
How To Fetch Email Thread By MessageId Using IMAP In NodeJS?
I want to fetch whole reply thread using the particular messageId something like this [email protected]
.
I have tried this:
const getInbox = () => {
return new Promise((resolve, reject) => {
imaps.connect(config).then(function (connection) {
return connection.openBox('INBOX').then(function () {
var searchCriteria = ['ALL'];
var fetchOptions = {
bodies: ['HEADER', 'TEXT', ''],
};
return connection.search(searchCriteria, fetchOptions).then(async function (messages) {
let promises = messages.map(item=>{
return new Promise((resolve,reject)=>{
var all = _.find(item.parts, { "which": "" })
var id = item.attributes.uid;
var idHeader = "Imap-Id: " + id + "\r\n";
simpleParser(idHeader + all.body, (err, mail) => {
resolve(mail);
});
});
});
Promise.all(promises).then(data=>{
let d = data.filter(obj=>obj.me).map(obj=>{
return {
from:obj.from.value.map(obj=>obj.address).join(','),
to:obj.to.value.map(obj=>obj.address).join(','),
subject:obj.subject,
attachments:obj.attachments,
message_id:obj.messageId,
date:obj.date
}
});
resolve(d);
})
});
});
});
}); }
I have tried this , it is returning whole inbox, I want particular message thread.
Ad
Answer
I tried this
var searchCriteria = [['HEADER','IN-REPLY-TO',messageId]];
it is working perfectly.
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad