mail 1.1.0 → 1.2.1

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.

Files changed (50) hide show
  1. data/CHANGELOG.rdoc +14 -1
  2. data/README.rdoc +37 -13
  3. data/lib/mail/configuration.rb +4 -0
  4. data/lib/mail/elements/address.rb +11 -0
  5. data/lib/mail/encodings/base64.rb +1 -0
  6. data/lib/mail/encodings/encodings.rb +133 -6
  7. data/lib/mail/encodings/quoted_printable.rb +1 -1
  8. data/lib/mail/field.rb +34 -34
  9. data/lib/mail/fields/bcc_field.rb +10 -1
  10. data/lib/mail/fields/cc_field.rb +10 -1
  11. data/lib/mail/fields/comments_field.rb +2 -1
  12. data/lib/mail/fields/common/common_address.rb +25 -1
  13. data/lib/mail/fields/common/common_date.rb +8 -5
  14. data/lib/mail/fields/common/common_field.rb +2 -74
  15. data/lib/mail/fields/common/common_message_id.rb +10 -0
  16. data/lib/mail/fields/common/parameter_hash.rb +10 -0
  17. data/lib/mail/fields/content_description_field.rb +3 -2
  18. data/lib/mail/fields/content_disposition_field.rb +12 -2
  19. data/lib/mail/fields/content_id_field.rb +12 -2
  20. data/lib/mail/fields/content_location_field.rb +12 -2
  21. data/lib/mail/fields/content_transfer_encoding_field.rb +12 -2
  22. data/lib/mail/fields/content_type_field.rb +26 -5
  23. data/lib/mail/fields/date_field.rb +11 -2
  24. data/lib/mail/fields/from_field.rb +10 -1
  25. data/lib/mail/fields/in_reply_to_field.rb +10 -1
  26. data/lib/mail/fields/keywords_field.rb +10 -1
  27. data/lib/mail/fields/message_id_field.rb +11 -2
  28. data/lib/mail/fields/mime_version_field.rb +11 -2
  29. data/lib/mail/fields/received_field.rb +10 -1
  30. data/lib/mail/fields/references_field.rb +10 -1
  31. data/lib/mail/fields/reply_to_field.rb +10 -1
  32. data/lib/mail/fields/resent_bcc_field.rb +10 -1
  33. data/lib/mail/fields/resent_cc_field.rb +10 -1
  34. data/lib/mail/fields/resent_date_field.rb +10 -1
  35. data/lib/mail/fields/resent_from_field.rb +10 -1
  36. data/lib/mail/fields/resent_message_id_field.rb +10 -1
  37. data/lib/mail/fields/resent_sender_field.rb +10 -1
  38. data/lib/mail/fields/resent_to_field.rb +10 -1
  39. data/lib/mail/fields/return_path_field.rb +10 -1
  40. data/lib/mail/fields/sender_field.rb +10 -1
  41. data/lib/mail/fields/subject_field.rb +2 -1
  42. data/lib/mail/fields/to_field.rb +10 -1
  43. data/lib/mail/fields/unstructured_field.rb +82 -0
  44. data/lib/mail/header.rb +2 -2
  45. data/lib/mail/message.rb +25 -9
  46. data/lib/mail/utilities.rb +7 -1
  47. data/lib/mail/version.rb +2 -2
  48. data/lib/mail/version_specific/ruby_1_8.rb +30 -10
  49. data/lib/mail/version_specific/ruby_1_9.rb +30 -8
  50. metadata +1 -1
data/lib/mail/header.rb CHANGED
@@ -160,7 +160,7 @@ module Mail
160
160
  def encoded
161
161
  buffer = ''
162
162
  fields.each do |field|
163
- buffer << field.encoded.to_s
163
+ buffer << field.encoded
164
164
  end
165
165
  buffer
166
166
  end
@@ -221,7 +221,7 @@ module Mail
221
221
  end
222
222
 
223
223
  def limited_field?(name)
224
- LIMITED_FIELDS.include?(name.downcase)
224
+ LIMITED_FIELDS.include?(name.to_s.downcase)
225
225
  end
226
226
 
227
227
  end
data/lib/mail/message.rb CHANGED
@@ -200,6 +200,20 @@ module Mail
200
200
  value ? self.from = value : header[:from]
201
201
  end
202
202
 
203
+ # Returns the list of addresses this message should be sent to by
204
+ # collecting the addresses off the to, cc and bcc fields.
205
+ #
206
+ # Example:
207
+ #
208
+ # mail.to = 'mikel@test.lindsaar.net'
209
+ # mail.cc = 'sam@test.lindsaar.net'
210
+ # mail.bcc = 'bob@test.lindsaar.net'
211
+ # mail.destinations.length #=> 3
212
+ # mail.destinations.first #=> 'mikel@test.lindsaar.net'
213
+ def destinations
214
+ [to, cc, bcc].map { |f| f.addresses if f }.compact.flatten
215
+ end
216
+
203
217
  # Sets the subject field in the message header.
204
218
  #
205
219
  # Example:
@@ -559,23 +573,21 @@ module Mail
559
573
 
560
574
  # Encodes the message, calls encode on all it's parts, gets an email message
561
575
  # ready to send
562
- def encode!
563
- parts.each { |part| part.encode! }
576
+ def ready_to_send!
577
+ parts.each { |part| part.ready_to_send! }
564
578
  add_required_fields
565
579
  end
566
-
567
- # Decodes the message, calls decode on all it's parts, gets an email message
568
- # ready to send
569
- def decode!
570
- parts.each { |part| part.decode! }
571
- add_required_fields
580
+
581
+ def encode!
582
+ STDERR.puts("Deprecated in 1.1.0 in favour of :ready_to_send! as it is less confusing with encoding and decoding.")
583
+ ready_to_send!
572
584
  end
573
585
 
574
586
  # Outputs an encoded string representation of the mail message including
575
587
  # all headers, attachments, etc. This is an encoded email in US-ASCII,
576
588
  # so it is able to be directly sent to an email server.
577
589
  def encoded
578
- encode!
590
+ ready_to_send!
579
591
  buffer = header.encoded
580
592
  buffer << "\r\n"
581
593
  buffer << body.encoded
@@ -584,6 +596,10 @@ module Mail
584
596
 
585
597
  alias :to_s :encoded
586
598
 
599
+ def decoded
600
+ raise NoMethodError, 'Can not decode an entire message, try calling #decoded on the various fields and body or parts if it is a multipart message.'
601
+ end
602
+
587
603
  private
588
604
 
589
605
  # 2.1. General Description
@@ -24,7 +24,13 @@ module Mail
24
24
  # If the string supplied has PHRASE unsafe characters in it, will return the string quoted
25
25
  # in double quotes, otherwise returns the string unmodified
26
26
  def quote_phrase( str )
27
- (PHRASE_UNSAFE === str) ? dquote(str) : str
27
+ if RUBY_VERSION >= '1.9'
28
+ string = str.dup
29
+ string.force_encoding('ASCII-8BIT')
30
+ (PHRASE_UNSAFE === string) ? dquote(str) : str
31
+ else
32
+ (PHRASE_UNSAFE === str) ? dquote(str) : str
33
+ end
28
34
  end
29
35
 
30
36
  # Returns true if the string supplied is free from characters not allowed as a TOKEN
data/lib/mail/version.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  module Mail
3
3
  module VERSION
4
4
  MAJOR = 1
5
- MINOR = 1
6
- TINY = 0
5
+ MINOR = 2
6
+ TINY = 1
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
@@ -36,29 +36,49 @@ module Mail
36
36
  def Ruby18.get_constant(klass, string)
37
37
  klass.const_get( string )
38
38
  end
39
-
40
- def Ruby18.b_encode(str, encoding)
39
+
40
+ def Ruby18.b_value_encode(str, encoding)
41
41
  # Ruby 1.8 requires an encoding to work
42
42
  raise ArgumentError, "Must supply an encoding" if encoding.nil?
43
- return str if str.ascii_only?
44
43
  encoding = encoding.to_s.upcase.gsub('_', '-')
45
- string = Encodings::Base64.encode(str)
46
- "=?#{encoding}?B?#{string.chomp}?="
44
+ [Encodings::Base64.encode(str), encoding]
47
45
  end
48
-
49
- def Ruby18.q_encode(str, encoding)
46
+
47
+ def Ruby18.b_value_decode(str)
48
+ match = str.match(/\=\?(.+)?\?B\?(.+)?\?\=/)
49
+ if match
50
+ encoding = match[1]
51
+ str = Ruby18.decode_base64(match[2])
52
+ end
53
+ str
54
+ end
55
+
56
+ def Ruby18.q_value_encode(str, encoding)
50
57
  # Ruby 1.8 requires an encoding to work
51
58
  raise ArgumentError, "Must supply an encoding" if encoding.nil?
52
- return str if str.ascii_only?
53
59
  encoding = encoding.to_s.upcase.gsub('_', '-')
54
- string = Encodings::QuotedPrintable.encode(str)
55
- "=?#{encoding}?Q?#{string.chomp}?="
60
+ [Encodings::QuotedPrintable.encode(str), encoding]
61
+ end
62
+
63
+ def Ruby18.q_value_decode(str)
64
+ match = str.match(/\=\?(.+)?\?Q\?(.+)?\?\=/)
65
+ if match
66
+ encoding = match[1]
67
+ str = Encodings::QuotedPrintable.decode(match[2])
68
+ end
69
+ str
56
70
  end
57
71
 
58
72
  def Ruby18.param_decode(str, encoding)
59
73
  URI.unescape(str)
60
74
  end
61
75
 
76
+ def Ruby18.param_encode(str)
77
+ encoding = $KCODE.to_s.downcase
78
+ language = Mail::Configuration.instance.param_encode_language
79
+ "#{encoding}'#{language}'#{URI.escape(str)}"
80
+ end
81
+
62
82
  end
63
83
 
64
84
  end
@@ -31,18 +31,34 @@ module Mail
31
31
  klass.const_get( string.to_sym )
32
32
  end
33
33
 
34
- def Ruby19.b_encode(str, encoding = nil)
35
- return str if str.ascii_only?
34
+ def Ruby19.b_value_encode(str, encoding = nil)
36
35
  encoding = str.encoding.to_s
37
- string = Encodings::Base64.encode(str)
38
- "=?#{encoding}?B?#{string.chomp}?="
36
+ [Ruby19.encode_base64(str), encoding]
39
37
  end
40
38
 
41
- def Ruby19.q_encode(str, encoding = nil)
42
- return str if str.ascii_only?
39
+ def Ruby19.b_value_decode(str)
40
+ match = str.match(/\=\?(.+)?\?B\?(.+)?\?\=/)
41
+ if match
42
+ encoding = match[1]
43
+ str = Ruby19.decode_base64(match[2])
44
+ str.force_encoding(encoding)
45
+ end
46
+ str
47
+ end
48
+
49
+ def Ruby19.q_value_encode(str, encoding = nil)
43
50
  encoding = str.encoding.to_s
44
- string = Encodings::QuotedPrintable.encode(str)
45
- "=?#{encoding}?Q?#{string.chomp}?="
51
+ [Encodings::QuotedPrintable.encode(str), encoding]
52
+ end
53
+
54
+ def Ruby19.q_value_decode(str)
55
+ match = str.match(/\=\?(.+)?\?Q\?(.+)?\?\=/)
56
+ if match
57
+ encoding = match[1]
58
+ str = Encodings::QuotedPrintable.decode(match[2])
59
+ str.force_encoding(encoding)
60
+ end
61
+ str
46
62
  end
47
63
 
48
64
  def Ruby19.param_decode(str, encoding)
@@ -51,5 +67,11 @@ module Mail
51
67
  string
52
68
  end
53
69
 
70
+ def Ruby19.param_encode(str)
71
+ encoding = str.encoding.to_s.downcase
72
+ language = Mail::Configuration.instance.param_encode_language
73
+ "#{encoding}'#{language}'#{URI.escape(str)}"
74
+ end
75
+
54
76
  end
55
77
  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: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikel Lindsaar