Created
June 23, 2011 17:53
-
-
Save amcjen/1043120 to your computer and use it in GitHub Desktop.
imap on('end') hang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* 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'); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment