gmail 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- ## PROJECT::SPECIFIC
22
- *.rdb
23
-
24
- ## Test Account details
25
- spec/account.yml
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
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --backtrace
@@ -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
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
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
- * [Nicolas Fouché](http://github.com/nfo)
18
- * [Stefano Bernardi](http://github.com/stefanobernardi)
19
- * [Benjamin Bock](http://github.com/bb)
20
- * [Arthur Chiu](http://github.com/achiu)
21
- * [Justin Perkins](http://github.com/justinperkins)
22
- * [Mikkel Malmberg](http://github.com/mikker)
23
- * [Julien Blanchard](http://github.com/julienXX)
24
- * [Federico Galassi](http://github.com/fgalassi)
25
-
26
- ## Installation
27
-
28
- You can install it easy using rubygems:
29
-
30
- sudo gem install gmail
31
-
32
- Or install it manualy:
33
-
34
- git clone git://github.com/nu7hatch/gmail.git
35
- cd gmail
36
- rake install
37
-
38
- To install gmail gem you have to met following requirements (with rubygems all
39
- will be installed automatically):
40
-
41
- * mail
42
- * mime
43
- * smpt_tls (Ruby < 1.8.7)
44
-
45
- ## Features
46
-
47
- * Search emails
48
- * Read emails (handles attachments)
49
- * Emails: label, archive, delete, mark as read/unread/spam, star
50
- * Manage labels
51
- * Create and send multipart email messages in plaintext and/or html, with inline
52
- images and attachments
53
- * Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates
54
- MIME properly.
55
-
56
- ## Basic usage
57
-
58
- First of all require the `gmail` library.
59
-
60
- require 'gmail'
61
-
62
- ### Authenticating gmail sessions
63
-
64
- This will you automatically log in to your account.
65
-
66
- gmail = Gmail.connect(username, password)
67
- # play with your gmail...
68
- gmail.logout
69
-
70
- If you pass a block, the session will be passed into the block, and the session
71
- will be logged out after the block is executed.
72
-
73
- Gmail.connect(username, password) do |gmail|
74
- # play with your gmail...
75
- end
76
-
77
- Examples above are "quiet", it means that it will not raise any errors when
78
- session couldn't be started (eg. because of connection error or invalid
79
- authorization data). You can use connection which handles errors raising:
80
-
81
- Gmail.connect!(username, password)
82
- Gmail.connect!(username, password) {|gmail| ... play with gmail ... }
83
-
84
- You can also check if you are logged in at any time:
85
-
86
- Gmail.connect(username, password) do |gmail|
87
- gmail.logged_in?
88
- end
89
-
90
- ### Counting and gathering emails
91
-
92
- Get counts for messages in the inbox:
93
-
94
- gmail.inbox.count
95
- gmail.inbox.count(:unread)
96
- gmail.inbox.count(:read)
97
-
98
- Count with some criteria:
99
-
100
- gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
101
- gmail.inbox.count(:on => Date.parse("2010-04-15"))
102
- gmail.inbox.count(:from => "myfriend@gmail.com")
103
- gmail.inbox.count(:to => "directlytome@gmail.com")
104
-
105
- Combine flags and options:
106
-
107
- gmail.inbox.count(:unread, :from => "myboss@gmail.com")
108
-
109
- Browsing labeled emails is similar to work with inbox.
110
-
111
- gmail.mailbox('Urgent').count
112
-
113
- Getting messages works the same way as counting: Remember that every message in a
114
- conversation/thread will come as a separate message.
115
-
116
- gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
117
-
118
- You can use also one of aliases:
119
-
120
- gmail.inbox.find(...)
121
- gmail.inbox.search(...)
122
- gmail.inbox.mails(...)
123
-
124
- Also you can manipulate each message using block style:
125
-
126
- gmail.inbox.find(:unread) do |email|
127
- email.read!
128
- end
129
-
130
- ### Working with emails!
131
-
132
- Any news older than 4-20, mark as read and archive it:
133
-
134
- gmail.inbox.find(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com") do |email|
135
- email.read! # can also unread!, spam! or star!
136
- email.archive!
137
- end
138
-
139
- Delete emails from X:
140
-
141
- gmail.inbox.find(:from => "x-fiance@gmail.com").each do |email|
142
- email.delete!
143
- end
144
-
145
- Save all attachments in the "Faxes" label to a local folder:
146
-
147
- folder = "/where/ever"
148
- gmail.mailbox("Faxes").emails do |email|
149
- if !email.message.attachments.empty?
150
- email.message.save_attachments_to(folder)
151
- end
152
- end
153
-
154
- You can use also `#label` method instead of `#mailbox`:
155
-
156
- gmail.label("Faxes").emails {|email| ... }
157
-
158
- Save just the first attachment from the newest unread email (assuming pdf):
159
-
160
- email = gmail.inbox.find(:unread).first
161
- email.attachments[0].save_to_file("/path/to/location")
162
-
163
- Add a label to a message:
164
-
165
- email.label("Faxes")
166
-
167
- Example above will raise error when you don't have the `Faxes` label. You can
168
- avoid this using:
169
-
170
- email.label!("Faxes") # The `Faxes` label will be automatically created now
171
-
172
- You can also move message to a label/mailbox:
173
-
174
- email.move_to("Faxes")
175
- email.move_to!("NewLabel")
176
-
177
- There is also few shortcuts to mark messages quickly:
178
-
179
- email.read!
180
- email.unread!
181
- email.spam!
182
- email.star!
183
- email.unstar!
184
-
185
- ### Managing labels
186
-
187
- With Gmail gem you can also manage your labels. You can get list of defined
188
- labels:
189
-
190
- gmail.labels.all
191
-
192
- Create new label:
193
-
194
- gmail.labels.new("Uregent")
195
- gmail.labels.add("AnotherOne")
196
-
197
- Remove labels:
198
-
199
- gmail.labels.delete("Uregent")
200
-
201
- Or check if given label exists:
202
-
203
- gmail.labels.exists?("Uregent") # => false
204
- gmail.labels.exists?("AnotherOne") # => true
205
-
206
- ### Composing and sending emails
207
-
208
- Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem.
209
- See its [documentation here](http://github.com/mikel/mail). The Ruby Gmail will
210
- automatically configure your Mail emails to be sent via your Gmail account's SMTP,
211
- so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From"
212
- email either, because ruby-gmail will set it for you.
213
-
214
- gmail.deliver do
215
- to "email@example.com"
216
- subject "Having fun in Puerto Rico!"
217
- text_part do
218
- body "Text of plaintext message."
219
- end
220
- html_part do
221
- body "<p>Text of <em>html</em> message.</p>"
222
- end
223
- add_file "/path/to/some_image.jpg"
224
- end
225
-
226
- Or, generate the message first and send it later
227
-
228
- email = gmail.generate_message do
229
- to "email@example.com"
230
- subject "Having fun in Puerto Rico!"
231
- body "Spent the day on the road..."
232
- end
233
- email.deliver! # or: gmail.deliver(email)
234
-
235
- ## Note on Patches/Pull Requests
236
-
237
- * Fork the project.
238
- * Make your feature addition or bug fix.
239
- * Add tests for it. This is important so I don't break it in a
240
- future version unintentionally.
241
- * Commit, do not mess with rakefile, version, or history.
242
- (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)
243
- * Send me a pull request. Bonus points for topic branches.
244
-
245
- ## Copyright
246
-
247
- * Copyrignt (c) 2010 Kriss 'nu7hatch' Kowalik
248
- * Copyright (c) 2009-2010 BehindLogic
249
-
250
- See LICENSE for details.
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
+