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.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +27 -27
- data/.rspec +1 -1
- data/.rubocop.yml +53 -13
- data/.rubocop_todo.yml +299 -239
- data/.travis.yml +19 -19
- data/CHANGELOG.md +152 -145
- data/Gemfile +5 -3
- data/LICENSE +21 -21
- data/README.md +380 -355
- data/Rakefile +44 -46
- data/gmail.gemspec +32 -34
- data/lib/gmail.rb +72 -78
- data/lib/gmail/client.rb +35 -34
- data/lib/gmail/client/base.rb +244 -229
- data/lib/gmail/client/plain.rb +24 -24
- data/lib/gmail/client/xoauth.rb +67 -68
- data/lib/gmail/client/xoauth2.rb +39 -39
- data/lib/gmail/imap_extensions.rb +156 -159
- data/lib/gmail/labels.rb +80 -79
- data/lib/gmail/mailbox.rb +178 -175
- data/lib/gmail/message.rb +212 -207
- data/lib/gmail/version.rb +3 -3
- data/spec/account.yml.example +1 -1
- data/spec/account.yml.obfus +2 -2
- data/spec/gmail/client/base_spec.rb +5 -5
- data/spec/gmail/client/plain_spec.rb +169 -169
- data/spec/gmail/client/xoauth2_spec.rb +186 -186
- data/spec/gmail/client/xoauth_spec.rb +5 -5
- data/spec/gmail/client_spec.rb +5 -5
- data/spec/gmail/imap_extensions_spec.rb +47 -47
- data/spec/gmail/labels_spec.rb +27 -27
- data/spec/gmail/mailbox_spec.rb +84 -84
- data/spec/gmail/message_spec.rb +181 -181
- data/spec/gmail_spec.rb +40 -39
- data/spec/recordings/gmail/_new_connects_with_client_and_give_it_context_when_block_given.yml +61 -28
- data/spec/recordings/gmail/_new_connects_with_gmail_service_and_return_valid_connection_object.yml +43 -28
- data/spec/recordings/gmail/_new_does_not_raise_error_when_couldn_t_connect_with_given_account.yml +21 -13
- data/spec/recordings/gmail/_new_raises_error_when_couldn_t_connect_with_given_account.yml +21 -13
- data/spec/recordings/gmail_client_plain/instance/delivers_inline_composed_email.yml +61 -42
- data/spec/recordings/gmail_client_plain/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +21 -13
- data/spec/recordings/gmail_client_plain/instance/does_not_raise_error_even_though_gmail_account_is_invalid.yml +21 -13
- data/spec/recordings/gmail_client_plain/instance/labels/checks_if_there_is_given_label_defined.yml +409 -196
- data/spec/recordings/gmail_client_plain/instance/labels/creates_given_label.yml +280 -151
- data/spec/recordings/gmail_client_plain/instance/labels/removes_existing_label.yml +271 -146
- data/spec/recordings/gmail_client_plain/instance/labels/returns_list_of_all_available_labels.yml +227 -113
- data/spec/recordings/gmail_client_plain/instance/properly_logs_in_to_valid_gmail_account.yml +61 -42
- data/spec/recordings/gmail_client_plain/instance/properly_logs_out_from_gmail.yml +61 -42
- data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox.yml +164 -109
- data/spec/recordings/gmail_client_plain/instance/properly_switches_to_given_mailbox_using_block_style.yml +164 -109
- data/spec/recordings/gmail_client_plain/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +21 -13
- data/spec/recordings/gmail_client_xo_auth2/instance/does_not_log_in_when_given_gmail_account_is_invalid.yml +24 -13
- data/spec/recordings/gmail_client_xo_auth2/instance/labels/checks_if_there_is_given_label_defined.yml +39 -27
- data/spec/recordings/gmail_client_xo_auth2/instance/labels/creates_given_label.yml +52 -39
- data/spec/recordings/gmail_client_xo_auth2/instance/labels/removes_existing_label.yml +52 -39
- data/spec/recordings/gmail_client_xo_auth2/instance/labels/returns_list_of_all_available_labels.yml +39 -27
- data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_in_to_valid_gmail_account.yml +26 -15
- data/spec/recordings/gmail_client_xo_auth2/instance/properly_logs_out_from_gmail.yml +26 -15
- data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox.yml +63 -40
- data/spec/recordings/gmail_client_xo_auth2/instance/properly_switches_to_given_mailbox_using_block_style.yml +63 -40
- data/spec/recordings/gmail_client_xo_auth2/instance/raises_error_when_given_gmail_account_is_invalid_and_errors_enabled.yml +24 -13
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/all/localizes_into_the_appropriate_label.yml +229 -116
- 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
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/drafts/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/flagged/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/important/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/inbox/localizes_into_the_appropriate_label.yml +61 -42
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/junk/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/sent/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_labels/localize/when_given_the_xl_is_tflag/trash/localizes_into_the_appropriate_label.yml +229 -116
- data/spec/recordings/gmail_mailbox/instance/counts_all_emails.yml +595 -277
- data/spec/recordings/gmail_mailbox/instance/finds_messages.yml +1049 -586
- data/spec/recordings/gmail_mailbox/instance/waits_once.yml +191 -136
- data/spec/recordings/gmail_mailbox/instance/waits_repeatedly.yml +217 -141
- data/spec/recordings/gmail_mailbox/instance/waits_with_29-minute_re-issue.yml +188 -136
- data/spec/recordings/gmail_mailbox/instance/waits_with_an_unblocked_connection.yml +644 -207
- data/spec/recordings/gmail_mailbox/on_initialize/sets_client_and_name.yml +61 -42
- data/spec/recordings/gmail_mailbox/on_initialize/works_in_inbox_by_default.yml +61 -42
- data/spec/recordings/gmail_message/initialize/sets_prefetch_attrs.yml +1068 -578
- data/spec/recordings/gmail_message/initialize/sets_uid_and_mailbox.yml +1068 -580
- data/spec/recordings/gmail_message/instance_methods/deletes_itself.yml +1084 -637
- data/spec/recordings/gmail_message/instance_methods/marks_itself_read.yml +1137 -682
- data/spec/recordings/gmail_message/instance_methods/marks_itself_unread.yml +1153 -686
- data/spec/recordings/gmail_message/instance_methods/moves_from_one_tag_to_other.yml +1447 -862
- data/spec/recordings/gmail_message/instance_methods/removes_a_given_label.yml +1288 -776
- data/spec/recordings/gmail_message/instance_methods/removes_a_given_label_with_old_method.yml +1288 -776
- data/spec/recordings/gmail_message/instance_methods/sets_given_label.yml +1165 -690
- data/spec/recordings/gmail_message/instance_methods/sets_given_label_with_old_method.yml +1157 -691
- data/spec/spec_helper.rb +56 -53
- data/spec/support/imap_mock.rb +181 -181
- data/spec/support/obfuscation.rb +49 -52
- metadata +21 -90
- data/spec/recordings/gmail_client_plain/instance/_connection_automatically_logs_in_to_gmail_account_when_it_s_called.yml +0 -42
data/spec/gmail/labels_spec.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Gmail::Labels do
|
4
|
-
context '#localize' do
|
5
|
-
context 'when given the XLIST flag ' do
|
6
|
-
[:Inbox, :All, :Drafts, :Sent, :Trash, :Important, :Junk, :Flagged].each do |flag|
|
7
|
-
context flag do
|
8
|
-
it 'localizes into the appropriate label' do
|
9
|
-
localized = ""
|
10
|
-
mock_client { |client| localized = client.labels.localize(flag) }
|
11
|
-
expect(localized).to be_a_kind_of(String)
|
12
|
-
expect(localized).to match(/\[Gmail|Google Mail\]|Inbox/i)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'and the mailbox does not exist' do
|
18
|
-
it 'returns the mailbox name as a string' do
|
19
|
-
localized = ""
|
20
|
-
mock_client { |client| localized = client.labels.localize(:All) }
|
21
|
-
expect(localized).to be_a_kind_of(String)
|
22
|
-
expect(localized).to eq 'All'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gmail::Labels do
|
4
|
+
context '#localize' do
|
5
|
+
context 'when given the XLIST flag ' do
|
6
|
+
[:Inbox, :All, :Drafts, :Sent, :Trash, :Important, :Junk, :Flagged].each do |flag|
|
7
|
+
context flag do
|
8
|
+
it 'localizes into the appropriate label' do
|
9
|
+
localized = ""
|
10
|
+
mock_client { |client| localized = client.labels.localize(flag) }
|
11
|
+
expect(localized).to be_a_kind_of(String)
|
12
|
+
expect(localized).to match(/\[Gmail|Google Mail\]|Inbox/i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'and the mailbox does not exist' do
|
18
|
+
it 'returns the mailbox name as a string' do
|
19
|
+
localized = ""
|
20
|
+
mock_client { |client| localized = client.labels.localize(:All) }
|
21
|
+
expect(localized).to be_a_kind_of(String)
|
22
|
+
expect(localized).to eq '[Gmail]/All Mail'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/gmail/mailbox_spec.rb
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Gmail::Mailbox do
|
4
|
-
subject { Gmail::Mailbox }
|
5
|
-
|
6
|
-
context "on initialize" do
|
7
|
-
it "sets client and name" do
|
8
|
-
within_gmail do |gmail|
|
9
|
-
mailbox = subject.new(gmail, "TEST")
|
10
|
-
expect(mailbox.instance_variable_get("@gmail")).to eq(gmail)
|
11
|
-
expect(mailbox.name).to eq("TEST")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "works in INBOX by default" do
|
16
|
-
within_gmail do |gmail|
|
17
|
-
mailbox = subject.new(@gmail)
|
18
|
-
expect(mailbox.name).to eq("INBOX")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "instance" do
|
24
|
-
it "counts all emails" do
|
25
|
-
mock_mailbox do |mailbox|
|
26
|
-
expect(mailbox.count).to be > 0
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "finds messages" do
|
31
|
-
mock_mailbox do |mailbox|
|
32
|
-
message = mailbox.emails.first
|
33
|
-
mailbox.emails(:all, :from => message.from.first.name) == message.from.first.name
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "waits once" do
|
38
|
-
mock_mailbox do |mailbox|
|
39
|
-
response = nil
|
40
|
-
mailbox.wait_once { |r| response = r }
|
41
|
-
expect(response).to be_kind_of(Net::IMAP::UntaggedResponse)
|
42
|
-
expect(response.name).to eq("EXISTS")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "waits with an unblocked connection" do
|
47
|
-
mock_mailbox do |mailbox|
|
48
|
-
mailbox.wait_once do |r|
|
49
|
-
expect(mailbox.count).to be > 0
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "waits repeatedly" do
|
55
|
-
responses = []
|
56
|
-
mock_mailbox do |mailbox|
|
57
|
-
mailbox.wait do |r|
|
58
|
-
responses << r
|
59
|
-
break if responses.size == 2
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
expect(responses.size).to eq(2)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "waits with 29-minute re-issue" do
|
67
|
-
client = mock_client
|
68
|
-
expect(client.conn).to receive(:idle).and_call_original.at_least(:twice)
|
69
|
-
|
70
|
-
mailbox = client.inbox
|
71
|
-
mailbox.wait_once(idle_timeout
|
72
|
-
end
|
73
|
-
|
74
|
-
it "performs full text search of message bodies" do
|
75
|
-
skip "This can wait..."
|
76
|
-
# mock_mailbox do |mailbox|
|
77
|
-
# message = mailbox.emails.first
|
78
|
-
# body = message.parts.blank? ? message.body.decoded : message.parts[0].body.decoded
|
79
|
-
# emails = mailbox.emails(:search => body.split(' ').first)
|
80
|
-
# emails.size.should > 0
|
81
|
-
# end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gmail::Mailbox do
|
4
|
+
subject { Gmail::Mailbox }
|
5
|
+
|
6
|
+
context "on initialize" do
|
7
|
+
it "sets client and name" do
|
8
|
+
within_gmail do |gmail|
|
9
|
+
mailbox = subject.new(gmail, "TEST")
|
10
|
+
expect(mailbox.instance_variable_get("@gmail")).to eq(gmail)
|
11
|
+
expect(mailbox.name).to eq("TEST")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "works in INBOX by default" do
|
16
|
+
within_gmail do |gmail|
|
17
|
+
mailbox = subject.new(@gmail)
|
18
|
+
expect(mailbox.name).to eq("INBOX")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "instance" do
|
24
|
+
it "counts all emails" do
|
25
|
+
mock_mailbox do |mailbox|
|
26
|
+
expect(mailbox.count).to be > 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "finds messages" do
|
31
|
+
mock_mailbox do |mailbox|
|
32
|
+
message = mailbox.emails.first
|
33
|
+
mailbox.emails(:all, :from => message.from.first.name) == message.from.first.name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "waits once" do
|
38
|
+
mock_mailbox do |mailbox|
|
39
|
+
response = nil
|
40
|
+
mailbox.wait_once { |r| response = r }
|
41
|
+
expect(response).to be_kind_of(Net::IMAP::UntaggedResponse)
|
42
|
+
expect(response.name).to eq("EXISTS")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "waits with an unblocked connection" do
|
47
|
+
mock_mailbox do |mailbox|
|
48
|
+
mailbox.wait_once do |r|
|
49
|
+
expect(mailbox.count).to be > 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "waits repeatedly" do
|
55
|
+
responses = []
|
56
|
+
mock_mailbox do |mailbox|
|
57
|
+
mailbox.wait do |r|
|
58
|
+
responses << r
|
59
|
+
break if responses.size == 2
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
expect(responses.size).to eq(2)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "waits with 29-minute re-issue" do
|
67
|
+
client = mock_client
|
68
|
+
expect(client.conn).to receive(:idle).and_call_original.at_least(:twice)
|
69
|
+
|
70
|
+
mailbox = client.inbox
|
71
|
+
mailbox.wait_once(:idle_timeout => 0.001)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "performs full text search of message bodies" do
|
75
|
+
skip "This can wait..."
|
76
|
+
# mock_mailbox do |mailbox|
|
77
|
+
# message = mailbox.emails.first
|
78
|
+
# body = message.parts.blank? ? message.body.decoded : message.parts[0].body.decoded
|
79
|
+
# emails = mailbox.emails(:search => body.split(' ').first)
|
80
|
+
# emails.size.should > 0
|
81
|
+
# end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/gmail/message_spec.rb
CHANGED
@@ -1,181 +1,181 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Gmail::Message do
|
4
|
-
describe "initialize" do
|
5
|
-
let(:client) { mock_client }
|
6
|
-
let(:mailbox) { client.mailbox(:all) }
|
7
|
-
|
8
|
-
subject do
|
9
|
-
mailbox.emails.first
|
10
|
-
end
|
11
|
-
|
12
|
-
it "sets uid and mailbox" do
|
13
|
-
expect(subject.instance_variable_get(:@mailbox)).to be_a Gmail::Mailbox
|
14
|
-
expect(subject.instance_variable_get(:@gmail)).to be_a Gmail::Client::Base
|
15
|
-
expect(subject.instance_variable_get(:@uid)).to be_a Integer
|
16
|
-
subject.labels
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets PREFETCH_ATTRS" do
|
20
|
-
expect(subject.uid).to be_a Integer
|
21
|
-
expect(subject.msg_id).to be_a Integer
|
22
|
-
expect(subject.thr_id).to be_a Integer
|
23
|
-
expect(subject.envelope).to be_a Net::IMAP::Envelope
|
24
|
-
expect(subject.message).to be_a Mail::Message
|
25
|
-
expect(subject.flags).to be_a Array
|
26
|
-
expect(subject.labels).to be_a Array
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "mocks" do
|
31
|
-
subject { Gmail::Message.new(double(:mailbox, :name => 'INBOX'), nil) }
|
32
|
-
before { allow_any_instance_of(Gmail::Message).to receive(:fetch).and_return('foo') }
|
33
|
-
|
34
|
-
describe "#mark" do
|
35
|
-
it "marks itself as read" do
|
36
|
-
expect(subject).to receive(:read!).with(no_args).once
|
37
|
-
subject.mark(:read)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "marks itself as unread" do
|
41
|
-
expect(subject).to receive(:unread!).with(no_args).once
|
42
|
-
subject.mark(:unread)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "marks itself as deleted" do
|
46
|
-
expect(subject).to receive(:delete!).with(no_args).once
|
47
|
-
subject.mark(:deleted)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "marks itself as spam" do
|
51
|
-
expect(subject).to receive(:spam!).with(no_args).once
|
52
|
-
subject.mark(:spam)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "marks itself with a flag" do
|
56
|
-
expect(subject).to receive(:flag).with(:my_flag).once
|
57
|
-
subject.mark(:my_flag)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#read!" do
|
62
|
-
it "flags itself as :Seen" do
|
63
|
-
expect(subject).to receive(:flag).with(:Seen).once
|
64
|
-
subject.read!
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "#unread!" do
|
69
|
-
it "unflags :Seen from itself" do
|
70
|
-
expect(subject).to receive(:unflag).with(:Seen).once
|
71
|
-
subject.unread!
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#star!" do
|
76
|
-
it "flags itself as '[Gmail]/Starred'" do
|
77
|
-
expect(subject).to receive(:flag).with(:Flagged).once
|
78
|
-
subject.star!
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe "#unstar!" do
|
83
|
-
it "unflags '[Gmail]/Starred' from itself" do
|
84
|
-
expect(subject).to receive(:unflag).with(:Flagged).once
|
85
|
-
subject.unstar!
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "#spam!" do
|
90
|
-
it "moves itself to the spam folder" do
|
91
|
-
expect(subject).to receive(:add_label).with("\\Spam").once
|
92
|
-
subject.spam!
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "#archive!" do
|
97
|
-
it "removes itself from the inbox" do
|
98
|
-
expect(subject).to receive(:remove_label).with("\\Inbox").once
|
99
|
-
subject.archive!
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "instance methods" do
|
105
|
-
let(:client) { mock_client }
|
106
|
-
let(:message) { client.mailbox(:all).emails(:unread, :from => TEST_ACCOUNT[0].to_s, :subject => "Hello world!").last }
|
107
|
-
|
108
|
-
after { client.logout if client.logged_in? }
|
109
|
-
|
110
|
-
it "sets given label" do
|
111
|
-
message.add_label 'Awesome'
|
112
|
-
message.add_label 'Great'
|
113
|
-
|
114
|
-
expect(message.labels).to include("Awesome")
|
115
|
-
expect(message.labels).to include("Great")
|
116
|
-
expect(message.labels).to include(
|
117
|
-
end
|
118
|
-
|
119
|
-
it "removes a given label" do
|
120
|
-
message.add_label 'Awesome'
|
121
|
-
message.add_label 'Great'
|
122
|
-
|
123
|
-
message.remove_label 'Awesome'
|
124
|
-
expect(message.labels).not_to include("Awesome")
|
125
|
-
expect(message.labels).to include("Great")
|
126
|
-
expect(message.labels).to include(
|
127
|
-
expect(message.flags).not_to include(:Seen)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "sets given label with old method" do
|
131
|
-
message.label! 'Awesome'
|
132
|
-
message.label! 'Great'
|
133
|
-
expect(message.labels).to include("Great")
|
134
|
-
expect(message.labels).to include("Awesome")
|
135
|
-
expect(message.labels).to include(
|
136
|
-
end
|
137
|
-
|
138
|
-
it "removes a given label with old method" do
|
139
|
-
message.add_label 'Awesome'
|
140
|
-
message.add_label 'Great'
|
141
|
-
|
142
|
-
message.remove_label! 'Awesome'
|
143
|
-
expect(message.labels).not_to include("Awesome")
|
144
|
-
expect(message.labels).to include("Great")
|
145
|
-
expect(message.labels).to include(
|
146
|
-
expect(message.flags).not_to include(:Seen)
|
147
|
-
end
|
148
|
-
|
149
|
-
it "moves from one tag to other" do
|
150
|
-
message.add_label 'Awesome'
|
151
|
-
message.remove_label 'Great'
|
152
|
-
|
153
|
-
message.move_to('Great', 'Awesome')
|
154
|
-
expect(message.labels).to include("Great")
|
155
|
-
expect(message.labels).not_to include("Awesome")
|
156
|
-
expect(message.labels).to include(
|
157
|
-
end
|
158
|
-
|
159
|
-
it "marks itself read" do
|
160
|
-
message.mark(:unread)
|
161
|
-
|
162
|
-
message.mark(:read)
|
163
|
-
expect(message.flags).to include(:Seen)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "marks itself unread" do
|
167
|
-
message.mark(:read)
|
168
|
-
|
169
|
-
message.mark(:unread)
|
170
|
-
expect(message.flags).not_to include(:Seen)
|
171
|
-
end
|
172
|
-
|
173
|
-
it "deletes itself" do
|
174
|
-
trash_count = client.mailbox(:trash).emails.count
|
175
|
-
|
176
|
-
message.delete!
|
177
|
-
|
178
|
-
expect(client.mailbox(:trash).emails.count).to eq(trash_count + 1)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gmail::Message do
|
4
|
+
describe "initialize" do
|
5
|
+
let(:client) { mock_client }
|
6
|
+
let(:mailbox) { client.mailbox(:all) }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
mailbox.emails.first
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets uid and mailbox" do
|
13
|
+
expect(subject.instance_variable_get(:@mailbox)).to be_a Gmail::Mailbox
|
14
|
+
expect(subject.instance_variable_get(:@gmail)).to be_a Gmail::Client::Base
|
15
|
+
expect(subject.instance_variable_get(:@uid)).to be_a Integer
|
16
|
+
subject.labels
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets PREFETCH_ATTRS" do
|
20
|
+
expect(subject.uid).to be_a Integer
|
21
|
+
expect(subject.msg_id).to be_a Integer
|
22
|
+
expect(subject.thr_id).to be_a Integer
|
23
|
+
expect(subject.envelope).to be_a Net::IMAP::Envelope
|
24
|
+
expect(subject.message).to be_a Mail::Message
|
25
|
+
expect(subject.flags).to be_a Array
|
26
|
+
expect(subject.labels).to be_a Array
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "mocks" do
|
31
|
+
subject { Gmail::Message.new(double(:mailbox, :name => 'INBOX'), nil) }
|
32
|
+
before { allow_any_instance_of(Gmail::Message).to receive(:fetch).and_return('foo') }
|
33
|
+
|
34
|
+
describe "#mark" do
|
35
|
+
it "marks itself as read" do
|
36
|
+
expect(subject).to receive(:read!).with(no_args).once
|
37
|
+
subject.mark(:read)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "marks itself as unread" do
|
41
|
+
expect(subject).to receive(:unread!).with(no_args).once
|
42
|
+
subject.mark(:unread)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "marks itself as deleted" do
|
46
|
+
expect(subject).to receive(:delete!).with(no_args).once
|
47
|
+
subject.mark(:deleted)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "marks itself as spam" do
|
51
|
+
expect(subject).to receive(:spam!).with(no_args).once
|
52
|
+
subject.mark(:spam)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "marks itself with a flag" do
|
56
|
+
expect(subject).to receive(:flag).with(:my_flag).once
|
57
|
+
subject.mark(:my_flag)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#read!" do
|
62
|
+
it "flags itself as :Seen" do
|
63
|
+
expect(subject).to receive(:flag).with(:Seen).once
|
64
|
+
subject.read!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#unread!" do
|
69
|
+
it "unflags :Seen from itself" do
|
70
|
+
expect(subject).to receive(:unflag).with(:Seen).once
|
71
|
+
subject.unread!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#star!" do
|
76
|
+
it "flags itself as '[Gmail]/Starred'" do
|
77
|
+
expect(subject).to receive(:flag).with(:Flagged).once
|
78
|
+
subject.star!
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#unstar!" do
|
83
|
+
it "unflags '[Gmail]/Starred' from itself" do
|
84
|
+
expect(subject).to receive(:unflag).with(:Flagged).once
|
85
|
+
subject.unstar!
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#spam!" do
|
90
|
+
it "moves itself to the spam folder" do
|
91
|
+
expect(subject).to receive(:add_label).with("\\Spam").once
|
92
|
+
subject.spam!
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#archive!" do
|
97
|
+
it "removes itself from the inbox" do
|
98
|
+
expect(subject).to receive(:remove_label).with("\\Inbox").once
|
99
|
+
subject.archive!
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "instance methods" do
|
105
|
+
let(:client) { mock_client }
|
106
|
+
let(:message) { client.mailbox(:all).emails(:unread, :from => TEST_ACCOUNT[0].to_s, :subject => "Hello world!").last }
|
107
|
+
|
108
|
+
after { client.logout if client.logged_in? }
|
109
|
+
|
110
|
+
it "sets given label" do
|
111
|
+
message.add_label 'Awesome'
|
112
|
+
message.add_label 'Great'
|
113
|
+
|
114
|
+
expect(message.labels).to include("Awesome")
|
115
|
+
expect(message.labels).to include("Great")
|
116
|
+
expect(message.labels).to include(:Inbox)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "removes a given label" do
|
120
|
+
message.add_label 'Awesome'
|
121
|
+
message.add_label 'Great'
|
122
|
+
|
123
|
+
message.remove_label 'Awesome'
|
124
|
+
expect(message.labels).not_to include("Awesome")
|
125
|
+
expect(message.labels).to include("Great")
|
126
|
+
expect(message.labels).to include(:Inbox)
|
127
|
+
expect(message.flags).not_to include(:Seen)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "sets given label with old method" do
|
131
|
+
message.label! 'Awesome'
|
132
|
+
message.label! 'Great'
|
133
|
+
expect(message.labels).to include("Great")
|
134
|
+
expect(message.labels).to include("Awesome")
|
135
|
+
expect(message.labels).to include(:Inbox)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "removes a given label with old method" do
|
139
|
+
message.add_label 'Awesome'
|
140
|
+
message.add_label 'Great'
|
141
|
+
|
142
|
+
message.remove_label! 'Awesome'
|
143
|
+
expect(message.labels).not_to include("Awesome")
|
144
|
+
expect(message.labels).to include("Great")
|
145
|
+
expect(message.labels).to include(:Inbox)
|
146
|
+
expect(message.flags).not_to include(:Seen)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "moves from one tag to other" do
|
150
|
+
message.add_label 'Awesome'
|
151
|
+
message.remove_label 'Great'
|
152
|
+
|
153
|
+
message.move_to('Great', 'Awesome')
|
154
|
+
expect(message.labels).to include("Great")
|
155
|
+
expect(message.labels).not_to include("Awesome")
|
156
|
+
expect(message.labels).to include(:Inbox)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "marks itself read" do
|
160
|
+
message.mark(:unread)
|
161
|
+
|
162
|
+
message.mark(:read)
|
163
|
+
expect(message.flags).to include(:Seen)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "marks itself unread" do
|
167
|
+
message.mark(:read)
|
168
|
+
|
169
|
+
message.mark(:unread)
|
170
|
+
expect(message.flags).not_to include(:Seen)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "deletes itself" do
|
174
|
+
trash_count = client.mailbox(:trash).emails.count
|
175
|
+
|
176
|
+
message.delete!
|
177
|
+
|
178
|
+
expect(client.mailbox(:trash).emails.count).to eq(trash_count + 1)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|