Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var Imap = require('imap'),
  4. inspect = require('util').inspect;
  5.  
  6. var imap = new Imap({
  7. user: 'heman@pling.net.br',
  8. password: 'teste',
  9. host: 'imap.pling.net.br',
  10. port: 993,
  11. tls: true,
  12. tlsOptions: { rejectUnauthorized: false }
  13. });
  14.  
  15. function openInbox (cb) {
  16.  
  17. imap.openBox('INBOX', true, cb);
  18. }
  19.  
  20. imap.once('ready', function() {
  21.  
  22. openInbox(function(err, box) {
  23.  
  24. if (err) throw err;
  25.  
  26. console.log('Estatisticas da caixa: ', box);
  27.  
  28. imap.search( ['ALL', ['UID', 6]], function(error, uid){
  29.  
  30. var f = imap.fetch(`${uid}`, {
  31. bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)'
  32. });
  33.  
  34. f.on('message', function(msg, seqno) {
  35.  
  36. var prefix = '(#' + seqno + ') ';
  37. msg.on('body', function(stream, info) {
  38.  
  39. var buffer = '';
  40. stream.on('data', function(chunk) {
  41. buffer += chunk.toString('utf8');
  42. });
  43. stream.once('end', function() {
  44.  
  45. console.log('Message #%d', seqno, "\n");
  46. console.log(prefix, 'Parsed header: ' + inspect(Imap.parseHeader(buffer), "\n\n"));
  47. });
  48. });
  49.  
  50. msg.once('attributes', function(attrs) {
  51. console.log('uid: ', attrs.uid, 'modseq: ', attrs.modseq );
  52. });
  53.  
  54. msg.once('end', function() {
  55. console.log(prefix, 'Finished', "\n\n");
  56. });
  57. });
  58.  
  59. f.once('error', function(err) {
  60. console.log('Fetch error: ' + err);
  61. });
  62.  
  63. f.once('end', function() {
  64. console.log('Done fetching all messages!');
  65. imap.end();
  66. });
  67. });
  68.  
  69.  
  70. });
  71.  
  72. /**
  73. * Return all boxes
  74. */
  75. imap.getBoxes( function(err, box){
  76. console.log( 'Box: ', box, "\n" );
  77. });
  78.  
  79. });
  80.  
  81. imap.once('error', function(err) {
  82. console.log(err);
  83. });
  84.  
  85. imap.once('end', function() {
  86. console.log('Connection ended');
  87. });
  88.  
  89. imap.connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement