Permalink
Browse files

* Added explicit tmail dependency in gemspec

* Added better README tutorial content
* Version bump to 0.1.1
  • Loading branch information...
1 parent f77f0a1 commit 91d335b9268c582d9585522751f99b4831edd335 dcparker committed May 11, 2010
Showing with 89 additions and 31 deletions.
  1. +7 −0 History.txt
  2. +73 −28 README.markdown
  3. +1 −0 Rakefile
  4. +1 −1 VERSION
  5. +7 −2 ruby-gmail.gemspec
View
@@ -1,3 +1,10 @@
+=== 0.1.1 / 2010-05-11
+
+* 1 minor fix
+
+ * Added explicit tmail dependency in gemspec
+ * Added better README tutorial content
+
=== 0.0.9 / 2010-04-17
* 1 bugfix
View
@@ -1,9 +1,3 @@
-# This fork
-
-contains a fix to a bug in the initializer, which was discussed [here](http://github.com/dcparker/ruby-gmail/issues#issue/7/comment/141607)
-
-* * * *
-
# ruby-gmail
* Homepage: [http://dcparker.github.com/ruby-gmail/](http://dcparker.github.com/ruby-gmail/)
@@ -41,32 +35,82 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
## Example Code:
+### 1) Require gmail
+
require 'gmail'
- gmail = Gmail.new(username, password) do |g|
- read_count = g.inbox.count(:read) # => .count take the same arguments as .emails
- unread = g.inbox.emails(:unread)
- unread[0].archive!
- unread[1].delete!
- unread[2].move_to('FunStuff') # => labels and removes from inbox
- unread[3].message # => a MIME::Message, parsed from the email body
- unread[3].mark(:read)
- unread[3].message.attachments.length
- unread[4].label('FunStuff') # => Just adds the label 'FunStuff'
- unread[4].message.save_attachments_to('path/to/save/into')
- unread[5].message.attachments[0].save_to_file('path/to/save/into')
- unread[6].mark(:spam)
+
+### 2) Start an authenticated gmail session
+
+ # If you pass a block, the session will be passed into the block,
+ # and the session will be logged out after the block is executed.
+ gmail = Gmail.new(username, password)
+ # ...do things...
+ gmail.logout
+
+ Gmail.new(username, password) do |gmail|
+ # ...do things...
+ end
+
+### 3) Count and gather emails!
+
+ # Get counts for messages in the inbox
+ gmail.inbox.count
+ gmail.inbox.count(:unread)
+ gmail.inbox.count(:read)
+
+ # Count with some criteria
+ gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
+ gmail.inbox.count(:on => Date.parse("2010-04-15"))
+ gmail.inbox.count(:from => "myfriend@gmail.com")
+ gmail.inbox.count(:to => "directlytome@gmail.com")
+
+ # Combine flags and options
+ gmail.inbox.count(:unread, :from => "myboss@gmail.com")
+
+ # Labels work the same way as inbox
+ gmail.mailbox('Urgent').count
+
+ # Getting messages works the same way as counting: optional flag, and optional arguments
+ # Remember that every message in a conversation/thread will come as a separate message.
+ gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
+
+### 4) Work with emails!
+
+ # any news older than 4-20, mark as read and archive it...
+ gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
+ email.mark(:read) # can also mark :unread or :spam
+ email.archive!
end
- # Optionally use a block like above to have the gem automatically login and logout,
- # or just use it without a block after creating the object like below, and it will
- # automatically logout at_exit. The block method is recommended in order to limit
- # your signed-in session.
+ # delete emails from X...
+ gmail.inbox.emails(:from => "x-fiancé@gmail.com").each do |email|
+ email.delete!
+ end
+
+ # Save all attachments in the "Faxes" label to a folder
+ folder = "/where/ever"
+ gmail.mailbox("Faxes").emails.each do |email|
+ if !email.message.attachments.empty?
+ email.message.save_attachments_to(folder)
+ end
+ end
+
+ # Save just the first attachment from the newest unread email (assuming pdf)
+ # For #save_to_file:
+ # + provide a path - save to attachment filename in path
+ # + provide a filename - save to file specified
+ # + provide no arguments - save to attachment filename in current directory
+ email = gmail.inbox.emails(:unread).first
+ email.attachments[0].save_to_file("/path/to/location")
+
+ # Add a label to a message
+ email.label("Faxes")
+
+ # Or "move" the message to a label
+ email.move_to("Faxes")
+
+### 5) Create new emails!
- older = gmail.inbox.emails(:after => '2009-03-04', :before => '2009-03-15')
- todays_date = Time.parse(Time.now.strftime('%Y-%m-%d'))
- yesterday = gmail.inbox.emails(:after => (todays_date - 24*60*60), :before => todays_date)
- todays_unread = gmail.inbox.emails(:unread, :after => todays_date)
-
new_email = MIME::Message.generate
new_email.to "email@example.com"
new_email.subject "Having fun in Puerto Rico!"
@@ -81,6 +125,7 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
* ruby
* net/smtp
* net/imap
+* tmail
* shared-mime-info rubygem (for MIME-detection when attaching files)
## Install
View
@@ -13,6 +13,7 @@ begin
gem.authors = ["BehindLogic"]
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"
gem.add_dependency('shared-mime-info', '>= 0')
+ gem.add_dependency('tmail', '>= 1.2.3')
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
View
@@ -1 +1 @@
-0.1.0
+0.1.1
View
@@ -5,18 +5,19 @@
Gem::Specification.new do |s|
s.name = %q{ruby-gmail}
- s.version = "0.0.9"
+ s.version = "0.1.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["BehindLogic"]
- s.date = %q{2010-04-18}
+ s.date = %q{2010-05-11}
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.}
s.email = %q{gems@behindlogic.com}
s.extra_rdoc_files = [
"README.markdown"
]
s.files = [
".autotest",
+ ".gitignore",
"History.txt",
"Manifest.txt",
"README.markdown",
@@ -31,6 +32,7 @@ Gem::Specification.new do |s|
"lib/mime/entity_tmail.rb",
"lib/mime/message.rb",
"lib/smtp_tls.rb",
+ "ruby-gmail.gemspec",
"test/test_gmail.rb",
"test/test_helper.rb"
]
@@ -55,11 +57,14 @@ Support me in making new and better gems: http://pledgie.com/campaign
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<shared-mime-info>, [">= 0"])
+ s.add_runtime_dependency(%q<tmail>, [">= 1.2.3"])
else
s.add_dependency(%q<shared-mime-info>, [">= 0"])
+ s.add_dependency(%q<tmail>, [">= 1.2.3"])
end
else
s.add_dependency(%q<shared-mime-info>, [">= 0"])
+ s.add_dependency(%q<tmail>, [">= 1.2.3"])
end
end

0 comments on commit 91d335b

Please sign in to comment.