Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Copyright (C) 2011, The Locker Project
- * All rights reserved.
- *
- * Please see the LICENSE file for more information.
- *
- */
- //testing for the IMAP connector against a live IMAP server
- var async = require('async'),
- util = require('util'),
- ImapConnection = require('imap').ImapConnection;
- process.on('uncaughtException',function(error){
- console.error(error);
- console.error(error.stack);
- });
- var auth = {
- username: '***',
- password: '***',
- host: 'imap.gmail.com',
- port: '993',
- secure: true
- // , debug: function(msg) {
- // console.log(msg);
- // }
- };
- async.series({
- connect: function(callback) {
- console.log('connect');
- imap = new ImapConnection(auth);
- imap.connect(function(err) {
- callback(err, 'connect');
- });
- },
- openbox: function(callback) {
- console.log('openbox');
- imap.openBox('INBOX', true, function(err, msg) {
- callback(err, 'openbox');
- });
- },
- test334: function(callback) {
- fetch('334', function(err, msg) {
- callback(err, msg);
- });
- },
- test80: function(callback) {
- fetch('80', function(err, msg) {
- callback(err, msg);
- });
- },
- test47: function(callback) {
- fetch('47', function(err, msg) {
- callback(err, msg);
- });
- },
- logout: function(callback) {
- console.log('logout');
- imap.logout(function(err) {
- callback(err, 'logout');
- });
- }
- },
- function(err, results) {
- if (err) {
- console.error(err);
- }
- console.log(util.inspect(results));
- });
- function fetch(uid, callback) {
- console.log('fetching uid: ' + uid);
- var headerFetch = imap.fetch([uid], { request: { headers: true } });
- headerFetch.on('message', function(headerMsg) {
- headerMsg.on('end', function() {
- var bodyFetch = imap.fetch(headerMsg.id, { request: { headers: false, body: true } });
- bodyFetch.on('message', function(bodyMsg) {
- console.log('bodyFetch.on(message)');
- bodyMsg.on('data', function(chunk) {
- console.log('bodyMsg.on(data)');
- });
- bodyMsg.on('end', function() {
- console.log('bodyMsg.on(end)');
- });
- });
- bodyFetch.on('end', function() {
- console.log('bodyFetch.on(end)');
- callback(null, 'fetch');
- });
- });
- });
- }
Add Comment
Please, Sign In to add comment