paulrosania/gmail-imap — pull request #3 by davidbalbert (2013-07-12 06:40:11+00:00)
Title: Fix response parsing bug in Ruby 2.0

The signature of Net::IMAP::ResponseParser#msg_att has changed in ruby 2.0.0. You can see [the relevant issue](http://bugs.ruby-lang.org/issues/5692), and [the diff]( http://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/34010).

This change caused some tests to fail when using gmail-imap 1.0.1 with Ruby 2.0. This patch adjusts to the new function signature while still allowing the library to work in versions of ruby older than 2.0. I've run the test suite on 1.9.3-p448 and 2.0.0-p247 and verified that everything works. The fix is pretty gross, but I didn't see a better way to do it.

I may try to see if it's possible to modify the 'net/imap' to create an interface that makes the sort of IMAP extension handling that you need for Gmail support easy to do without monkey patching. If I end up looking into this, and it is possible, I will submit a patch to ruby-core and see what happens. It would be nice not to have to worry about internal API changes for this project.

I've included the test errors below:

```
$ rake test

*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.

Loaded suite /Users/david/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader
Started
...E
===============================================================================
Error: test_parses_gmail_fetch_attributes(Net::IMAP::ResponseParser::GmailTest)
ArgumentError: wrong number of arguments (1 for 0)
/private/tmp/gmail-imap/lib/net/imap/response_parser/gmail.rb:2:in `msg_att'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2210:in `numeric_response'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2152:in `response_untagged'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2132:in `response'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2058:in `parse'
/private/tmp/gmail-imap/test/net/imap/response_parser/test_gmail.rb:9:in `test_parses_gmail_fetch_attributes'
6: message = File.read(File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'fixtures', 'response.log')))
7:
8: parser = Net::IMAP::ResponseParser::Gmail.new
=> 9: result = parser.parse(message)
10:
11: assert_equal 123, result.data.attr['X-GM-MSGID']
12: assert_equal 789, result.data.attr['X-GM-THRID']
===============================================================================
E
===============================================================================
Error: test_parses_gmail_fetch_quoted_labels(Net::IMAP::ResponseParser::GmailTest)
ArgumentError: wrong number of arguments (1 for 0)
/private/tmp/gmail-imap/lib/net/imap/response_parser/gmail.rb:2:in `msg_att'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2210:in `numeric_response'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2152:in `response_untagged'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2132:in `response'
/Users/david/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/net/imap.rb:2058:in `parse'
/private/tmp/gmail-imap/test/net/imap/response_parser/test_gmail.rb:20:in `test_parses_gmail_fetch_quoted_labels'
17: message = File.read(File.expand_path(File.join(__FILE__, '..', '..', '..', '..', 'fixtures', 'response-quoted-labels.log')))
18:
19: parser = Net::IMAP::ResponseParser::Gmail.new
=> 20: result = parser.parse(message)
21:
22: assert_equal ['Inbox', 'This', 'Supports Spaces'], result.data.attr['X-GM-LABELS']
23: end
===============================================================================

Finished in 0.01111 seconds.

5 tests, 3 assertions, 0 failures, 2 errors, 0 pendings, 0 omissions, 0 notifications
60% passed

450.05 tests/s, 270.03 assertions/s
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/Users/david/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib" "/Users/david/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_test_loader.rb" "test/net/imap/response_parser/test_gmail.rb" "test/net/imap/test_gmail.rb" ]

Tasks: TOP => test
(See full trace by running task with --trace)
```