I want to fetch only answered emails from Google mail via IMAP.

There is a flag /Answered but it seems not work. For fetch mails on Ruby I wrote

imap_privider.fetch(1..15, ["BODY[HEADER.FIELDS (SUBJECT)]", "FLAGS"])

And I got response for letter (which I know for sure is a reply):

#<struct Net::IMAP::FetchData
  seqno=14,
  attr=
   {"FLAGS"=>[:Seen],
    "BODY[HEADER.FIELDS (SUBJECT)]"=>"Subject: RE: salut\r\n\r\n"}>,

I think that in attr it should be [:Answered].

So what do I do wrong?

有帮助吗?

解决方案

Your message 14 isn't answered, it is an answer. Look at the message it answers, that's where you may find the \answered flag.

Note that some/many clients don't bother to set the \answered flag.

Another approach would be to retrieve x-gm-thrid and envelope and look at the thread. If the thread contains just one message, that message has not been answered. If it contains more, the highest-numbered message hasn't been answered, and you may consider that the earlier messages have.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top