ruby-gmail 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/README.markdown +73 -22
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/ruby-gmail.gemspec +5 -2
- metadata +17 -3
data/History.txt
CHANGED
data/README.markdown
CHANGED
@@ -41,32 +41,82 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
|
|
41
41
|
|
42
42
|
## Example Code:
|
43
43
|
|
44
|
+
### 1) Require gmail
|
45
|
+
|
44
46
|
require 'gmail'
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
|
48
|
+
### 2) Start an authenticated gmail session
|
49
|
+
|
50
|
+
# If you pass a block, the session will be passed into the block,
|
51
|
+
# and the session will be logged out after the block is executed.
|
52
|
+
gmail = Gmail.new(username, password)
|
53
|
+
# ...do things...
|
54
|
+
gmail.logout
|
55
|
+
|
56
|
+
Gmail.new(username, password) do |gmail|
|
57
|
+
# ...do things...
|
58
|
+
end
|
59
|
+
|
60
|
+
### 3) Count and gather emails!
|
61
|
+
|
62
|
+
# Get counts for messages in the inbox
|
63
|
+
gmail.inbox.count
|
64
|
+
gmail.inbox.count(:unread)
|
65
|
+
gmail.inbox.count(:read)
|
66
|
+
|
67
|
+
# Count with some criteria
|
68
|
+
gmail.inbox.count(:after => Date.parse("2010-02-20"), :before => Date.parse("2010-03-20"))
|
69
|
+
gmail.inbox.count(:on => Date.parse("2010-04-15"))
|
70
|
+
gmail.inbox.count(:from => "myfriend@gmail.com")
|
71
|
+
gmail.inbox.count(:to => "directlytome@gmail.com")
|
72
|
+
|
73
|
+
# Combine flags and options
|
74
|
+
gmail.inbox.count(:unread, :from => "myboss@gmail.com")
|
75
|
+
|
76
|
+
# Labels work the same way as inbox
|
77
|
+
gmail.mailbox('Urgent').count
|
78
|
+
|
79
|
+
# Getting messages works the same way as counting: optional flag, and optional arguments
|
80
|
+
# Remember that every message in a conversation/thread will come as a separate message.
|
81
|
+
gmail.inbox.emails(:unread, :before => Date.parse("2010-04-20"), :from => "myboss@gmail.com")
|
82
|
+
|
83
|
+
### 4) Work with emails!
|
84
|
+
|
85
|
+
# any news older than 4-20, mark as read and archive it...
|
86
|
+
gmail.inbox.emails(:before => Date.parse("2010-04-20"), :from => "news@nbcnews.com").each do |email|
|
87
|
+
email.mark(:read) # can also mark :unread or :spam
|
88
|
+
email.archive!
|
89
|
+
end
|
90
|
+
|
91
|
+
# delete emails from X...
|
92
|
+
gmail.inbox.emails(:from => "x-fiancé").each do |email|
|
93
|
+
email.delete!
|
94
|
+
end
|
95
|
+
|
96
|
+
# Save all attachments in the "Faxes" label to a folder
|
97
|
+
folder = "/where/ever"
|
98
|
+
gmail.mailbox("Faxes").emails.each do |email|
|
99
|
+
if !email.message.attachments.empty?
|
100
|
+
email.message.save_attachments_to(folder)
|
101
|
+
end
|
58
102
|
end
|
59
103
|
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
104
|
+
# Save just the first attachment from the newest unread email (assuming pdf)
|
105
|
+
# For #save_to_file:
|
106
|
+
# + provide a path - save to attachment filename in path
|
107
|
+
# + provide a filename - save to file specified
|
108
|
+
# + provide no arguments - save to attachment filename in current directory
|
109
|
+
email = gmail.inbox.emails(:unread).first
|
110
|
+
email.attachments[0].save_to_file("/path/to/location")
|
111
|
+
|
112
|
+
# Add a label to a message
|
113
|
+
email.label("Faxes")
|
114
|
+
|
115
|
+
# Or "move" the message to a label
|
116
|
+
email.move_to("Faxes")
|
117
|
+
|
118
|
+
### 5) Create new emails!
|
64
119
|
|
65
|
-
older = gmail.inbox.emails(:after => '2009-03-04', :before => '2009-03-15')
|
66
|
-
todays_date = Time.parse(Time.now.strftime('%Y-%m-%d'))
|
67
|
-
yesterday = gmail.inbox.emails(:after => (todays_date - 24*60*60), :before => todays_date)
|
68
|
-
todays_unread = gmail.inbox.emails(:unread, :after => todays_date)
|
69
|
-
|
70
120
|
new_email = MIME::Message.generate
|
71
121
|
new_email.to "email@example.com"
|
72
122
|
new_email.subject "Having fun in Puerto Rico!"
|
@@ -81,6 +131,7 @@ A Rubyesque interface to Gmail, with all the tools you'll need. Search, read and
|
|
81
131
|
* ruby
|
82
132
|
* net/smtp
|
83
133
|
* net/imap
|
134
|
+
* tmail
|
84
135
|
* shared-mime-info rubygem (for MIME-detection when attaching files)
|
85
136
|
|
86
137
|
## Install
|
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ begin
|
|
13
13
|
gem.authors = ["BehindLogic"]
|
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
|
+
gem.add_dependency('tmail', '>= 1.2.3')
|
16
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
18
|
end
|
18
19
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/ruby-gmail.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby-gmail}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.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"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-11}
|
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 = [
|
@@ -57,11 +57,14 @@ Support me in making new and better gems:[0m [31;4mhttp://pledgie.com/campaign
|
|
57
57
|
|
58
58
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
59
|
s.add_runtime_dependency(%q<shared-mime-info>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<tmail>, [">= 1.2.3"])
|
60
61
|
else
|
61
62
|
s.add_dependency(%q<shared-mime-info>, [">= 0"])
|
63
|
+
s.add_dependency(%q<tmail>, [">= 1.2.3"])
|
62
64
|
end
|
63
65
|
else
|
64
66
|
s.add_dependency(%q<shared-mime-info>, [">= 0"])
|
67
|
+
s.add_dependency(%q<tmail>, [">= 1.2.3"])
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- BehindLogic
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-11 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +29,20 @@ dependencies:
|
|
29
29
|
version: "0"
|
30
30
|
type: :runtime
|
31
31
|
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: tmail
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 1
|
41
|
+
- 2
|
42
|
+
- 3
|
43
|
+
version: 1.2.3
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
32
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.
|
33
47
|
email: gems@behindlogic.com
|
34
48
|
executables: []
|