JS imap получить текст
Нужно вытянуть текст из сообщения подскажите как это сделать использую вот такой код.Но сейчас идёт запись в файл всего содержимого,а мне надо долько текст как это сделать?
var Imap = require('imap'),
inspect = require('util').inspect;
var imap = new Imap({
user: '',
password: '',
host: 'imap.gmail.com',
port: 993,
tls: true,
tlsOptions: {rejectUnauthorized: false}
});
function openInbox(cb) {
imap.openBox('INBOX', true, cb);
}
imap.once('ready', function() {
var fs = require('fs'), fileStream;
openInbox(function(err, box) {
if (err) throw err;
imap.search([ 'UNSEEN', ['SINCE', 'March 26, 2020'] ], function(err, results) {
if (err) throw err;
var f = imap.fetch(results, { bodies: '' });
f.on('message', function(msg, seqno) {
var prefix = '(#' + seqno + ') ';
msg.on('body', function(stream, info) {
console.log(msg.on);
stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
console.log(stream.pipe);
});
console.log(msg.on);
msg.once('attributes', function(attrs) {
});
msg.once('end', function() {
});
});
f.once('error', function(err) {
});
f.once('end', function() {
console.log('Done fetching all messages!');
imap.end();
});
});
});
});
imap.once('error', function(err) {
console.log(err);
});
imap.once('end', function() {
console.log('Connection ended');
});
imap.connect();