0

我的 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 上找到我的完整工作代码

谢谢你的帮助

4

1 回答 1

1

对于搜索,日期必须采用特定格式,详见 RFC 3501:

d-MON-YYYY

d: 是月份日期的一位或两位数字
MON: 是以下三个字母缩写之一:Jan、Feb、Mar、Apr、May、Jun、Jul、Aug、Sep、Oct、Nov、Dec
YYYY:是四数字年份。

示例:2017 年 1 月 3 日、1998 年 3 月 1 日、2000 年 6 月 22 日。

我不太确定这一点,因为我不知道 node.js 和这个库,但你可能还必须将你的折叠[ 'UNSEEN', ['SINCE', 'May 20, 2017'] ]成一个数组;没有必要嵌套它们。 [ 'UNSEEN', 'SINCE', 'May 20, 2017']

于 2017-11-12T21:24:30.843 回答