You can try
imap.search(["FROM", "space@nasa.com", "SUBJECT", "life on mars", "OR", "life on venus", "NOT", "life on earth"])
Full documentation is available here: http://www.ruby-doc.org/stdlib-2.0/libdoc/net/imap/rdoc/Net/IMAP.html
Question
I have code using which I am able to fetch emails from authenticated gmail account. At the moment there is a basic filter applied on it. But my requirement needs me to apply multiple filters like:
[from: space@nasa.com]
AND [subject: life on mars]
OR [subject: life on venus]
AND [subject "not": life on earth]
Can any when suggest how I can apply filters like this on imap.search command?
Solution
You can try
imap.search(["FROM", "space@nasa.com", "SUBJECT", "life on mars", "OR", "life on venus", "NOT", "life on earth"])
Full documentation is available here: http://www.ruby-doc.org/stdlib-2.0/libdoc/net/imap/rdoc/Net/IMAP.html
OTHER TIPS
In case you wish to perform the following query:
(FROM == "from-lookup-email@gmail.com" || TO == "to-lookup-email@gmail.com")
You can use the following seacrh command:
search_result = imap.search(["OR", "FROM", "from-lookup-email@gmail.com", "TO", "to-lookup-email@gmail.com"])