我需要在 nodejs 中使用 imap 获取邮件正文
imap.openBox("INBOX", true, function(err, box) {
imap.search(['ALL', ['BODY', 'Powered by']], function(err, results){
let f = imap.fetch(results, {bodies: ['HEADER.FIELDS (FROM)', 'HEADER.FIELDS (TO)', 'HEADER.FIELDS (SUBJECT)', 'HEADER.FIELDS (MESSAGE-ID)', 'HEADER.FIELDS (REFERENCES)', 'TEXT']});
f.on('message', function(msg, seqno) {
msg.on('body', function(stream, info) {
let buffer = '', count = 0;
stream.on('data', function(chunk) {
buffer += chunk.toString('utf8');
if (info.which === 'TEXT'){
content = buffer;
console.log("Content === > ", content);
}
.............................................
.............................................
这里的内容没有正确获取
Content === > --000000000000e919ec05c1f7b3ec
Content-Type: text/plain; charset="UTF-8"
This is test reply1 from company email
On Mon, May 10, 2021 at 4:25 PM <reply@test.com> wrote:
> This is a test mail from server
--000000000000e919ec05c1f7b3ec
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This is test reply1 from company=C2=A0email</div><br><div =
class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, May 10,=
2021 at 4:25 PM <<a href=3D"mailto:reply@test.com">reply@test.com</=
a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Th=
is is a test mail from server</blockquote></div>
--000000000000e919ec05c1f7b3ec--
一些不需要的字符出现,例如 --000000000000e919ec05c1f7b3ec 和内容类型。我只需要获取邮件正文。如何得到它?