我对node.js (8.9.1版) libary 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上找到我完整的工作代码。
谢谢你的帮助
发布于 2017-11-12 21:24:30
对于搜索,日期必须采用特定格式,详见RFC 3501:
d-MON-YYYY
d:月中的一到两位数。
MON:是以下三个字母缩写之一:一月、二月、三月、四月、五月、六月、七月、八月、九月、十月、十一月、十二月
YYYY:是四位数的年份。
例子:2017年1月3日,1998年3月1日,2000年6月22日.
我对此不太确定,因为我不太了解node.js和这个库,但是您也可能不得不将[ 'UNSEEN', ['SINCE', 'May 20, 2017'] ]折叠到一个数组中;没有必要嵌套它们。[ 'UNSEEN', 'SINCE', 'May 20, 2017']
https://stackoverflow.com/questions/47251550
复制相似问题