Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Thread support #11

Closed
superfeedr opened this Issue Feb 8, 2010 · 8 comments

Comments

Projects
None yet
5 participants
@ghost

ghost commented Feb 8, 2010

Hey, one of the great advantages of Gmail is threads... is there a way for a given message to retrieve th ethread?

Thanks!

Owner

dcparker commented Feb 12, 2010

I don't know of any way right now, so no foreseeable way to add this -- BUT if anyone finds a way to get all emails of a certain Thread (Gmail conversations) via IMAP or some other way, please comment here!

data = gmail.imap.fetch(message.uid, "(X-GM-MSGID)")

I'm getting ParseError exception - Ruby's net/imap does not recognize the attribute.

I'm now trying to monkey-patch net/imap in the Large Hadron Collider.

Found the patch somewhere (adds two last when cases):

module Net
  class IMAP
    class ResponseParser 
      def msg_att
        match(T_LPAR)
        attr = {}
        while true
          token = lookahead
          case token.symbol
          when T_RPAR
            shift_token
            break
          when T_SPACE
            shift_token
            token = lookahead
          end
          case token.value
          when /\A(?:ENVELOPE)\z/ni
            name, val = envelope_data
          when /\A(?:FLAGS)\z/ni
            name, val = flags_data
          when /\A(?:INTERNALDATE)\z/ni
            name, val = internaldate_data
          when /\A(?:RFC822(?:\.HEADER|\.TEXT)?)\z/ni
            name, val = rfc822_text
          when /\A(?:RFC822\.SIZE)\z/ni
            name, val = rfc822_size
          when /\A(?:BODY(?:STRUCTURE)?)\z/ni
            name, val = body_data
          when /\A(?:UID)\z/ni
            name, val = uid_data

          when /\A(?:X-GM-MSGID)\z/ni  # Added X-GM-MSGID extension
            name, val = uid_data
          when /\A(?:X-GM-THRID)\z/ni  # Added X-GM-THRID extension
            name, val = uid_data

          else
            parse_error("unknown attribute `%s'", token.value)
          end
          attr[name] = val
        end
        return attr
      end

    end
  end
end

(I'll try to rework it to add only significant lines with alias_method or sth)

And then:

  data = gmail.imap.fetch(uid, "(X-GM-THRID)")
  thread_id =  data[0].attr["X-GM-THRID"].to_s(16)

alagu commented Jan 25, 2012

Thanks @wojt-eu , that patch worked!

Glad to hear, @alagu. I recall I have tried to make the patch smaller (so that it didn't repeat whole msg_att method) but failed. It works though, It's used in production.

Collaborator

myobie commented Dec 19, 2012

Is there a pull request for this anywhere? If not, I'll try to get this in as soon as I can get a test written.

@ghost ghost assigned myobie Dec 19, 2012

Collaborator

myobie commented Mar 28, 2014

I didn't find a PR for this and I don't want to monkey patch IMAP so I am going to close this. If there is another way to do this without modifying internals then please open a new issue.

@myobie myobie closed this Mar 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment