gmail 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +27 -27
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +13 -13
  5. data/.rubocop_todo.yml +239 -239
  6. data/.travis.yml +19 -19
  7. data/CHANGELOG.md +145 -139
  8. data/Gemfile +3 -3
  9. data/LICENSE +21 -21
  10. data/README.md +355 -354
  11. data/Rakefile +46 -46
  12. data/gmail.gemspec +34 -34
  13. data/lib/gmail.rb +78 -78
  14. data/lib/gmail/client.rb +34 -34
  15. data/lib/gmail/client/base.rb +229 -229
  16. data/lib/gmail/client/plain.rb +24 -24
  17. data/lib/gmail/client/xoauth.rb +68 -68
  18. data/lib/gmail/client/xoauth2.rb +39 -39
  19. data/lib/gmail/imap_extensions.rb +159 -150
  20. data/lib/gmail/labels.rb +79 -79
  21. data/lib/gmail/mailbox.rb +175 -135
  22. data/lib/gmail/message.rb +207 -207
  23. data/lib/gmail/version.rb +3 -3
  24. data/spec/account.yml.example +1 -1
  25. data/spec/account.yml.obfus +2 -2
  26. data/spec/gmail/client/base_spec.rb +5 -5
  27. data/spec/gmail/client/plain_spec.rb +169 -168
  28. data/spec/gmail/client/xoauth2_spec.rb +186 -186
  29. data/spec/gmail/client/xoauth_spec.rb +5 -5
  30. data/spec/gmail/client_spec.rb +5 -5
  31. data/spec/gmail/imap_extensions_spec.rb +47 -12
  32. data/spec/gmail/labels_spec.rb +27 -18
  33. data/spec/gmail/mailbox_spec.rb +84 -47
  34. data/spec/gmail/message_spec.rb +181 -181
  35. data/spec/gmail_spec.rb +39 -39
  36. data/spec/recordings/gmail/_new_connects_with_client_and_give_it_context_when_block_given.yml +28 -28
  37. data/spec/recordings/gmail/_new_connects_with_gmail_service_and_return_valid_connection_object.yml +28 -28
  38. data/spec/recordings/gmail/_new_does_not_raise_error_when_couldn_t_connect_with_given_account.yml +13 -13
  39. data/spec/recordings/gmail/_new_raises_error_when_couldn_t_connect_with_given_account.yml +13 -13
  40. data/spec/recordings/gmail_client_plain/instance/_connection_automatically_logs_in_to_gmail_account_when_it_s_called.yml +42 -42
  41. data/spec/recordings/gmail_client_plain/instance/delivers_inline_composed_email.yml +42 -42
  42. data/spec/recordings/gmail_client_plain/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +13 -13
  43. data/spec/recordings/gmail_client_plain/instance/does_not_raise_error_even_though_gmail_account_is_invalid.yml +13 -13
  44. data/spec/recordings/gmail_client_plain/instance/labels/checks_if_there_is_given_label_defined.yml +196 -196
  45. data/spec/recordings/gmail_client_plain/instance/labels/creates_given_label.yml +151 -151
  46. data/spec/recordings/gmail_client_plain/instance/labels/removes_existing_label.yml +146 -146
  47. data/spec/recordings/gmail_client_plain/instance/labels/returns_list_of_all_available_labels.yml +113 -113
  48. data/spec/recordings/gmail_client_plain/instance/properly_logs_in_to_valid_gmail_account.yml +42 -42
  49. data/spec/recordings/gmail_client_plain/instance/properly_logs_out_from_gmail.yml +42 -42
  50. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox.yml +109 -109
  51. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox_using_block_style.yml +109 -109
  52. data/spec/recordings/gmail_client_plain/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +13 -13
  53. data/spec/recordings/gmail_client_xo_auth2/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +13 -13
  54. data/spec/recordings/gmail_client_xo_auth2/instance/labels/checks_if_there_is_given_label_defined.yml +27 -27
  55. data/spec/recordings/gmail_client_xo_auth2/instance/labels/creates_given_label.yml +39 -39
  56. data/spec/recordings/gmail_client_xo_auth2/instance/labels/removes_existing_label.yml +39 -39
  57. data/spec/recordings/gmail_client_xo_auth2/instance/labels/returns_list_of_all_available_labels.yml +27 -27
  58. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_in_to_valid_gmail_account.yml +15 -15
  59. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_out_from_gmail.yml +15 -15
  60. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox.yml +40 -40
  61. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox_using_block_style.yml +40 -40
  62. data/spec/recordings/gmail_client_xo_auth2/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +13 -13
  63. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/all/localizes_into_the_appropriate_label.yml +116 -116
  64. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/and_the_mailbox_does_not_exist/returns_the_mailbox_name_as_a_string.yml +110 -0
  65. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/drafts/localizes_into_the_appropriate_label.yml +116 -116
  66. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/flagged/localizes_into_the_appropriate_label.yml +116 -116
  67. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/important/localizes_into_the_appropriate_label.yml +116 -116
  68. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/inbox/localizes_into_the_appropriate_label.yml +42 -42
  69. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/junk/localizes_into_the_appropriate_label.yml +116 -116
  70. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/sent/localizes_into_the_appropriate_label.yml +116 -116
  71. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/trash/localizes_into_the_appropriate_label.yml +116 -116
  72. data/spec/recordings/gmail_mailbox/instance/counts_all_emails.yml +277 -277
  73. data/spec/recordings/gmail_mailbox/instance/finds_messages.yml +586 -586
  74. data/spec/recordings/gmail_mailbox/instance/waits_once.yml +136 -0
  75. data/spec/recordings/gmail_mailbox/instance/waits_repeatedly.yml +141 -0
  76. data/spec/recordings/gmail_mailbox/instance/waits_with_29-minute_re-issue.yml +136 -0
  77. data/spec/recordings/gmail_mailbox/instance/waits_with_an_unblocked_connection.yml +207 -0
  78. data/spec/recordings/gmail_mailbox/on_initialize/sets_client_and_name.yml +42 -42
  79. data/spec/recordings/gmail_mailbox/on_initialize/works_in_inbox_by_default.yml +42 -42
  80. data/spec/recordings/gmail_message/initialize/sets_prefetch_attrs.yml +578 -578
  81. data/spec/recordings/gmail_message/initialize/sets_uid_and_mailbox.yml +580 -580
  82. data/spec/recordings/gmail_message/instance_methods/deletes_itself.yml +637 -637
  83. data/spec/recordings/gmail_message/instance_methods/marks_itself_read.yml +682 -682
  84. data/spec/recordings/gmail_message/instance_methods/marks_itself_unread.yml +686 -686
  85. data/spec/recordings/gmail_message/instance_methods/moves_from_one_tag_to_other.yml +862 -862
  86. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label.yml +776 -776
  87. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label_with_old_method.yml +776 -776
  88. data/spec/recordings/gmail_message/instance_methods/sets_given_label.yml +690 -690
  89. data/spec/recordings/gmail_message/instance_methods/sets_given_label_with_old_method.yml +691 -691
  90. data/spec/spec_helper.rb +53 -53
  91. data/spec/support/imap_mock.rb +181 -129
  92. data/spec/support/obfuscation.rb +52 -52
  93. metadata +78 -5
