gmail 0.4.0 → 0.4.2
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.
- checksums.yaml +7 -0
- data/.gitignore +26 -25
- data/.rspec +2 -0
- data/CHANGELOG.md +82 -82
- data/Gemfile +3 -0
- data/LICENSE +21 -21
- data/README.md +271 -251
- data/Rakefile +35 -45
- data/TODO.md +12 -7
- data/gmail.gemspec +34 -23
- data/lib/gmail.rb +65 -82
- data/lib/gmail/client.rb +30 -22
- data/lib/gmail/client/base.rb +225 -220
- data/lib/gmail/client/imap_extensions.rb +54 -0
- data/lib/gmail/client/plain.rb +20 -18
- data/lib/gmail/client/xoauth.rb +51 -49
- data/lib/gmail/labels.rb +62 -48
- data/lib/gmail/mailbox.rb +117 -117
- data/lib/gmail/message.rb +166 -164
- data/lib/gmail/version.rb +3 -12
- data/spec/account.yml.example +1 -1
- data/spec/client_spec.rb +178 -173
- data/spec/gmail_spec.rb +39 -38
- data/spec/mailbox_spec.rb +47 -49
- data/spec/message_spec.rb +51 -51
- data/spec/spec_helper.rb +28 -28
- metadata +109 -110
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3e753fcd22946f3ad280435f97d76e1eb4ec7e0
|
4
|
+
data.tar.gz: 4bfe8802c7750714025da3b52a1e15bfdc46ea02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 084f0398746da01275b728cee3a700c02c6f43a8fd67e6e3826da737c51547cf1a547cae8073adf48f0c582df66a80b98025c3b686d4100ef478d76d8b31df1c
|
7
|
+
data.tar.gz: 5a7c3721ed3e94d74ea092d756d2826b63496c8f4ec5f8abdcda1ed6b7ea6c441ba602a9b089e40e2ca11facbfc487733c292d97961d6f30cce9120b1c5f9e99
|
data/.gitignore
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## PROJECT::GENERAL
|
17
|
-
coverage
|
18
|
-
rdoc
|
19
|
-
pkg
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
Gemfile.lock
|
21
|
+
|
22
|
+
## PROJECT::SPECIFIC
|
23
|
+
*.rdb
|
24
|
+
|
25
|
+
## Test Account details
|
26
|
+
spec/account.yml
|
data/.rspec
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
# Gmail gem changelog
|
2
|
-
|
3
|
-
## 0.4.0
|
4
|
-
|
5
|
-
* Added XOAUTH authentication method (Thanks Stefano Bernardi and Nicolas Fouché)
|
6
|
-
* Separated clients
|
7
|
-
* Fixed specs
|
8
|
-
|
9
|
-
## 0.3.4
|
10
|
-
|
11
|
-
* Fixes in mailbox filters shortcuts (Thanks Benjamin Bock)
|
12
|
-
|
13
|
-
## 0.3.3
|
14
|
-
|
15
|
-
* Added #expunge to Mailbox (Thanks Benjamin Bock)
|
16
|
-
* Added more mailbox filters (Thanks Benjamin Bock)
|
17
|
-
* Added shortcuts for mailbox filters
|
18
|
-
* Minor bugfixes
|
19
|
-
|
20
|
-
## 0.3.2
|
21
|
-
|
22
|
-
* Added envelope fetching
|
23
|
-
* Minor bugfixes
|
24
|
-
|
25
|
-
## 0.3.0
|
26
|
-
|
27
|
-
* Refactoring
|
28
|
-
* Fixed bugs
|
29
|
-
* API improvements
|
30
|
-
* Better documentation
|
31
|
-
* Code cleanup
|
32
|
-
* RSpec for everything
|
33
|
-
|
34
|
-
## 0.1.1 / 2010-05-11
|
35
|
-
|
36
|
-
* Added explicit tmail dependency in gemspec
|
37
|
-
* Added better README tutorial content
|
38
|
-
|
39
|
-
## 0.0.9 / 2010-04-17
|
40
|
-
|
41
|
-
* Fixed content-transfer-encoding when sending email
|
42
|
-
|
43
|
-
## 0.0.8 / 2009-12-23
|
44
|
-
|
45
|
-
* Fixed attaching a file to an empty message
|
46
|
-
|
47
|
-
## 0.0.7 / 2009-12-23
|
48
|
-
|
49
|
-
* Improved multipart message parsing reliability
|
50
|
-
|
51
|
-
## 0.0.6 / 2009-12-21
|
52
|
-
|
53
|
-
* Fixed multipart parsing for when the boundary is marked in quotes.
|
54
|
-
|
55
|
-
## 0.0.5 / 2009-12-16
|
56
|
-
|
57
|
-
* Fixed IMAP initializer to work with Ruby 1.9's net/imap
|
58
|
-
* Better logout depending on the IMAP connection itself
|
59
|
-
* Added MIME::Message#text and MIME::Message#html for easier access to an email body
|
60
|
-
* Improved the MIME-parsing API slightly
|
61
|
-
* Added some tests
|
62
|
-
|
63
|
-
## 0.0.4 / 2009-11-30
|
64
|
-
|
65
|
-
* Added label creation (thanks to Justin Perkins / http://github.com/justinperkins)
|
66
|
-
* Made the gem login automatically when first needed
|
67
|
-
* Added an optional block on the Gmail.new object that will login and logout for you
|
68
|
-
* Added several search options (thanks to Mikkel Malmberg / http://github.com/mikker)
|
69
|
-
|
70
|
-
## 0.0.3 / 2009-11-19
|
71
|
-
|
72
|
-
* Fixed MIME::Message#content= for messages without an encoding
|
73
|
-
* Added Gmail#new_message
|
74
|
-
|
75
|
-
## 0.0.2 / 2009-11-18
|
76
|
-
|
77
|
-
* Made all of the examples in the README possible
|
78
|
-
|
79
|
-
## 0.0.1 / 2009-11-18
|
80
|
-
|
81
|
-
* Birthday!
|
82
|
-
|
1
|
+
# Gmail gem changelog
|
2
|
+
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
* Added XOAUTH authentication method (Thanks Stefano Bernardi and Nicolas Fouché)
|
6
|
+
* Separated clients
|
7
|
+
* Fixed specs
|
8
|
+
|
9
|
+
## 0.3.4
|
10
|
+
|
11
|
+
* Fixes in mailbox filters shortcuts (Thanks Benjamin Bock)
|
12
|
+
|
13
|
+
## 0.3.3
|
14
|
+
|
15
|
+
* Added #expunge to Mailbox (Thanks Benjamin Bock)
|
16
|
+
* Added more mailbox filters (Thanks Benjamin Bock)
|
17
|
+
* Added shortcuts for mailbox filters
|
18
|
+
* Minor bugfixes
|
19
|
+
|
20
|
+
## 0.3.2
|
21
|
+
|
22
|
+
* Added envelope fetching
|
23
|
+
* Minor bugfixes
|
24
|
+
|
25
|
+
## 0.3.0
|
26
|
+
|
27
|
+
* Refactoring
|
28
|
+
* Fixed bugs
|
29
|
+
* API improvements
|
30
|
+
* Better documentation
|
31
|
+
* Code cleanup
|
32
|
+
* RSpec for everything
|
33
|
+
|
34
|
+
## 0.1.1 / 2010-05-11
|
35
|
+
|
36
|
+
* Added explicit tmail dependency in gemspec
|
37
|
+
* Added better README tutorial content
|
38
|
+
|
39
|
+
## 0.0.9 / 2010-04-17
|
40
|
+
|
41
|
+
* Fixed content-transfer-encoding when sending email
|
42
|
+
|
43
|
+
## 0.0.8 / 2009-12-23
|
44
|
+
|
45
|
+
* Fixed attaching a file to an empty message
|
46
|
+
|
47
|
+
## 0.0.7 / 2009-12-23
|
48
|
+
|
49
|
+
* Improved multipart message parsing reliability
|
50
|
+
|
51
|
+
## 0.0.6 / 2009-12-21
|
52
|
+
|
53
|
+
* Fixed multipart parsing for when the boundary is marked in quotes.
|
54
|
+
|
55
|
+
## 0.0.5 / 2009-12-16
|
56
|
+
|
57
|
+
* Fixed IMAP initializer to work with Ruby 1.9's net/imap
|
58
|
+
* Better logout depending on the IMAP connection itself
|
59
|
+
* Added MIME::Message#text and MIME::Message#html for easier access to an email body
|
60
|
+
* Improved the MIME-parsing API slightly
|
61
|
+
* Added some tests
|
62
|
+
|
63
|
+
## 0.0.4 / 2009-11-30
|
64
|
+
|
65
|
+
* Added label creation (thanks to Justin Perkins / http://github.com/justinperkins)
|
66
|
+
* Made the gem login automatically when first needed
|
67
|
+
* Added an optional block on the Gmail.new object that will login and logout for you
|
68
|
+
* Added several search options (thanks to Mikkel Malmberg / http://github.com/mikker)
|
69
|
+
|
70
|
+
## 0.0.3 / 2009-11-19
|
71
|
+
|
72
|
+
* Fixed MIME::Message#content= for messages without an encoding
|
73
|
+
* Added Gmail#new_message
|
74
|
+
|
75
|
+
## 0.0.2 / 2009-11-18
|
76
|
+
|
77
|
+
* Made all of the examples in the README possible
|
78
|
+
|
79
|
+
## 0.0.1 / 2009-11-18
|
80
|
+
|
81
|
+
* Birthday!
|
82
|
+
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
Copyrignt (c) 2010 Kriss 'nu7hatch' Kowalik
|
2
|
-
Copyright (c) 2009-2010 BehindLogic
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
a copy of this software and associated documentation files (the
|
6
|
-
"Software"), to deal in the Software without restriction, including
|
7
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be
|
13
|
-
included in all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyrignt (c) 2010 Kriss 'nu7hatch' Kowalik
|
2
|
+
Copyright (c) 2009-2010 BehindLogic
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,251 +1,271 @@
|
|
1
|
-
# GMail for Ruby
|
2
|
-
|
3
|
-
A Rubyesque interface to Google's GMail, with all the tools you'll need. Search,
|
4
|
-
read and send multipart emails, archive, mark as read/unread, delete emails,
|
5
|
-
and manage labels.
|
6
|
-
|
7
|
-
It's based on Daniel Parker's ruby-gmail gem. This version has more friendy
|
8
|
-
API, is well tested, better documented and have many other improvements.
|
9
|
-
|
10
|
-
## Author(s)
|
11
|
-
|
12
|
-
* Kriss 'nu7hatch' Kowalik
|
13
|
-
* [Daniel Parker of BehindLogic.com](http://github.com/dcparker)
|
14
|
-
|
15
|
-
Extra thanks for specific feature contributions from:
|
16
|
-
|
17
|
-
* [
|
18
|
-
* [
|
19
|
-
* [
|
20
|
-
* [
|
21
|
-
* [
|
22
|
-
* [
|
23
|
-
* [
|
24
|
-
* [
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
*
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
*
|
52
|
-
|
53
|
-
*
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
Gmail.connect(username, password)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
gmail.inbox.
|
121
|
-
gmail.inbox.
|
122
|
-
gmail.inbox.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
gmail.inbox.
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
gmail.inbox.
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
email.
|
180
|
-
email.
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
gmail.
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
1
|
+
# GMail for Ruby
|
2
|
+
|
3
|
+
A Rubyesque interface to Google's GMail, with all the tools you'll need. Search,
|
4
|
+
read and send multipart emails, archive, mark as read/unread, delete emails,
|
5
|
+
and manage labels.
|
6
|
+
|
7
|
+
It's based on Daniel Parker's ruby-gmail gem. This version has more friendy
|
8
|
+
API, is well tested, better documented and have many other improvements.
|
9
|
+
|
10
|
+
## Author(s)
|
11
|
+
|
12
|
+
* Kriss 'nu7hatch' Kowalik
|
13
|
+
* [Daniel Parker of BehindLogic.com](http://github.com/dcparker)
|
14
|
+
|
15
|
+
Extra thanks for specific feature contributions from:
|
16
|
+
|
17
|
+
* [abhishiv](http://github.com/abhishiv)
|
18
|
+
* [Michael Young](http://github.com/myoung8)
|
19
|
+
* [Nicolas Fouché](http://github.com/nfo)
|
20
|
+
* [Stefano Bernardi](http://github.com/stefanobernardi)
|
21
|
+
* [Benjamin Bock](http://github.com/bb)
|
22
|
+
* [Arthur Chiu](http://github.com/achiu)
|
23
|
+
* [Justin Perkins](http://github.com/justinperkins)
|
24
|
+
* [Mikkel Malmberg](http://github.com/mikker)
|
25
|
+
* [Julien Blanchard](http://github.com/julienXX)
|
26
|
+
* [Federico Galassi](http://github.com/fgalassi)
|
27
|
+
* [Alex Genco](http://github.com/alexgenco)
|
28
|
+
* [Justin Grevich](http://github.com/jgrevich)
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
You can install it easy using rubygems:
|
33
|
+
|
34
|
+
sudo gem install gmail
|
35
|
+
|
36
|
+
Or install it manually:
|
37
|
+
|
38
|
+
git clone git://github.com/nu7hatch/gmail.git
|
39
|
+
cd gmail
|
40
|
+
rake install
|
41
|
+
|
42
|
+
gmail gem has the following dependencies (with Bundler all will be installed automatically):
|
43
|
+
|
44
|
+
* mail (Ruby 1.8.7 users should lock mail gem version at 2.5.3)
|
45
|
+
* mime
|
46
|
+
* gmail_xoauth
|
47
|
+
* smpt_tls (Ruby < 1.8.7)
|
48
|
+
|
49
|
+
## Features
|
50
|
+
|
51
|
+
* Search emails
|
52
|
+
* Read emails (handles attachments)
|
53
|
+
* Emails: label, archive, delete, mark as read/unread/spam, star
|
54
|
+
* Manage labels
|
55
|
+
* Create and send multipart email messages in plaintext and/or html, with inline
|
56
|
+
images and attachments
|
57
|
+
* Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates
|
58
|
+
MIME properly.
|
59
|
+
|
60
|
+
## Basic usage
|
61
|
+
|
62
|
+
First of all require the `gmail` library.
|
63
|
+
|
64
|
+
require 'gmail'
|
65
|
+
|
66
|
+
### Authenticating gmail sessions
|
67
|
+
|
68
|
+
This will you automatically log in to your account.
|
69
|
+
|
70
|
+
gmail = Gmail.connect(username, password)
|
71
|
+
# play with your gmail...
|
72
|
+
gmail.logout
|
73
|
+
|
74
|
+
If you pass a block, the session will be passed into the block, and the session
|
75
|
+
will be logged out after the block is executed.
|
76
|
+
|
77
|
+
Gmail.connect(username, password) do |gmail|
|
78
|
+
# play with your gmail...
|
79
|
+
end
|
80
|
+
|
81
|
+
Examples above are "quiet", it means that it will not raise any errors when
|
82
|
+
session couldn't be started (eg. because of connection error or invalid
|
83
|
+
authorization data). You can use connection which handles errors raising:
|
84
|
+
|
85
|
+
Gmail.connect!(username, password)
|
86
|
+
Gmail.connect!(username, password) {|gmail| ... play with gmail ... }
|
87
|
+
|
88
|
+
You can also check if you are logged in at any time:
|
89
|
+
|
90
|
+
Gmail.connect(username, password) do |gmail|
|
91
|
+
gmail.logged_in?
|
92
|
+
end
|
93
|
+
|
94
|
+
### XOAuth authentication
|
95
|
+
|
96
|
+
From v0.4.0 it's possible to authenticate with your Gmail account using XOAuth
|
97
|
+
method. It's very simple:
|
98
|
+
|
99
|
+
gmail = Gmail.connect(:xoauth, "email@domain.com",
|
100
|
+
:token => 'TOKEN',
|
101
|
+
:secret => 'TOKEN_SECRET',
|
102
|
+
:consumer_key => 'CONSUMER_KEY',
|
103
|
+
:consumer_secret => 'CONSUMER_SECRET'
|
104
|
+
)
|
105
|
+
|
106
|
+
For more information check out the [gmail_xoauth](https://github.com/nfo/gmail_xoauth)
|
107
|
+
gem from Nicolas Fouché.
|
108
|
+
|
109
|
+
### Counting and gathering emails
|
110
|
+
|
111
|
+
Get counts for messages in the inbox:
|
112
|
+
|
113
|
+
gmail.inbox.count
|
114
|
+
gmail.inbox.count(:unread)
|
115
|
+
gmail.inbox.count(:read)
|
116
|
+
|
117
|
+
Count with some criteria:
|
118
|
+
|
119
|
+
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
|
120
|
+
gmail.inbox.count(:on => Date.parse("2010-04-15"))
|
121
|
+
gmail.inbox.count(:from => "myfriend@gmail.com")
|
122
|
+
gmail.inbox.count(:to => "directlytome@gmail.com")
|
123
|
+
|
124
|
+
Combine flags and options:
|
125
|
+
|
126
|
+
gmail.inbox.count(:unread, :from => "myboss@gmail.com")
|
127
|
+
|
128
|
+
Browsing labeled emails is similar to work with inbox.
|
129
|
+
|
130
|
+
gmail.mailbox('Urgent').count
|
131
|
+
|
132
|
+
Getting messages works the same way as counting: Remember that every message in a
|
133
|
+
conversation/thread will come as a separate message.
|
134
|
+
|
135
|
+
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
|
136
|
+
|
137
|
+
You can use also one of aliases:
|
138
|
+
|
139
|
+
gmail.inbox.find(...)
|
140
|
+
gmail.inbox.search(...)
|
141
|
+
gmail.inbox.mails(...)
|
142
|
+
|
143
|
+
Also you can manipulate each message using block style:
|
144
|
+
|
145
|
+
gmail.inbox.find(:unread).each do |email|
|
146
|
+
email.read!
|
147
|
+
end
|
148
|
+
|
149
|
+
### Working with emails!
|
150
|
+
|
151
|
+
Any news older than 4-20, mark as read and archive it:
|
152
|
+
|
153
|
+
gmail.inbox.find(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
|
154
|
+
email.read! # can also unread!, spam! or star!
|
155
|
+
email.archive!
|
156
|
+
end
|
157
|
+
|
158
|
+
Delete emails from X:
|
159
|
+
|
160
|
+
gmail.inbox.find(:from => "x-fiance@gmail.com").each do |email|
|
161
|
+
email.delete!
|
162
|
+
end
|
163
|
+
|
164
|
+
Save all attachments in the "Faxes" label to a local folder:
|
165
|
+
|
166
|
+
folder = "/where/ever"
|
167
|
+
gmail.mailbox("Faxes").emails.each do |email|
|
168
|
+
if !email.message.attachments.empty?
|
169
|
+
email.message.save_attachments_to(folder)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
You can use also `#label` method instead of `#mailbox`:
|
174
|
+
|
175
|
+
gmail.label("Faxes").emails {|email| ... }
|
176
|
+
|
177
|
+
Save just the first attachment from the newest unread email (assuming pdf):
|
178
|
+
|
179
|
+
email = gmail.inbox.find(:unread).first
|
180
|
+
email.attachments[0].save_to_file("/path/to/location")
|
181
|
+
|
182
|
+
Add a label to a message:
|
183
|
+
|
184
|
+
email.label("Faxes")
|
185
|
+
|
186
|
+
Example above will raise error when you don't have the `Faxes` label. You can
|
187
|
+
avoid this using:
|
188
|
+
|
189
|
+
email.label!("Faxes") # The `Faxes` label will be automatically created now
|
190
|
+
|
191
|
+
You can also move message to a label/mailbox:
|
192
|
+
|
193
|
+
email.move_to("Faxes")
|
194
|
+
email.move_to!("NewLabel")
|
195
|
+
|
196
|
+
There is also few shortcuts to mark messages quickly:
|
197
|
+
|
198
|
+
email.read!
|
199
|
+
email.unread!
|
200
|
+
email.spam!
|
201
|
+
email.star!
|
202
|
+
email.unstar!
|
203
|
+
|
204
|
+
### Managing labels
|
205
|
+
|
206
|
+
With Gmail gem you can also manage your labels. You can get list of defined
|
207
|
+
labels:
|
208
|
+
|
209
|
+
gmail.labels.all
|
210
|
+
|
211
|
+
Create new label:
|
212
|
+
|
213
|
+
gmail.labels.new("Urgent")
|
214
|
+
gmail.labels.add("AnotherOne")
|
215
|
+
|
216
|
+
Remove labels:
|
217
|
+
|
218
|
+
gmail.labels.delete("Urgent")
|
219
|
+
|
220
|
+
Or check if given label exists:
|
221
|
+
|
222
|
+
gmail.labels.exists?("Urgent") # => false
|
223
|
+
gmail.labels.exists?("AnotherOne") # => true
|
224
|
+
|
225
|
+
### Composing and sending emails
|
226
|
+
|
227
|
+
Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem.
|
228
|
+
See its [documentation here](http://github.com/mikel/mail). The Ruby Gmail will
|
229
|
+
automatically configure your Mail emails to be sent via your Gmail account's SMTP,
|
230
|
+
so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From"
|
231
|
+
email either, because ruby-gmail will set it for you.
|
232
|
+
|
233
|
+
gmail.deliver do
|
234
|
+
to "email@example.com"
|
235
|
+
subject "Having fun in Puerto Rico!"
|
236
|
+
text_part do
|
237
|
+
body "Text of plaintext message."
|
238
|
+
end
|
239
|
+
html_part do
|
240
|
+
content_type 'text/html; charset=UTF-8'
|
241
|
+
body "<p>Text of <em>html</em> message.</p>"
|
242
|
+
end
|
243
|
+
add_file "/path/to/some_image.jpg"
|
244
|
+
end
|
245
|
+
|
246
|
+
Or, compose the message first and send it later
|
247
|
+
|
248
|
+
email = gmail.compose do
|
249
|
+
to "email@example.com"
|
250
|
+
subject "Having fun in Puerto Rico!"
|
251
|
+
body "Spent the day on the road..."
|
252
|
+
end
|
253
|
+
email.deliver! # or: gmail.deliver(email)
|
254
|
+
|
255
|
+
## Note on Patches/Pull Requests
|
256
|
+
|
257
|
+
* Fork the project.
|
258
|
+
* Make your feature addition or bug fix.
|
259
|
+
* Add tests for it. This is important so I don't break it in a
|
260
|
+
future version unintentionally.
|
261
|
+
* Commit, do not mess with rakefile, version, or history.
|
262
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
263
|
+
* Send me a pull request. Bonus points for topic branches.
|
264
|
+
|
265
|
+
## Copyright
|
266
|
+
|
267
|
+
* Copyrignt (c) 2010 Kriss 'nu7hatch' Kowalik
|
268
|
+
* Copyright (c) 2009-2010 BehindLogic
|
269
|
+
|
270
|
+
See LICENSE for details.
|
271
|
+
|