Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Message #8
- (#8) Body ['TEXT'] found, 6897 total bytes
- (#8) Body ['TEXT'] (330/6897)
- (#8) Body ['TEXT'] (1356/6897)
- (#8) Body ['TEXT'] (2757/6897)
- (#8) Body ['TEXT'] (3406/6897)
- (#8) Body ['TEXT'] (4807/6897)
- (#8) Body ['TEXT'] (6208/6897)
- (#8) Body ['TEXT'] (6897/6897)
- (#8) Body ['TEXT'] Finished
- (#8) Parsed header: { from: [ 'Google <no-reply@accounts.google.com>' ] }
- (#8) Attributes: { date: 2017-08-21T20:16:36.000Z,
- flags: [ '\Seen' ],
- uid: 13,
- modseq: '2554',
- 'x-gm-labels': [],
- 'x-gm-msgid': '1576373160393136995',
- 'x-gm-thrid': '1576373160393136995' }
- (#8) Finished
- Done fetching all messages!
- Connection ended
- let imap = new Imap({
- user: 'email@gmail.com',
- password: 'senha',
- 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;
- let f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
- f.on('message', function(msg, seqno) {
- console.log('Message #%d', seqno);
- let prefix = '(#' + seqno + ') ';
- msg.on('body', function(stream, info) {
- if (info.which === 'TEXT')
- console.log(prefix + 'Body [%s] found, %d total bytes', inspect(info.which), info.size);
- let 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));
- });
- });
- 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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement