ruby-gmail 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,18 @@
1
1
  # Notice
2
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.
3
+ I have pushed verion 0.3.1 to rubygems.org (Yay, thanks Nick Quaranto for the help) which is a build straight from master.
4
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.
5
+ Second, this gem is getting back on track. See [this issue here](https://github.com/dcparker/ruby-gmail/issues/58) for more information.
6
6
 
7
7
  # ruby-gmail
8
8
 
9
- * Homepage: [http://dcparker.github.com/ruby-gmail/](http://dcparker.github.com/ruby-gmail/)
10
9
  * Code: [http://github.com/dcparker/ruby-gmail](http://github.com/dcparker/ruby-gmail)
11
- * Gem: [http://gemcutter.org/gems/ruby-gmail](http://gemcutter.org/gems/ruby-gmail)
10
+ * Gem: [http://gemcutter.org/gems/ruby-gmail](http://rubygems.org/gems/ruby-gmail)
12
11
 
13
12
  ## Author(s)
14
13
 
15
14
  * Daniel Parker of BehindLogic.com
15
+ * Nathan Herald
16
16
 
17
17
  Extra thanks for specific feature contributions from:
18
18
 
@@ -100,19 +100,13 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
100
100
  # Save all attachments in the "Faxes" label to a folder
101
101
  folder = "/where/ever"
102
102
  gmail.mailbox("Faxes").emails.each do |email|
103
- if !email.message.attachments.empty?
104
- email.message.save_attachments_to(folder)
103
+ email.attachments.each do |attachment|
104
+ file = File.new(folder + attachment.filename, "w+")
105
+ file << attachment.decoded
106
+ file.close
105
107
  end
106
108
  end
107
109
 
108
- # Save just the first attachment from the newest unread email (assuming pdf)
109
- # For #save_to_file:
110
- # + provide a path - save to attachment filename in path
111
- # + provide a filename - save to file specified
112
- # + provide no arguments - save to attachment filename in current directory
113
- email = gmail.inbox.emails(:unread).first
114
- email.attachments[0].save_to_file("/path/to/location")
115
-
116
110
  # Add a label to a message
117
111
  email.label("Faxes")
118
112
 
@@ -130,6 +124,7 @@ Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubyg
130
124
  body "Text of plaintext message."
131
125
  end
132
126
  html_part do
127
+ content_type 'text/html; charset=UTF-8'
133
128
  body "<p>Text of <em>html</em> message.</p>"
134
129
  end
135
130
  add_file "/path/to/some_image.jpg"
data/Rakefile CHANGED
@@ -21,3 +21,7 @@ begin
21
21
  rescue LoadError
22
22
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
23
  end
24
+
25
+ task :default do
26
+ sh "find test -type f -name '*rb' -exec testrb -I lib:test {} +"
27
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -38,14 +38,29 @@ class Gmail
38
38
  in_label('inbox')
39
39
  end
40
40
 
41
+ def destroy_label(name)
42
+ imap.delete(name)
43
+ end
44
+
45
+ def rename_label(oldname, newname)
46
+ imap.rename(oldname, newname)
47
+ end
48
+
41
49
  def create_label(name)
42
50
  imap.create(name)
43
51
  end
44
52
 
53
+ def mailbox_list
54
+ imap.list("","*")
55
+ end
56
+
45
57
  # List the available labels
46
58
  def labels
47
- (imap.list("", "%") + imap.list("[Gmail]/", "%")).inject([]) { |labels,label|
48
- label[:name].each_line { |l| labels << l }; labels }
59
+ mailbox_list.inject([]) do |labels,label|
60
+ labels << label[:name] unless label.attr.include?(:Noselect)
61
+
62
+ labels
63
+ end
49
64
  end
50
65
 
51
66
  # gmail.label(name)
@@ -54,18 +69,22 @@ class Gmail
54
69
  end
55
70
  alias :mailbox :label
56
71
 
72
+ def find_label_by_attribute(attribute)
73
+ mailbox_list.find{ |label| label.attr.include?(attribute.to_sym.capitalize) }
74
+ end
75
+
57
76
  # don't mark emails as read on the server when downloading them
58
77
  attr_accessor :peek
59
78
 
60
79
  ###########################
61
80
  # MAKING EMAILS
62
- #
81
+ #
63
82
  # gmail.generate_message do
64
83
  # ...inside Mail context...
65
84
  # end
66
- #
85
+ #
67
86
  # gmail.deliver do ... end
68
- #
87
+ #
69
88
  # mail = Mail.new...
70
89
  # gmail.deliver!(mail)
71
90
  ###########################
@@ -105,12 +124,12 @@ class Gmail
105
124
  @logged_in = false if res && res.name == 'OK'
106
125
  end
107
126
  end
108
-
127
+
109
128
  # Shutdown socket and disconnect
110
129
  def disconnect
111
130
  logout if logged_in?
112
131
  @imap.disconnect unless @imap.disconnected?
113
- end
132
+ end
114
133
 
115
134
  def in_mailbox(mailbox, &block)
116
135
  if block_given?
@@ -139,7 +158,7 @@ class Gmail
139
158
  def inspect
140
159
  "#<Gmail:#{'0x%x' % (object_id << 1)} (#{meta.username}) #{'dis' if !logged_in?}connected>"
141
160
  end
142
-
161
+
143
162
  # Accessor for @imap, but ensures that it's logged in first.
144
163
  def imap
145
164
  unless logged_in?
@@ -38,7 +38,7 @@ class Gmail
38
38
  when :deleted
39
39
  flag(:Deleted)
40
40
  when :spam
41
- move_to('[Gmail]/Spam')
41
+ move_to_special_folder(:Junk)
42
42
  end ? true : false
43
43
  end
44
44
 
@@ -78,11 +78,14 @@ class Gmail
78
78
  label(name) && delete!
79
79
  end
80
80
 
81
- def archive!
82
- move_to('[Gmail]/All Mail')
81
+ def move_to_special_folder(attribute)
82
+ name = @gmail.find_label_by_attribute(attribute).name
83
+ move_to(name)
83
84
  end
84
85
 
85
- private
86
+ def archive!
87
+ move_to_special_folder(:All)
88
+ end
86
89
 
87
90
  # Parsed MIME message object
88
91
  def message
@@ -93,6 +96,8 @@ class Gmail
93
96
  @message ||= Mail.new(_body)
94
97
  end
95
98
 
99
+ private
100
+
96
101
  # Delegate all other methods to the Mail message
97
102
  def method_missing(*args, &block)
98
103
  if block_given?
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-gmail}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["BehindLogic"]
@@ -1,4 +1,4 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- require 'mocha'
3
+ require 'mocha/setup'
4
4
  require 'gmail'
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2014-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shared-mime-info
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 1.8.23
106
+ rubygems_version: 1.8.23.2
107
107
  signing_key:
108
108
  specification_version: 3
109
109
  summary: A Rubyesque interface to Gmail, with all the tools you'll need.