karthik-ruby-gmail 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/History.txt +9 -70
- data/README.markdown +42 -4
- data/VERSION +1 -1
- data/lib/gmail.rb +2 -0
- data/lib/gmail/mailbox.rb +30 -14
- data/lib/gmail/message.rb +2 -0
- data/lib/smtp_tls.rb +2 -0
- data/ruby-gmail.gemspec +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MzM0OTg1YzdkOGFiYzhjMDU2YTQ2MjU5YTM4MDk4ZDQ1YjkyNzBiOA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2db109d6fd679f2d827ad0ae62c50eecf1be252
|
4
|
+
data.tar.gz: e7ddfa43853d76f42ece898ac0d3de17e3a0df07
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NTg3ZjBhOTM0NzUxZjUwOThkNWQ3N2YzZDdjMTBkZmVhYjJiYjRhOTc2ODk1
|
11
|
-
YzZlZTc0M2ZmNDRjNjJjNmEyMGE5ZTk3N2IyYTI5ODMzMTE3Njk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MTM1YzE5NTI4NzIwNzBkZTA0N2Q5MGVhOWFiYWI0Y2JjYzE1YzVhYjYwMWFk
|
14
|
-
MDJlYjRmMGY2NGU1MGY0Y2E5YjQ4NzEwYjZiNjMyYmQ5MzZlNGU2OGE1YjVm
|
15
|
-
ZTk1ZmIxNGJjODNkODdhNTcyMzNiNjgzNDYwMjJlZGIzMjJlN2I=
|
6
|
+
metadata.gz: 0b159845574cf1ea98d2885d1583b1b2775b6e80bc6078efd516f694415c12cda8042d06d0d04c2c925a8a6c6c4e7505ec96a29817721a69ac768f175983d7d9
|
7
|
+
data.tar.gz: 664c4ad265476844821cf932ceb5780d12deb97a584cf6129423383e7ebcb95b87767f3f7f57456a638208aa02c14b56b1e53926711f4641f998d4fedf2b1869
|
data/History.txt
CHANGED
@@ -1,75 +1,14 @@
|
|
1
|
-
=== 0.1.1 / 2010-05-11
|
2
1
|
|
3
|
-
|
2
|
+
=== 1.0.1 / 04-04-2014
|
4
3
|
|
5
|
-
|
6
|
-
* Added better README tutorial content
|
4
|
+
* 1 minor fix and updated README
|
7
5
|
|
8
|
-
|
6
|
+
* Modified search by subject to accommodate non-ASCII strings. Retrieves all matching emails and then filter by the subject field (slower method but no way around the encoding issues with IMAP)
|
7
|
+
* Updated README
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
* Fixed content-transfer-encoding when sending email
|
13
|
-
|
14
|
-
=== 0.0.8 / 2009-12-23
|
15
|
-
|
16
|
-
* 1 bugfix
|
17
|
-
|
18
|
-
* Fixed attaching a file to an empty message
|
19
|
-
|
20
|
-
=== 0.0.7 / 2009-12-23
|
21
|
-
|
22
|
-
* 1 bugfix
|
23
|
-
|
24
|
-
* Improved multipart message parsing reliability
|
25
|
-
|
26
|
-
=== 0.0.6 / 2009-12-21
|
27
|
-
|
28
|
-
* 1 bugfix
|
29
|
-
|
30
|
-
* Fixed multipart parsing for when the boundary is marked in quotes.
|
31
|
-
|
32
|
-
=== 0.0.5 / 2009-12-16
|
33
|
-
|
34
|
-
* 1 bugfix
|
35
|
-
|
36
|
-
* Fixed IMAP initializer to work with Ruby 1.9's net/imap
|
37
|
-
|
38
|
-
* 4 minor enhancements
|
39
|
-
|
40
|
-
* Better logout depending on the IMAP connection itself
|
41
|
-
* Added MIME::Message#text and MIME::Message#html for easier access to an email body
|
42
|
-
* Improved the MIME-parsing API slightly
|
43
|
-
* Added some tests
|
44
|
-
|
45
|
-
=== 0.0.4 / 2009-11-30
|
46
|
-
|
47
|
-
* 4 minor enhancement
|
48
|
-
|
49
|
-
* Added label creation (thanks to Justin Perkins / http://github.com/justinperkins)
|
50
|
-
* Made the gem login automatically when first needed
|
51
|
-
* Added an optional block on the Gmail.new object that will login and logout for you
|
52
|
-
* Added several search options (thanks to Mikkel Malmberg / http://github.com/mikker)
|
53
|
-
|
54
|
-
=== 0.0.3 / 2009-11-19
|
55
|
-
|
56
|
-
* 1 bugfix
|
57
|
-
|
58
|
-
* Fixed MIME::Message#content= for messages without an encoding
|
59
|
-
|
60
|
-
* 1 minor enhancement
|
61
|
-
|
62
|
-
* Added Gmail#new_message
|
63
|
-
|
64
|
-
=== 0.0.2 / 2009-11-18
|
65
|
-
|
66
|
-
* 1 minor enhancement
|
67
|
-
|
68
|
-
* Made all of the examples in the README possible
|
69
|
-
|
70
|
-
=== 0.0.1 / 2009-11-18
|
71
|
-
|
72
|
-
* 1 major enhancement
|
73
|
-
|
74
|
-
* Birthday!
|
9
|
+
=== 1.0.0 / 03-04-2014
|
75
10
|
|
11
|
+
* Modified email search
|
12
|
+
|
13
|
+
* Added search by subject
|
14
|
+
* Limit search results
|
data/README.markdown
CHANGED
@@ -1,5 +1,44 @@
|
|
1
|
+
# Documentation
|
1
2
|
|
2
|
-
|
3
|
+
## New features
|
4
|
+
|
5
|
+
* Search by subject
|
6
|
+
* Limit the email search results
|
7
|
+
|
8
|
+
## Description
|
9
|
+
|
10
|
+
This is a fork of the original ruby-gmail gem created by Daniel Parker (http://github.com/dcparker/). Minor improvements have been made in email search functionality.
|
11
|
+
Search functionality now supports search by email subject and a limit on the number of search results.
|
12
|
+
|
13
|
+
## Example Code:
|
14
|
+
|
15
|
+
All the examples of the old ruby-gmail gem also hold good. The following examples demonstrate the newer search and limit capabilities.
|
16
|
+
|
17
|
+
### 1) Require gmail
|
18
|
+
|
19
|
+
require 'gmail'
|
20
|
+
|
21
|
+
### 2) Search emails
|
22
|
+
|
23
|
+
# Start an authenticated gmail session
|
24
|
+
gmail = Gmail.new(username, password)
|
25
|
+
|
26
|
+
# Get unread emails
|
27
|
+
gmail.inbox.email(:unread)
|
28
|
+
|
29
|
+
# Get unread emails from a specific sender to a specific recipient.
|
30
|
+
gmail.inbox.emails(:unread, to: 'foo@bar.com', from: 'bar@foo.com')
|
31
|
+
|
32
|
+
# Get emails matching a subject
|
33
|
+
gmail.inbox.emails(:unread, to: 'foo@bar.com', from: 'bar@foo.com', subject: 'Hello')
|
34
|
+
|
35
|
+
# Limit email search results
|
36
|
+
gmail.inbox.emails(:unread, limit: 5)
|
37
|
+
|
38
|
+
## Author
|
39
|
+
* Karthik Mallavarapu
|
40
|
+
|
41
|
+
# Old ruby-gmail documentation
|
3
42
|
|
4
43
|
* Code: [http://github.com/dcparker/ruby-gmail](http://github.com/dcparker/ruby-gmail)
|
5
44
|
* Gem: [http://gemcutter.org/gems/ruby-gmail](http://rubygems.org/gems/ruby-gmail)
|
@@ -18,12 +57,11 @@ Extra thanks for specific feature contributions from:
|
|
18
57
|
|
19
58
|
## Description
|
20
59
|
|
21
|
-
|
22
|
-
Search functionality now supports search by email subject and a limit on the number of search results. 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.
|
60
|
+
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.
|
23
61
|
|
24
62
|
## Features
|
25
63
|
|
26
|
-
* Search emails
|
64
|
+
* Search emails
|
27
65
|
* Read emails (handles attachments)
|
28
66
|
* Emails: Label, archive, delete, mark as read/unread/spam
|
29
67
|
* Create and delete labels
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/gmail.rb
CHANGED
data/lib/gmail/mailbox.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require 'time'
|
5
|
+
|
3
6
|
class Object
|
4
7
|
def to_imap_date
|
5
8
|
Date.parse(to_s).strftime("%d-%B-%Y")
|
@@ -29,6 +32,9 @@ class Gmail
|
|
29
32
|
# Adding subject as a search parameter option.
|
30
33
|
# Also adding a param called limit, for limiting the number of results.
|
31
34
|
def emails(key_or_opts = :all, opts={})
|
35
|
+
# filter results by search or limit if search or limit are not nil
|
36
|
+
subject = nil
|
37
|
+
limit = nil
|
32
38
|
if key_or_opts.is_a?(Hash) && opts.empty?
|
33
39
|
search = ['ALL']
|
34
40
|
opts = key_or_opts
|
@@ -52,22 +58,15 @@ class Gmail
|
|
52
58
|
search.concat ['ON', opts[:on].to_imap_date] if opts[:on]
|
53
59
|
search.concat ['FROM', opts[:from]] if opts[:from]
|
54
60
|
search.concat ['TO', opts[:to]] if opts[:to]
|
55
|
-
|
56
|
-
|
57
|
-
if
|
58
|
-
raise ArgumentError "limit parameter must be an integer to limit the email search results" unless
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# puts "Gathering #{(aliases[key] || key).inspect} messages for mailbox '#{name}'..."
|
63
|
-
@gmail.in_mailbox(self) do
|
64
|
-
email_results = @gmail.imap.uid_search(search).collect { |uid| messages[uid] ||= Message.new(@gmail, self, uid) }
|
65
|
-
limit = email_results.count
|
66
|
-
if opts[:limit]
|
67
|
-
limit = opts[:limit]
|
61
|
+
subject = opts[:subject]
|
62
|
+
limit = opts[:limit]
|
63
|
+
if limit
|
64
|
+
raise ArgumentError "limit parameter must be an integer to limit the email search results" unless limit.is_a? Integer
|
68
65
|
end
|
69
|
-
email_results.first(limit)
|
70
66
|
end
|
67
|
+
result = search_emails(search, subject)
|
68
|
+
limit = result.count if limit.nil?
|
69
|
+
result.first(limit)
|
71
70
|
end
|
72
71
|
|
73
72
|
# This is a convenience method that really probably shouldn't need to exist, but it does make code more readable
|
@@ -76,6 +75,23 @@ class Gmail
|
|
76
75
|
emails(*args).length
|
77
76
|
end
|
78
77
|
|
78
|
+
# Search mailbox with the given search string params and filter results by subject.
|
79
|
+
# Subject is not added to the search string, since IMAP raises an exception for non-ASCII strings
|
80
|
+
def search_emails(search, subject)
|
81
|
+
@gmail.in_mailbox(self) do
|
82
|
+
email_results = @gmail.imap.uid_search(search).collect { |uid| messages[uid] ||= Message.new(@gmail, self, uid) }
|
83
|
+
# If subject is not nil, filter results by subject and mark the rest of the emails as unread.
|
84
|
+
if subject
|
85
|
+
result = email_results.select {|email| email.subject == subject}
|
86
|
+
email_results.reject {|email| email.subject == subject}.each do |email|
|
87
|
+
email.mark(:unread)
|
88
|
+
end
|
89
|
+
return result
|
90
|
+
end
|
91
|
+
return email_results
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
79
95
|
def messages
|
80
96
|
@messages ||= {}
|
81
97
|
end
|
data/lib/gmail/message.rb
CHANGED
data/lib/smtp_tls.rb
CHANGED
data/ruby-gmail.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karthik-ruby-gmail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karthik Mallavarapu
|
@@ -14,45 +14,45 @@ dependencies:
|
|
14
14
|
name: shared-mime-info
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mail
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.2.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.2.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mime
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.1'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.1'
|
55
|
-
description:
|
55
|
+
description: "A Rubyesque interface to Gmail, with all the tools you'll need. Search,
|
56
56
|
read and send multipart emails; archive, mark as read/unread, delete emails; and
|
57
57
|
manage labels. Fork of \n the original ruby-gmail gem (https://github.com/dcparker/ruby-gmail).
|
58
58
|
Added search by subject, limit number of email search results."
|
@@ -86,17 +86,17 @@ require_paths:
|
|
86
86
|
- lib
|
87
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.0.0
|
100
100
|
signing_key:
|
101
101
|
specification_version: 3
|
102
102
|
summary: A Rubyesque interface to Gmail, with all the tools you'll need.
|