ruby-gmail 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +15 -2
- data/lib/gmail.rb +7 -7
- data/lib/gmail/message.rb +10 -0
- data/lib/mime/entity.rb +4 -2
- data/test/test_gmail.rb +72 -0
- data/test/test_helper.rb +4 -0
- metadata +5 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
@@ -1,10 +1,23 @@
|
|
1
|
+
=== 0.0.5 / 2009-12-16
|
2
|
+
|
3
|
+
* 1 bugfix
|
4
|
+
|
5
|
+
* Fixed IMAP initializer to work with Ruby 1.9's net/imap
|
6
|
+
|
7
|
+
* 4 minor enhancements
|
8
|
+
|
9
|
+
* Better logout depending on the IMAP connection itself
|
10
|
+
* Added MIME::Message#text and MIME::Message#html for easier access to an email body
|
11
|
+
* Improved the MIME-parsing API slightly
|
12
|
+
* Added some tests
|
13
|
+
|
1
14
|
=== 0.0.4 / 2009-11-30
|
2
15
|
|
3
16
|
* 4 minor enhancement
|
4
17
|
|
5
18
|
* Added label creation (thanks to Justin Perkins / http://github.com/justinperkins)
|
6
19
|
* Made the gem login automatically when first needed
|
7
|
-
* Added an optional block on the Gmail.new object that will login and logout for you
|
20
|
+
* Added an optional block on the Gmail.new object that will login and logout for you
|
8
21
|
* Added several search options (thanks to Mikkel Malmberg / http://github.com/mikker)
|
9
22
|
|
10
23
|
=== 0.0.3 / 2009-11-19
|
@@ -21,7 +34,7 @@
|
|
21
34
|
|
22
35
|
* 1 minor enhancement
|
23
36
|
|
24
|
-
* Made all of the examples in the README possible
|
37
|
+
* Made all of the examples in the README possible
|
25
38
|
|
26
39
|
=== 0.0.1 / 2009-11-18
|
27
40
|
|
data/lib/gmail.rb
CHANGED
@@ -3,7 +3,7 @@ require 'net/smtp'
|
|
3
3
|
require 'smtp_tls'
|
4
4
|
|
5
5
|
class Gmail
|
6
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.5'
|
7
7
|
|
8
8
|
class NoLabel < RuntimeError; end
|
9
9
|
|
@@ -18,9 +18,9 @@ class Gmail
|
|
18
18
|
end
|
19
19
|
meta.username = username =~ /@/ ? username : username + '@gmail.com'
|
20
20
|
meta.password = password
|
21
|
-
@imap = Net::IMAP.new('imap.gmail.com',993,true)
|
21
|
+
@imap = Net::IMAP.new('imap.gmail.com',993,true,nil,false)
|
22
22
|
if block_given?
|
23
|
-
@
|
23
|
+
@imap.login(username, password)
|
24
24
|
yield self
|
25
25
|
logout
|
26
26
|
end
|
@@ -37,16 +37,16 @@ class Gmail
|
|
37
37
|
end
|
38
38
|
# Accessor for @imap, but ensures that it's logged in first.
|
39
39
|
def imap
|
40
|
-
if
|
40
|
+
if @imap.disconnected?
|
41
41
|
meta = class << self; self end
|
42
|
-
@
|
43
|
-
at_exit { logout
|
42
|
+
@imap.login(meta.username, meta.password)
|
43
|
+
at_exit { logout } # Set up auto-logout for later.
|
44
44
|
end
|
45
45
|
@imap
|
46
46
|
end
|
47
47
|
# Log out of gmail
|
48
48
|
def logout
|
49
|
-
@
|
49
|
+
@imap.logout unless @imap.disconnected?
|
50
50
|
end
|
51
51
|
|
52
52
|
def create_label(name)
|
data/lib/gmail/message.rb
CHANGED
@@ -6,6 +6,7 @@ class Gmail
|
|
6
6
|
@mailbox = mailbox
|
7
7
|
@uid = uid
|
8
8
|
end
|
9
|
+
|
9
10
|
def inspect
|
10
11
|
"<#Message:#{object_id} mailbox=#{@mailbox.name}#{' uid='+@uid.to_s if @uid}#{' message_id='+@message_id.to_s if @message_id}>"
|
11
12
|
end
|
@@ -14,6 +15,7 @@ class Gmail
|
|
14
15
|
def uid
|
15
16
|
@uid ||= @gmail.imap.uid_search(['HEADER', 'Message-ID', message_id])[0]
|
16
17
|
end
|
18
|
+
|
17
19
|
def message_id
|
18
20
|
@message_id || begin
|
19
21
|
@gmail.in_mailbox(@mailbox) do
|
@@ -22,6 +24,7 @@ class Gmail
|
|
22
24
|
end
|
23
25
|
@message_id
|
24
26
|
end
|
27
|
+
|
25
28
|
def body
|
26
29
|
@body ||= @gmail.in_mailbox(@mailbox) do
|
27
30
|
@gmail.imap.uid_fetch(uid, "RFC822")[0].attr["RFC822"]
|
@@ -39,6 +42,7 @@ class Gmail
|
|
39
42
|
@gmail.imap.uid_store(uid, "+FLAGS", [flg])
|
40
43
|
end
|
41
44
|
end
|
45
|
+
|
42
46
|
def unflag(flg)
|
43
47
|
@gmail.in_mailbox(@mailbox) do
|
44
48
|
@gmail.imap.uid_store(uid, "-FLAGS", [flg])
|
@@ -58,10 +62,12 @@ class Gmail
|
|
58
62
|
move_to('[Gmail]/Spam')
|
59
63
|
end
|
60
64
|
end
|
65
|
+
|
61
66
|
def delete!
|
62
67
|
@mailbox.messages.delete(uid)
|
63
68
|
flag(:Deleted)
|
64
69
|
end
|
70
|
+
|
65
71
|
def label(name)
|
66
72
|
@gmail.in_mailbox(@mailbox) do
|
67
73
|
begin
|
@@ -71,6 +77,7 @@ class Gmail
|
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
80
|
+
|
74
81
|
def label!(name)
|
75
82
|
@gmail.in_mailbox(@mailbox) do
|
76
83
|
begin
|
@@ -82,13 +89,16 @@ class Gmail
|
|
82
89
|
end
|
83
90
|
end
|
84
91
|
end
|
92
|
+
|
85
93
|
# We're not sure of any 'labels' except the 'mailbox' we're in at the moment.
|
86
94
|
# Research whether we can find flags that tell which other labels this email is a part of.
|
87
95
|
# def remove_label(name)
|
88
96
|
# end
|
97
|
+
|
89
98
|
def move_to(name)
|
90
99
|
label(name) && delete!
|
91
100
|
end
|
101
|
+
|
92
102
|
def archive!
|
93
103
|
move_to('[Gmail]/All Mail')
|
94
104
|
end
|
data/lib/mime/entity.rb
CHANGED
@@ -12,7 +12,7 @@ module MIME
|
|
12
12
|
class Entity
|
13
13
|
def initialize(arg=nil)
|
14
14
|
if arg.is_a?(String)
|
15
|
-
@raw = arg
|
15
|
+
@raw = arg.gsub(/\r\r+/, "\r").gsub(/([^\r])\n/, "\\1\r\n") # normalizes end-of-line characters
|
16
16
|
from_parsed(IETF::RFC2045.parse_rfc2045_from(@raw))
|
17
17
|
elsif arg.is_a?(Hash)
|
18
18
|
@headers = arg
|
@@ -98,7 +98,7 @@ module MIME
|
|
98
98
|
$1
|
99
99
|
end
|
100
100
|
end
|
101
|
-
|
101
|
+
attr_writer :encoding
|
102
102
|
def encoding
|
103
103
|
@encoding ||= headers['content-transfer-encoding'] || nil
|
104
104
|
end
|
@@ -158,6 +158,8 @@ module MIME
|
|
158
158
|
@content.unpack('M')[0]
|
159
159
|
when 'base64'
|
160
160
|
@content.unpack('m')[0]
|
161
|
+
# when '7bit'
|
162
|
+
# # should get this 7bit encoding done too...
|
161
163
|
else
|
162
164
|
@content
|
163
165
|
end
|
data/test/test_gmail.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GmailTest < Test::Unit::TestCase
|
4
|
+
def test_initialize
|
5
|
+
imap = mock('imap')
|
6
|
+
Net::IMAP.expects(:new).with('imap.gmail.com', 993, true, nil, false).returns(imap)
|
7
|
+
gmail = Gmail.new('test', 'password')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_imap_does_login
|
11
|
+
setup_mocks(:at_exit => true)
|
12
|
+
|
13
|
+
@imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
|
14
|
+
@imap.expects(:login).with('test@gmail.com', 'password')
|
15
|
+
@gmail.imap
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_imap_does_login_only_once
|
19
|
+
setup_mocks(:at_exit => true)
|
20
|
+
|
21
|
+
@imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
|
22
|
+
@imap.expects(:login).with('test@gmail.com', 'password')
|
23
|
+
@gmail.imap
|
24
|
+
@gmail.imap
|
25
|
+
@gmail.imap
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_imap_does_login_without_appending_gmail_domain
|
29
|
+
setup_mocks(:at_exit => true)
|
30
|
+
|
31
|
+
@imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
|
32
|
+
@imap.expects(:login).with('test@gmail.com', 'password')
|
33
|
+
@gmail.imap
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_imap_logs_out
|
37
|
+
setup_mocks(:at_exit => true)
|
38
|
+
|
39
|
+
@imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
|
40
|
+
@imap.expects(:login).with('test@gmail.com', 'password')
|
41
|
+
@gmail.imap
|
42
|
+
@imap.expects(:logout).returns(true)
|
43
|
+
@gmail.logout
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_imap_logout_does_nothing_if_not_logged_in
|
47
|
+
setup_mocks
|
48
|
+
|
49
|
+
@imap.expects(:disconnected?).returns(true)
|
50
|
+
@imap.expects(:logout).never
|
51
|
+
@gmail.logout
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_imap_calls_create_label
|
55
|
+
setup_mocks(:at_exit => true)
|
56
|
+
@imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
|
57
|
+
@imap.expects(:login).with('test@gmail.com', 'password')
|
58
|
+
@imap.expects(:create).with('foo')
|
59
|
+
@gmail.create_label('foo')
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def setup_mocks(options = {})
|
64
|
+
options = {:at_exit => false}.merge(options)
|
65
|
+
@imap = mock('imap')
|
66
|
+
Net::IMAP.expects(:new).with('imap.gmail.com', 993, true, nil, false).returns(@imap)
|
67
|
+
@gmail = Gmail.new('test@gmail.com', 'password')
|
68
|
+
|
69
|
+
# need this for the at_exit block that auto-exits after this test method completes
|
70
|
+
@imap.expects(:logout).at_least(0) if options[:at_exit]
|
71
|
+
end
|
72
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-gmail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Parker
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
teST6sOe8lUhZQ==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2009-12-
|
33
|
+
date: 2009-12-16 00:00:00 -05:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -108,5 +108,6 @@ rubygems_version: 1.3.5
|
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
110
|
summary: A Rubyesque interface to Gmail, with all the tools you'll need
|
111
|
-
test_files:
|
112
|
-
|
111
|
+
test_files:
|
112
|
+
- test/test_gmail.rb
|
113
|
+
- test/test_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|