mail 2.2.9.1 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,12 @@
1
+ == Wed 17 Nov 2010 00:43:31 UTC Mikel Lindsaar <mikel@rubyx.com>
2
+
3
+ * Added test retriever and updated documentation (Donald Ball)
4
+ * Fix test suite to work in any timezone (Donald Ball)
5
+ * Added dependency for tlsmail for Ruby 1.8.6 (Donald Ball)
6
+ * Added new feature, replies for mail message
7
+ * Fix references header to use CFWS instead of comma as the separator per RFC2822
8
+ * Version Bum to 2.2.10 and pushed.
9
+
1
10
  == Mon Nov 15 13:04:41 UTC 2010 Mikel Lindsaar <mikel@rubyx.com>
2
11
 
3
12
  * Add find_and_delete convenience method for consistency with POP3, document delete_after_find option (Donald Ball)
data/lib/VERSION CHANGED
@@ -1,4 +1,4 @@
1
- patch:9
1
+ patch:10
2
2
  major:2
3
- build:1
3
+ build:
4
4
  minor:2
@@ -55,6 +55,8 @@ module Mail
55
55
  Mail::POP3
56
56
  when :imap
57
57
  Mail::IMAP
58
+ when :test
59
+ Mail::TestRetriever
58
60
  else
59
61
  method
60
62
  end
@@ -33,11 +33,11 @@ module Mail
33
33
  private
34
34
 
35
35
  def do_encode(field_name)
36
- %Q{#{field_name}: #{message_ids.map { |m| "<#{m}>" }.join(', ')}\r\n}
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 = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
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 = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
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 in a POP3 server.
145
- # See Mail::POP3 for a complete documentation.
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 a POP3 server.
151
- # See Mail::POP3 for a complete documentation.
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 a Pop3 server.
157
- # See Mail::POP3 for a complete documentation.
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 a Pop3 server.
163
- # See Mail::POP3 for a complete documentation.
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 a POP3 server.
169
- # See Mail::POP3 for a complete documentation.
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 a POP3 server.
180
- # See Mail::POP3 for a complete documentation.
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:
@@ -139,23 +91,6 @@ module Mail
139
91
  end
140
92
  end
141
93
 
142
- # Find emails in a IMAP mailbox, and then deletes them. Without any options, the
143
- # five last received emails are returned.
144
- #
145
- # Possible options:
146
- # what: last or first emails. The default is :first.
147
- # order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
148
- # count: number of emails to retrieve. The default value is 10. A value of 1 returns an
149
- # instance of Message, not an array of Message instances.
150
- # delete_after_find: flag for whether to delete each retreived email after find. Default
151
- # is true. Use #find_and_delete if you would like this to default to false.
152
- #
153
- def find_and_delete(options = {}, &block)
154
- options ||= {}
155
- options[:delete_after_find] ||= true
156
- find(options, &block)
157
- end
158
-
159
94
  # Delete all emails from a IMAP mailbox
160
95
  def delete_all(mailbox='INBOX')
161
96
  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,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 89
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 9
10
- - 1
11
- version: 2.2.9.1
9
+ - 10
10
+ version: 2.2.10
12
11
  platform: ruby
13
12
  authors:
14
13
  - Mikel Lindsaar
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-11-16 00:00:00 +11:00
18
+ date: 2010-11-17 00:00:00 +11:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -72,7 +71,7 @@ dependencies:
72
71
  requirement: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
- - - ">="
74
+ - - ~>
76
75
  - !ruby/object:Gem::Version
77
76
  hash: 13
78
77
  segments:
@@ -170,8 +169,10 @@ files:
170
169
  - lib/mail/network/delivery_methods/sendmail.rb
171
170
  - lib/mail/network/delivery_methods/smtp.rb
172
171
  - lib/mail/network/delivery_methods/test_mailer.rb
172
+ - lib/mail/network/retriever_methods/base.rb
173
173
  - lib/mail/network/retriever_methods/imap.rb
174
174
  - lib/mail/network/retriever_methods/pop3.rb
175
+ - lib/mail/network/retriever_methods/test_retriever.rb
175
176
  - lib/mail/network.rb
176
177
  - lib/mail/parsers/address_lists.rb
177
178
  - lib/mail/parsers/address_lists.treetop