Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var Imap = require('imap'),
- inspect = require('util').inspect;
- var imap = new Imap({
- user: 'heman@pling.net.br',
- password: 'teste',
- host: 'imap.pling.net.br',
- port: 993,
- tls: true,
- tlsOptions: { rejectUnauthorized: false }
- });
- function openInbox (cb) {
- imap.openBox('INBOX', true, cb);
- }
- imap.once('ready', function() {
- openInbox(function(err, box) {
- if (err) throw err;
- console.log('Estatisticas da caixa: ', box);
- imap.search( ['ALL', ['UID', 6]], function(error, uid){
- var f = imap.fetch(`${uid}`, {
- bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)'
- });
- f.on('message', function(msg, seqno) {
- var prefix = '(#' + seqno + ') ';
- msg.on('body', function(stream, info) {
- var buffer = '';
- stream.on('data', function(chunk) {
- buffer += chunk.toString('utf8');
- });
- stream.once('end', function() {
- console.log('Message #%d', seqno, "\n");
- console.log(prefix, 'Parsed header: ' + inspect(Imap.parseHeader(buffer), "\n\n"));
- });
- });
- msg.once('attributes', function(attrs) {
- console.log('uid: ', attrs.uid, 'modseq: ', attrs.modseq );
- });
- msg.once('end', function() {
- console.log(prefix, 'Finished', "\n\n");
- });
- });
- f.once('error', function(err) {
- console.log('Fetch error: ' + err);
- });
- f.once('end', function() {
- console.log('Done fetching all messages!');
- imap.end();
- });
- });
- });
- /**
- * Return all boxes
- */
- imap.getBoxes( function(err, box){
- console.log( 'Box: ', box, "\n" );
- });
- });
- 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