Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. Message #8
  2. (#8) Body ['TEXT'] found, 6897 total bytes
  3. (#8) Body ['TEXT'] (330/6897)
  4. (#8) Body ['TEXT'] (1356/6897)
  5. (#8) Body ['TEXT'] (2757/6897)
  6. (#8) Body ['TEXT'] (3406/6897)
  7. (#8) Body ['TEXT'] (4807/6897)
  8. (#8) Body ['TEXT'] (6208/6897)
  9. (#8) Body ['TEXT'] (6897/6897)
  10. (#8) Body ['TEXT'] Finished
  11. (#8) Parsed header: { from: [ 'Google <no-reply@accounts.google.com>' ] }
  12. (#8) Attributes: { date: 2017-08-21T20:16:36.000Z,
  13. flags: [ '\Seen' ],
  14. uid: 13,
  15. modseq: '2554',
  16. 'x-gm-labels': [],
  17. 'x-gm-msgid': '1576373160393136995',
  18. 'x-gm-thrid': '1576373160393136995' }
  19. (#8) Finished
  20. Done fetching all messages!
  21. Connection ended
  22.  
  23. let imap = new Imap({
  24. user: 'email@gmail.com',
  25. password: 'senha',
  26. host: 'imap.gmail.com',
  27. port: 993,
  28. tls: true
  29. });
  30.  
  31. function openInbox(cb) {
  32. imap.openBox('INBOX', true, cb);
  33. }
  34.  
  35. imap.once('ready', function() {
  36. openInbox(function(err, box) {
  37. if (err) throw err;
  38. let f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM)','TEXT'] });
  39. f.on('message', function(msg, seqno) {
  40. console.log('Message #%d', seqno);
  41. let prefix = '(#' + seqno + ') ';
  42. msg.on('body', function(stream, info) {
  43. if (info.which === 'TEXT')
  44. console.log(prefix + 'Body [%s] found, %d total bytes', inspect(info.which), info.size);
  45. let buffer = '', count = 0;
  46. stream.on('data', function(chunk) {
  47. count += chunk.length;
  48. buffer += chunk.toString('utf8');
  49. if (info.which === 'TEXT')
  50. console.log(prefix + 'Body [%s] (%d/%d)', inspect(info.which), count, info.size);
  51. });
  52. stream.once('end', function() {
  53. if (info.which !== 'TEXT')
  54. console.log(prefix + 'Parsed header: %s', inspect(Imap.parseHeader(buffer)));
  55. else
  56. console.log(prefix + 'Body [%s] Finished', inspect(info.which));
  57. });
  58. });
  59. msg.once('attributes', function(attrs) {
  60. console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8));
  61. });
  62. msg.once('end', function() {
  63. console.log(prefix + 'Finished');
  64. });
  65. });
  66. f.once('error', function(err) {
  67. console.log('Fetch error: ' + err);
  68. });
  69. f.once('end', function() {
  70. console.log('Done fetching all messages!');
  71. imap.end();
  72. });
  73. });
  74. });
  75.  
  76. imap.once('error', function(err) {
  77. console.log(err);
  78. });
  79.  
  80. imap.once('end', function() {
  81. console.log('Connection ended');
  82. });
  83.  
  84. imap.connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement