Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.fetchMail = function(ind, done) {
- var imap = new Imap({
- user: config.email.user,
- password: config.email.password,
- host: config.email.host,
- tls: false,
- tlsOptions: { rejectUnauthorized: false }
- })
- imap.once('ready', function() {
- imap.openBox('Inbox', true, function(err, box) {
- if (err) return done(err)
- var imapFetch = imap.seq.fetch(ind, {
- bodies: ['HEADER.FIELDS (FROM TO SUBJECT DATE)', 'TEXT'],
- struct: true
- })
- imapFetch.on('message', function(msg, seqno) {
- var body = ''
- , header = ''
- , parsedMsg = {}
- msg.on('body', function(stream, info) {
- if (info.which === 'TEXT') {
- stream.on('data', function(chunk) { body += chunk.toString('utf8') })
- stream.once('end', function() { parsedMsg.body = body })
- } else {
- stream.on('data', function(chunk) { header += chunk.toString('utf8') })
- stream.once('end', function() { parsedMsg.header = Imap.parseHeader(header) })
- }
- })
- msg.once('attributes', function(attrs) {
- parsedMsg.attrs = attrs
- })
- msg.once('end', function() {
- done(null, parsedMsg)
- })
- })
- imapFetch.once('error', done)
- })
- })
- imap.once('error', done)
- imap.connect()
- }
Advertisement
Add Comment
Please, Sign In to add comment