mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.16k stars 380 forks source link

IMap search getting stuck #832

Closed 734776328 closed 3 years ago

734776328 commented 3 years ago

Why is this "search" invalid? image

mscdex commented 3 years ago

'UNSEEN' doesn't have any parameters, so you should instead have something like:

const query = [
  'UNSEEN',
  ['FROM', 'hello@gmail.com'],
]
734776328 commented 3 years ago

'UNSEEN' doesn't have any parameters, so you should instead have something like:

const query = [
  'UNSEEN',
  ['FROM', 'hello@gmail.com'],
]

Hello, thank you, @mscdex , but I used your example and returned all the emails.Have you ever encountered this kind of problem. image

734776328 commented 3 years ago

The "search" method is invalid and always returns all messages. The completion code is as follows: image

mscdex commented 3 years ago

I'm not sure what you're meaning by "invalid", the server or imap shouldn't be rejecting the search criteria. If you mean it's just giving you unexpected results then that's another thing.

My only suggestion would be to try to use ['HEADER', 'From', 'xxxx'] instead of ['FROM', 'xxxx']. The searches are performed by the server, so ultimately you're at the whims of whatever server implementation and whether or not they deviate from the IMAP spec.

734776328 commented 3 years ago

I'm not sure what you're meaning by "invalid", the server or imap shouldn't be rejecting the search criteria. If you mean it's just giving you unexpected results then that's another thing.

My only suggestion would be to try to use ['HEADER', 'From', 'xxxx'] instead of ['FROM', 'xxxx']. The searches are performed by the server, so ultimately you're at the whims of whatever server implementation and whether or not they deviate from the IMAP spec.

thank @mscdex .

734776328 commented 3 years ago

@mscdex hi, @mscdex , Is this "imap" library for Gmail only?

mscdex commented 3 years ago

Is this "imap" library for Gmail only?

No

Romax-91 commented 2 years ago

Faced the same problem. I don't know how to solve it

imap.search(
    [
        'All',
        ['SINCE', 'July 30, 2022'],
        [ 'FROM', 'mail@mail.ru']
    ],

error:' Unexpected search option: ' + criteria Error: Unexpected search option: FROM at buildSearchQuery (E:\JS\shellCodeBot\node_modules\node-imap\lib\utils.js:252:19) at Connection._search (E:\JS\shellCodeBot\node_modules\node-imap\lib\Connection.js:519:79) at Connection.search (E:\JS\shellCodeBot\node_modules\node-imap\lib\Connection.js:512:10) at E:\JS\shellCodeBot\get_promo\index.js:34:11 at Connection.<anonymous> (E:\JS\shellCodeBot\node_modules\node-imap\lib\Connection.js:407:9) at Connection._resTagged (E:\JS\shellCodeBot\node_modules\node-imap\lib\Connection.js:1307:24) at Parser.<anonymous> (E:\JS\shellCodeBot\node_modules\node-imap\lib\Connection.js:190:12) at Parser.emit (node:events:390:28) at Parser._resTagged (E:\JS\shellCodeBot\node_modules\node-imap\lib\Parser.js:169:12) at Parser._parse (E:\JS\shellCodeBot\node_modules\node-imap\lib\Parser.js:135:18)

I'm try to use ['HEADER', 'From', 'xxxx'] but it didn't help

mscdex commented 2 years ago

@Romax-91 You're using a different module called node-imap, which is maintained by someone else. This module is simply called imap on npm.