dcparker / ruby-gmail

A Rubyesque interface to Gmail. Connect to Gmail via IMAP and manipulate emails and labels. Send email with your Gmail account via SMTP. Includes full support for parsing and generating MIME messages.
http://dcparker.github.com/ruby-gmail
792 stars 123 forks source link

Thread support #11

Closed superfeedr closed 10 years ago

superfeedr commented 14 years ago

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

Thanks!

dcparker commented 14 years ago

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!

wkrsz commented 12 years ago

http://code.google.com/apis/gmail/imap/#x-gm-thrid

wkrsz commented 12 years ago

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.

wkrsz commented 12 years ago

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 12 years ago

Thanks @wojt-eu , that patch worked!

wkrsz commented 12 years ago

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.

myobie commented 11 years ago

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.

myobie commented 10 years ago

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.