@@ -1,19 +1,19 @@
1
- rvm:
2
- - 1.9.3
3
- - 2.0.0
4
- - 2.1.5
5
- - 2.2.0
6
- - rbx
7
- - jruby
8
-
9
- matrix:
10
- allow_failures:
11
- - rvm: rbx
12
- - rvm: jruby
13
-
14
- # http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/
15
- sudo: false
16
-
17
- # script:
18
- # - bundle exec rspec
19
- # - bundle exec rubocop
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.0
6
+ - rbx
7
+ - jruby
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: rbx
12
+ - rvm: jruby
13
+
14
+ # http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/
15
+ sudo: false
16
+
17
+ # script:
18
+ # - bundle exec rspec
19
+ # - bundle exec rubocop
@@ -1,139 +1,145 @@
1
- # Gmail Gem Changelog
2
-
3
- ## Unreleased
4
-
5
- * Your change here
6
-
7
-
8
- ## 0.5.0 - 2015-01-26
9
-
10
- * Migrate primary repo to https://github.com/gmailgem/gmail with new project governance (@johnnyshields, @bootstraponline)
11
- * Create logo for project (@johnnyshields)
12
- * Implement IMAP recorder for specs and get all specs passing (@jcarbo)
13
- * Add Rubocop to porject and fix offenses (@jcarbo)
14
- * Fix: #connect method not invoking a block (@jcarbo)
15
- * Support X-GM-RAW (raw Gmail search syntax) in filter query (@bootstraponline)
16
- * Bugfix: Improperly processing labels containing parentheses (@ryanlchan #82)
17
- * Add support for localizing labels (@ryanlchan #83)
18
- * Support for XOAuth2 Client (@KieranP)
19
- * Improve support for non-english labels and mailboxes (@KieranP)
20
- * Fix IMAP library patch on Ruby 2 (@bootstraponline, @johnnyshields, @awakia)
21
- * Ability to search emails by a UID filter (@KieranP)
22
- * Add a way to disconnect the IMAP socket (@KieranP)
23
- * Better support for timezones (@KieranP)
24
- * Add `emails_in_batches` method (@KieranP)
25
- * Gmail Message class: Include X-GM-THRID which is the thread id (@jcarbo)
26
- * Gmail Message class: Include X-GM-MSGID which is a unique, non-changing email identifier (@KieranP)
27
- * Gmail Message class: Fetch values in bulk and cache them (performance) (@KieranP)
28
- * Gmail Message class: Pull FLAGS to make #read? and #starred? methods work (@KieranP)
29
- * Gmail Message class: Don't mark an email as read when accessing the message (@KieranP)
30
- * Gmail Message class: Reorganisation and cleanup of method definitions (@KieranP)
31
- * Bugfix: Fix for XOAuth SMTP settings (@molsder #24)
32
- * Implement Travis CI (@johnnyshields)
33
- * Remove legacy dependency on MIME gem (@johnnyshields)
34
- * Upgrade to RSpec 3.1 and remove Mocha dependency (@johnnyshields, @jcarbo #156)
35
-
36
-
37
- ## 0.4.2
38
-
39
- * Fix issue related to Mail gem version lock (@johnnyshields)
40
-
41
-
42
- ## 0.4.1
43
-
44
- * n/a
45
-
46
-
47
- ## 0.4.0
48
-
49
- * Added XOAuth authentication method (Stefano Bernardi, Nicolas Fouché)
50
- * Separated clients
51
- * Fixed specs
52
-
53
-
54
- ## 0.3.4
55
-
56
- * Fixes in mailbox filters shortcuts (Benjamin Bock)
57
-
58
-
59
- ## 0.3.3
60
-
61
- * Added #expunge to Mailbox (Benjamin Bock)
62
- * Added more mailbox filters (Benjamin Bock)
63
- * Added shortcuts for mailbox filters
64
- * Minor bugfixes
65
-
66
-
67
- ## 0.3.2
68
-
69
- * Added envelope fetching
70
- * Minor bugfixes
71
-
72
-
73
- ## 0.3.0
74
-
75
- * Refactoring
76
- * Fixed bugs
77
- * API improvements
78
- * Better documentation
79
- * Code cleanup
80
- * RSpec for everything
81
-
82
-
83
- ## 0.1.1 - 2010-05-11
84
-
85
- * Added explicit tmail dependency in gemspec
86
- * Added better README tutorial content
87
-
88
-
89
- ## 0.0.9 - 2010-04-17
90
-
91
- * Fixed content-transfer-encoding when sending email
92
-
93
-
94
- ## 0.0.8 - 2009-12-23
95
-
96
- * Fixed attaching a file to an empty message
97
-
98
-
99
- ## 0.0.7 - 2009-12-23
100
-
101
- * Improved multipart message parsing reliability
102
-
103
-
104
- ## 0.0.6 - 2009-12-21
105
-
106
- * Fixed multipart parsing for when the boundary is marked in quotes.
107
-
108
-
109
- ## 0.0.5 - 2009-12-16
110
-
111
- * Fixed IMAP initializer to work with Ruby 1.9's net/imap
112
- * Better logout depending on the IMAP connection itself
113
- * Added MIME::Message#text and MIME::Message#html for easier access to an email body
114
- * Improved the MIME-parsing API slightly
115
- * Added some tests
116
-
117
-
118
- ## 0.0.4 - 2009-11-30
119
-
120
- * Added label creation (@justinperkins)
121
- * Made the gem login automatically when first needed
122
- * Added an optional block on the Gmail.new object that will login and logout for you
123
- * Added several search options (@mikker)
124
-
125
-
126
- ## 0.0.3 - 2009-11-19
127
-
128
- * Fixed MIME::Message#content= for messages without an encoding
129
- * Added Gmail#new_message
130
-
131
-
132
- ## 0.0.2 - 2009-11-18
133
-
134
- * Made all of the examples in the README possible
135
-
136
-
137
- ## 0.0.1 - 2009-11-18
138
-
139
- * Birthday!
1
+ # Gmail Gem Changelog
2
+
3
+ ## Unreleased
4
+
5
+ * Your change here
6
+
7
+ ## 0.6.0 - 2015-8-24
8
+
9
+ * [Fix: Labels#localize to not return nil (@afn)](https://github.com/gmailgem/gmail/pull/176)
10
+ * [Fix: label parsing (@yn)](https://github.com/gmailgem/gmail/pull/179)
11
+ * [Feature: Add IDLE support (@alexeymorozov)](https://github.com/gmailgem/gmail/pull/167)
12
+ * [Fix: #deliver to always invoke compose (@kuboon)](https://github.com/gmailgem/gmail/pull/163)
13
+
14
+ ## 0.5.0 - 2015-01-26
15
+
16
+ * Migrate primary repo to https://github.com/gmailgem/gmail with new project governance (@johnnyshields, @bootstraponline)
17
+ * Create logo for project (@johnnyshields)
18
+ * Implement IMAP recorder for specs and get all specs passing (@jcarbo)
19
+ * Add Rubocop to porject and fix offenses (@jcarbo)
20
+ * Fix: #connect method not invoking a block (@jcarbo)
21
+ * Support X-GM-RAW (raw Gmail search syntax) in filter query (@bootstraponline)
22
+ * Bugfix: Improperly processing labels containing parentheses (@ryanlchan #82)
23
+ * Add support for localizing labels (@ryanlchan #83)
24
+ * Support for XOAuth2 Client (@KieranP)
25
+ * Improve support for non-english labels and mailboxes (@KieranP)
26
+ * Fix IMAP library patch on Ruby 2 (@bootstraponline, @johnnyshields, @awakia)
27
+ * Ability to search emails by a UID filter (@KieranP)
28
+ * Add a way to disconnect the IMAP socket (@KieranP)
29
+ * Better support for timezones (@KieranP)
30
+ * Add `emails_in_batches` method (@KieranP)
31
+ * Gmail Message class: Include X-GM-THRID which is the thread id (@jcarbo)
32
+ * Gmail Message class: Include X-GM-MSGID which is a unique, non-changing email identifier (@KieranP)
33
+ * Gmail Message class: Fetch values in bulk and cache them (performance) (@KieranP)
34
+ * Gmail Message class: Pull FLAGS to make #read? and #starred? methods work (@KieranP)
35
+ * Gmail Message class: Don't mark an email as read when accessing the message (@KieranP)
36
+ * Gmail Message class: Reorganisation and cleanup of method definitions (@KieranP)
37
+ * Bugfix: Fix for XOAuth SMTP settings (@molsder #24)
38
+ * Implement Travis CI (@johnnyshields)
39
+ * Remove legacy dependency on MIME gem (@johnnyshields)
40
+ * Upgrade to RSpec 3.1 and remove Mocha dependency (@johnnyshields, @jcarbo #156)
41
+
42
+
43
+ ## 0.4.2
44
+
45
+ * Fix issue related to Mail gem version lock (@johnnyshields)
46
+
47
+
48
+ ## 0.4.1
49
+
50
+ * n/a
51
+
52
+
53
+ ## 0.4.0
54
+
55
+ * Added XOAuth authentication method (Stefano Bernardi, Nicolas Fouché)
56
+ * Separated clients
57
+ * Fixed specs
58
+
59
+
60
+ ## 0.3.4
61
+
62
+ * Fixes in mailbox filters shortcuts (Benjamin Bock)
63
+
64
+
65
+ ## 0.3.3
66
+
67
+ * Added #expunge to Mailbox (Benjamin Bock)
68
+ * Added more mailbox filters (Benjamin Bock)
69
+ * Added shortcuts for mailbox filters
70
+ * Minor bugfixes
71
+
72
+
73
+ ## 0.3.2
74
+
75
+ * Added envelope fetching
76
+ * Minor bugfixes
77
+
78
+
79
+ ## 0.3.0
80
+
81
+ * Refactoring
82
+ * Fixed bugs
83
+ * API improvements
84
+ * Better documentation
85
+ * Code cleanup
86
+ * RSpec for everything
87
+
88
+
89
+ ## 0.1.1 - 2010-05-11
90
+
91
+ * Added explicit tmail dependency in gemspec
92
+ * Added better README tutorial content
93
+
94
+
95
+ ## 0.0.9 - 2010-04-17
96
+
97
+ * Fixed content-transfer-encoding when sending email
98
+
99
+
100
+ ## 0.0.8 - 2009-12-23
101
+
102
+ * Fixed attaching a file to an empty message
103
+
104
+
105
+ ## 0.0.7 - 2009-12-23
106
+
107
+ * Improved multipart message parsing reliability
108
+
109
+
110
+ ## 0.0.6 - 2009-12-21
111
+
112
+ * Fixed multipart parsing for when the boundary is marked in quotes.
113
+
114
+
115
+ ## 0.0.5 - 2009-12-16
116
+
117
+ * Fixed IMAP initializer to work with Ruby 1.9's net/imap
118
+ * Better logout depending on the IMAP connection itself
119
+ * Added MIME::Message#text and MIME::Message#html for easier access to an email body
120
+ * Improved the MIME-parsing API slightly
121
+ * Added some tests
122
+
123
+
124
+ ## 0.0.4 - 2009-11-30
125
+
126
+ * Added label creation (@justinperkins)
127
+ * Made the gem login automatically when first needed
128
+ * Added an optional block on the Gmail.new object that will login and logout for you
129
+ * Added several search options (@mikker)
130
+
131
+
132
+ ## 0.0.3 - 2009-11-19
133
+
134
+ * Fixed MIME::Message#content= for messages without an encoding
135
+ * Added Gmail#new_message
136
+
137
+
138
+ ## 0.0.2 - 2009-11-18
139
+
140
+ * Made all of the examples in the README possible
141
+
142
+
143
+ ## 0.0.1 - 2009-11-18
144
+
145
+ * Birthday!
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
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,354 +1,355 @@
1
- <img alt="Gmail for Ruby" src="https://cloud.githubusercontent.com/assets/27655/5792399/fd5d076e-9f59-11e4-826c-22c311e38356.png">
2
-
3
- [![Build Status](https://travis-ci.org/gmailgem/gmail.svg)](https://travis-ci.org/gmailgem/gmail)
4
- [![Code Climate](https://codeclimate.com/github/gmailgem/gmail.svg)](https://codeclimate.com/github/gmailgem/gmail)
5
- [![Gem Version](https://badge.fury.io/rb/gmail.svg)](http://badge.fury.io/rb/gmail)
6
-
7
- A Rubyesque interface to Google's Gmail, with all the tools you'll need. Search,
8
- read and send multipart emails, archive, mark as read/unread, delete emails,
9
- and manage labels.
10
-
11
- It's based on Daniel Parker's ruby-gmail gem. This version has more friendly
12
- API, is well tested, better documented and have many other improvements.
13
-
14
- ## Installation
15
-
16
- You can install it easy using rubygems:
17
-
18
- sudo gem install gmail
19
-
20
- Or install it manually:
21
-
22
- git clone git://github.com/gmailgem/gmail.git
23
- cd gmail
24
- rake install
25
-
26
- gmail gem has the following dependencies (with Bundler all will be installed automatically):
27
-
28
- * mail
29
- * gmail_xoauth
30
-
31
- ## Version Support
32
-
33
- * Ruby 2.0.0+ is supported
34
- * Ruby 1.9.3 is supported but deprecated and is planned to be dropped from gmail v0.6.0
35
- * Ruby 1.8.7 users should use gmail v0.4.1
36
-
37
- ## Features
38
-
39
- * Search emails
40
- * Read emails (handles attachments)
41
- * Emails: label, archive, delete, mark as read/unread/spam, star
42
- * Manage labels
43
- * Create and send multipart email messages in plaintext and/or html, with inline
44
- images and attachments
45
- * Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates
46
- MIME properly.
47
-
48
- ## Basic usage
49
-
50
- First of all require the `gmail` library.
51
-
52
- ```ruby
53
- require 'gmail'
54
- ```
55
-
56
- ### Authenticating gmail sessions
57
-
58
- This will let you automatically log in to your account.
59
-
60
- ```ruby
61
- gmail = Gmail.connect(username, password)
62
- # play with your gmail...
63
- gmail.logout
64
- ```
65
-
66
- If you pass a block, the session will be passed into the block, and the session
67
- will be logged out after the block is executed.
68
-
69
- ```ruby
70
- Gmail.connect(username, password) do |gmail|
71
- # play with your gmail...
72
- end
73
- ```
74
-
75
- Examples above are "quiet", it means that it will not raise any errors when
76
- session couldn't be started (eg. because of connection error or invalid
77
- authorization data). You can use connection which handles errors raising:
78
-
79
- ```ruby
80
- Gmail.connect!(username, password)
81
- Gmail.connect!(username, password) {|gmail| ... play with gmail ... }
82
- ```
83
-
84
- You can also check if you are logged in at any time:
85
-
86
- ```ruby
87
- Gmail.connect(username, password) do |gmail|
88
- gmail.logged_in?
89
- end
90
- ```
91
-
92
- ### XOAuth authentication
93
-
94
- From v0.4.0 it's possible to authenticate with your Gmail account using XOAuth
95
- method. It's very simple:
96
-
97
- ```ruby
98
- gmail = Gmail.connect(:xoauth, "email@domain.com",
99
- :token => 'TOKEN',
100
- :secret => 'TOKEN_SECRET',
101
- :consumer_key => 'CONSUMER_KEY',
102
- :consumer_secret => 'CONSUMER_SECRET'
103
- )
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
- ```ruby
114
- gmail.inbox.count
115
- gmail.inbox.count(:unread)
116
- gmail.inbox.count(:read)
117
- ```
118
-
119
- Count with some criteria:
120
-
121
- ```ruby
122
- gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
123
- gmail.inbox.count(:on => Date.parse("2010-04-15"))
124
- gmail.inbox.count(:from => "myfriend@gmail.com")
125
- gmail.inbox.count(:to => "directlytome@gmail.com")
126
- ```
127
-
128
- Combine flags and options:
129
-
130
- ```ruby
131
- gmail.inbox.count(:unread, :from => "myboss@gmail.com")
132
- ```
133
-
134
- Browsing labeled emails is similar to work with inbox.
135
-
136
- ```ruby
137
- gmail.mailbox('Urgent').count
138
- ```
139
-
140
- Getting messages works the same way as counting: Remember that every message in a
141
- conversation/thread will come as a separate message.
142
-
143
- ```ruby
144
- gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
145
- ```
146
-
147
- The [gm option](https://developers.google.com/gmail/imap_extensions?csw=1#extension_of_the_search_command_x-gm-raw) enables use of the Gmail search syntax.
148
-
149
- ```ruby
150
- gmail.inbox.emails(gm: '"testing"')
151
- ```
152
-
153
- You can use also one of aliases:
154
-
155
- ```ruby
156
- gmail.inbox.find(...)
157
- gmail.inbox.search(...)
158
- gmail.inbox.mails(...)
159
- ```
160
-
161
- Also you can manipulate each message using block style:
162
-
163
- ```ruby
164
- gmail.inbox.find(:unread).each do |email|
165
- email.read!
166
- end
167
- ```
168
-
169
- ### Working with emails!
170
-
171
- Any news older than 4-20, mark as read and archive it:
172
-
173
- ```ruby
174
- gmail.inbox.find(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
175
- email.read! # can also unread!, spam! or star!
176
- email.archive!
177
- end
178
- ```
179
-
180
- Delete emails from X:
181
-
182
- ```ruby
183
- gmail.inbox.find(:from => "x-fiance@gmail.com").each do |email|
184
- email.delete!
185
- end
186
- ```
187
-
188
- Save all attachments in the "Faxes" label to a local folder (uses functionality from `Mail` gem):
189
-
190
- ```ruby
191
- folder = Dir.pwd # for example
192
- gmail.mailbox("Faxes").emails.each do |email|
193
- email.message.attachments.each do |f|
194
- File.write(File.join(folder, f.filename), f.body.decoded)
195
- end
196
- end
197
- ```
198
-
199
- You can use also `#label` method instead of `#mailbox`:
200
-
201
- ```ruby
202
- gmail.label("Faxes").emails {|email| ... }
203
- ```
204
-
205
- Save just the first attachment from the newest unread email (assuming pdf):
206
-
207
- ```ruby
208
- email = gmail.inbox.find(:unread).first
209
- email.attachments[0].save_to_file("/path/to/location")
210
- ```
211
-
212
- Add a label to a message:
213
-
214
- ```ruby
215
- email.label("Faxes")
216
- ```
217
-
218
- Example above will raise error when you don't have the `Faxes` label. You can
219
- avoid this using:
220
-
221
- ```ruby
222
- email.label!("Faxes") # The `Faxes` label will be automatically created now
223
- ```
224
-
225
- You can also move message to a label/mailbox:
226
-
227
- ```ruby
228
- email.move_to("Faxes")
229
- email.move_to!("NewLabel")
230
- ```
231
-
232
- There is also few shortcuts to mark messages quickly:
233
-
234
- ```ruby
235
- email.read!
236
- email.unread!
237
- email.spam!
238
- email.star!
239
- email.unstar!
240
- ```
241
-
242
- ### Managing labels
243
-
244
- With Gmail gem you can also manage your labels. You can get list of defined
245
- labels:
246
-
247
- ```ruby
248
- gmail.labels.all
249
- ```
250
-
251
- Create new label:
252
-
253
- ```ruby
254
- gmail.labels.new("Urgent")
255
- gmail.labels.add("AnotherOne")
256
- ```
257
-
258
- Remove labels:
259
-
260
- ```ruby
261
- gmail.labels.delete("Urgent")
262
- ```
263
-
264
- Or check if given label exists:
265
-
266
- ```ruby
267
- gmail.labels.exists?("Urgent") # => false
268
- gmail.labels.exists?("AnotherOne") # => true
269
- ```
270
-
271
- Localize label names using the LIST special-use extension flags,
272
- :Inbox, :All, :Drafts, :Sent, :Trash, :Important, :Junk, and :Flagged
273
-
274
- ```ruby
275
- gmail.labels.localize(:all) # => "[Gmail]\All Mail"
276
- # => "[Google Mail]\All Mail"
277
- ```
278
-
279
- ### Composing and sending emails
280
-
281
- Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem.
282
- See its [documentation here](http://github.com/mikel/mail). The Ruby Gmail will
283
- automatically configure your Mail emails to be sent via your Gmail account's SMTP,
284
- so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From"
285
- email either, because ruby-gmail will set it for you.
286
-
287
- ```ruby
288
- gmail.deliver do
289
- to "email@example.com"
290
- subject "Having fun in Puerto Rico!"
291
- text_part do
292
- body "Text of plaintext message."
293
- end
294
- html_part do
295
- content_type 'text/html; charset=UTF-8'
296
- body "<p>Text of <em>html</em> message.</p>"
297
- end
298
- add_file "/path/to/some_image.jpg"
299
- end
300
- ```
301
-
302
- Or, compose the message first and send it later
303
-
304
- ```ruby
305
- email = gmail.compose do
306
- to "email@example.com"
307
- subject "Having fun in Puerto Rico!"
308
- body "Spent the day on the road..."
309
- end
310
- email.deliver! # or: gmail.deliver(email)
311
- ```
312
-
313
- ## Troubleshooting
314
-
315
- If you are having trouble connecting to Gmail:
316
- * Please ensure your account is verified
317
- * In [Gmail Security Settings](https://www.google.com/settings/security), enable access for less secure applications.
318
- * Read [this support answer re: suspicious activity](https://support.google.com/mail/answer/78754) and try things like entering a captcha.
319
-
320
- ## Note on Patches/Pull Requests
321
-
322
- * Fork the project.
323
- * Make your feature addition or bug fix.
324
- * Add tests for it. This is important so I don't break it in a
325
- future version unintentionally.
326
- * Commit, do not mess with rakefile, version, or history.
327
- (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)
328
- * Send me a pull request. Bonus points for topic branches.
329
-
330
- ## Authors
331
-
332
- #### Core Team
333
-
334
- This project follows on Open Governance model. The Core Team is responsible for technical guidance, reviewing/merging PRs, and releases.
335
-
336
- * Jeff Carbonella - [@jcarbo](https://github.com/jcarbo)
337
- * Johnny Shields - [@johnnyshields](https://github.com/johnnyshields)
338
- * Alexandre Loureiro Solleiro - [@webcracy](https://github.com/webcracy)
339
- * Justin Grevitch - [@jgrevich](https://github.com/jgrevich)
340
- * [@bootstraponline](https://github.com/bootstraponline)
341
-
342
- #### Legacy Contributors
343
-
344
- * Kriss Kowalik - [@nu7hatch](https://github.com/nu7hatch)
345
- * Daniel Parker - [@dcparker](https://github.com/dcparker)
346
- * Refer to [CHANGELOG](https://github.com/gmailgem/gmail/blob/master/CHANGELOG.md) for individual contributions
347
-
348
- ## Copyright
349
-
350
- * Copyright (c) 2015 GmailGem team
351
- * Copyright (c) 2010-2014 Kriss 'nu7hatch' Kowalik
352
- * Copyright (c) 2009-2010 BehindLogic
353
-
354
- Licensed under the MIT license. See [LICENSE](https://github.com/gmailgem/gmail/blob/master/LICENSE) for details.
1
+ <img alt="Gmail for Ruby" src="https://cloud.githubusercontent.com/assets/27655/5792399/fd5d076e-9f59-11e4-826c-22c311e38356.png">
2
+
3
+ [![Build Status](https://travis-ci.org/gmailgem/gmail.svg)](https://travis-ci.org/gmailgem/gmail)
4
+ [![Code Climate](https://codeclimate.com/github/gmailgem/gmail.svg)](https://codeclimate.com/github/gmailgem/gmail)
5
+ [![Gem Version](https://badge.fury.io/rb/gmail.svg)](http://badge.fury.io/rb/gmail)
6
+
7
+ A Rubyesque interface to Google's Gmail, with all the tools you'll need. Search,
8
+ read and send multipart emails, archive, mark as read/unread, delete emails,
9
+ and manage labels.
10
+
11
+ It's based on Daniel Parker's ruby-gmail gem. This version has more friendly
12
+ API, is well tested, better documented and have many other improvements.
13
+
14
+ ## Installation
15
+
16
+ You can install it easy using rubygems:
17
+
18
+ sudo gem install gmail
19
+
20
+ Or install it manually:
21
+
22
+ git clone git://github.com/gmailgem/gmail.git
23
+ cd gmail
24
+ rake install
25
+
26
+ gmail gem has the following dependencies (with Bundler all will be installed automatically):
27
+
28
+ * mail
29
+ * gmail_xoauth
30
+
31
+ ## Version Support
32
+
33
+ * Ruby 2.0.0+ is supported
34
+ * Ruby 1.9.3 is supported but deprecated and is planned to be dropped from gmail v0.6.0
35
+ * Ruby 1.8.7 users should use gmail v0.4.1
36
+
37
+ ## Features
38
+
39
+ * Search emails
40
+ * Read emails (handles attachments)
41
+ * Emails: label, archive, delete, mark as read/unread/spam, star
42
+ * Manage labels
43
+ * Create and send multipart email messages in plaintext and/or html, with inline
44
+ images and attachments
45
+ * Utilizes Gmail's IMAP & SMTP, MIME-type detection and parses and generates
46
+ MIME properly.
47
+
48
+ ## Basic usage
49
+
50
+ First of all require the `gmail` library.
51
+
52
+ ```ruby
53
+ require 'gmail'
54
+ ```
55
+
56
+ ### Authenticating gmail sessions
57
+
58
+ This will let you automatically log in to your account.
59
+
60
+ ```ruby
61
+ gmail = Gmail.connect(username, password)
62
+ # play with your gmail...
63
+ gmail.logout
64
+ ```
65
+
66
+ If you pass a block, the session will be passed into the block, and the session
67
+ will be logged out after the block is executed.
68
+
69
+ ```ruby
70
+ Gmail.connect(username, password) do |gmail|
71
+ # play with your gmail...
72
+ end
73
+ ```
74
+
75
+ Examples above are "quiet", it means that it will not raise any errors when
76
+ session couldn't be started (eg. because of connection error or invalid
77
+ authorization data). You can use connection which handles errors raising:
78
+
79
+ ```ruby
80
+ Gmail.connect!(username, password)
81
+ Gmail.connect!(username, password) {|gmail| ... play with gmail ... }
82
+ ```
83
+
84
+ You can also check if you are logged in at any time:
85
+
86
+ ```ruby
87
+ Gmail.connect(username, password) do |gmail|
88
+ gmail.logged_in?
89
+ end
90
+ ```
91
+
92
+ ### XOAuth authentication
93
+
94
+ From v0.4.0 it's possible to authenticate with your Gmail account using XOAuth
95
+ method. It's very simple:
96
+
97
+ ```ruby
98
+ gmail = Gmail.connect(:xoauth, "email@domain.com",
99
+ :token => 'TOKEN',
100
+ :secret => 'TOKEN_SECRET',
101
+ :consumer_key => 'CONSUMER_KEY',
102
+ :consumer_secret => 'CONSUMER_SECRET'
103
+ )
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
+ ```ruby
114
+ gmail.inbox.count
115
+ gmail.inbox.count(:unread)
116
+ gmail.inbox.count(:read)
117
+ ```
118
+
119
+ Count with some criteria:
120
+
121
+ ```ruby
122
+ gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
123
+ gmail.inbox.count(:on => Date.parse("2010-04-15"))
124
+ gmail.inbox.count(:from => "myfriend@gmail.com")
125
+ gmail.inbox.count(:to => "directlytome@gmail.com")
126
+ ```
127
+
128
+ Combine flags and options:
129
+
130
+ ```ruby
131
+ gmail.inbox.count(:unread, :from => "myboss@gmail.com")
132
+ ```
133
+
134
+ Browsing labeled emails is similar to work with inbox.
135
+
136
+ ```ruby
137
+ gmail.mailbox('Urgent').count
138
+ ```
139
+
140
+ Getting messages works the same way as counting: Remember that every message in a
141
+ conversation/thread will come as a separate message.
142
+
143
+ ```ruby
144
+ gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
145
+ ```
146
+
147
+ The [gm option](https://developers.google.com/gmail/imap_extensions?csw=1#extension_of_the_search_command_x-gm-raw) enables use of the Gmail search syntax.
148
+
149
+ ```ruby
150
+ gmail.inbox.emails(gm: '"testing"')
151
+ ```
152
+
153
+ You can use also one of aliases:
154
+
155
+ ```ruby
156
+ gmail.inbox.find(...)
157
+ gmail.inbox.search(...)
158
+ gmail.inbox.mails(...)
159
+ ```
160
+
161
+ Also you can manipulate each message using block style:
162
+
163
+ ```ruby
164
+ gmail.inbox.find(:unread).each do |email|
165
+ email.read!
166
+ end
167
+ ```
168
+
169
+ ### Working with emails!
170
+
171
+ Any news older than 4-20, mark as read and archive it:
172
+
173
+ ```ruby
174
+ gmail.inbox.find(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
175
+ email.read! # can also unread!, spam! or star!
176
+ email.archive!
177
+ end
178
+ ```
179
+
180
+ Delete emails from X:
181
+
182
+ ```ruby
183
+ gmail.inbox.find(:from => "x-fiance@gmail.com").each do |email|
184
+ email.delete!
185
+ end
186
+ ```
187
+
188
+ Save all attachments in the "Faxes" label to a local folder (uses functionality from `Mail` gem):
189
+
190
+ ```ruby
191
+ folder = Dir.pwd # for example
192
+ gmail.mailbox("Faxes").emails.each do |email|
193
+ email.message.attachments.each do |f|
194
+ File.write(File.join(folder, f.filename), f.body.decoded)
195
+ end
196
+ end
197
+ ```
198
+
199
+ You can use also `#label` method instead of `#mailbox`:
200
+
201
+ ```ruby
202
+ gmail.label("Faxes").emails {|email| ... }
203
+ ```
204
+
205
+ Save just the first attachment from the newest unread email (assuming pdf):
206
+
207
+ ```ruby
208
+ email = gmail.inbox.find(:unread).first
209
+ email.attachments[0].save_to_file("/path/to/location")
210
+ ```
211
+
212
+ Add a label to a message:
213
+
214
+ ```ruby
215
+ email.label("Faxes")
216
+ ```
217
+
218
+ Example above will raise error when you don't have the `Faxes` label. You can
219
+ avoid this using:
220
+
221
+ ```ruby
222
+ email.label!("Faxes") # The `Faxes` label will be automatically created now
223
+ ```
224
+
225
+ You can also move message to a label/mailbox:
226
+
227
+ ```ruby
228
+ email.move_to("Faxes")
229
+ email.move_to!("NewLabel")
230
+ ```
231
+
232
+ There is also few shortcuts to mark messages quickly:
233
+
234
+ ```ruby
235
+ email.read!
236
+ email.unread!
237
+ email.spam!
238
+ email.star!
239
+ email.unstar!
240
+ ```
241
+
242
+ ### Managing labels
243
+
244
+ With Gmail gem you can also manage your labels. You can get list of defined
245
+ labels:
246
+
247
+ ```ruby
248
+ gmail.labels.all
249
+ ```
250
+
251
+ Create new label:
252
+
253
+ ```ruby
254
+ gmail.labels.new("Urgent")
255
+ gmail.labels.add("AnotherOne")
256
+ ```
257
+
258
+ Remove labels:
259
+
260
+ ```ruby
261
+ gmail.labels.delete("Urgent")
262
+ ```
263
+
264
+ Or check if given label exists:
265
+
266
+ ```ruby
267
+ gmail.labels.exists?("Urgent") # => false
268
+ gmail.labels.exists?("AnotherOne") # => true
269
+ ```
270
+
271
+ Localize label names using the LIST special-use extension flags,
272
+ :Inbox, :All, :Drafts, :Sent, :Trash, :Important, :Junk, and :Flagged
273
+
274
+ ```ruby
275
+ gmail.labels.localize(:all) # => "[Gmail]\All Mail"
276
+ # => "[Google Mail]\All Mail"
277
+ ```
278
+
279
+ ### Composing and sending emails
280
+
281
+ Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem.
282
+ See its [documentation here](http://github.com/mikel/mail). The Ruby Gmail will
283
+ automatically configure your Mail emails to be sent via your Gmail account's SMTP,
284
+ so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From"
285
+ email either, because ruby-gmail will set it for you.
286
+
287
+ ```ruby
288
+ gmail.deliver do
289
+ to "email@example.com"
290
+ subject "Having fun in Puerto Rico!"
291
+ text_part do
292
+ body "Text of plaintext message."
293
+ end
294
+ html_part do
295
+ content_type 'text/html; charset=UTF-8'
296
+ body "<p>Text of <em>html</em> message.</p>"
297
+ end
298
+ add_file "/path/to/some_image.jpg"
299
+ end
300
+ ```
301
+
302
+ Or, compose the message first and send it later
303
+
304
+ ```ruby
305
+ email = gmail.compose do
306
+ to "email@example.com"
307
+ subject "Having fun in Puerto Rico!"
308
+ body "Spent the day on the road..."
309
+ end
310
+ email.deliver! # or: gmail.deliver(email)
311
+ ```
312
+
313
+ ## Troubleshooting
314
+
315
+ If you are having trouble connecting to Gmail:
316
+ * Please ensure your account is verified
317
+ * In [Gmail Security Settings](https://www.google.com/settings/security), enable access for less secure applications.
318
+ * Read [this support answer re: suspicious activity](https://support.google.com/mail/answer/78754) and try things like entering a captcha.
319
+
320
+ ## Note on Patches/Pull Requests
321
+
322
+ * Fork the project.
323
+ * Make your feature addition or bug fix.
324
+ * Add tests for it. This is important so I don't break it in a
325
+ future version unintentionally.
326
+ * Commit, do not mess with rakefile, version, or history.
327
+ (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)
328
+ * Send me a pull request. Bonus points for topic branches.
329
+
330
+ ## Authors
331
+
332
+ #### Core Team
333
+
334
+ This project follows on Open Governance model. The Core Team is responsible for technical guidance, reviewing/merging PRs, and releases.
335
+
336
+ * Jeff Carbonella - [@jcarbo](https://github.com/jcarbo)
337
+ * Johnny Shields - [@johnnyshields](https://github.com/johnnyshields)
338
+ * Alexandre Loureiro Solleiro - [@webcracy](https://github.com/webcracy)
339
+ * Justin Grevich - [@jgrevich](https://github.com/jgrevich)
340
+ * [@bootstraponline](https://github.com/bootstraponline)
341
+ * Nathan Herald - [@myobie](https://github.com/myobie)
342
+
343
+ #### Legacy Contributors
344
+
345
+ * Kriss Kowalik - [@nu7hatch](https://github.com/nu7hatch)
346
+ * Daniel Parker - [@dcparker](https://github.com/dcparker)
347
+ * Refer to [CHANGELOG](https://github.com/gmailgem/gmail/blob/master/CHANGELOG.md) for individual contributions
348
+
349
+ ## Copyright
350
+
351
+ * Copyright (c) 2015 GmailGem team
352
+ * Copyright (c) 2010-2014 Kriss 'nu7hatch' Kowalik
353
+ * Copyright (c) 2009-2010 BehindLogic
354
+
355
+ Licensed under the MIT license. See [LICENSE](https://github.com/gmailgem/gmail/blob/master/LICENSE) for details.