gmail_gm_raw 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +82 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +275 -0
- data/Rakefile +35 -0
- data/TODO.md +12 -0
- data/gmail.gemspec +34 -0
- data/lib/gmail.rb +65 -0
- data/lib/gmail/client.rb +30 -0
- data/lib/gmail/client/base.rb +225 -0
- data/lib/gmail/client/imap_extensions.rb +54 -0
- data/lib/gmail/client/plain.rb +20 -0
- data/lib/gmail/client/xoauth.rb +51 -0
- data/lib/gmail/labels.rb +62 -0
- data/lib/gmail/mailbox.rb +118 -0
- data/lib/gmail/message.rb +166 -0
- data/lib/gmail/version.rb +3 -0
- data/spec/account.yml.example +2 -0
- data/spec/client_spec.rb +178 -0
- data/spec/gmail_spec.rb +39 -0
- data/spec/mailbox_spec.rb +47 -0
- data/spec/message_spec.rb +51 -0
- data/spec/spec_helper.rb +29 -0
- metadata +174 -0
data/spec/gmail_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Any object" do
|
4
|
+
it "should be able to convert itself to IMAP date format" do
|
5
|
+
"20-12-1988".to_imap_date.should == "20-December-1988"
|
6
|
+
end
|
7
|
+
|
8
|
+
%w[new new!].each do |method|
|
9
|
+
it "##{method} should properly connect with GMail service and return valid connection object" do
|
10
|
+
gmail = Gmail.send(method, *TEST_ACCOUNT)
|
11
|
+
gmail.should be_kind_of(Gmail::Client::Plain)
|
12
|
+
gmail.connection.should_not be_nil
|
13
|
+
gmail.should be_logged_in
|
14
|
+
end
|
15
|
+
|
16
|
+
it "##{method} should connect with client and give it context when block given" do
|
17
|
+
Gmail.send(method, *TEST_ACCOUNT) do |gmail|
|
18
|
+
gmail.should be_kind_of(Gmail::Client::Plain)
|
19
|
+
gmail.connection.should_not be_nil
|
20
|
+
gmail.should be_logged_in
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#new should not raise error when couldn't connect with given account" do
|
26
|
+
lambda {
|
27
|
+
gmail = Gmail.new("foo", "bar")
|
28
|
+
gmail.should_not be_logged_in
|
29
|
+
}.should_not raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it "#new! should raise error when couldn't connect with given account" do
|
33
|
+
lambda {
|
34
|
+
gmail = Gmail.new!("foo", "bar")
|
35
|
+
gmail.should_not be_logged_in
|
36
|
+
}.should raise_error
|
37
|
+
### FIX: can someone dig to the bottom of this? We are getting NoMethodError instead of Gmail::Client::AuthorizationError in 1.9
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "A Gmail mailbox" do
|
4
|
+
subject { Gmail::Mailbox }
|
5
|
+
|
6
|
+
context "on initialize" do
|
7
|
+
it "should set client and name" do
|
8
|
+
within_gmail do |gmail|
|
9
|
+
mailbox = subject.new(gmail, "TEST")
|
10
|
+
mailbox.instance_variable_get("@gmail").should == gmail
|
11
|
+
mailbox.name.should == "TEST"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should work in INBOX by default" do
|
16
|
+
within_gmail do |gmail|
|
17
|
+
mailbox = subject.new(@gmail)
|
18
|
+
mailbox.name.should == "INBOX"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "instance" do
|
24
|
+
it "should be able to count all emails" do
|
25
|
+
mock_mailbox do |mailbox|
|
26
|
+
mailbox.count.should > 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to find messages" do
|
31
|
+
mock_mailbox do |mailbox|
|
32
|
+
message = mailbox.emails.first
|
33
|
+
mailbox.emails(:all, :from => message.from.first.name) == message.from.first.name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be able to do a full text search of message bodies" do
|
38
|
+
pending "This can wait..."
|
39
|
+
#mock_mailbox do |mailbox|
|
40
|
+
# message = mailbox.emails.first
|
41
|
+
# body = message.parts.blank? ? message.body.decoded : message.parts[0].body.decoded
|
42
|
+
# emails = mailbox.emails(:search => body.split(' ').first)
|
43
|
+
# emails.size.should > 0
|
44
|
+
#end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "A Gmail message" do
|
4
|
+
context "on initialize" do
|
5
|
+
it "should set uid and mailbox" do
|
6
|
+
pending
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "instance" do
|
11
|
+
it "should be able to mark itself as read" do
|
12
|
+
pending
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to mark itself as unread" do
|
16
|
+
pending
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to set star itself" do
|
20
|
+
pending
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be able to unset start" do
|
24
|
+
pending
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to archive itself" do
|
28
|
+
pending
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to delete itself" do
|
32
|
+
pending
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to move itself to spam" do
|
36
|
+
pending
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be able to set given label" do
|
40
|
+
pending
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be able to mark itself with given flag" do
|
44
|
+
pending
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to move itself to given box" do
|
48
|
+
pending
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rspec'
|
6
|
+
require 'mocha'
|
7
|
+
require 'yaml'
|
8
|
+
require 'gmail'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :mocha
|
12
|
+
end
|
13
|
+
|
14
|
+
def within_gmail(&block)
|
15
|
+
gmail = Gmail.connect!(*TEST_ACCOUNT)
|
16
|
+
yield(gmail)
|
17
|
+
gmail.logout if gmail
|
18
|
+
end
|
19
|
+
|
20
|
+
def mock_mailbox(box="INBOX", &block)
|
21
|
+
within_gmail do |gmail|
|
22
|
+
mailbox = subject.new(gmail, box)
|
23
|
+
yield(mailbox) if block_given?
|
24
|
+
mailbox
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Run test by creating your own test account with credentials in account.yml
|
29
|
+
TEST_ACCOUNT = YAML.load_file(File.join(File.dirname(__FILE__), 'account.yml'))
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmail_gm_raw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Kowalik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mime
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gmail_xoauth
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem-release
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: "A Rubyesque interface to Gmail, with all the tools you will need.\n
|
112
|
+
\ Search, read and send multipart emails; archive, mark as read/unread,\n delete
|
113
|
+
emails; and manage labels.\n "
|
114
|
+
email:
|
115
|
+
- chris@nu7hat.ch
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- TODO.md
|
128
|
+
- gmail.gemspec
|
129
|
+
- lib/gmail.rb
|
130
|
+
- lib/gmail/client.rb
|
131
|
+
- lib/gmail/client/base.rb
|
132
|
+
- lib/gmail/client/imap_extensions.rb
|
133
|
+
- lib/gmail/client/plain.rb
|
134
|
+
- lib/gmail/client/xoauth.rb
|
135
|
+
- lib/gmail/labels.rb
|
136
|
+
- lib/gmail/mailbox.rb
|
137
|
+
- lib/gmail/message.rb
|
138
|
+
- lib/gmail/version.rb
|
139
|
+
- spec/account.yml.example
|
140
|
+
- spec/client_spec.rb
|
141
|
+
- spec/gmail_spec.rb
|
142
|
+
- spec/mailbox_spec.rb
|
143
|
+
- spec/message_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: http://github.com/nu7hatch/gmail
|
146
|
+
licenses: []
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.2.2
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: A Rubyesque interface to Gmail, with all the tools you will need.
|
168
|
+
test_files:
|
169
|
+
- spec/account.yml.example
|
170
|
+
- spec/client_spec.rb
|
171
|
+
- spec/gmail_spec.rb
|
172
|
+
- spec/mailbox_spec.rb
|
173
|
+
- spec/message_spec.rb
|
174
|
+
- spec/spec_helper.rb
|