ruby-gmail 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ # Notice
2
+
3
+ First, the gem on rubygems.org is out of date. I am trying to gain ownership over that gem, but it is proving difficult - I may have to rename the gem.
4
+
5
+ Second, this gem needs to get back on track. I am looking for people to help go through issues and fix bugs. I want to push a solid, stable release first, then look at charting out the future of the gem. Please email me at <myobie@gmail.com> if you want to help or just get started on the issues.
6
+
1
7
  # ruby-gmail
2
8
 
3
9
  * Homepage: [http://dcparker.github.com/ruby-gmail/](http://dcparker.github.com/ruby-gmail/)
@@ -74,6 +80,10 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
74
80
  # Remember that every message in a conversation/thread will come as a separate message.
75
81
  gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
76
82
 
83
+ # Get messages without marking them as read on the server.
84
+ gmail.peek = true
85
+ gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
86
+
77
87
  ### 4) Work with emails!
78
88
 
79
89
  # any news older than 4-20, mark as read and archive it...
@@ -90,8 +100,8 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
90
100
  # Save all attachments in the "Faxes" label to a folder
91
101
  folder = "/where/ever"
92
102
  gmail.mailbox("Faxes").emails.each do |email|
93
- if !email.attachments.empty?
94
- email.save_attachments_to(folder)
103
+ if !email.message.attachments.empty?
104
+ email.message.save_attachments_to(folder)
95
105
  end
96
106
  end
97
107
 
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ begin
14
14
  gem.post_install_message = "\n\033[34mIf ruby-gmail saves you TWO hours of work, want to compensate me for, like, a half-hour?\nSupport me in making new and better gems:\033[0m \033[31;4mhttp://pledgie.com/campaigns/7087\033[0m\n\n"
15
15
  gem.add_dependency('shared-mime-info', '>= 0')
16
16
  gem.add_dependency('mail', '>= 2.2.1')
17
+ gem.add_dependency('mime', '>= 0.1')
17
18
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
19
  end
19
20
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -28,16 +28,16 @@ class Gmail
28
28
 
29
29
  ###########################
30
30
  # READING EMAILS
31
- #
31
+ #
32
32
  # gmail.inbox
33
33
  # gmail.label('News')
34
- #
34
+ #
35
35
  ###########################
36
36
 
37
37
  def inbox
38
38
  in_label('inbox')
39
39
  end
40
-
40
+
41
41
  def create_label(name)
42
42
  imap.create(name)
43
43
  end
@@ -50,10 +50,13 @@ class Gmail
50
50
 
51
51
  # gmail.label(name)
52
52
  def label(name)
53
- mailboxes[name] ||= Mailbox.new(self, mailbox)
53
+ mailboxes[name] ||= Mailbox.new(self, name)
54
54
  end
55
55
  alias :mailbox :label
56
56
 
57
+ # don't mark emails as read on the server when downloading them
58
+ attr_accessor :peek
59
+
57
60
  ###########################
58
61
  # MAKING EMAILS
59
62
  #
@@ -84,13 +87,13 @@ class Gmail
84
87
  mail.from = meta.username unless mail.from
85
88
  mail.deliver!
86
89
  end
87
-
90
+
88
91
  ###########################
89
92
  # LOGIN
90
93
  ###########################
91
94
  def login
92
95
  res = @imap.login(meta.username, meta.password)
93
- @logged_in = true if res.name == 'OK'
96
+ @logged_in = true if res && res.name == 'OK'
94
97
  end
95
98
  def logged_in?
96
99
  !!@logged_in
@@ -99,9 +102,15 @@ class Gmail
99
102
  def logout
100
103
  if logged_in?
101
104
  res = @imap.logout
102
- @logged_in = false if res.name == 'OK'
105
+ @logged_in = false if res && res.name == 'OK'
103
106
  end
104
107
  end
108
+
109
+ # Shutdown socket and disconnect
110
+ def disconnect
111
+ logout if logged_in?
112
+ @imap.disconnect unless @imap.disconnected?
113
+ end
105
114
 
106
115
  def in_mailbox(mailbox, &block)
107
116
  if block_given?
@@ -1,4 +1,3 @@
1
- require 'mime/message'
2
1
  class Gmail
3
2
  class Message
4
3
  def initialize(gmail, mailbox, uid)
@@ -83,16 +82,14 @@ class Gmail
83
82
  move_to('[Gmail]/All Mail')
84
83
  end
85
84
 
86
- def save_attachments_to(path=nil)
87
- attachments.each {|a| a.save_to_file(path) }
88
- end
89
-
90
85
  private
91
86
 
92
87
  # Parsed MIME message object
93
88
  def message
94
89
  require 'mail'
95
- _body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, "RFC822")[0].attr["RFC822"] }
90
+ request,part = 'RFC822','RFC822'
91
+ request,part = 'BODY.PEEK[]','BODY[]' if @gmail.peek
92
+ _body = @gmail.in_mailbox(@mailbox) { @gmail.imap.uid_fetch(uid, request)[0].attr[part] }
96
93
  @message ||= Mail.new(_body)
97
94
  end
98
95
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-gmail}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["BehindLogic"]
12
- s.date = %q{2010-05-14}
12
+ s.date = %q{2010-11-07}
13
13
  s.description = %q{A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and send multipart emails; archive, mark as read/unread, delete emails; and manage labels.}
14
14
  s.email = %q{gems@behindlogic.com}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
26
26
  "lib/gmail.rb",
27
27
  "lib/gmail/mailbox.rb",
28
28
  "lib/gmail/message.rb",
29
- "lib/mail/part.rb",
30
29
  "lib/smtp_tls.rb",
31
30
  "ruby-gmail.gemspec",
32
31
  "test/test_gmail.rb",
@@ -40,7 +39,7 @@ Support me in making new and better gems: http://pledgie.com/campaign
40
39
  }
41
40
  s.rdoc_options = ["--charset=UTF-8"]
42
41
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.6}
42
+ s.rubygems_version = %q{1.3.7}
44
43
  s.summary = %q{A Rubyesque interface to Gmail, with all the tools you'll need.}
45
44
  s.test_files = [
46
45
  "test/test_gmail.rb",
@@ -51,16 +50,19 @@ Support me in making new and better gems: http://pledgie.com/campaign
51
50
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
51
  s.specification_version = 3
53
52
 
54
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
54
  s.add_runtime_dependency(%q<shared-mime-info>, [">= 0"])
56
55
  s.add_runtime_dependency(%q<mail>, [">= 2.2.1"])
56
+ s.add_runtime_dependency(%q<mime>, [">= 0.1"])
57
57
  else
58
58
  s.add_dependency(%q<shared-mime-info>, [">= 0"])
59
59
  s.add_dependency(%q<mail>, [">= 2.2.1"])
60
+ s.add_dependency(%q<mime>, [">= 0.1"])
60
61
  end
61
62
  else
62
63
  s.add_dependency(%q<shared-mime-info>, [">= 0"])
63
64
  s.add_dependency(%q<mail>, [">= 2.2.1"])
65
+ s.add_dependency(%q<mime>, [">= 0.1"])
64
66
  end
65
67
  end
66
68
 
@@ -6,20 +6,26 @@ class GmailTest < Test::Unit::TestCase
6
6
  Net::IMAP.expects(:new).with('imap.gmail.com', 993, true, nil, false).returns(imap)
7
7
  gmail = Gmail.new('test', 'password')
8
8
  end
9
-
9
+
10
10
  def test_imap_does_login
11
11
  setup_mocks(:at_exit => true)
12
+ res = mock('res')
13
+ res.expects(:name).at_least(1).returns('OK')
12
14
 
13
- @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
14
- @imap.expects(:login).with('test@gmail.com', 'password')
15
+ # @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
16
+ # TODO: figure why this was here in the first place
17
+ @imap.expects(:login).with('test@gmail.com', 'password').returns(res)
15
18
  @gmail.imap
16
19
  end
17
20
 
18
21
  def test_imap_does_login_only_once
19
22
  setup_mocks(:at_exit => true)
23
+ res = mock('res')
24
+ res.expects(:name).at_least(1).returns('OK')
20
25
 
21
- @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
22
- @imap.expects(:login).with('test@gmail.com', 'password')
26
+ # @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
27
+ # TODO: figure why this was here in the first place
28
+ @imap.expects(:login).with('test@gmail.com', 'password').returns(res)
23
29
  @gmail.imap
24
30
  @gmail.imap
25
31
  @gmail.imap
@@ -27,46 +33,55 @@ class GmailTest < Test::Unit::TestCase
27
33
 
28
34
  def test_imap_does_login_without_appending_gmail_domain
29
35
  setup_mocks(:at_exit => true)
36
+ res = mock('res')
37
+ res.expects(:name).at_least(1).returns('OK')
30
38
 
31
- @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
32
- @imap.expects(:login).with('test@gmail.com', 'password')
39
+ # @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
40
+ # TODO: figure why this was here in the first place
41
+ @imap.expects(:login).with('test@gmail.com', 'password').returns(res)
33
42
  @gmail.imap
34
43
  end
35
-
44
+
36
45
  def test_imap_logs_out
37
46
  setup_mocks(:at_exit => true)
47
+ res = mock('res')
48
+ res.expects(:name).at_least(1).returns('OK')
38
49
 
39
- @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
40
- @imap.expects(:login).with('test@gmail.com', 'password')
50
+ # @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
51
+ # TODO: figure why this was here in the first place
52
+ @imap.expects(:login).with('test@gmail.com', 'password').returns(res)
41
53
  @gmail.imap
42
- @imap.expects(:logout).returns(true)
54
+ @imap.expects(:logout).returns(res)
43
55
  @gmail.logout
44
56
  end
45
57
 
46
58
  def test_imap_logout_does_nothing_if_not_logged_in
47
59
  setup_mocks
48
60
 
49
- @imap.expects(:disconnected?).returns(true)
61
+ @gmail.expects(:logged_in?).returns(false)
50
62
  @imap.expects(:logout).never
51
63
  @gmail.logout
52
64
  end
53
-
65
+
54
66
  def test_imap_calls_create_label
55
67
  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')
68
+ res = mock('res')
69
+ res.expects(:name).at_least(1).returns('OK')
70
+ # @imap.expects(:disconnected?).at_least_once.returns(true).then.returns(false)
71
+ # TODO: figure out why this was here in the first place
72
+ @imap.expects(:login).with('test@gmail.com', 'password').returns(res)
58
73
  @imap.expects(:create).with('foo')
59
74
  @gmail.create_label('foo')
60
75
  end
61
-
76
+
62
77
  private
63
78
  def setup_mocks(options = {})
64
79
  options = {:at_exit => false}.merge(options)
65
80
  @imap = mock('imap')
66
81
  Net::IMAP.expects(:new).with('imap.gmail.com', 993, true, nil, false).returns(@imap)
67
82
  @gmail = Gmail.new('test@gmail.com', 'password')
68
-
83
+
69
84
  # need this for the at_exit block that auto-exits after this test method completes
70
85
  @imap.expects(:logout).at_least(0) if options[:at_exit]
71
86
  end
72
- end
87
+ end
metadata CHANGED
@@ -1,59 +1,74 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-gmail
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - BehindLogic
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-05-14 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: shared-mime-info
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :runtime
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
33
31
  name: mail
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.2.1
38
+ type: :runtime
34
39
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 2
41
- - 2
42
- - 1
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
43
45
  version: 2.2.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: mime
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0.1'
44
54
  type: :runtime
45
- version_requirements: *id002
46
- description: A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and send multipart emails; archive, mark as read/unread, delete emails; and manage labels.
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ description: A Rubyesque interface to Gmail, with all the tools you'll need. Search,
63
+ read and send multipart emails; archive, mark as read/unread, delete emails; and
64
+ manage labels.
47
65
  email: gems@behindlogic.com
48
66
  executables: []
49
-
50
67
  extensions: []
51
-
52
- extra_rdoc_files:
68
+ extra_rdoc_files:
53
69
  - README.markdown
54
- files:
70
+ files:
55
71
  - .autotest
56
- - .gitignore
57
72
  - History.txt
58
73
  - Manifest.txt
59
74
  - README.markdown
@@ -62,43 +77,34 @@ files:
62
77
  - lib/gmail.rb
63
78
  - lib/gmail/mailbox.rb
64
79
  - lib/gmail/message.rb
65
- - lib/mail/part.rb
66
80
  - lib/smtp_tls.rb
67
81
  - ruby-gmail.gemspec
68
82
  - test/test_gmail.rb
69
83
  - test/test_helper.rb
70
- has_rdoc: true
71
84
  homepage: http://dcparker.github.com/ruby-gmail
72
85
  licenses: []
73
-
74
- post_install_message: "\n\
75
- \e[34mIf ruby-gmail saves you TWO hours of work, want to compensate me for, like, a half-hour?\n\
76
- Support me in making new and better gems:\e[0m \e[31;4mhttp://pledgie.com/campaigns/7087\e[0m\n\n"
77
- rdoc_options:
78
- - --charset=UTF-8
79
- require_paths:
86
+ post_install_message: ! "\n\e[34mIf ruby-gmail saves you TWO hours of work, want to
87
+ compensate me for, like, a half-hour?\nSupport me in making new and better gems:\e[0m
88
+ \e[31;4mhttp://pledgie.com/campaigns/7087\e[0m\n\n"
89
+ rdoc_options: []
90
+ require_paths:
80
91
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
- version: "0"
88
- required_rubygems_version: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
- version: "0"
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
95
104
  requirements: []
96
-
97
105
  rubyforge_project:
98
- rubygems_version: 1.3.6
106
+ rubygems_version: 1.8.23
99
107
  signing_key:
100
108
  specification_version: 3
101
109
  summary: A Rubyesque interface to Gmail, with all the tools you'll need.
102
- test_files:
103
- - test/test_gmail.rb
104
- - test/test_helper.rb
110
+ test_files: []
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg
@@ -1,24 +0,0 @@
1
- module Mail
2
- class Message
3
- def attachment?
4
- !!find_attachment
5
- end
6
- end
7
- class Part < Message
8
- def save_to_file(path=nil)
9
- return false unless attachment?
10
- fname = path if path && !File.exists?(path) # If path doesn't exist, assume it's a filename
11
- fname ||= path + '/' + filename if path && File.directory?(path) # If path does exist, and we're saving an attachment, use the attachment filename
12
- fname ||= (path || filename) # Use the path, or the attachment filename
13
- if File.directory?(fname)
14
- i = 0
15
- begin
16
- i += 1
17
- fname = fname + "/attachment-#{i}"
18
- end until !File.exists(fname)
19
- end
20
- # After all that trouble to get a filename to save to...
21
- File.open(fname, 'w') { |f| f << read }
22
- end
23
- end
24
- end