mail 2.1.2 → 2.1.3

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/README.rdoc CHANGED
@@ -264,49 +264,46 @@ mail.deliver!
264
264
 
265
265
  The most recent email:
266
266
 
267
- require 'mail'
268
-
269
267
  Mail.defaults do
270
- pop3 'mail.myhost.com.au', 110 do
271
- user 'mikel'
272
- pass 'mypass'
273
- end
274
- end
275
-
276
- emails = Mail.last do |email|
277
- email.reply!("I'll be back on Monday, please be patient!") # +reply!+ still not implemented ^^
268
+ retriever_method :pop3, { :address => "pop.gmail.com",
269
+ :port => 995,
270
+ :user_name => '<username>',
271
+ :password => '<password>',
272
+ :enable_ssl => true }
278
273
  end
279
274
 
280
- The 3 oldest emails sorted by date in descendent order:
275
+ Mail.all #=> Returns an array of all emails
276
+ Mail.first #=> Returns the first unread email
277
+ Mail.last #=> Returns the first unread email
278
+
279
+ The first 10 emails sorted by date in ascending order:
281
280
 
282
281
  require 'mail'
283
282
 
284
283
  Mail.defaults do
285
- pop3 'mail.myhost.co.jp', 995 do
286
- user 'mikel'
287
- pass 'mypass'
288
- enable_tls
289
- end
284
+ retriever_method :pop3, { :address => "pop.gmail.com",
285
+ :port => 995,
286
+ :user_name => '<username>',
287
+ :password => '<password>',
288
+ :enable_ssl => true }
290
289
  end
291
290
 
292
- emails = Mail.first(:count => 3, :order => :desc) do |email|
293
- email.date
294
- end
291
+ emails = Mail.find(:what => :first, :count => 10, :order => :asc)
292
+ emails.length #=> 10
295
293
 
296
294
  Or even all emails:
297
295
 
298
- require 'mail'
299
-
300
296
  Mail.defaults do
301
- pop3 'mail.myhost.com.au' do
302
- user 'mikel'
303
- pass 'mypass'
304
- end
297
+ retriever_method :pop3, { :address => "pop.gmail.com",
298
+ :port => 995,
299
+ :user_name => '<username>',
300
+ :password => '<password>',
301
+ :enable_ssl => true }
305
302
  end
306
303
 
307
304
  emails = Mail.all
308
305
 
309
- emails.length #=> 12
306
+ emails.length #=> LOTS!
310
307
 
311
308
  === Reading an Email
312
309
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'bundler'
12
12
 
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = "mail"
15
- s.version = "2.1.2"
15
+ s.version = "2.1.3"
16
16
  s.author = "Mike Lindsaar"
17
17
  s.email = "raasdnil@gmail.com"
18
18
  s.homepage = "http://github.com/mikel/mail"
data/lib/mail/header.rb CHANGED
@@ -174,6 +174,10 @@ module Mail
174
174
  raise NoMethodError, 'Can not decode an entire header as there could be character set conflicts, try calling #decoded on the various fields.'
175
175
  end
176
176
 
177
+ def field_summary
178
+ fields.map { |f| "<#{f.name}: #{f.value}>" }.join(", ")
179
+ end
180
+
177
181
  # Returns true if the header has a Message-ID defined (empty or not)
178
182
  def has_message_id?
179
183
  !fields.select { |f| f.responsible_for?('Message-ID') }.empty?
data/lib/mail/mail.rb CHANGED
@@ -170,6 +170,46 @@ module Mail
170
170
  Mail.new(File.read(filename))
171
171
  end
172
172
 
