Я ожидаю токен из тела письма, но после каждой строки он выдает дамп = знак - PullRequest
0 голосов
/ 01 февраля 2019

Я использую пакет npm ( node-imap ) для извлечения тела письма, и я успешно могу получить тело письма, но оно выводит = после каждой строки в последней

Мой код:

var Imap = require('imap'),
    inspect = require('util').inspect;

var imap = new Imap({
  user: 'XXXXXXXX',
  password: 'XXXXXX',
  host: 'imap.gmail.com',
  port: 993,
  tls: true
});

function openInbox(cb) {
  imap.openBox("INBOX", true, cb);
}

imap.once('ready', function() {
    openInbox(function(err, box) {
      if (err) throw err;
      var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
      f.on('message', function(msg, seqno) {
        console.log('Message #%d', seqno);
        var prefix = '(#' + seqno + ') ';
        msg.on('body', function(stream, info) {
          if (info.which === 'TEXT')
            console.log(prefix + '\nBody [%s] found, %d total bytes\n', inspect(info.which), info.size);
          var buffer = '', count = 0;
          stream.on('data', function(chunk) {
            count += chunk.length;
            buffer += chunk.toString('utf8');
            if (info.which === 'TEXT')
              console.log(prefix + 'Body [%s] (%d/%d)', inspect(info.which), count, info.size);
          });
          stream.once('end', function() {
            if (info.which !== 'TEXT')
              console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
            else
              console.log(prefix + 'Body [%s] Finished', inspect(info.which));
            console.log(buffer.toString());
          });
        });
        msg.once('attributes', function(attrs) {
          console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
        });
        msg.once('end', function() {
          console.log(prefix + 'Finished');
        });
      });
      f.once('error', function(err) {
        console.log('Fetch error: ' + 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();

И вывод, который я получаю, выглядит примерно так:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.=
w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=3D"http://www.w3.=
org/1999/xhtml">        <head>          <title>Untitled Page</title>    </head> <body>          =
<table style=3D"text-align:left;font-family:Tahoma;font-size:small;" =
width=3D"100%">                 <tr>                            <td style=3D"font-weight:bold; =
text-align:center;">                            &nbsp;                          </td>               </tr>
        <tr>                            <td =
style=3D"font-weight:bold; text-align:left;">                                   Dear User,                      </td>
                =
</tr>                   <tr>                            <td align=3D"center" style=3D"text-align: left">
                        =
<br/>Request is generated for reset password.                           </td>                   </tr><tr>       <td =
align=3D"center" style=3D"text-align: left">            <br/>Please click here to =
reset password. </td></tr><tr>  <td style=3D"font-weight:bold; =
text-align:left;" >             <br/>           <a style=3D" background-color:#4d90fe;border:1p=
x solid #3079ed;border-radius:2px;color:white;                  display:inline-block;font-=
family:Roboto,Arial,Helvetica,sans-serif;font-size:11px;                        =
font-weight:bold;min-height:29px;line-height:29px;min-width:54px;outline:0p=
x;padding:0 8px;                        padding:0 8px;text-align:center;text-decoration:none;cur=

1 Ответ

0 голосов
/ 01 февраля 2019

Попробуйте это:

Установив цитируемый с возможностью печати , вы сможете решить эту проблему.

npm i quoted-printable

для получения более подробной информации: https://www.npmjs.com/package/quoted-printable

Спасибо !!!

...