gmail 0.3.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 +22 -0
- data/CHANGELOG.md +60 -0
- data/LICENSE +21 -0
- data/README.md +247 -0
- data/Rakefile +52 -0
- data/TODO.md +5 -0
- data/VERSION +1 -0
- data/lib/gmail.rb +47 -0
- data/lib/gmail/client.rb +221 -0
- data/lib/gmail/labels.rb +42 -0
- data/lib/gmail/mailbox.rb +92 -0
- data/lib/gmail/message.rb +137 -0
- data/lib/gmail/version.rb +12 -0
- data/spec/client_spec.rb +173 -0
- data/spec/gmail_spec.rb +38 -0
- data/spec/mailbox_spec.rb +48 -0
- data/spec/message_spec.rb +51 -0
- data/spec/spec_helper.rb +13 -0
- metadata +150 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
module Gmail
|
2
|
+
class Version #:nodoc:
|
3
|
+
STRING = File.open(File.join(File.dirname(__FILE__), "../../VERSION")).read.strip
|
4
|
+
MAJOR = STRING.split(".")[0]
|
5
|
+
MINOR = STRING.split(".")[1]
|
6
|
+
TINY = STRING.split(".")[2]
|
7
|
+
end # Version
|
8
|
+
|
9
|
+
def self.version # :nodoc:
|
10
|
+
Version::STRING
|
11
|
+
end
|
12
|
+
end # Gmail
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Gmail client" do
|
4
|
+
subject { Gmail::Client }
|
5
|
+
|
6
|
+
context "on initialize" do
|
7
|
+
it "should set username, password and options" do
|
8
|
+
client = subject.new("test@gmail.com", "pass", :foo => :bar)
|
9
|
+
client.username.should == "test@gmail.com"
|
10
|
+
client.password.should == "pass"
|
11
|
+
client.options[:foo].should == :bar
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should convert simple name to gmail email" do
|
15
|
+
client = subject.new("test", "pass")
|
16
|
+
client.username.should == "test@gmail.com"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "instance" do
|
21
|
+
def mock_client(&block)
|
22
|
+
client = Gmail::Client.new(*TEST_ACCOUNT)
|
23
|
+
if block_given?
|
24
|
+
client.connect
|
25
|
+
yield client
|
26
|
+
client.logout
|
27
|
+
end
|
28
|
+
client
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should connect to GMail IMAP service" do
|
32
|
+
lambda {
|
33
|
+
client = mock_client
|
34
|
+
client.connect!.should be_true
|
35
|
+
}.should_not raise_error(Gmail::Client::ConnectionError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should properly login to valid GMail account" do
|
39
|
+
client = mock_client
|
40
|
+
client.connect.should be_true
|
41
|
+
client.login.should be_true
|
42
|
+
client.should be_logged_in
|
43
|
+
client.logout
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should raise error when given GMail account is invalid and errors enabled" do
|
47
|
+
lambda {
|
48
|
+
client = Gmail::Client.new("foo", "bar")
|
49
|
+
client.connect.should be_true
|
50
|
+
client.login!.should_not be_true
|
51
|
+
}.should raise_error(Gmail::Client::AuthorizationError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "shouldn't login when given GMail account is invalid" do
|
55
|
+
lambda {
|
56
|
+
client = Gmail::Client.new("foo", "bar")
|
57
|
+
client.connect.should be_true
|
58
|
+
client.login.should_not be_true
|
59
|
+
}.should_not raise_error(Gmail::Client::AuthorizationError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should properly logout from GMail" do
|
63
|
+
client = mock_client
|
64
|
+
client.connect
|
65
|
+
client.login.should be_true
|
66
|
+
client.logout.should be_true
|
67
|
+
client.should_not be_logged_in
|
68
|
+
end
|
69
|
+
|
70
|
+
it "#connection should automatically log in to GMail account when it's called" do
|
71
|
+
mock_client do |client|
|
72
|
+
client.expects(:login).once.returns(false)
|
73
|
+
client.connection.should_not be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should properly compose message" do
|
78
|
+
mail = mock_client.compose do
|
79
|
+
from "test@gmail.com"
|
80
|
+
to "friend@gmail.com"
|
81
|
+
subject "Hello world!"
|
82
|
+
end
|
83
|
+
mail.from.should == ["test@gmail.com"]
|
84
|
+
mail.to.should == ["friend@gmail.com"]
|
85
|
+
mail.subject.should == "Hello world!"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "#compose should automatically add `from` header when it is not specified" do
|
89
|
+
mail = mock_client.compose
|
90
|
+
mail.from.should == [TEST_ACCOUNT[0]]
|
91
|
+
mail = mock_client.compose(Mail.new)
|
92
|
+
mail.from.should == [TEST_ACCOUNT[0]]
|
93
|
+
mail = mock_client.compose {}
|
94
|
+
mail.from.should == [TEST_ACCOUNT[0]]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should deliver inline composed email" do
|
98
|
+
mock_client do |client|
|
99
|
+
client.deliver do
|
100
|
+
to TEST_ACCOUNT[0]
|
101
|
+
subject "Hello world!"
|
102
|
+
body "Yeah, hello there!"
|
103
|
+
end.should be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not raise error when mail can't be delivered and errors are disabled" do
|
108
|
+
lambda {
|
109
|
+
client = mock_client
|
110
|
+
client.deliver(Mail.new {}).should be_false
|
111
|
+
}.should_not raise_error(Gmail::Client::DeliveryError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should raise error when mail can't be delivered and errors are disabled" do
|
115
|
+
lambda {
|
116
|
+
client = mock_client
|
117
|
+
client.deliver!(Mail.new {})
|
118
|
+
}.should raise_error(Gmail::Client::DeliveryError)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should properly switch to given mailbox" do
|
122
|
+
mock_client do |client|
|
123
|
+
mailbox = client.mailbox("TEST")
|
124
|
+
mailbox.should be_kind_of(Gmail::Mailbox)
|
125
|
+
mailbox.name.should == "TEST"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should properly switch to given mailbox using block style" do
|
130
|
+
mock_client do |client|
|
131
|
+
client.mailbox("TEST") do |mailbox|
|
132
|
+
mailbox.should be_kind_of(Gmail::Mailbox)
|
133
|
+
mailbox.name.should == "TEST"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "labels" do
|
139
|
+
subject {
|
140
|
+
client = Gmail::Client.new(*TEST_ACCOUNT)
|
141
|
+
client.connect
|
142
|
+
client.labels
|
143
|
+
}
|
144
|
+
|
145
|
+
it "should get list of all available labels" do
|
146
|
+
labels = subject
|
147
|
+
labels.all.should include("TEST", "INBOX")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should be able to check if there is given label defined" do
|
151
|
+
labels = subject
|
152
|
+
labels.exists?("TEST").should be_true
|
153
|
+
labels.exists?("FOOBAR").should be_false
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should be able to create given label" do
|
157
|
+
labels = subject
|
158
|
+
labels.create("MYLABEL")
|
159
|
+
labels.exists?("MYLABEL").should be_true
|
160
|
+
labels.create("MYLABEL").should be_false
|
161
|
+
labels.delete("MYLABEL")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should be able to remove existing label" do
|
165
|
+
labels = subject
|
166
|
+
labels.create("MYLABEL")
|
167
|
+
labels.delete("MYLABEL").should be_true
|
168
|
+
labels.exists?("MYLABEL").should be_false
|
169
|
+
labels.delete("MYLABEL").should be_false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/spec/gmail_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
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)
|
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)
|
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(Gmail::Client::AuthorizationError)
|
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(Gmail::Client::AuthorizationError)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "A Gmail mailbox" do
|
4
|
+
subject { Gmail::Mailbox }
|
5
|
+
|
6
|
+
def within_gmail(&block)
|
7
|
+
gmail = Gmail.connect!(*TEST_ACCOUNT)
|
8
|
+
yield(gmail)
|
9
|
+
gmail.logout if gmail
|
10
|
+
end
|
11
|
+
|
12
|
+
context "on initialize" do
|
13
|
+
it "should set client and name" do
|
14
|
+
within_gmail do |gmail|
|
15
|
+
mailbox = subject.new(gmail, "TEST")
|
16
|
+
mailbox.instance_variable_get("@gmail").should == gmail
|
17
|
+
mailbox.name.should == "TEST"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should work in INBOX by default" do
|
22
|
+
within_gmail do |gmail|
|
23
|
+
mailbox = subject.new(@gmail)
|
24
|
+
mailbox.name.should == "INBOX"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "instance" do
|
30
|
+
def mock_mailbox(box="INBOX", &block)
|
31
|
+
within_gmail do |gmail|
|
32
|
+
mailbox = subject.new(gmail, box)
|
33
|
+
yield(mailbox) if block_given?
|
34
|
+
mailbox
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to count all emails" do
|
39
|
+
mock_mailbox do |mailbox|
|
40
|
+
mailbox.count.should > 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to find messages" do
|
45
|
+
pending
|
46
|
+
end
|
47
|
+
end
|
48
|
+
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,13 @@
|
|
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 'gmail'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
12
|
+
|
13
|
+
TEST_ACCOUNT = ["test@gmail.com", "test"]
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- BehindLogic
|
14
|
+
- Kriss 'nu7hatch' Kowalik
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-10-20 00:00:00 +02:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: mime
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 9
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 1
|
34
|
+
version: "0.1"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mail
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 2
|
49
|
+
- 1
|
50
|
+
version: 2.2.1
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
version: "2.0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: mocha
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 25
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 9
|
80
|
+
version: "0.9"
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
description: " A Rubyesque interface to Gmail, with all the tools you'll need. Search, \n read and send multipart emails; archive, mark as read/unread, delete emails; \n and manage labels.\n"
|
84
|
+
email: kriss.kowalik@gmail.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
files:
|
93
|
+
- .gitignore
|
94
|
+
- CHANGELOG.md
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- TODO.md
|
99
|
+
- VERSION
|
100
|
+
- lib/gmail.rb
|
101
|
+
- lib/gmail/client.rb
|
102
|
+
- lib/gmail/labels.rb
|
103
|
+
- lib/gmail/mailbox.rb
|
104
|
+
- lib/gmail/message.rb
|
105
|
+
- lib/gmail/version.rb
|
106
|
+
- spec/client_spec.rb
|
107
|
+
- spec/gmail_spec.rb
|
108
|
+
- spec/mailbox_spec.rb
|
109
|
+
- spec/message_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
has_rdoc: true
|
112
|
+
homepage: http://github.com/nu7hatch/gmail
|
113
|
+
licenses: []
|
114
|
+
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options:
|
117
|
+
- --charset=UTF-8
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
requirements: []
|
139
|
+
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.3.7
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: A Rubyesque interface to Gmail, with all the tools you'll need.
|
145
|
+
test_files:
|
146
|
+
- spec/message_spec.rb
|
147
|
+
- spec/mailbox_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/client_spec.rb
|
150
|
+
- spec/gmail_spec.rb
|