mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.17k stars 382 forks source link

How to search messages from multiple sender (FROM email addresses) #861

Closed ratribiana closed 2 years ago

ratribiana commented 2 years ago

I tried this but not working

  [ 'TO', 'to@receiver.com' ],
  [
    'OR',
    [ 'FROM', 'test@email1.com' ],
    [ 'FROM', 'test2@email2.com' ]
  ],
    [
    'OR',
    [ 'FROM', 'test3@live1.com' ],
    [ 'FROM', 'test4@live2.com' ]
  ]

I tried this too but not working as well, there is no return

   [ 'TO', 'to@receiver.com' ],
   [ 'FROM', 'test@email1.com' ],
   [ 'FROM', 'test2@email2.com' ],
   [ 'FROM', 'test@email1.com' ],
   [ 'FROM', 'test2@email2.com' ]
mscdex commented 2 years ago

If you're trying to find messages where the 'From' matches only one of those addresses, you need to continually nest each 'OR':

[
  [ 'TO', 'to@receiver.com' ],
  [ 'OR',
    [ 'FROM', 'test@email1.com' ],
    [ 'OR',
      [ 'FROM', 'test2@email2.com' ],
      // etc.
    ],
  ],
]
ratribiana commented 2 years ago

Will it return messages from 2 out of those email accounts or just only one? Once the search found the match for one address, will it continue to check other addresses or will return the message immediately?

mscdex commented 2 years ago

If you add all of the addresses you're searching for, it should return all messages where the 'From' matches only one of those addresses. It's saying "find messages addressed to tospan>@</spanreceiver.com AND is from either testspan>@</spanemail1.com or test2span>@</spanemail2.com or .... etc."

ratribiana commented 2 years ago

Many thanks!