Skip to content

Instantly share code, notes, and snippets.

@aenario
Created August 29, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aenario/b466f9f1cc6dd301e36d to your computer and use it in GitHub Desktop.
Save aenario/b466f9f1cc6dd301e36d to your computer and use it in GitHub Desktop.
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