173
+ # Initialize the observers and interceptors arrays
174
+ @@delivery_notification_observers = []
175
+ @@delivery_interceptors = []
176
+
177
+ # You can register an object to be informed of every email that is sent through
178
+ # this method.
179
+ #
180
+ # Your object needs to respond to a single method #delivered_email(mail)
181
+ # which receives the email that is sent.
182
+ def Mail.register_observer(observer)
183
+ unless @@delivery_notification_observers.include?(observer)
184
+ @@delivery_notification_observers << observer
185
+ end
186
+ end
187
+
188
+ # You can register an object to be given every mail object that will be sent,
189
+ # before it is sent. So if you want to add special headers or modify any
190
+ # email that gets sent through the Mail library, you can do so.
191
+ #
192
+ # Your object needs to respond to a single method #delivering_email(mail)
193
+ # which receives the email that is about to be sent. Make your modifications
194
+ # directly to this object.
195
+ def Mail.register_interceptor(interceptor)
196
+ unless @@delivery_interceptors.include?(interceptor)
197
+ @@delivery_interceptors << interceptor
198
+ end
199
+ end
200
+
201
+ def Mail.inform_observers(mail)
202
+ @@delivery_notification_observers.each do |observer|
203
+ observer.delivered_email(mail)
204
+ end
205
+ end
206
+
207
+ def Mail.inform_interceptors(mail)
208
+ @@delivery_interceptors.each do |interceptor|
209
+ interceptor.delivering_email(mail)
210
+ end
211
+ end
212
+
173
213
  protected
174
214
 
175
215
  def Mail.random_tag
data/lib/mail/message.rb CHANGED
@@ -46,7 +46,7 @@ module Mail
46
46
 
47
47
  include Patterns
48
48
  include Utilities
49
-
49
+
50
50
  # ==Making an email
51
51
  #
52
52
  # You can make an new mail object via a block, passing a string, file or direct assignment.
@@ -106,8 +106,7 @@ module Mail
106
106
  @delivery_handler = nil
107
107
 
108
108
  @delivery_method = Mail.delivery_method.dup
109
- @delivery_notification_observers = []
110
-
109
+
111
110
  if args.flatten.first.respond_to?(:each_pair)
112
111
  init_with_hash(args.flatten.first)
113
112
  else
@@ -194,15 +193,16 @@ module Mail
194
193
  attr_accessor :raise_delivery_errors
195
194
 
196
195
  def register_for_delivery_notification(observer)
197
- unless @delivery_notification_observers.include?(observer)
198
- @delivery_notification_observers << observer
199
- end
196
+ STDERR.puts("Message#register_for_delivery_notification is deprecated, please call Mail.register_observer instead")
197
+ Mail.register_observer(observer)
200
198
  end
201
199
 
202
200
  def inform_observers
203
- @delivery_notification_observers.each do |observer|
204
- observer.delivered_email(self)
205
- end
201
+ Mail.inform_observers(self)
202
+ end
203
+
204
+ def inform_interceptors
205
+ Mail.inform_interceptors(self)
206
206
  end
207
207
 
208
208
  # Delivers an mail object.
@@ -212,12 +212,13 @@ module Mail
212
212
  # mail = Mail.read('file.eml')
213
213
  # mail.deliver
214
214
  def deliver
215
+ inform_interceptors
215
216
  if delivery_handler
216
217
  delivery_handler.deliver_mail(self) { do_delivery }
217
218
  else
218
219
  do_delivery
219
- inform_observers
220
220
  end
221
+ inform_observers
221
222
  self
222
223
  end
223
224
 
@@ -1611,6 +1612,10 @@ module Mail
1611
1612
  encoded
1612
1613
  end
1613
1614
 
1615
+ def inspect
1616
+ "#<#{self.class}:#{self.object_id}, Multipart: #{multipart?}, Headers: #{header.field_summary}>"
1617
+ end
1618
+
1614
1619
  def decoded
1615
1620
  if self.attachment?
1616
1621
  decode_body
@@ -1681,7 +1686,7 @@ module Mail
1681
1686
  end
1682
1687
 
1683
1688
  def set_envelope_header
1684
- if match_data = raw_source.to_s.match(/^From\s(#{TEXT}+)#{CRLF}(.*)/m)
1689
+ if match_data = raw_source.to_s.match(/\AFrom\s(#{TEXT}+)#{CRLF}(.*)/m)
1685
1690
  set_envelope(match_data[1])
1686
1691
  self.raw_source = match_data[2]
1687
1692
  end
data/lib/mail/version.rb CHANGED
@@ -3,7 +3,7 @@ module Mail
3
3
  module VERSION
4
4
  MAJOR = 2
5
5
  MINOR = 1
6
- TINY = 2
6
+ TINY = 3
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Lindsaar
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-28 00:00:00 +11:00
12
+ date: 2010-02-22 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency