gmail 0.6.0 → 0.7.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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +27 -27
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +53 -13
  6. data/.rubocop_todo.yml +299 -239
  7. data/.travis.yml +19 -19
  8. data/CHANGELOG.md +152 -145
  9. data/Gemfile +5 -3
  10. data/LICENSE +21 -21
  11. data/README.md +380 -355
  12. data/Rakefile +44 -46
  13. data/gmail.gemspec +32 -34
  14. data/lib/gmail.rb +72 -78
  15. data/lib/gmail/client.rb +35 -34
  16. data/lib/gmail/client/base.rb +244 -229
  17. data/lib/gmail/client/plain.rb +24 -24
  18. data/lib/gmail/client/xoauth.rb +67 -68
  19. data/lib/gmail/client/xoauth2.rb +39 -39
  20. data/lib/gmail/imap_extensions.rb +156 -159
  21. data/lib/gmail/labels.rb +80 -79
  22. data/lib/gmail/mailbox.rb +178 -175
  23. data/lib/gmail/message.rb +212 -207
  24. data/lib/gmail/version.rb +3 -3
  25. data/spec/account.yml.example +1 -1
  26. data/spec/account.yml.obfus +2 -2
  27. data/spec/gmail/client/base_spec.rb +5 -5
  28. data/spec/gmail/client/plain_spec.rb +169 -169
  29. data/spec/gmail/client/xoauth2_spec.rb +186 -186
  30. data/spec/gmail/client/xoauth_spec.rb +5 -5
  31. data/spec/gmail/client_spec.rb +5 -5
  32. data/spec/gmail/imap_extensions_spec.rb +47 -47
  33. data/spec/gmail/labels_spec.rb +27 -27
  34. data/spec/gmail/mailbox_spec.rb +84 -84
  35. data/spec/gmail/message_spec.rb +181 -181
  36. data/spec/gmail_spec.rb +40 -39
  37. data/spec/recordings/gmail/_new_connects_with_client_and_give_it_context_when_block_given.yml +61 -28
  38. data/spec/recordings/gmail/_new_connects_with_gmail_service_and_return_valid_connection_object.yml +43 -28
  39. data/spec/recordings/gmail/_new_does_not_raise_error_when_couldn_t_connect_with_given_account.yml +21 -13
  40. data/spec/recordings/gmail/_new_raises_error_when_couldn_t_connect_with_given_account.yml +21 -13
  41. data/spec/recordings/gmail_client_plain/instance/delivers_inline_composed_email.yml +61 -42
  42. data/spec/recordings/gmail_client_plain/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +21 -13
  43. data/spec/recordings/gmail_client_plain/instance/does_not_raise_error_even_though_gmail_account_is_invalid.yml +21 -13
  44. data/spec/recordings/gmail_client_plain/instance/labels/checks_if_there_is_given_label_defined.yml +409 -196
  45. data/spec/recordings/gmail_client_plain/instance/labels/creates_given_label.yml +280 -151
  46. data/spec/recordings/gmail_client_plain/instance/labels/removes_existing_label.yml +271 -146
  47. data/spec/recordings/gmail_client_plain/instance/labels/returns_list_of_all_available_labels.yml +227 -113
  48. data/spec/recordings/gmail_client_plain/instance/properly_logs_in_to_valid_gmail_account.yml +61 -42
  49. data/spec/recordings/gmail_client_plain/instance/properly_logs_out_from_gmail.yml +61 -42
  50. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox.yml +164 -109
  51. data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox_using_block_style.yml +164 -109
  52. data/spec/recordings/gmail_client_plain/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +21 -13
  53. data/spec/recordings/gmail_client_xo_auth2/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +24 -13
  54. data/spec/recordings/gmail_client_xo_auth2/instance/labels/checks_if_there_is_given_label_defined.yml +39 -27
  55. data/spec/recordings/gmail_client_xo_auth2/instance/labels/creates_given_label.yml +52 -39
  56. data/spec/recordings/gmail_client_xo_auth2/instance/labels/removes_existing_label.yml +52 -39
  57. data/spec/recordings/gmail_client_xo_auth2/instance/labels/returns_list_of_all_available_labels.yml +39 -27
  58. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_in_to_valid_gmail_account.yml +26 -15
  59. data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_out_from_gmail.yml +26 -15
  60. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox.yml +63 -40
  61. data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox_using_block_style.yml +63 -40
  62. data/spec/recordings/gmail_client_xo_auth2/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +24 -13
  63. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/all/localizes_into_the_appropriate_label.yml +229 -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 +229 -110
  65. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/drafts/localizes_into_the_appropriate_label.yml +229 -116
  66. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/flagged/localizes_into_the_appropriate_label.yml +229 -116
  67. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/important/localizes_into_the_appropriate_label.yml +229 -116
  68. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/inbox/localizes_into_the_appropriate_label.yml +61 -42
  69. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/junk/localizes_into_the_appropriate_label.yml +229 -116
  70. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/sent/localizes_into_the_appropriate_label.yml +229 -116
  71. data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/trash/localizes_into_the_appropriate_label.yml +229 -116
  72. data/spec/recordings/gmail_mailbox/instance/counts_all_emails.yml +595 -277
  73. data/spec/recordings/gmail_mailbox/instance/finds_messages.yml +1049 -586
  74. data/spec/recordings/gmail_mailbox/instance/waits_once.yml +191 -136
  75. data/spec/recordings/gmail_mailbox/instance/waits_repeatedly.yml +217 -141
  76. data/spec/recordings/gmail_mailbox/instance/waits_with_29-minute_re-issue.yml +188 -136
  77. data/spec/recordings/gmail_mailbox/instance/waits_with_an_unblocked_connection.yml +644 -207
  78. data/spec/recordings/gmail_mailbox/on_initialize/sets_client_and_name.yml +61 -42
  79. data/spec/recordings/gmail_mailbox/on_initialize/works_in_inbox_by_default.yml +61 -42
  80. data/spec/recordings/gmail_message/initialize/sets_prefetch_attrs.yml +1068 -578
  81. data/spec/recordings/gmail_message/initialize/sets_uid_and_mailbox.yml +1068 -580
  82. data/spec/recordings/gmail_message/instance_methods/deletes_itself.yml +1084 -637
  83. data/spec/recordings/gmail_message/instance_methods/marks_itself_read.yml +1137 -682
  84. data/spec/recordings/gmail_message/instance_methods/marks_itself_unread.yml +1153 -686
  85. data/spec/recordings/gmail_message/instance_methods/moves_from_one_tag_to_other.yml +1447 -862
  86. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label.yml +1288 -776
  87. data/spec/recordings/gmail_message/instance_methods/removes_a_given_label_with_old_method.yml +1288 -776
  88. data/spec/recordings/gmail_message/instance_methods/sets_given_label.yml +1165 -690
  89. data/spec/recordings/gmail_message/instance_methods/sets_given_label_with_old_method.yml +1157 -691
  90. data/spec/spec_helper.rb +56 -53
  91. data/spec/support/imap_mock.rb +181 -181
  92. data/spec/support/obfuscation.rb +49 -52
  93. metadata +21 -90
  94. data/spec/recordings/gmail_client_plain/instance/_connection_automatically_logs_in_to_gmail_account_when_it_s_called.yml +0 -42
