node.jswindowscmdfrisby.jsnode-imap

I'm expecting token from the body of email but it dumps = sign after every line


I'm using npm package(node-imap) to retrieve the body of email and I'm successfully able to retrieve the body of email but it dumping = after every line in the last

My code is:

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();

And the output I'm getting is something like this:

<!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=

Solution

  • Try this:

    By installing quoted-printable you can able to resolve this issue.

    npm i quoted-printable
    

    for more details: https://www.npmjs.com/package/quoted-printable

    Thanks!!!