ruby-gmail 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -90,8 +90,8 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
90
90
  # Save all attachments in the "Faxes" label to a folder
91
91
  folder = "/where/ever"
92
92
  gmail.mailbox("Faxes").emails.each do |email|
93
- if !email.message.attachments.empty?
94
- email.message.save_attachments_to(folder)
93
+ if !email.attachments.empty?
94
+ email.save_attachments_to(folder)
95
95
  end
96
96
  end
97
97
 
@@ -111,14 +111,28 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
111
111
 
112
112
  ### 5) Create new emails!
113
113
 
114
- new_email = MIME::Message.generate
115
- new_email.to "email@example.com"
116
- new_email.subject "Having fun in Puerto Rico!"
117
- plain, html = new_email.generate_multipart('text/plain', 'text/html')
118
- plain.content = "Text of plain message."
119
- html.content = "<p>Text of <em>html</em> message.</p>"
120
- new_email.attach_file('some_image.dmg')
121
- gmail.send_email(new_email)
114
+ Creating emails now uses the amazing [Mail](http://rubygems.org/gems/mail) rubygem. See its [documentation here](http://github.com/mikel/mail). Ruby-gmail will automatically configure your Mail emails to be sent via your Gmail account's SMTP, so they will be in your Gmail's "Sent" folder. Also, no need to specify the "From" email either, because ruby-gmail will set it for you.
115
+
116
+ gmail.deliver do
117
+ to "email@example.com"
118
+ subject "Having fun in Puerto Rico!"
119
+ text_part do
120
+ body "Text of plaintext message."
121
+ end
122
+ html_part do
123
+ body "<p>Text of <em>html</em> message.</p>"
124
+ end
125
+ add_file "/path/to/some_image.jpg"
126
+ end
127
+ # Or, generate the message first and send it later
128
+ email = gmail.generate_message do
129
+ to "email@example.com"
130
+ subject "Having fun in Puerto Rico!"
131
+ body "Spent the day on the road..."
132
+ end
133
+ email.deliver!
134
+ # Or...
135
+ gmail.deliver(email)
122
136
 
123
137
  ## Requirements
124
138
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/gmail.rb CHANGED
@@ -119,7 +119,7 @@ class Gmail
119
119
  end
120
120
  return value
121
121
  else
122
- mailboxes[name] ||= Mailbox.new(self, mailbox)
122
+ mailboxes[mailbox] ||= Mailbox.new(self, mailbox)
123
123
  end
124
124
  end
125
125
  alias :in_label :in_mailbox
data/lib/gmail/message.rb CHANGED
@@ -83,6 +83,10 @@ class Gmail
83
83
  move_to('[Gmail]/All Mail')
84
84
  end
85
85
 
86
+ def save_attachments_to(path=nil)
87
+ attachments.each {|a| a.save_to_file(path) }
88
+ end
89
+
86
90
  private
87
91
 
88
92
  # Parsed MIME message object
data/lib/mail/part.rb ADDED
@@ -0,0 +1,24 @@
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
data/ruby-gmail.gemspec CHANGED
@@ -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.0"
8
+ s.version = "0.2.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"]
@@ -26,6 +26,7 @@ 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",
29
30
  "lib/smtp_tls.rb",
30
31
  "ruby-gmail.gemspec",
31
32
  "test/test_gmail.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - BehindLogic
@@ -62,6 +62,7 @@ files:
62
62
  - lib/gmail.rb
63
63
  - lib/gmail/mailbox.rb
64
64
  - lib/gmail/message.rb
65
+ - lib/mail/part.rb
65
66
  - lib/smtp_tls.rb
66
67
  - ruby-gmail.gemspec
67
68
  - test/test_gmail.rb