@@ -1,186 +1,186 @@
1
- require 'spec_helper'
2
-
3
- describe Gmail::Client::XOAuth2 do
4
- subject { Gmail::Client::XOAuth2 }
5
-
6
- context "on initialize" do
7
- it "sets username, oauth2_token and options" do
8
- client = subject.new("test@gmail.com", {
9
- :token => "token",
10
- :foo => :bar
11
- })
12
- expect(client.username).to eq("test@gmail.com")
13
- expect(client.token).to eq({ :token => "token", :foo => :bar })
14
- end
15
-
16
- it "converts simple name to gmail email" do
17
- client = subject.new("test", { :token => "token" })
18
- expect(client.username).to eq("test@gmail.com")
19
- end
20
- end
21
-
22
- context "instance" do
23
- def mock_client(&block)
24
- client = Gmail::Client::XOAuth2.new(*TEST_ACCOUNT)
25
- if block_given?
26
- client.connect
27
- yield client
28
- client.logout
29
- end
30
- client
31
- end
32
-
33
- it "connects to Gmail IMAP service" do
34
- expect(-> {
35
- client = mock_client
36
- expect(client.connect!).to be_truthy
37
- }).to_not raise_error
38
- end
39
-
40
- it "properly logs in to valid Gmail account" do
41
- pending
42
- client = mock_client
43
- expect(client.connect).to be_truthy
44
- expect(client.login).to be_truthy
45
- expect(client).to be_logged_in
46
- client.logout
47
- end
48
-
49
- it "raises error when given Gmail account is invalid and errors enabled" do
50
- expect(-> {
51
- client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
52
- expect(client.connect).to be_truthy
53
- expect(client.login!).not_to be_truthy
54
- }).to raise_error(Gmail::Client::AuthorizationError)
55
- end
56
-
57
- it "does not log in when given Gmail account is invalid" do
58
- expect(-> {
59
- client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
60
- expect(client.connect).to be_truthy
61
- expect(client.login).not_to be_truthy
62
- }).to_not raise_error
63
- end
64
-
65
- it "properly logs out from Gmail" do
66
- pending
67
- client = mock_client
68
- client.connect
69
- expect(client.login).to be_truthy
70
- expect(client.logout).to be_truthy
71
- expect(client).not_to be_logged_in
72
- end
73
-
74
- it "#connection automatically logs in to Gmail account when it's called" do
75
- mock_client do |client|
76
- expect(client).to receive(:login).once.and_return(false)
77
- expect(client.connection).not_to be_nil
78
- end
79
- end
80
-
81
- it "properly composes message" do
82
- mail = mock_client.compose do
83
- from "test@gmail.com"
84
- to "friend@gmail.com"
85
- subject "Hello world!"
86
- end
87
- expect(mail.from).to eq(["test@gmail.com"])
88
- expect(mail.to).to eq(["friend@gmail.com"])
89
- expect(mail.subject).to eq("Hello world!")
90
- end
91
-
92
- it "#compose automatically adds `from` header when it is not specified" do
93
- mail = mock_client.compose
94
- expect(mail.from).to eq([TEST_ACCOUNT[0]])
95
- mail = mock_client.compose(Mail.new)
96
- expect(mail.from).to eq([TEST_ACCOUNT[0]])
97
- mail = mock_client.compose {}
98
- expect(mail.from).to eq([TEST_ACCOUNT[0]])
99
- end
100
-
101
- it "delivers inline composed email" do
102
- pending
103
- mock_client do |client|
104
- response = client.deliver do
105
- to TEST_ACCOUNT[0]
106
- subject "Hello world!"
107
- body "Yeah, hello there!"
108
- end
109
-
110
- expect(response).to be_truthy
111
- end
112
- end
113
-
114
- it "does not raise error when mail can't be delivered and errors are disabled" do
115
- expect(-> {
116
- client = mock_client
117
- expect(client.deliver(Mail.new {})).to be_falsey
118
- }).to_not raise_error
119
- end
120
-
121
- it "raises error when mail can't be delivered and errors are disabled" do
122
- expect(-> {
123
- client = mock_client
124
- client.deliver!(Mail.new {})
125
- }).to raise_error(Gmail::Client::DeliveryError)
126
- end
127
-
128
- it "properly switches to given mailbox" do
129
- pending
130
- mock_client do |client|
131
- mailbox = client.mailbox("TEST")
132
- expect(mailbox).to be_kind_of(Gmail::Mailbox)
133
- expect(mailbox.name).to eq("TEST")
134
- end
135
- end
136
-
137
- it "properly switches to given mailbox using block style" do
138
- pending
139
- mock_client do |client|
140
- client.mailbox("TEST") do |mailbox|
141
- expect(mailbox).to be_kind_of(Gmail::Mailbox)
142
- expect(mailbox.name).to eq("TEST")
143
- end
144
- end
145
- end
146
-
147
- context "labels" do
148
- subject {
149
- client = Gmail::Client::XOAuth2.new(*TEST_ACCOUNT)
150
- client.connect
151
- client.labels
152
- }
153
-
154
- it "returns list of all available labels" do
155
- pending
156
- labels = subject
157
- expect(labels.all).to include("TEST", "INBOX")
158
- end
159
-
160
- it "checks if there is given label defined" do
161
- pending
162
- labels = subject
163
- expect(labels.exists?("TEST")).to be_truthy
164
- expect(labels.exists?("FOOBAR")).to be_falsey
165
- end
166
-
167
- it "creates given label" do
168
- pending
169
- labels = subject
170
- labels.create("MYLABEL")
171
- expect(labels.exists?("MYLABEL")).to be_truthy
172
- expect(labels.create("MYLABEL")).to be_falsey
173
- labels.delete("MYLABEL")
174
- end
175
-
176
- it "removes existing label" do
177
- pending
178
- labels = subject
179
- labels.create("MYLABEL")
180
- expect(labels.delete("MYLABEL")).to be_truthy
181
- expect(labels.exists?("MYLABEL")).to be_falsey
182
- expect(labels.delete("MYLABEL")).to be_falsey
183
- end
184
- end
185
- end
186
- end
1
+ require 'spec_helper'
2
+
3
+ describe Gmail::Client::XOAuth2 do
4
+ subject { Gmail::Client::XOAuth2 }
5
+
6
+ context "on initialize" do
7
+ it "sets username, oauth2_token and options" do
8
+ client = subject.new("test@gmail.com", {
9
+ :token => "token",
10
+ :foo => :bar
11
+ })
12
+ expect(client.username).to eq("test@gmail.com")
13
+ expect(client.token).to eq({ :token => "token", :foo => :bar })
14
+ end
15
+
16
+ it "converts simple name to gmail email" do
17
+ client = subject.new("test", { :token => "token" })
18
+ expect(client.username).to eq("test@gmail.com")
19
+ end
20
+ end
21
+
22
+ context "instance" do
23
+ def mock_client(&block)
24
+ client = Gmail::Client::XOAuth2.new(*TEST_ACCOUNT)
25
+ if block_given?
26
+ client.connect
27
+ yield client
28
+ client.logout
29
+ end
30
+ client
31
+ end
32
+
33
+ it "connects to Gmail IMAP service" do
34
+ expect(-> do
35
+ client = mock_client
36
+ expect(client.connect!).to be_truthy
37
+ end).to_not raise_error
38
+ end
39
+
40
+ it "properly logs in to valid Gmail account" do
41
+ pending
42
+ client = mock_client
43
+ expect(client.connect).to be_truthy
44
+ expect(client.login).to be_truthy
45
+ expect(client).to be_logged_in
46
+ client.logout
47
+ end
48
+
49
+ it "raises error when given Gmail account is invalid and errors enabled" do
50
+ expect(-> do
51
+ client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
52
+ expect(client.connect).to be_truthy
53
+ expect(client.login!).not_to be_truthy
54
+ end).to raise_error(Gmail::Client::AuthorizationError)
55
+ end
56
+
57
+ it "does not log in when given Gmail account is invalid" do
58
+ expect(-> do
59
+ client = Gmail::Client::XOAuth2.new("foo", { :token => "bar" })
60
+ expect(client.connect).to be_truthy
61
+ expect(client.login).not_to be_truthy
62
+ end).to_not raise_error
63
+ end
64
+
65
+ it "properly logs out from Gmail" do
66
+ pending
67
+ client = mock_client
68
+ client.connect
69
+ expect(client.login).to be_truthy
70
+ expect(client.logout).to be_truthy
71
+ expect(client).not_to be_logged_in
72
+ end
73
+
74
+ it "#connection automatically logs in to Gmail account when it's called" do
75
+ mock_client do |client|
76
+ expect(client).to receive(:login).once.and_return(false)
77
+ expect(client.connection).not_to be_nil
78
+ end
79
+ end
80
+
81
+ it "properly composes message" do
82
+ mail = mock_client.compose do
83
+ from "test@gmail.com"
84
+ to "friend@gmail.com"
85
+ subject "Hello world!"
86
+ end
87
+ expect(mail.from).to eq(["test@gmail.com"])
88
+ expect(mail.to).to eq(["friend@gmail.com"])
89
+ expect(mail.subject).to eq("Hello world!")
90
+ end
91
+
92
+ it "#compose automatically adds `from` header when it is not specified" do
93
+ mail = mock_client.compose
94
+ expect(mail.from).to eq([TEST_ACCOUNT[0]])
95
+ mail = mock_client.compose(Mail.new)
96
+ expect(mail.from).to eq([TEST_ACCOUNT[0]])
97
+ mail = mock_client.compose {}
98
+ expect(mail.from).to eq([TEST_ACCOUNT[0]])
99
+ end
100
+
101
+ it "delivers inline composed email" do
102
+ pending
103
+ mock_client do |client|
104
+ response = client.deliver do
105
+ to TEST_ACCOUNT[0]
106
+ subject "Hello world!"
107
+ body "Yeah, hello there!"
108
+ end
109
+
110
+ expect(response).to be_truthy
111
+ end
112
+ end
113
+
114
+ it "does not raise error when mail can't be delivered and errors are disabled" do
115
+ expect(-> do
116
+ client = mock_client
117
+ expect(client.deliver(Mail.new {})).to be_falsey
118
+ end).to_not raise_error
119
+ end
120
+
121
+ it "raises error when mail can't be delivered and errors are disabled" do
122
+ expect(-> do
123
+ client = mock_client
124
+ client.deliver!(Mail.new {})
125
+ end).to raise_error(Gmail::Client::DeliveryError)
126
+ end
127
+
128
+ it "properly switches to given mailbox" do
129
+ pending
130
+ mock_client do |client|
131
+ mailbox = client.mailbox("TEST")
132
+ expect(mailbox).to be_kind_of(Gmail::Mailbox)
133
+ expect(mailbox.name).to eq("TEST")
134
+ end
135
+ end
136
+
137
+ it "properly switches to given mailbox using block style" do
138
+ pending
139
+ mock_client do |client|
140
+ client.mailbox("TEST") do |mailbox|
141
+ expect(mailbox).to be_kind_of(Gmail::Mailbox)
142
+ expect(mailbox.name).to eq("TEST")
143
+ end
144
+ end
145
+ end
146
+
147
+ context "labels" do
148
+ subject do
149
+ client = Gmail::Client::XOAuth2.new(*TEST_ACCOUNT)
150
+ client.connect
151
+ client.labels
152
+ end
153
+
154
+ it "returns list of all available labels" do
155
+ pending
156
+ labels = subject
157
+ expect(labels.all).to include("TEST", "INBOX")
158
+ end
159
+
160
+ it "checks if there is given label defined" do
161
+ pending
162
+ labels = subject
163
+ expect(labels.exists?("TEST")).to be_truthy
164
+ expect(labels.exists?("FOOBAR")).to be_falsey
165
+ end
166
+
167
+ it "creates given label" do
168
+ pending
169
+ labels = subject
170
+ labels.create("MYLABEL")
171
+ expect(labels.exists?("MYLABEL")).to be_truthy
172
+ expect(labels.create("MYLABEL")).to be_falsey
173
+ labels.delete("MYLABEL")
174
+ end
175
+
176
+ it "removes existing label" do
177
+ pending
178
+ labels = subject
179
+ labels.create("MYLABEL")
180
+ expect(labels.delete("MYLABEL")).to be_truthy
181
+ expect(labels.exists?("MYLABEL")).to be_falsey
182
+ expect(labels.delete("MYLABEL")).to be_falsey
183
+ end
184
+ end
185
+ end
186
+ end
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
-
3
- describe Gmail::Client::XOAuth do
4
- skip "add some examples to (or delete) #{__FILE__}"
5
- end
1
+ require 'spec_helper'
2
+
3
+ describe Gmail::Client::XOAuth do
4
+ skip "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
-
3
- describe Gmail::Client do
4
- skip "add some examples to (or delete) #{__FILE__}"
5
- end
1
+ require 'spec_helper'
2
+
3
+ describe Gmail::Client do
4
+ skip "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -1,47 +1,47 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- require 'net/imap'
4
- require 'gmail/imap_extensions'
5
-
6
- describe Gmail::ImapExtensions do
7
- it 'does not modify arity' do
8
- Gmail::ImapExtensions::patch_net_imap_response_parser
9
- expect(Net::IMAP::ResponseParser.new).to respond_to(:msg_att).with(0).arguments
10
- expect(Net::IMAP::ResponseParser.new).to respond_to(:msg_att).with(1).arguments
11
- end
12
-
13
- it 'parses 1 label without spaces correctly' do
14
- Gmail::ImapExtensions::patch_net_imap_response_parser
15
- server_response = %[* 1 FETCH (X-GM-LABELS (Hello))\r\n]
16
- parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
17
- expect(parsed_labels).to contain_exactly("Hello")
18
- end
19
-
20
- it 'parses 2 label without spaces correctly' do
21
- Gmail::ImapExtensions::patch_net_imap_response_parser
22
- server_response = %[* 1 FETCH (X-GM-LABELS (Hello World))\r\n]
23
- parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
24
- expect(parsed_labels).to contain_exactly("World", "Hello")
25
- end
26
-
27
- it 'parses 1 label with a space correctly' do
28
- Gmail::ImapExtensions::patch_net_imap_response_parser
29
- server_response = %[* 1 FETCH (X-GM-LABELS ("Hello World"))\r\n]
30
- parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
31
- expect(parsed_labels).to contain_exactly("Hello World")
32
- end
33
-
34
- it 'parses 2 labels, each with a space, correctly' do
35
- Gmail::ImapExtensions::patch_net_imap_response_parser
36
- server_response = %[* 1 FETCH (X-GM-LABELS ("Foo Bar" "Hello World"))\r\n]
37
- parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
38
- expect(parsed_labels).to contain_exactly("Hello World", "Foo Bar")
39
- end
40
-
41
- it 'parses a mixture of space and non-space labels correctly' do
42
- Gmail::ImapExtensions::patch_net_imap_response_parser
43
- server_response = %[* 1 FETCH (X-GM-LABELS ("Foo Bar" "\\Important" Hello World))\r\n]
44
- parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
45
- expect(parsed_labels).to contain_exactly(:Important, "Hello", "World", "Foo Bar")
46
- end
47
- end
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'net/imap'
4
+ require 'gmail/imap_extensions'
5
+
6
+ describe Gmail::ImapExtensions do
7
+ it 'does not modify arity' do
8
+ Gmail::ImapExtensions::patch_net_imap_response_parser
9
+ expect(Net::IMAP::ResponseParser.new).to respond_to(:msg_att).with(0).arguments
10
+ expect(Net::IMAP::ResponseParser.new).to respond_to(:msg_att).with(1).arguments
11
+ end
12
+
13
+ it 'parses 1 label without spaces correctly' do
14
+ Gmail::ImapExtensions::patch_net_imap_response_parser
15
+ server_response = %[* 1 FETCH (X-GM-LABELS (Hello))\r\n]
16
+ parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
17
+ expect(parsed_labels).to contain_exactly("Hello")
18
+ end
19
+
20
+ it 'parses 2 label without spaces correctly' do
21
+ Gmail::ImapExtensions::patch_net_imap_response_parser
22
+ server_response = %[* 1 FETCH (X-GM-LABELS (Hello World))\r\n]
23
+ parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
24
+ expect(parsed_labels).to contain_exactly("World", "Hello")
25
+ end
26
+
27
+ it 'parses 1 label with a space correctly' do
28
+ Gmail::ImapExtensions::patch_net_imap_response_parser
29
+ server_response = %[* 1 FETCH (X-GM-LABELS ("Hello World"))\r\n]
30
+ parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
31
+ expect(parsed_labels).to contain_exactly("Hello World")
32
+ end
33
+
34
+ it 'parses 2 labels, each with a space, correctly' do
35
+ Gmail::ImapExtensions::patch_net_imap_response_parser
36
+ server_response = %[* 1 FETCH (X-GM-LABELS ("Foo Bar" "Hello World"))\r\n]
37
+ parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
38
+ expect(parsed_labels).to contain_exactly("Hello World", "Foo Bar")
39
+ end
40
+
41
+ it 'parses a mixture of space and non-space labels correctly' do
42
+ Gmail::ImapExtensions::patch_net_imap_response_parser
43
+ server_response = %[* 1 FETCH (X-GM-LABELS ("Foo Bar" "\\Important" Hello World))\r\n]
44
+ parsed_labels = Net::IMAP::ResponseParser.new.parse(server_response).data.attr["X-GM-LABELS"]
45
+ expect(parsed_labels).to contain_exactly(:Important, "Hello", "World", "Foo Bar")
46
+ end
47
+ end