Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getMails: function (req, res) {
- var body = req.body
- , parser = new MailParser();
- if(body.encryptedSecret !== undefined) {
- User.findOne({"email": req.user.email}, function (err, user) {
- var mailAccount = user.mailAccounts[0]
- , imap = new Imap({
- user: mailAccount.imap_user,
- password: mailAccount.imap_pass,
- host: mailAccount.imap_host,
- port: mailAccount.imap_port,
- tls: true
- });
- getMailsFromServer(parser, imap, res)
- });
- } else {
- response.error(res, '400', '2-7')
- }
- }
- {
- "message": "error",
- "internalErrrorCode": "2-9",
- "data": {
- "type": "bad",
- "source": "protocol"
- }
- }
- imap.once('ready', function () {
- imap.openBox('INBOX', true, function (err, box) {
- if (err) throw err;
- imap.search([ 'UNSEEN', ['SINCE', 'May 20, 2017'] ], function(err, results) {
- var f = imap.seq.fetch(results, { bodies: '' });
- f.on('message', function (msg, seqno) {
- msg.on('body', function (stream, info) {
- stream.on('data', function (chunk) {
- parser.write(chunk.toString("utf8"));
- })
- })
- msg.once('end', function () {
- parser.end();
- });
- })
- f.once('error', function (err) {
- error = true
- response.error(res, 500, '2-9', err)
- });
- f.once('end', function () {
- if (!error) {
- parser.on('data', function (data) {
- response.success(res, data.html)
- });
- console.log('Done fetching all messages!');
- imap.end();
- }
- });
- })
- })
- })
Add Comment
Please, Sign In to add comment