Created
March 7, 2013 11:16
-
-
Save lperrin/5107373 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function fetchEmails = function (range, options, query, mailbox, done) { | |
var emails = []; | |
if(!mailbox) | |
return done({error: 'mailbox not ready'}); | |
query.cb = function (fetch) { | |
fetch.on('message', function (msg) { | |
var headers = {}, | |
body = ''; | |
msg.on('headers', function (hdrs) { | |
headers = hdrs; | |
}); | |
msg.on('data', function (chunk) { | |
body += chunk.toString('utf8'); | |
}); | |
msg.on('end', function () { | |
emails.push({ | |
seq: msg.seqno, | |
gmid: msg['x-gm-msgid'], | |
thrid: msg['x-gm-thrid'], | |
headers: headers, | |
structure: msg.structure, | |
body: body | |
}); | |
}); | |
}; | |
imap.seq.fetch(range, options, query, function (err) { | |
if(err) | |
return done(err); | |
done(null, emails); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment