gmail-imap 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/gmail-imap.gemspec +19 -0
- data/lib/gmail_imap.rb +3 -0
- data/lib/net/imap/gmail.rb +9 -0
- data/lib/net/imap/response_parser/gmail.rb +43 -0
- data/test/fixtures/response.log +1 -0
- data/test/net/imap/response_parser/test_gmail.rb +15 -0
- data/test/net/imap/test_gmail.rb +27 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Paul Rosania
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# gmail-imap
|
2
|
+
|
3
|
+
A Gmail extension-aware accessory to Net::IMAP.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gmail-imap'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gmail-imap
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'net/imap/gmail'
|
22
|
+
|
23
|
+
Replace calls to `Net::IMAP` with `Net::IMAP::Gmail`.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/gmail-imap.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/gmail_imap', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Paul Rosania"]
|
6
|
+
gem.email = ["paul.rosania@gmail.com"]
|
7
|
+
gem.description = %q{Use with Net::IMAP to interact with Gmail's IMAP extensions.}
|
8
|
+
gem.summary = %q{A Gmail extension-aware accessory to Net::IMAP.}
|
9
|
+
gem.homepage = "https://github.com/paulrosania/gmail-imap"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "gmail-imap"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = GmailImap::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "mocha", ['>= 0']
|
19
|
+
end
|
data/lib/gmail_imap.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class Net::IMAP::ResponseParser::Gmail < Net::IMAP::ResponseParser
|
2
|
+
def msg_att
|
3
|
+
match(T_LPAR)
|
4
|
+
attr = {}
|
5
|
+
while true
|
6
|
+
token = lookahead
|
7
|
+
case token.symbol
|
8
|
+
when T_RPAR
|
9
|
+
shift_token
|
10
|
+
break
|
11
|
+
when T_SPACE
|
12
|
+
shift_token
|
13
|
+
next
|
14
|
+
end
|
15
|
+
case token.value
|
16
|
+
when /\A(?:ENVELOPE)\z/ni
|
17
|
+
name, val = envelope_data
|
18
|
+
when /\A(?:FLAGS)\z/ni
|
19
|
+
name, val = flags_data
|
20
|
+
when /\A(?:INTERNALDATE)\z/ni
|
21
|
+
name, val = internaldate_data
|
22
|
+
when /\A(?:RFC822(?:\.HEADER|\.TEXT)?)\z/ni
|
23
|
+
name, val = rfc822_text
|
24
|
+
when /\A(?:RFC822\.SIZE)\z/ni
|
25
|
+
name, val = rfc822_size
|
26
|
+
when /\A(?:BODY(?:STRUCTURE)?)\z/ni
|
27
|
+
name, val = body_data
|
28
|
+
when /\A(?:UID)\z/ni
|
29
|
+
name, val = uid_data
|
30
|
+
when /\A(?:X-GM-LABELS)\z/ni
|
31
|
+
name, val = flags_data
|
32
|
+
when /\A(?:X-GM-MSGID)\z/ni
|
33
|
+
name, val = uid_data
|
34
|
+
when /\A(?:X-GM-THRID)\z/ni
|
35
|
+
name, val = uid_data
|
36
|
+
else
|
37
|
+
parse_error("unknown attribute `%s'", token.value)
|
38
|
+
end
|
39
|
+
attr[name] = val
|
40
|
+
end
|
41
|
+
return attr
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
* 3 FETCH (X-GM-THRID 789 X-GM-MSGID 123 X-GM-LABELS (Foo Bar))
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'net/imap/response_parser/gmail'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class Net::IMAP::ResponseParser::GmailTest < Test::Unit::TestCase
|
5
|
+
def 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']
|
13
|
+
assert_equal ['Foo', 'Bar'], result.data.attr['X-GM-LABELS']
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'net/imap/gmail'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
class Net::IMAP::GmailTest < Test::Unit::TestCase
|
6
|
+
def test_is_imap
|
7
|
+
assert_equal Net::IMAP, Net::IMAP::Gmail.superclass
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
file = stub
|
12
|
+
file.stubs(:write).returns(1)
|
13
|
+
file.stubs(:gets).returns("* OK Ready.\r\n")
|
14
|
+
TCPSocket.stubs(:open).returns(file)
|
15
|
+
Thread.stubs(:start).returns(stub)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_initializes_imap
|
19
|
+
imap = Net::IMAP::Gmail.new('imap.gmail.com', :port => 143, :ssl => false)
|
20
|
+
assert_equal 'OK', imap.greeting.name
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_patches_response_parser
|
24
|
+
imap = Net::IMAP::Gmail.new('imap.gmail.com', :port => 143, :ssl => false)
|
25
|
+
assert_equal Net::IMAP::ResponseParser::Gmail, imap.instance_variable_get(:@parser).class
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmail-imap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Rosania
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mocha
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Use with Net::IMAP to interact with Gmail's IMAP extensions.
|
31
|
+
email:
|
32
|
+
- paul.rosania@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- gmail-imap.gemspec
|
43
|
+
- lib/gmail_imap.rb
|
44
|
+
- lib/net/imap/gmail.rb
|
45
|
+
- lib/net/imap/response_parser/gmail.rb
|
46
|
+
- test/fixtures/response.log
|
47
|
+
- test/net/imap/response_parser/test_gmail.rb
|
48
|
+
- test/net/imap/test_gmail.rb
|
49
|
+
homepage: https://github.com/paulrosania/gmail-imap
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.23
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: A Gmail extension-aware accessory to Net::IMAP.
|
73
|
+
test_files:
|
74
|
+
- test/fixtures/response.log
|
75
|
+
- test/net/imap/response_parser/test_gmail.rb
|
76
|
+
- test/net/imap/test_gmail.rb
|