ruby on rails - Read Gmail XOAUTH mails without marking it read -
i'm trying read email gmail using gmail-xoauth gem. want read email , leave unread status.
first, tried reading header. works.
imap = net::imap.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false) imap.authenticate('xoauth2', email, access_token) imap.select('inbox') imap.search(["since", since]).each |message_id| msg = imap.fetch(message_id,'rfc822.header')[0].attr['rfc822.header'] mail = mail.read_from_string msg puts mail.subject end
now, want read body/text of email without marking read.
based on documentation need use store
method. documentation mentions:
store(set, attr, flags)
sends store command alter data associated messages in mailbox, in particular flags. set parameter number or array of numbers or range object. each number message sequence number. attr name of data item store: ‘flags’ means replace message’s flag list provided one; ‘+flags’ means add provided flags; , ‘-flags’ means remove them. flags list of flags.
the return value array of net::imap::fetchdata. example:
p imap.store(6..8, "+flags", [:deleted]) #=> [#<net::imap::fetchdata seqno=6, attr={"flags"=>[:seen, :deleted]}>, \\ #<net::imap::fetchdata seqno=7, attr={"flags"=>[:seen, :deleted]}>, \\ #<net::imap::fetchdata seqno=8, attr={"flags"=>[:seen, :deleted]}>]
so have remove :seen
flag
imap.store(message_id, "-flags", [:seen])
Comments
Post a Comment