Created
May 7, 2011 10:55
-
-
Save huancz/960404 to your computer and use it in GitHub Desktop.
demonstrate crash in node-imap
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
var sys = require('sys'); | |
var imap = require('imap'); | |
var mailCnt = undefined; | |
function dumpMsg(aMsg) { | |
console.log(JSON.stringify(aMsg, null, "\t")); | |
if (aMsg.headers) { | |
console.log("New mail, subject: " + aMsg.headers["subject"].join(", ")); | |
} else { | |
console.log("no headers for us? :-("); | |
} | |
mailCnt++; | |
} | |
function beginMsg(aMsg) { | |
aMsg.on('end', dumpMsg.bind(undefined, aMsg)); | |
} | |
function newMailCallback(conn, aCount) { | |
console.log("new mail detected (" + aCount + " messages), trying to fetch"); | |
var msgs = mailCnt + ":*"; | |
var fetch = conn.fetch(msgs, { markSeen : false, request: { struct : false, headers : [ 'Subject' ], body: false } }); | |
fetch.on('message', beginMsg); | |
} | |
function connectCallback(conn, aBoxName, aError) { | |
conn.openBox(aBoxName, true /*readonly*/, function (aError, aBox) { | |
if (aError) { | |
console.log("error on connect: " + aError); | |
throw "die"; | |
} | |
// console.log("box is open: " + sys.inspect(aBox)); | |
mailCnt = aBox._uidnext; | |
conn.on('mail', newMailCallback.bind(undefined, conn)); | |
// newMailCallback(1); | |
}); | |
} | |
exports.start = function(aMailboxParams) { | |
var conn = new (imap.ImapConnection)(aMailboxParams); | |
conn.connect(connectCallback.bind(undefined, conn, aMailboxParams.mailbox)); | |
} | |
exports.start({username:'...', password:'...', host: '...', port: '143', mailbox: 'INBOX.test'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment