mail 2.2.5 → 2.2.19

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.
Files changed (152) hide show
  1. data/CHANGELOG.rdoc +163 -7
  2. data/README.rdoc +56 -65
  3. data/Rakefile +31 -6
  4. data/lib/VERSION +2 -2
  5. data/lib/mail/attachments_list.rb +4 -4
  6. data/lib/mail/body.rb +6 -2
  7. data/lib/mail/configuration.rb +7 -1
  8. data/lib/mail/core_extensions/shellwords.rb +55 -0
  9. data/lib/mail/core_extensions/smtp.rb +24 -0
  10. data/lib/mail/elements/address.rb +6 -6
  11. data/lib/mail/elements/content_disposition_element.rb +1 -1
  12. data/lib/mail/elements/content_type_element.rb +2 -2
  13. data/lib/mail/encodings.rb +55 -57
  14. data/lib/mail/field.rb +2 -1
  15. data/lib/mail/field_list.rb +1 -1
  16. data/lib/mail/fields/common/common_field.rb +10 -9
  17. data/lib/mail/fields/common/common_message_id.rb +6 -5
  18. data/lib/mail/fields/common/parameter_hash.rb +14 -4
  19. data/lib/mail/fields/content_disposition_field.rb +1 -1
  20. data/lib/mail/fields/content_type_field.rb +41 -28
  21. data/lib/mail/fields/date_field.rb +3 -1
  22. data/lib/mail/fields/received_field.rb +11 -3
  23. data/lib/mail/fields/resent_date_field.rb +1 -1
  24. data/lib/mail/fields/return_path_field.rb +1 -0
  25. data/lib/mail/fields/unstructured_field.rb +4 -1
  26. data/lib/mail/header.rb +8 -5
  27. data/lib/mail/mail.rb +71 -57
  28. data/lib/mail/message.rb +518 -391
  29. data/lib/mail/network/delivery_methods/sendmail.rb +15 -15
  30. data/lib/mail/network/delivery_methods/smtp.rb +33 -6
  31. data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
  32. data/lib/mail/network/retriever_methods/base.rb +63 -0
  33. data/lib/mail/network/retriever_methods/imap.rb +147 -7
  34. data/lib/mail/network/retriever_methods/pop3.rb +25 -44
  35. data/lib/mail/network/retriever_methods/test_retriever.rb +40 -0
  36. data/lib/mail/network.rb +4 -0
  37. data/lib/mail/parsers/address_lists.rb +2 -2
  38. data/lib/mail/parsers/address_lists.treetop +2 -2
  39. data/lib/mail/parsers/content_disposition.rb +166 -18
  40. data/lib/mail/parsers/content_disposition.treetop +1 -1
  41. data/lib/mail/parsers/content_type.rb +477 -49
  42. data/lib/mail/parsers/content_type.treetop +12 -2
  43. data/lib/mail/parsers/rfc2822.rb +58 -35
  44. data/lib/mail/parsers/rfc2822.treetop +2 -2
  45. data/lib/mail/part.rb +2 -2
  46. data/lib/mail/parts_list.rb +16 -8
  47. data/lib/mail/patterns.rb +7 -2
  48. data/lib/mail/utilities.rb +31 -1
  49. data/lib/mail/version.rb +10 -8
  50. data/lib/mail/version_specific/ruby_1_8.rb +2 -2
  51. data/lib/mail/version_specific/ruby_1_9.rb +29 -8
  52. data/lib/mail.rb +8 -4
  53. metadata +44 -110
  54. data/lib/mail/attachments_list.rbc +0 -1983
  55. data/lib/mail/body.rbc +0 -3809
  56. data/lib/mail/configuration.rbc +0 -1112
  57. data/lib/mail/core_extensions/nil.rbc +0 -244
  58. data/lib/mail/core_extensions/string.rbc +0 -0
  59. data/lib/mail/elements/address.rbc +0 -4112
  60. data/lib/mail/elements/address_list.rbc +0 -1309
  61. data/lib/mail/elements/content_disposition_element.rbc +0 -701
  62. data/lib/mail/elements/content_location_element.rbc +0 -573
  63. data/lib/mail/elements/content_transfer_encoding_element.rbc +0 -535
  64. data/lib/mail/elements/content_type_element.rbc +0 -786
  65. data/lib/mail/elements/date_time_element.rbc +0 -583
  66. data/lib/mail/elements/envelope_from_element.rbc +0 -771
  67. data/lib/mail/elements/message_ids_element.rbc +0 -740
  68. data/lib/mail/elements/mime_version_element.rbc +0 -583
  69. data/lib/mail/elements/phrase_list.rbc +0 -562
  70. data/lib/mail/elements/received_element.rbc +0 -725
  71. data/lib/mail/elements.rbc +0 -362
  72. data/lib/mail/encodings/7bit.rbc +0 -538
  73. data/lib/mail/encodings/8bit.rbc +0 -541
  74. data/lib/mail/encodings/base64.rbc +0 -629
  75. data/lib/mail/encodings/binary.rbc +0 -529
  76. data/lib/mail/encodings/quoted_printable.rbc +0 -766
  77. data/lib/mail/encodings/transfer_encoding.rbc +0 -1134
  78. data/lib/mail/encodings.rbc +0 -0
  79. data/lib/mail/envelope.rbc +0 -719
  80. data/lib/mail/field.rbc +0 -4708
  81. data/lib/mail/field_list.rbc +0 -518
  82. data/lib/mail/fields/bcc_field.rbc +0 -564
  83. data/lib/mail/fields/cc_field.rbc +0 -579
  84. data/lib/mail/fields/comments_field.rbc +0 -383
  85. data/lib/mail/fields/common/address_container.rbc +0 -363
  86. data/lib/mail/fields/common/common_address.rbc +0 -3550
  87. data/lib/mail/fields/common/common_date.rbc +0 -908
  88. data/lib/mail/fields/common/common_field.rbc +0 -973
  89. data/lib/mail/fields/common/common_message_id.rbc +0 -1051
  90. data/lib/mail/fields/common/parameter_hash.rbc +0 -1335
  91. data/lib/mail/fields/content_description_field.rbc +0 -396
  92. data/lib/mail/fields/content_disposition_field.rbc +0 -1440
  93. data/lib/mail/fields/content_id_field.rbc +0 -1236
  94. data/lib/mail/fields/content_location_field.rbc +0 -892
  95. data/lib/mail/fields/content_transfer_encoding_field.rbc +0 -1184
  96. data/lib/mail/fields/content_type_field.rbc +0 -3958
  97. data/lib/mail/fields/date_field.rbc +0 -712
  98. data/lib/mail/fields/from_field.rbc +0 -579
  99. data/lib/mail/fields/in_reply_to_field.rbc +0 -579
  100. data/lib/mail/fields/keywords_field.rbc +0 -979
  101. data/lib/mail/fields/message_id_field.rbc +0 -1008
  102. data/lib/mail/fields/mime_version_field.rbc +0 -1107
  103. data/lib/mail/fields/optional_field.rbc +0 -153
  104. data/lib/mail/fields/received_field.rbc +0 -1137
  105. data/lib/mail/fields/references_field.rbc +0 -574
  106. data/lib/mail/fields/reply_to_field.rbc +0 -579
  107. data/lib/mail/fields/resent_bcc_field.rbc +0 -579
  108. data/lib/mail/fields/resent_cc_field.rbc +0 -579
  109. data/lib/mail/fields/resent_date_field.rbc +0 -656
  110. data/lib/mail/fields/resent_from_field.rbc +0 -579
  111. data/lib/mail/fields/resent_message_id_field.rbc +0 -639
  112. data/lib/mail/fields/resent_sender_field.rbc +0 -731
  113. data/lib/mail/fields/resent_to_field.rbc +0 -579
  114. data/lib/mail/fields/return_path_field.rbc +0 -737
  115. data/lib/mail/fields/sender_field.rbc +0 -799
  116. data/lib/mail/fields/structured_field.rbc +0 -671
  117. data/lib/mail/fields/subject_field.rbc +0 -378
  118. data/lib/mail/fields/to_field.rbc +0 -579
  119. data/lib/mail/fields/unstructured_field.rbc +0 -2292
  120. data/lib/mail/fields.rbc +0 -782
  121. data/lib/mail/header.rbc +0 -3720
  122. data/lib/mail/mail.rbc +0 -2168
  123. data/lib/mail/message.rbc +0 -19034
  124. data/lib/mail/network/delivery_methods/file_delivery.rbc +0 -722
  125. data/lib/mail/network/delivery_methods/sendmail.rbc +0 -800
  126. data/lib/mail/network/delivery_methods/smtp.rbc +0 -1081
  127. data/lib/mail/network/delivery_methods/test_mailer.rbc +0 -552
  128. data/lib/mail/network/retriever_methods/pop3.rbc +0 -2447
  129. data/lib/mail/network.rbc +0 -236
  130. data/lib/mail/parsers/address_lists.rbc +0 -1307
  131. data/lib/mail/parsers/content_disposition.rbc +0 -5968
  132. data/lib/mail/parsers/content_location.rbc +0 -2166
  133. data/lib/mail/parsers/content_transfer_encoding.rbc +0 -2591
  134. data/lib/mail/parsers/content_type.rbc +0 -7949
  135. data/lib/mail/parsers/date_time.rbc +0 -1836
  136. data/lib/mail/parsers/envelope_from.rbc +0 -3106
  137. data/lib/mail/parsers/message_ids.rbc +0 -989
  138. data/lib/mail/parsers/mime_version.rbc +0 -2254
  139. data/lib/mail/parsers/phrase_lists.rbc +0 -989
  140. data/lib/mail/parsers/received.rbc +0 -1267
  141. data/lib/mail/parsers/rfc2045.rbc +0 -5614
  142. data/lib/mail/parsers/rfc2822.rbc +0 -74848
  143. data/lib/mail/parsers/rfc2822_obsolete.rbc +0 -55220
  144. data/lib/mail/part.rbc +0 -2314
  145. data/lib/mail/parts_list.rbc +0 -832
  146. data/lib/mail/patterns.rbc +0 -0
  147. data/lib/mail/utilities.rbc +0 -2377
  148. data/lib/mail/version.rbc +0 -450
  149. data/lib/mail/version_specific/ruby_1_8.rbc +0 -2496
  150. data/lib/mail.rbc +0 -1151
  151. data/lib/tasks/corpus.rake.compiled.rbc +0 -2195
  152. data/lib/tasks/treetop.rake.compiled.rbc +0 -297
@@ -2866,7 +2866,7 @@ module Mail
2866
2866
 
2867
2867
  module AddressList0
2868
2868
  def addr_value
2869
- elements[2]
2869
+ elements[3]
2870
2870
  end
2871
2871
  end
2872
2872
 
@@ -2892,52 +2892,75 @@ module Mail
2892
2892
  end
2893
2893
 
2894
2894
  i0, s0 = index, []
2895
- r1 = _nt_address
2895
+ r2 = _nt_address
2896
+ if r2
2897
+ r1 = r2
2898
+ else
2899
+ r1 = instantiate_node(SyntaxNode,input, index...index)
2900
+ end
2896
2901
  s0 << r1
2897
2902
  if r1
2898
- s2, i2 = [], index
2903
+ s3, i3 = [], index
2899
2904
  loop do
2900
- i3, s3 = index, []
2901
- if has_terminal?(",", false, index)
2902
- r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
2903
- @index += 1
2904
- else
2905
- terminal_parse_failure(",")
2906
- r4 = nil
2905
+ i4, s4 = index, []
2906
+ s5, i5 = [], index
2907
+ loop do
2908
+ r6 = _nt_FWS
2909
+ if r6
2910
+ s5 << r6
2911
+ else
2912
+ break
2913
+ end
2907
2914
  end
2908
- s3 << r4
2909
- if r4
2910
- s5, i5 = [], index
2911
- loop do
2912
- r6 = _nt_FWS
2913
- if r6
2914
- s5 << r6
2915
- else
2916
- break
2917
- end
2915
+ r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
2916
+ s4 << r5
2917
+ if r5
2918
+ if has_terminal?(",", false, index)
2919
+ r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
2920
+ @index += 1
2921
+ else
2922
+ terminal_parse_failure(",")
2923
+ r7 = nil
2918
2924
  end
2919
- r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
2920
- s3 << r5
2921
- if r5
2922
- r7 = _nt_address
2923
- s3 << r7
2925
+ s4 << r7
2926
+ if r7
2927
+ s8, i8 = [], index
2928
+ loop do
2929
+ r9 = _nt_FWS
2930
+ if r9
2931
+ s8 << r9
2932
+ else
2933
+ break
2934
+ end
2935
+ end
2936
+ r8 = instantiate_node(SyntaxNode,input, i8...index, s8)
2937
+ s4 << r8
2938
+ if r8
2939
+ r11 = _nt_address
2940
+ if r11
2941
+ r10 = r11
2942
+ else
2943
+ r10 = instantiate_node(SyntaxNode,input, index...index)
2944
+ end
2945
+ s4 << r10
2946
+ end
2924
2947
  end
2925
2948
  end
2926
- if s3.last
2927
- r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2928
- r3.extend(AddressList0)
2949
+ if s4.last
2950
+ r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
2951
+ r4.extend(AddressList0)
2929
2952
  else
2930
- @index = i3
2931
- r3 = nil
2953
+ @index = i4
2954
+ r4 = nil
2932
2955
  end
2933
- if r3
2934
- s2 << r3
2956
+ if r4
2957
+ s3 << r4
2935
2958
  else
2936
2959
  break
2937
2960
  end
2938
2961
  end
2939
- r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
2940
- s0 << r2
2962
+ r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
2963
+ s0 << r3
2941
2964
  end
2942
2965
  if s0.last
2943
2966
  r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
@@ -5315,4 +5338,4 @@ module Mail
5315
5338
  include RFC2822
5316
5339
  end
5317
5340
 
5318
- end
5341
+ end
@@ -265,7 +265,7 @@ module Mail
265
265
  end
266
266
 
267
267
  rule address_list
268
- first_addr:address other_addr:("," FWS* addr_value:address)*
268
+ first_addr:address? other_addr:(FWS* "," FWS* addr_value:address?)*
269
269
  end
270
270
 
271
271
  rule date_time
@@ -407,4 +407,4 @@ module Mail
407
407
 
408
408
 
409
409
  end
410
- end
410
+ end
data/lib/mail/part.rb CHANGED
@@ -43,7 +43,7 @@ module Mail
43
43
  end
44
44
 
45
45
  def delivery_status_report_part?
46
- main_type =~ /message/i && sub_type =~ /delivery-status/i
46
+ (main_type =~ /message/i && sub_type =~ /delivery-status/i) && body =~ /Status:/
47
47
  end
48
48
 
49
49
  def delivery_status_data
@@ -103,7 +103,7 @@ module Mail
103
103
  self.body = body_part
104
104
  else
105
105
  self.header = "Content-Type: text/plain\r\n"
106
- self.body = header_part
106
+ self.body = raw_source
107
107
  end
108
108
  end
109
109
 
@@ -1,6 +1,6 @@
1
1
  module Mail
2
2
  class PartsList < Array
3
-
3
+
4
4
  def attachments
5
5
  Mail::AttachmentsList.new(self)
6
6
  end
@@ -14,30 +14,38 @@ module Mail
14
14
  to_a
15
15
  end
16
16
  end
17
-
17
+
18
18
  undef :map
19
19
  alias_method :map, :collect
20
20
 
21
21
  def map!
22
22
  raise NoMethodError, "#map! is not defined, please call #collect and create a new PartsList"
23
23
  end
24
-
24
+
25
25
  def collect!
26
26
  raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList"
27
27
  end
28
-
28
+
29
29
  def sort!(order)
30
30
  sorted = self.sort do |a, b|
31
31
  # OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a
32
32
  # single email message... please show me a use case and I'll put more work into this method,
33
33
  # in the meantime, it works :)
34
- a_order = order.index(a[:content_type].string.downcase) || 10000
35
- b_order = order.index(b[:content_type].string.downcase) || 10000
36
- a_order <=> b_order
34
+ get_order_value(a, order) <=> get_order_value(b, order)
37
35
  end
38
36
  self.clear
39
37
  sorted.each { |p| self << p }
40
38
  end
41
-
39
+
40
+ private
41
+
42
+ def get_order_value(part, order)
43
+ if part.respond_to?(:content_type)
44
+ order.index(part[:content_type].string.downcase) || 10000
45
+ else
46
+ 10000
47
+ end
48
+ end
49
+
42
50
  end
43
51
  end
data/lib/mail/patterns.rb CHANGED
@@ -9,8 +9,13 @@ module Mail
9
9
  aspecial = %Q|()<>[]:;@\\,."| # RFC5322
10
10
  tspecial = %Q|()<>@,;:\\"/[]?=| # RFC2045
11
11
  lwsp = %Q| \t\r\n|
12
+ sp = %Q| |
12
13
  control = %Q|\x00-\x1f\x7f-\xff|
13
14
 
15
+ if control.respond_to?(:force_encoding)
16
+ control = control.force_encoding(Encoding::BINARY)
17
+ end
18
+
14
19
  CRLF = /\r\n/
15
20
  WSP = /[#{white_space}]/
16
21
  FWS = /#{CRLF}#{WSP}*/
@@ -23,8 +28,8 @@ module Mail
23
28
  QP_UNSAFE = /[^#{qp_safe}]/
24
29
  QP_SAFE = /[#{qp_safe}]/
25
30
  CONTROL_CHAR = /[#{control}]/n
26
- ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{lwsp}]/n
31
+ ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{sp}]/n
27
32
  PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
28
- TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{lwsp}]/n
33
+ TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{sp}]/n
29
34
  end
30
35
  end
@@ -176,6 +176,36 @@ module Mail
176
176
  def underscoreize( str )
177
177
  str.to_s.downcase.gsub('-', '_')
178
178
  end
179
-
179
+
180
+ if RUBY_VERSION <= '1.8.6'
181
+
182
+ def map_lines( str, &block )
183
+ results = []
184
+ str.each_line do |line|
185
+ results << yield(line)
186
+ end
187
+ results
188
+ end
189
+
190
+ def map_with_index( enum, &block )
191
+ results = []
192
+ enum.each_with_index do |token, i|
193
+ results[i] = yield(token, i)
194
+ end
195
+ results
196
+ end
197
+
198
+ else
199
+
200
+ def map_lines( str, &block )
201
+ str.each_line.map(&block)
202
+ end
203
+
204
+ def map_with_index( enum, &block )
205
+ enum.each_with_index.map(&block)
206
+ end
207
+
208
+ end
209
+
180
210
  end
181
211
  end
data/lib/mail/version.rb CHANGED
@@ -2,14 +2,11 @@
2
2
  module Mail
3
3
  module VERSION
4
4
 
5
- def self.version
6
- version_hash = {}
7
- File.read(File.join(File.dirname(__FILE__), '../', 'VERSION')).each_line do |line|
8
- type, value = line.chomp.split(":")
9
- next if type =~ /^\s+$/ || value =~ /^\s+$/
10
- version_hash[type] = value
11
- end
12
- version_hash
5
+ version = {}
6
+ File.read(File.join(File.dirname(__FILE__), '../', 'VERSION')).each_line do |line|
7
+ type, value = line.chomp.split(":")
8
+ next if type =~ /^\s+$/ || value =~ /^\s+$/
9
+ version[type] = value
13
10
  end
14
11
 
15
12
  MAJOR = version['major']
@@ -18,5 +15,10 @@ module Mail
18
15
  BUILD = version['build']
19
16
 
20
17
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
18
+
19
+ def self.version
20
+ STRING
21
+ end
22
+
21
23
  end
22
24
  end
@@ -37,7 +37,7 @@ module Mail
37
37
  end
38
38
 
39
39
  def Ruby18.decode_base64(str)
40
- Base64.decode64(str)
40
+ Base64.decode64(str) if str
41
41
  end
42
42
 
43
43
  def Ruby18.encode_base64(str)
@@ -90,7 +90,7 @@ module Mail
90
90
 
91
91
  def Ruby18.param_encode(str)
92
92
  encoding = $KCODE.to_s.downcase
93
- language = Mail::Configuration.instance.param_encode_language
93
+ language = Configuration.instance.param_encode_language
94
94
  "#{encoding}'#{language}'#{URI.escape(str)}"
95
95
  end
96
96
  end
@@ -27,7 +27,7 @@ module Mail
27
27
  end
28
28
 
29
29
  def Ruby19.decode_base64(str)
30
- str.unpack( 'm' ).first.force_encoding(Encoding::BINARY)
30
+ str.unpack( 'm' ).first
31
31
  end
32
32
 
33
33
  def Ruby19.encode_base64(str)
@@ -35,11 +35,11 @@ module Mail
35
35
  end
36
36
 
37
37
  def Ruby19.has_constant?(klass, string)
38
- klass.constants.include?( string.to_sym )
38
+ klass.const_defined?( string, false )
39
39
  end
40
40
 
41
41
  def Ruby19.get_constant(klass, string)
42
- klass.const_get( string.to_sym )
42
+ klass.const_get( string )
43
43
  end
44
44
 
45
45
  def Ruby19.b_value_encode(str, encoding = nil)
@@ -52,9 +52,10 @@ module Mail
52
52
  if match
53
53
  encoding = match[1]
54
54
  str = Ruby19.decode_base64(match[2])
55
- str.force_encoding(encoding)
55
+ str.force_encoding(fix_encoding(encoding))
56
56
  end
57
- str
57
+ decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
58
+ decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
58
59
  end
59
60
 
60
61
  def Ruby19.q_value_encode(str, encoding = nil)
@@ -67,9 +68,10 @@ module Mail
67
68
  if match
68
69
  encoding = match[1]
69
70
  str = Encodings::QuotedPrintable.decode(match[2])
70
- str.force_encoding(encoding)
71
+ str.force_encoding(fix_encoding(encoding))
71
72
  end
72
- str
73
+ decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
74
+ decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
73
75
  end
74
76
 
75
77
  def Ruby19.param_decode(str, encoding)
@@ -80,8 +82,27 @@ module Mail
80
82
 
81
83
  def Ruby19.param_encode(str)
82
84
  encoding = str.encoding.to_s.downcase
83
- language = Mail::Configuration.instance.param_encode_language
85
+ language = Configuration.instance.param_encode_language
84
86
  "#{encoding}'#{language}'#{URI.escape(str)}"
85
87
  end
88
+
89
+ # mails somtimes includes invalid encodings like iso885915 or utf8 so we transform them to iso885915 or utf8
90
+ # TODO: add this as a test somewhere
91
+ # Encoding.list.map{|e| [e.to_s.upcase==fix_encoding(e.to_s.downcase.gsub("-", "")), e.to_s] }.select {|a,b| !b}
92
+ # Encoding.list.map{|e| [e.to_s==fix_encoding(e.to_s), e.to_s] }.select {|a,b| !b}
93
+ def Ruby19.fix_encoding(encoding)
94
+ case encoding
95
+ # ISO-8859-15, ISO-2022-JP and alike
96
+ when /iso-?(\d{4})-?(\w{1,2})/i then return "ISO-#{$1}-#{$2}"
97
+ # "ISO-2022-JP-KDDI" and alike
98
+ when /iso-?(\d{4})-?(\w{1,2})-?(\w*)/i then return "ISO-#{$1}-#{$2}-#{$3}"
99
+ # UTF-8, UTF-32BE and alike
100
+ when /utf-?(\d{1,2})?(\w{1,2})/i then return "UTF-#{$1}#{$2}"
101
+ # Windows-1252 and alike
102
+ when /Windows-?(.*)/i then return "Windows-#{$1}"
103
+ #more aliases to be added if needed
104
+ else return encoding
105
+ end
106
+ end
86
107
  end
87
108
  end
data/lib/mail.rb CHANGED
@@ -2,11 +2,13 @@
2
2
  module Mail # :doc:
3
3
 
4
4
  require 'date'
5
+ require 'shellwords'
5
6
 
6
7
  require 'active_support'
8
+ require 'active_support/core_ext/class/attribute_accessors'
7
9
  require 'active_support/core_ext/hash/indifferent_access'
8
10
  require 'active_support/core_ext/object/blank'
9
- require 'active_support/core_ext/string'
11
+ require 'active_support/inflector'
10
12
 
11
13
  require 'uri'
12
14
  require 'net/smtp'
@@ -22,16 +24,18 @@ module Mail # :doc:
22
24
 
23
25
  if RUBY_VERSION >= "1.9.1"
24
26
  require 'mail/version_specific/ruby_1_9'
25
- RubyVer = Mail::Ruby19
27
+ RubyVer = Ruby19
26
28
  else
27
29
  require 'mail/version_specific/ruby_1_8'
28
- RubyVer = Mail::Ruby18
30
+ RubyVer = Ruby18
29
31
  end
30
32
 
31
33
  require 'mail/version'
32
34
 
33
35
  require 'mail/core_extensions/nil'
34
36
  require 'mail/core_extensions/string'
37
+ require 'mail/core_extensions/shellwords' unless String.new.respond_to?(:shellescape)
38
+ require 'mail/core_extensions/smtp' if RUBY_VERSION < '1.9.3'
35
39
 
36
40
  require 'mail/patterns'
37
41
  require 'mail/utilities'
@@ -52,7 +56,7 @@ module Mail # :doc:
52
56
  require 'mail/envelope'
53
57
 
54
58
  parsers = %w[ rfc2822_obsolete rfc2822 address_lists phrase_lists
55
- date_time received message_ids envelope_from rfc2045
59
+ date_time received message_ids envelope_from rfc2045
56
60
  mime_version content_type content_disposition
57
61
  content_transfer_encoding content_location ]
58
62