Created
August 29, 2014 16:51
-
-
Save aenario/b466f9f1cc6dd301e36d to your computer and use it in GitHub Desktop.
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
Imap = require('imap'); | |
MailParser = require("mailparser").MailParser; | |
connection = new Imap({ | |
user: "romain.foucault@cozycloud.cc", | |
password: "XXXX", | |
host: "imap.gmail.com", | |
port: 993, | |
tls: true, | |
tlsOptions: { | |
rejectUnauthorized: false | |
}, | |
debug: console.log | |
}); | |
// debug: (x) -> console.log 'IMAP', x.substring(0, 80) | |
connection.once('ready', function () { | |
connection.openBox('INBOX', function () { | |
connection.search( [[ 'UID', '1:200']], function (err, ids) { | |
fetch = connection.fetch(ids, { | |
size: true, | |
bodies: '' | |
}); | |
i = 0; | |
fetch.on('message', function (msg) { | |
console.log("HANDLE MSG", i++, "/", ids.length); | |
msg.on('body', function(stream, info){ | |
// stream.on('data', function(){}); | |
// stream.on('end', function(){}); | |
mailparser = new MailParser({streamAttachments: true}); | |
mailparser.on('attachment', function(attachment) {}); | |
mailparser.on('end', function(){ | |
console.log("DONE MSG"); | |
}); | |
stream.pipe(mailparser); | |
}); | |
}); | |
fetch.on('end', function(){ | |
console.log("END OF FETCH"); | |
connection.end() | |
}); | |
}); | |
}); | |
}); | |
connection.connect(); | |
//result = http://pastebin.com/7Puhcs3j |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment