dball-mail 2.2.9.4 → 2.2.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/lib/VERSION +1 -1
- data/lib/mail/fields/common/common_message_id.rb +2 -2
- data/lib/mail/fields/date_field.rb +1 -1
- data/lib/mail/fields/resent_date_field.rb +1 -1
- data/lib/mail/mail.rb +12 -12
- data/lib/mail/message.rb +36 -0
- data/lib/mail/network.rb +3 -0
- data/lib/mail/network/retriever_methods/base.rb +63 -0
- data/lib/mail/network/retriever_methods/imap.rb +1 -66
- data/lib/mail/network/retriever_methods/pop3.rb +1 -55
- data/lib/mail/network/retriever_methods/test_retriever.rb +40 -0
- metadata +23 -8
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== Mon Nov 15 13:04:41 UTC 2010 Mikel Lindsaar <mikel@rubyx.com>
|
2
|
+
|
3
|
+
* Add find_and_delete convenience method for consistency with POP3, document delete_after_find option (Donald Ball)
|
4
|
+
* Documenting the openssl_verify_mode setting (Donald Ball)
|
5
|
+
* Added ruby-1.8.6 back into the list of tested platforms (Donald Ball)
|
6
|
+
* Relax i18n dependency until we remove active support requirement
|
7
|
+
* Version Bump to 2.2.9.1 to include new i18n dependency
|
8
|
+
|
1
9
|
== Tue Oct 26 07:14:36 UTC 2010 Mikel Lindsaar <mikel@rubyx.com>
|
2
10
|
|
3
11
|
* Version Bump to 2.2.9 and tag
|
data/lib/VERSION
CHANGED
@@ -33,11 +33,11 @@ module Mail
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def do_encode(field_name)
|
36
|
-
%Q{#{field_name}: #{
|
36
|
+
%Q{#{field_name}: #{do_decode}\r\n}
|
37
37
|
end
|
38
38
|
|
39
39
|
def do_decode
|
40
|
-
"#{message_ids.map { |m| "<#{m}>" }.join('
|
40
|
+
"#{message_ids.map { |m| "<#{m}>" }.join(' ')}"
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -34,7 +34,7 @@ module Mail
|
|
34
34
|
def initialize(value = nil, charset = 'utf-8')
|
35
35
|
self.charset = charset
|
36
36
|
if value.blank?
|
37
|
-
value =
|
37
|
+
value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
|
38
38
|
else
|
39
39
|
value = strip_field(FIELD_NAME, value)
|
40
40
|
value.to_s.gsub!(/\(.*?\)/, '')
|
@@ -14,7 +14,7 @@ module Mail
|
|
14
14
|
def initialize(value = nil, charset = 'utf-8')
|
15
15
|
self.charset = charset
|
16
16
|
if value.blank?
|
17
|
-
value =
|
17
|
+
value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
|
18
18
|
else
|
19
19
|
value = strip_field(FIELD_NAME, value)
|
20
20
|
value = ::DateTime.parse(value.to_s).strftime('%a, %d %b %Y %H:%M:%S %z')
|
data/lib/mail/mail.rb
CHANGED
@@ -141,32 +141,32 @@ module Mail
|
|
141
141
|
mail
|
142
142
|
end
|
143
143
|
|
144
|
-
# Find emails
|
145
|
-
# See Mail::
|
144
|
+
# Find emails from the default retriever
|
145
|
+
# See Mail::Retriever for a complete documentation.
|
146
146
|
def self.find(*args, &block)
|
147
147
|
retriever_method.find(*args, &block)
|
148
148
|
end
|
149
149
|
|
150
|
-
# Finds and then deletes retrieved emails from
|
151
|
-
# See Mail::
|
150
|
+
# Finds and then deletes retrieved emails from the default retriever
|
151
|
+
# See Mail::Retriever for a complete documentation.
|
152
152
|
def self.find_and_delete(*args, &block)
|
153
153
|
retriever_method.find_and_delete(*args, &block)
|
154
154
|
end
|
155
155
|
|
156
|
-
# Receive the first email(s) from
|
157
|
-
# See Mail::
|
156
|
+
# Receive the first email(s) from the default retriever
|
157
|
+
# See Mail::Retriever for a complete documentation.
|
158
158
|
def self.first(*args, &block)
|
159
159
|
retriever_method.first(*args, &block)
|
160
160
|
end
|
161
161
|
|
162
|
-
# Receive the first email(s) from
|
163
|
-
# See Mail::
|
162
|
+
# Receive the first email(s) from the default retriever
|
163
|
+
# See Mail::Retriever for a complete documentation.
|
164
164
|
def self.last(*args, &block)
|
165
165
|
retriever_method.last(*args, &block)
|
166
166
|
end
|
167
167
|
|
168
|
-
# Receive all emails from
|
169
|
-
# See Mail::
|
168
|
+
# Receive all emails from the default retriever
|
169
|
+
# See Mail::Retriever for a complete documentation.
|
170
170
|
def self.all(*args, &block)
|
171
171
|
retriever_method.all(*args, &block)
|
172
172
|
end
|
@@ -176,8 +176,8 @@ module Mail
|
|
176
176
|
self.new(File.open(filename, 'rb') { |f| f.read })
|
177
177
|
end
|
178
178
|
|
179
|
-
# Delete all emails from
|
180
|
-
# See Mail::
|
179
|
+
# Delete all emails from the default retriever
|
180
|
+
# See Mail::Retriever for a complete documentation.
|
181
181
|
def self.delete_all(*args, &block)
|
182
182
|
retriever_method.delete_all(*args, &block)
|
183
183
|
end
|
data/lib/mail/message.rb
CHANGED
@@ -253,6 +253,42 @@ module Mail
|
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
256
|
+
def reply(*args, &block)
|
257
|
+
self.class.new.tap do |reply|
|
258
|
+
if message_id
|
259
|
+
bracketed_message_id = "<#{message_id}>"
|
260
|
+
reply.in_reply_to = bracketed_message_id
|
261
|
+
if !references.nil?
|
262
|
+
reply.references = (references.to_a.map { |r| "<#{r}>" } << bracketed_message_id).join(' ')
|
263
|
+
elsif !in_reply_to.nil? && !in_reply_to.kind_of?(Array)
|
264
|
+
reply.references = "<#{in_reply_to}> #{bracketed_message_id}"
|
265
|
+
end
|
266
|
+
reply.references ||= bracketed_message_id
|
267
|
+
end
|
268
|
+
if subject
|
269
|
+
reply.subject = "RE: #{subject}"
|
270
|
+
end
|
271
|
+
if reply_to || from
|
272
|
+
reply.to = self[reply_to ? :reply_to : :from].to_s
|
273
|
+
end
|
274
|
+
if to
|
275
|
+
reply.from = self[:to].formatted.first.to_s
|
276
|
+
end
|
277
|
+
|
278
|
+
unless args.empty?
|
279
|
+
if args.flatten.first.respond_to?(:each_pair)
|
280
|
+
reply.send(:init_with_hash, args.flatten.first)
|
281
|
+
else
|
282
|
+
reply.send(:init_with_string, args.flatten[0].to_s.strip)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
if block_given?
|
287
|
+
reply.instance_eval(&block)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
256
292
|
# Provides the operator needed for sort et al.
|
257
293
|
#
|
258
294
|
# Compares this mail object with another mail object, this is done by date, so an
|
data/lib/mail/network.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mail/network/retriever_methods/base'
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
autoload :SMTP, 'mail/network/delivery_methods/smtp'
|
3
5
|
autoload :FileDelivery, 'mail/network/delivery_methods/file_delivery'
|
@@ -6,4 +8,5 @@ module Mail
|
|
6
8
|
|
7
9
|
autoload :POP3, 'mail/network/retriever_methods/pop3'
|
8
10
|
autoload :IMAP, 'mail/network/retriever_methods/imap'
|
11
|
+
autoload :TestRetriever, 'mail/network/retriever_methods/test_retriever'
|
9
12
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
|
5
|
+
class Retriever
|
6
|
+
|
7
|
+
# Get the oldest received email(s)
|
8
|
+
#
|
9
|
+
# Possible options:
|
10
|
+
# count: number of emails to retrieve. The default value is 1.
|
11
|
+
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
12
|
+
#
|
13
|
+
def first(options = {}, &block)
|
14
|
+
options ||= {}
|
15
|
+
options[:what] = :first
|
16
|
+
options[:count] ||= 1
|
17
|
+
find(options, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the most recent received email(s)
|
21
|
+
#
|
22
|
+
# Possible options:
|
23
|
+
# count: number of emails to retrieve. The default value is 1.
|
24
|
+
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
25
|
+
#
|
26
|
+
def last(options = {}, &block)
|
27
|
+
options ||= {}
|
28
|
+
options[:what] = :last
|
29
|
+
options[:count] ||= 1
|
30
|
+
find(options, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get all emails.
|
34
|
+
#
|
35
|
+
# Possible options:
|
36
|
+
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
37
|
+
#
|
38
|
+
def all(options = {}, &block)
|
39
|
+
options ||= {}
|
40
|
+
options[:count] = :all
|
41
|
+
find(options, &block)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Find emails in the mailbox, and then deletes them. Without any options, the
|
45
|
+
# five last received emails are returned.
|
46
|
+
#
|
47
|
+
# Possible options:
|
48
|
+
# what: last or first emails. The default is :first.
|
49
|
+
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
50
|
+
# count: number of emails to retrieve. The default value is 10. A value of 1 returns an
|
51
|
+
# instance of Message, not an array of Message instances.
|
52
|
+
# delete_after_find: flag for whether to delete each retreived email after find. Default
|
53
|
+
# is true. Call #find if you would like this to default to false.
|
54
|
+
#
|
55
|
+
def find_and_delete(options = {}, &block)
|
56
|
+
options ||= {}
|
57
|
+
options[:delete_after_find] ||= true
|
58
|
+
find(options, &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -32,7 +32,7 @@ module Mail
|
|
32
32
|
# Mail.find(:what => :first, :count => 10, :order => :asc)
|
33
33
|
# #=> Returns the first 10 emails in ascending order
|
34
34
|
#
|
35
|
-
class IMAP
|
35
|
+
class IMAP < Retriever
|
36
36
|
require 'net/imap'
|
37
37
|
|
38
38
|
def initialize(values)
|
@@ -46,54 +46,6 @@ module Mail
|
|
46
46
|
|
47
47
|
attr_accessor :settings
|
48
48
|
|
49
|
-
# Get the oldest received email(s)
|
50
|
-
#
|
51
|
-
# Possible options:
|
52
|
-
# mailbox: mailbox to retrieve the oldest received email(s) from. The default is 'INBOX'.
|
53
|
-
# count: number of emails to retrieve. The default value is 1.
|
54
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
55
|
-
# keys: keywords for the imap SEARCH command. Can be either a string holding the entire
|
56
|
-
# search string or a single-dimension array of search keywords and arguments.
|
57
|
-
#
|
58
|
-
def first(options={}, &block)
|
59
|
-
options ||= {}
|
60
|
-
options[:what] = :first
|
61
|
-
options[:count] ||= 1
|
62
|
-
find(options, &block)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Get the most recent received email(s)
|
66
|
-
#
|
67
|
-
# Possible options:
|
68
|
-
# mailbox: mailbox to retrieve the most recent received email(s) from. The default is 'INBOX'.
|
69
|
-
# count: number of emails to retrieve. The default value is 1.
|
70
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
71
|
-
# keys: keywords for the imap SEARCH command. Can be either a string holding the entire
|
72
|
-
# search string or a single-dimension array of search keywords and arguments.
|
73
|
-
#
|
74
|
-
def last(options={}, &block)
|
75
|
-
options ||= {}
|
76
|
-
options[:what] = :last
|
77
|
-
options[:count] ||= 1
|
78
|
-
find(options, &block)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Get all emails.
|
82
|
-
#
|
83
|
-
# Possible options:
|
84
|
-
# mailbox: mailbox to retrieve all email(s) from. The default is 'INBOX'.
|
85
|
-
# count: number of emails to retrieve. The default value is 1.
|
86
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
87
|
-
# keys: keywords for the imap SEARCH command. Can be either a string holding the entire
|
88
|
-
# search string or a single-dimension array of search keywords and arguments.
|
89
|
-
#
|
90
|
-
def all(options={}, &block)
|
91
|
-
options ||= {}
|
92
|
-
options[:count] = :all
|
93
|
-
options[:keys] = 'ALL'
|
94
|
-
find(options, &block)
|
95
|
-
end
|
96
|
-
|
97
49
|
# Find emails in a IMAP mailbox. Without any options, the 10 last received emails are returned.
|
98
50
|
#
|
99
51
|
# Possible options:
|
@@ -143,23 +95,6 @@ module Mail
|
|
143
95
|
end
|
144
96
|
end
|
145
97
|
|
146
|
-
# Find emails in a IMAP mailbox, and then deletes them. Without any options, the
|
147
|
-
# five last received emails are returned.
|
148
|
-
#
|
149
|
-
# Possible options:
|
150
|
-
# what: last or first emails. The default is :first.
|
151
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
152
|
-
# count: number of emails to retrieve. The default value is 10. A value of 1 returns an
|
153
|
-
# instance of Message, not an array of Message instances.
|
154
|
-
# delete_after_find: flag for whether to delete each retreived email after find. Default
|
155
|
-
# is true. Use #find_and_delete if you would like this to default to false.
|
156
|
-
#
|
157
|
-
def find_and_delete(options = {}, &block)
|
158
|
-
options ||= {}
|
159
|
-
options[:delete_after_find] ||= true
|
160
|
-
find(options, &block)
|
161
|
-
end
|
162
|
-
|
163
98
|
# Delete all emails from a IMAP mailbox
|
164
99
|
def delete_all(mailbox='INBOX')
|
165
100
|
mailbox ||= 'INBOX'
|
@@ -31,7 +31,7 @@ module Mail
|
|
31
31
|
# Mail.find(:what => :first, :count => 10, :order => :asc)
|
32
32
|
# #=> Returns the first 10 emails in ascending order
|
33
33
|
#
|
34
|
-
class POP3
|
34
|
+
class POP3 < Retriever
|
35
35
|
require 'net/pop'
|
36
36
|
|
37
37
|
def initialize(values)
|
@@ -45,43 +45,6 @@ module Mail
|
|
45
45
|
|
46
46
|
attr_accessor :settings
|
47
47
|
|
48
|
-
# Get the oldest received email(s)
|
49
|
-
#
|
50
|
-
# Possible options:
|
51
|
-
# count: number of emails to retrieve. The default value is 1.
|
52
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
53
|
-
#
|
54
|
-
def first(options = {}, &block)
|
55
|
-
options ||= {}
|
56
|
-
options[:what] = :first
|
57
|
-
options[:count] ||= 1
|
58
|
-
find(options, &block)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Get the most recent received email(s)
|
62
|
-
#
|
63
|
-
# Possible options:
|
64
|
-
# count: number of emails to retrieve. The default value is 1.
|
65
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
66
|
-
#
|
67
|
-
def last(options = {}, &block)
|
68
|
-
options ||= {}
|
69
|
-
options[:what] = :last
|
70
|
-
options[:count] ||= 1
|
71
|
-
find(options, &block)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Get all emails.
|
75
|
-
#
|
76
|
-
# Possible options:
|
77
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
78
|
-
#
|
79
|
-
def all(options = {}, &block)
|
80
|
-
options ||= {}
|
81
|
-
options[:count] = :all
|
82
|
-
find(options, &block)
|
83
|
-
end
|
84
|
-
|
85
48
|
# Find emails in a POP3 mailbox. Without any options, the 5 last received emails are returned.
|
86
49
|
#
|
87
50
|
# Possible options:
|
@@ -125,23 +88,6 @@ module Mail
|
|
125
88
|
end
|
126
89
|
end
|
127
90
|
|
128
|
-
# Find emails in a POP3 mailbox, and then deletes them. Without any options, the
|
129
|
-
# five last received emails are returned.
|
130
|
-
#
|
131
|
-
# Possible options:
|
132
|
-
# what: last or first emails. The default is :first.
|
133
|
-
# order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
|
134
|
-
# count: number of emails to retrieve. The default value is 10. A value of 1 returns an
|
135
|
-
# instance of Message, not an array of Message instances.
|
136
|
-
# delete_after_find: flag for whether to delete each retreived email after find. Default
|
137
|
-
# is true. Call #find if you would like this to default to false.
|
138
|
-
#
|
139
|
-
def find_and_delete(options = {}, &block)
|
140
|
-
options ||= {}
|
141
|
-
options[:delete_after_find] ||= true
|
142
|
-
find(options, &block)
|
143
|
-
end
|
144
|
-
|
145
91
|
# Delete all emails from a POP3 server
|
146
92
|
def delete_all
|
147
93
|
start do |pop3|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
|
5
|
+
class TestRetriever < Retriever
|
6
|
+
cattr_accessor :emails
|
7
|
+
|
8
|
+
def initialize(values)
|
9
|
+
@@emails = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(options = {}, &block)
|
13
|
+
options[:count] ||= :all
|
14
|
+
options[:order] ||= :asc
|
15
|
+
options[:what] ||= :first
|
16
|
+
emails = @@emails.dup
|
17
|
+
emails.reverse! if options[:what] == :last
|
18
|
+
emails = case count = options[:count]
|
19
|
+
when :all then emails
|
20
|
+
when 1 then emails.first
|
21
|
+
when Fixnum then emails[0, count]
|
22
|
+
else
|
23
|
+
raise 'Invalid count option value: ' + count.inspect
|
24
|
+
end
|
25
|
+
if options[:what] == :last && options[:order] == :asc || options[:what] == :first && options[:order] == :desc
|
26
|
+
emails.reverse!
|
27
|
+
end
|
28
|
+
emails.each { |email| email.mark_for_delete = true } if options[:delete_after_find]
|
29
|
+
if block_given?
|
30
|
+
emails.each { |email| yield email }
|
31
|
+
else
|
32
|
+
emails
|
33
|
+
end.tap do |results|
|
34
|
+
emails.each { |email| @@emails.delete(email) if email.is_marked_for_delete? } if options[:delete_after_find]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dball-mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 87
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 2
|
9
9
|
- 9
|
10
|
-
-
|
11
|
-
version: 2.2.9.
|
10
|
+
- 6
|
11
|
+
version: 2.2.9.6
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Mikel Lindsaar
|
15
|
-
- Donald Ball
|
16
15
|
autorequire:
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
@@ -83,10 +82,24 @@ dependencies:
|
|
83
82
|
requirement: *id004
|
84
83
|
type: :runtime
|
85
84
|
name: i18n
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 29
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
- 0
|
95
|
+
- 1
|
96
|
+
version: 0.0.1
|
97
|
+
prerelease: false
|
98
|
+
requirement: *id005
|
99
|
+
type: :runtime
|
100
|
+
name: tlsmail
|
86
101
|
description: A really Ruby Mail handler.
|
87
|
-
email:
|
88
|
-
- raasdnil@gmail.com
|
89
|
-
- donald.ball@gmail.com
|
102
|
+
email: raasdnil@gmail.com
|
90
103
|
executables: []
|
91
104
|
|
92
105
|
extensions: []
|
@@ -173,8 +186,10 @@ files:
|
|
173
186
|
- lib/mail/network/delivery_methods/sendmail.rb
|
174
187
|
- lib/mail/network/delivery_methods/smtp.rb
|
175
188
|
- lib/mail/network/delivery_methods/test_mailer.rb
|
189
|
+
- lib/mail/network/retriever_methods/base.rb
|
176
190
|
- lib/mail/network/retriever_methods/imap.rb
|
177
191
|
- lib/mail/network/retriever_methods/pop3.rb
|
192
|
+
- lib/mail/network/retriever_methods/test_retriever.rb
|
178
193
|
- lib/mail/network.rb
|
179
194
|
- lib/mail/parsers/address_lists.rb
|
180
195
|
- lib/mail/parsers/address_lists.treetop
|
@@ -217,7 +232,7 @@ files:
|
|
217
232
|
- lib/VERSION
|
218
233
|
- CHANGELOG.rdoc
|
219
234
|
has_rdoc: true
|
220
|
-
homepage: http://github.com/
|
235
|
+
homepage: http://github.com/mikel/mail
|
221
236
|
licenses: []
|
222
237
|
|
223
238
|
post_install_message:
|