gmail 0.4.2 → 0.5.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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +13 -0
  4. data/.rubocop_todo.yml +239 -0
  5. data/.travis.yml +19 -0
  6. data/CHANGELOG.md +75 -18
  7. data/Gemfile +1 -1
  8. data/README.md +214 -131
  9. data/Rakefile +11 -0
  10. data/gmail.gemspec +8 -8
  11. data/lib/gmail.rb +31 -18
  12. data/lib/gmail/client.rb +11 -7
  13. data/lib/gmail/client/base.rb +52 -48
  14. data/lib/gmail/client/plain.rb +9 -5
  15. data/lib/gmail/client/xoauth.rb +23 -6
  16. data/lib/gmail/client/xoauth2.rb +39 -0
  17. data/lib/gmail/imap_extensions.rb +150 -0
  18. data/lib/gmail/labels.rb +33 -16
  19. data/lib/gmail/mailbox.rb +60 -42
  20. data/lib/gmail/message.rb +142 -101
  21. data/lib/gmail/version.rb +2 -2
  22. data/spec/account.yml.obfus +2 -0
  23. data/spec/gmail/client/base_spec.rb +5 -0
  24. data/spec/gmail/client/plain_spec.rb +168 -0
  25. data/spec/gmail/client/xoauth2_spec.rb +186 -0
  26. data/spec/gmail/client/xoauth_spec.rb +5 -0
  27. data/spec/gmail/client_spec.rb +5 -0
  28. data/spec/gmail/imap_extensions_spec.rb +12 -0
  29. data/spec/gmail/labels_spec.rb +18 -0
  30. data/spec/{mailbox_spec.rb → gmail/mailbox_spec.rb} +14 -14
  31. data/spec/gmail/message_spec.rb +181 -0
  32. data/spec/gmail_spec.rb +21 -21
  33. data/spec/recordings/gmail/_new_connects_with_client_and_give_it_context_when_block_given.yml +28 -0
  34. data/spec/recordings/gmail/_new_connects_with_gmail_service_and_return_valid_connection_object.yml +28 -0
  35. data/spec/recordings/gmail/_new_does_not_raise_error_when_couldn_t_connect_with_given_account.yml +13 -0
  36. data/spec/recordings/gmail/_new_raises_error_when_couldn_t_connect_with_given_account.yml +13 -0
  37. data/spec/recordings/gmail_client_plain/instance/_connection_automatically_logs_in_to_gmail_account_when_it_s_called.yml +42 -0
  38. data/spec/recordings/gmail_client_plain/instance/delivers_inline_composed_email.yml +42 -0
  39. data/spec/recordings/gmail_client_plain/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +13 -0
  40. data/spec/recordings/gmail_client_plain/instance/does_not_raise_error_even_though_gmail_account_is_invalid.yml +13 -0
  41. data/spec/recordings/gmail_client_plain/instance/labels/checks_if_there_is_given_label_defined.yml +196 -0
  42. data/spec/recordings/gmail_client_plain/instance/labels/creates_given_label.yml +151 -0
  43. data/spec/recordings/gmail_client_plain/instance/labels/removes_existing_label.yml +146 -0
  44. data/spec/recordings/gmail_client_plain/instance/labels/returns_list_of_all_available_labels.yml +113 -0
  45. data/spec/recordings/gmail_client_plain/instance/properly_logs_in_to_valid_gmail_account.yml +42 -0
  46. data/spec/recordings/gmail_client_plain/instance/properly_logs_out_from_gmail.yml +42 -0
  47. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox.yml +109 -0
  48. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox_using_block_style.yml +109 -0
  49. data/spec/recordings/gmail_client_plain/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +13 -0
  50. data/spec/recordings/gmail_client_xo_auth2/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +13 -0
  51. data/spec/recordings/gmail_client_xo_auth2/instance/labels/checks_if_there_is_given_label_defined.yml +27 -0
  52. data/spec/recordings/gmail_client_xo_auth2/instance/labels/creates_given_label.yml +39 -0
  53. data/spec/recordings/gmail_client_xo_auth2/instance/labels/removes_existing_label.yml +39 -0
  54. data/spec/recordings/gmail_client_xo_auth2/instance/labels/returns_list_of_all_available_labels.yml +27 -0
  55. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_in_to_valid_gmail_account.yml +15 -0
  56. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_out_from_gmail.yml +15 -0
  57. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox.yml +40 -0
  58. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox_using_block_style.yml +40 -0
  59. data/spec/recordings/gmail_client_xo_auth2/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +13 -0
  60. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/all/localizes_into_the_appropriate_label.yml +116 -0
  61. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/drafts/localizes_into_the_appropriate_label.yml +116 -0
  62. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/flagged/localizes_into_the_appropriate_label.yml +116 -0
  63. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/important/localizes_into_the_appropriate_label.yml +116 -0
  64. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/inbox/localizes_into_the_appropriate_label.yml +42 -0
  65. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/junk/localizes_into_the_appropriate_label.yml +116 -0
  66. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/sent/localizes_into_the_appropriate_label.yml +116 -0
  67. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/trash/localizes_into_the_appropriate_label.yml +116 -0
  68. data/spec/recordings/gmail_mailbox/instance/counts_all_emails.yml +277 -0
  69. data/spec/recordings/gmail_mailbox/instance/finds_messages.yml +586 -0
  70. data/spec/recordings/gmail_mailbox/on_initialize/sets_client_and_name.yml +42 -0
  71. data/spec/recordings/gmail_mailbox/on_initialize/works_in_inbox_by_default.yml +42 -0
  72. data/spec/recordings/gmail_message/initialize/sets_prefetch_attrs.yml +578 -0
  73. data/spec/recordings/gmail_message/initialize/sets_uid_and_mailbox.yml +580 -0
  74. data/spec/recordings/gmail_message/instance_methods/deletes_itself.yml +637 -0
  75. data/spec/recordings/gmail_message/instance_methods/marks_itself_read.yml +682 -0
  76. data/spec/recordings/gmail_message/instance_methods/marks_itself_unread.yml +686 -0
  77. data/spec/recordings/gmail_message/instance_methods/moves_from_one_tag_to_other.yml +862 -0
  78. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label.yml +776 -0
  79. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label_with_old_method.yml +776 -0
  80. data/spec/recordings/gmail_message/instance_methods/sets_given_label.yml +690 -0
  81. data/spec/recordings/gmail_message/instance_methods/sets_given_label_with_old_method.yml +691 -0
  82. data/spec/spec_helper.rb +34 -10
  83. data/spec/support/imap_mock.rb +129 -0
  84. data/spec/support/obfuscation.rb +52 -0
  85. metadata +79 -30
  86. data/TODO.md +0 -12
  87. data/lib/gmail/client/imap_extensions.rb +0 -54
  88. data/spec/client_spec.rb +0 -178
  89. data/spec/message_spec.rb +0 -51
@@ -1,178 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Gmail client (Plain)" do
4
- subject { Gmail::Client::Plain }
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::Plain.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
- client = mock_client
33
- client.connect!.should be_true
34
- end
35
-
36
- it "should properly login to valid GMail account" do
37
- client = mock_client
38
- client.connect.should be_true
39
- client.login.should be_true
40
- client.should be_logged_in
41
- client.logout
42
- end
43
-
44
- it "should raise error when given GMail account is invalid and errors enabled" do
45
- lambda {
46
- client = Gmail::Client::Plain.new("foo", "bar")
47
- client.connect.should be_true
48
- client.login!.should_not be_nil
49
- }.should raise_error
50
- ### FIX: can someone dig to the bottom of this? We are getting NoMethodError instead of Gmail::Client::AuthorizationError in 1.9
51
- end
52
-
53
- it "shouldn't raise error even though GMail account is invalid" do
54
- lambda {
55
- client = Gmail::Client::Plain.new("foo", "bar")
56
- client.connect.should be_true
57
- expect(client.login).to_not be_true
58
- }.should_not raise_error
59
- end
60
-
61
- it "shouldn't login when given GMail account is invalid" do
62
- client = Gmail::Client::Plain.new("foo", "bar")
63
- client.connect.should be_true
64
- client.login.should be_false
65
- end
66
-
67
- it "should properly logout from GMail" do
68
- client = mock_client
69
- client.connect
70
- client.login.should be_true
71
- client.logout.should be_true
72
- client.should_not be_logged_in
73
- end
74
-
75
- it "#connection should automatically log in to GMail account when it's called" do
76
- mock_client do |client|
77
- client.expects(:login).once.returns(false)
78
- client.connection.should_not be_nil
79
- end
80
- end
81
-
82
- it "should properly compose message" do
83
- mail = mock_client.compose do
84
- from "test@gmail.com"
85
- to "friend@gmail.com"
86
- subject "Hello world!"
87
- end
88
- mail.from.should == ["test@gmail.com"]
89
- mail.to.should == ["friend@gmail.com"]
90
- mail.subject.should == "Hello world!"
91
- end
92
-
93
- it "#compose should automatically add `from` header when it is not specified" do
94
- mail = mock_client.compose
95
- mail.from.should == [TEST_ACCOUNT[0]]
96
- mail = mock_client.compose(Mail.new)
97
- mail.from.should == [TEST_ACCOUNT[0]]
98
- mail = mock_client.compose {}
99
- mail.from.should == [TEST_ACCOUNT[0]]
100
- end
101
-
102
- it "should deliver inline composed email" do
103
- mock_client do |client|
104
- client.deliver do
105
- to TEST_ACCOUNT[0]
106
- subject "Hello world!"
107
- body "Yeah, hello there!"
108
- end.should be_true
109
- end
110
- end
111
-
112
- it "should not raise error when mail can't be delivered and errors are disabled" do
113
- lambda {
114
- client = mock_client
115
- client.deliver(Mail.new {}).should be_false
116
- }.should_not raise_error
117
- end
118
-
119
- it "should raise error when mail can't be delivered and errors are disabled" do
120
- lambda {
121
- client = mock_client
122
- client.deliver!(Mail.new {})
123
- }.should raise_error(Gmail::Client::DeliveryError)
124
- end
125
-
126
- it "should properly switch to given mailbox" do
127
- mock_client do |client|
128
- mailbox = client.mailbox("INBOX")
129
- mailbox.should be_kind_of(Gmail::Mailbox)
130
- mailbox.name.should == "INBOX"
131
- end
132
- end
133
-
134
- it "should properly switch to given mailbox using block style" do
135
- mock_client do |client|
136
- client.mailbox("INBOX") do |mailbox|
137
- mailbox.should be_kind_of(Gmail::Mailbox)
138
- mailbox.name.should == "INBOX"
139
- end
140
- end
141
- end
142
-
143
- context "labels" do
144
- subject {
145
- client = Gmail::Client::Plain.new(*TEST_ACCOUNT)
146
- client.connect
147
- client.labels
148
- }
149
-
150
- it "should get list of all available labels" do
151
- labels = subject
152
- labels.all.should include("INBOX")
153
- end
154
-
155
- it "should be able to check if there is given label defined" do
156
- labels = subject
157
- labels.exists?("INBOX").should be_true
158
- labels.exists?("FOOBAR").should be_false
159
- end
160
-
161
- it "should be able to create given label" do
162
- labels = subject
163
- labels.create("MYLABEL")
164
- labels.exists?("MYLABEL").should be_true
165
- labels.create("MYLABEL").should be_false
166
- labels.delete("MYLABEL")
167
- end
168
-
169
- it "should be able to remove existing label" do
170
- labels = subject
171
- labels.create("MYLABEL")
172
- labels.delete("MYLABEL").should be_true
173
- labels.exists?("MYLABEL").should be_false
174
- labels.delete("MYLABEL").should be_false
175
- end
176
- end
177
- end
178
- end
@@ -1,51 +0,0 @@
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