我的 node.js(8.9.1 版)库imap有问题。如果我向函数发送请求
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"
}
}
我的 getMailsFromServer 函数是:
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();
}
});
})
})
})
如果我删除 imap.search 并将其设置var f = imap.seq.fetch(results
为例如var f = imap.seq.fetch( box.messages.total + ':*'
请求有效。你可以在GitHub 上找到我的完整工作代码
谢谢你的帮助