mail 2.5.2 → 2.6.4

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 (187) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +124 -0
  3. data/CONTRIBUTING.md +21 -6
  4. data/Dependencies.txt +0 -1
  5. data/Gemfile +7 -22
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +86 -31
  8. data/Rakefile +11 -22
  9. data/lib/mail/attachments_list.rb +4 -2
  10. data/lib/mail/body.rb +36 -11
  11. data/lib/mail/check_delivery_params.rb +13 -22
  12. data/lib/mail/configuration.rb +1 -0
  13. data/lib/mail/{patterns.rb → constants.rb} +29 -6
  14. data/lib/mail/core_extensions/smtp.rb +13 -13
  15. data/lib/mail/core_extensions/string/access.rb +1 -0
  16. data/lib/mail/core_extensions/string/multibyte.rb +1 -0
  17. data/lib/mail/core_extensions/string.rb +5 -17
  18. data/lib/mail/elements/address.rb +86 -145
  19. data/lib/mail/elements/address_list.rb +10 -42
  20. data/lib/mail/elements/content_disposition_element.rb +4 -7
  21. data/lib/mail/elements/content_location_element.rb +8 -11
  22. data/lib/mail/elements/content_transfer_encoding_element.rb +4 -10
  23. data/lib/mail/elements/content_type_element.rb +5 -8
  24. data/lib/mail/elements/date_time_element.rb +4 -7
  25. data/lib/mail/elements/envelope_from_element.rb +19 -13
  26. data/lib/mail/elements/message_ids_element.rb +8 -11
  27. data/lib/mail/elements/mime_version_element.rb +4 -7
  28. data/lib/mail/elements/phrase_list.rb +3 -7
  29. data/lib/mail/elements/received_element.rb +4 -7
  30. data/lib/mail/elements.rb +1 -0
  31. data/lib/mail/encodings/7bit.rb +1 -0
  32. data/lib/mail/encodings/8bit.rb +8 -2
  33. data/lib/mail/encodings/base64.rb +7 -1
  34. data/lib/mail/encodings/binary.rb +1 -0
  35. data/lib/mail/encodings/quoted_printable.rb +11 -4
  36. data/lib/mail/encodings/transfer_encoding.rb +27 -17
  37. data/lib/mail/encodings/unix_to_unix.rb +18 -0
  38. data/lib/mail/encodings.rb +54 -39
  39. data/lib/mail/envelope.rb +1 -5
  40. data/lib/mail/field.rb +81 -31
  41. data/lib/mail/field_list.rb +19 -18
  42. data/lib/mail/fields/bcc_field.rb +17 -5
  43. data/lib/mail/fields/cc_field.rb +3 -3
  44. data/lib/mail/fields/comments_field.rb +2 -1
  45. data/lib/mail/fields/common/address_container.rb +1 -0
  46. data/lib/mail/fields/common/common_address.rb +34 -28
  47. data/lib/mail/fields/common/common_date.rb +2 -8
  48. data/lib/mail/fields/common/common_field.rb +9 -5
  49. data/lib/mail/fields/common/common_message_id.rb +3 -2
  50. data/lib/mail/fields/common/parameter_hash.rb +4 -3
  51. data/lib/mail/fields/content_description_field.rb +1 -0
  52. data/lib/mail/fields/content_disposition_field.rb +13 -12
  53. data/lib/mail/fields/content_id_field.rb +4 -4
  54. data/lib/mail/fields/content_location_field.rb +2 -1
  55. data/lib/mail/fields/content_transfer_encoding_field.rb +4 -9
  56. data/lib/mail/fields/content_type_field.rb +4 -3
  57. data/lib/mail/fields/date_field.rb +16 -15
  58. data/lib/mail/fields/from_field.rb +3 -3
  59. data/lib/mail/fields/in_reply_to_field.rb +3 -1
  60. data/lib/mail/fields/keywords_field.rb +2 -2
  61. data/lib/mail/fields/message_id_field.rb +4 -4
  62. data/lib/mail/fields/mime_version_field.rb +3 -2
  63. data/lib/mail/fields/optional_field.rb +1 -0
  64. data/lib/mail/fields/received_field.rb +4 -3
  65. data/lib/mail/fields/references_field.rb +3 -1
  66. data/lib/mail/fields/reply_to_field.rb +3 -3
  67. data/lib/mail/fields/resent_bcc_field.rb +3 -3
  68. data/lib/mail/fields/resent_cc_field.rb +3 -3
  69. data/lib/mail/fields/resent_date_field.rb +2 -1
  70. data/lib/mail/fields/resent_from_field.rb +3 -3
  71. data/lib/mail/fields/resent_message_id_field.rb +1 -0
  72. data/lib/mail/fields/resent_sender_field.rb +4 -4
  73. data/lib/mail/fields/resent_to_field.rb +3 -3
  74. data/lib/mail/fields/return_path_field.rb +1 -1
  75. data/lib/mail/fields/sender_field.rb +9 -9
  76. data/lib/mail/fields/structured_field.rb +1 -0
  77. data/lib/mail/fields/subject_field.rb +1 -0
  78. data/lib/mail/fields/to_field.rb +3 -3
  79. data/lib/mail/fields/unstructured_field.rb +15 -8
  80. data/lib/mail/fields.rb +1 -0
  81. data/lib/mail/header.rb +21 -29
  82. data/lib/mail/indifferent_hash.rb +1 -0
  83. data/lib/mail/mail.rb +16 -1
  84. data/lib/mail/matchers/attachment_matchers.rb +29 -0
  85. data/lib/mail/matchers/has_sent_mail.rb +61 -4
  86. data/lib/mail/message.rb +175 -72
  87. data/lib/mail/multibyte/chars.rb +3 -2
  88. data/lib/mail/multibyte/exceptions.rb +1 -0
  89. data/lib/mail/multibyte/unicode.rb +22 -15
  90. data/lib/mail/multibyte/utils.rb +1 -0
  91. data/lib/mail/multibyte.rb +1 -0
  92. data/lib/mail/network/delivery_methods/exim.rb +3 -7
  93. data/lib/mail/network/delivery_methods/file_delivery.rb +2 -1
  94. data/lib/mail/network/delivery_methods/sendmail.rb +33 -10
  95. data/lib/mail/network/delivery_methods/smtp.rb +32 -34
  96. data/lib/mail/network/delivery_methods/smtp_connection.rb +7 -6
  97. data/lib/mail/network/delivery_methods/test_mailer.rb +3 -2
  98. data/lib/mail/network/retriever_methods/base.rb +1 -0
  99. data/lib/mail/network/retriever_methods/imap.rb +19 -13
  100. data/lib/mail/network/retriever_methods/pop3.rb +1 -0
  101. data/lib/mail/network/retriever_methods/test_retriever.rb +1 -0
  102. data/lib/mail/network.rb +1 -0
  103. data/lib/mail/parsers/address_lists_parser.rb +133 -0
  104. data/lib/mail/parsers/content_disposition_parser.rb +68 -0
  105. data/lib/mail/parsers/content_location_parser.rb +36 -0
  106. data/lib/mail/parsers/content_transfer_encoding_parser.rb +34 -0
  107. data/lib/mail/parsers/content_type_parser.rb +67 -0
  108. data/lib/mail/parsers/date_time_parser.rb +39 -0
  109. data/lib/mail/parsers/envelope_from_parser.rb +46 -0
  110. data/lib/mail/parsers/message_ids_parser.rb +40 -0
  111. data/lib/mail/parsers/mime_version_parser.rb +42 -0
  112. data/lib/mail/parsers/phrase_lists_parser.rb +36 -0
  113. data/lib/mail/parsers/ragel/common.rl +185 -0
  114. data/lib/mail/parsers/ragel/date_time.rl +30 -0
  115. data/lib/mail/parsers/ragel/parser_info.rb +61 -0
  116. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +14864 -0
  117. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +37 -0
  118. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +751 -0
  119. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +37 -0
  120. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +614 -0
  121. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +37 -0
  122. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +447 -0
  123. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +37 -0
  124. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +825 -0
  125. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +37 -0
  126. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +817 -0
  127. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +37 -0
  128. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +2149 -0
  129. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +37 -0
  130. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +1570 -0
  131. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +37 -0
  132. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +440 -0
  133. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +37 -0
  134. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +564 -0
  135. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +37 -0
  136. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +51 -0
  137. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +5144 -0
  138. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +37 -0
  139. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +37 -0
  140. data/lib/mail/parsers/ragel/ruby.rb +40 -0
  141. data/lib/mail/parsers/ragel.rb +18 -0
  142. data/lib/mail/parsers/received_parser.rb +49 -0
  143. data/lib/mail/parsers.rb +27 -0
  144. data/lib/mail/part.rb +11 -4
  145. data/lib/mail/parts_list.rb +30 -10
  146. data/lib/mail/utilities.rb +127 -63
  147. data/lib/mail/values/unicode_tables.dat +0 -0
  148. data/lib/mail/version.rb +8 -15
  149. data/lib/mail/version_specific/ruby_1_8.rb +18 -7
  150. data/lib/mail/version_specific/ruby_1_9.rb +136 -32
  151. data/lib/mail.rb +12 -6
  152. metadata +115 -77
  153. data/lib/VERSION +0 -4
  154. data/lib/load_parsers.rb +0 -41
  155. data/lib/mail/core_extensions/nil.rb +0 -19
  156. data/lib/mail/core_extensions/object.rb +0 -13
  157. data/lib/mail/core_extensions/shell_escape.rb +0 -56
  158. data/lib/mail/parsers/address_lists.rb +0 -64
  159. data/lib/mail/parsers/address_lists.treetop +0 -19
  160. data/lib/mail/parsers/content_disposition.rb +0 -535
  161. data/lib/mail/parsers/content_disposition.treetop +0 -46
  162. data/lib/mail/parsers/content_location.rb +0 -139
  163. data/lib/mail/parsers/content_location.treetop +0 -20
  164. data/lib/mail/parsers/content_transfer_encoding.rb +0 -162
  165. data/lib/mail/parsers/content_transfer_encoding.treetop +0 -20
  166. data/lib/mail/parsers/content_type.rb +0 -967
  167. data/lib/mail/parsers/content_type.treetop +0 -68
  168. data/lib/mail/parsers/date_time.rb +0 -114
  169. data/lib/mail/parsers/date_time.treetop +0 -11
  170. data/lib/mail/parsers/envelope_from.rb +0 -194
  171. data/lib/mail/parsers/envelope_from.treetop +0 -32
  172. data/lib/mail/parsers/message_ids.rb +0 -45
  173. data/lib/mail/parsers/message_ids.treetop +0 -15
  174. data/lib/mail/parsers/mime_version.rb +0 -144
  175. data/lib/mail/parsers/mime_version.treetop +0 -19
  176. data/lib/mail/parsers/phrase_lists.rb +0 -45
  177. data/lib/mail/parsers/phrase_lists.treetop +0 -15
  178. data/lib/mail/parsers/received.rb +0 -71
  179. data/lib/mail/parsers/received.treetop +0 -11
  180. data/lib/mail/parsers/rfc2045.rb +0 -464
  181. data/lib/mail/parsers/rfc2045.treetop +0 -36
  182. data/lib/mail/parsers/rfc2822.rb +0 -5397
  183. data/lib/mail/parsers/rfc2822.treetop +0 -410
  184. data/lib/mail/parsers/rfc2822_obsolete.rb +0 -3768
  185. data/lib/mail/parsers/rfc2822_obsolete.treetop +0 -241
  186. data/lib/tasks/corpus.rake +0 -125
  187. data/lib/tasks/treetop.rake +0 -10
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Mail
4
5
  class Ruby18
@@ -54,19 +55,23 @@ module Mail
54
55
  klass.const_get( string )
55
56
  end
56
57
 
58
+ def Ruby18.transcode_charset(str, from_encoding, to_encoding = 'UTF-8')
59
+ Iconv.conv("#{normalize_iconv_charset_encoding(to_encoding)}//IGNORE", normalize_iconv_charset_encoding(from_encoding), str)
60
+ end
61
+
57
62
  def Ruby18.b_value_encode(str, encoding)
58
63
  # Ruby 1.8 requires an encoding to work
59
64
  raise ArgumentError, "Must supply an encoding" if encoding.nil?
60
65
  encoding = encoding.to_s.upcase.gsub('_', '-')
61
- [Encodings::Base64.encode(str), encoding]
66
+ [Encodings::Base64.encode(str), normalize_iconv_charset_encoding(encoding)]
62
67
  end
63
68
 
64
69
  def Ruby18.b_value_decode(str)
65
- match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
70
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
66
71
  if match
67
72
  encoding = match[1]
68
73
  str = Ruby18.decode_base64(match[2])
69
- str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str)
74
+ str = transcode_charset(str, encoding)
70
75
  end
71
76
  str
72
77
  end
@@ -79,14 +84,14 @@ module Mail
79
84
  end
80
85
 
81
86
  def Ruby18.q_value_decode(str)
82
- match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
87
+ match = str.match(/\=\?(.+)?\?[Qq]\?(.*)\?\=/m)
83
88
  if match
84
89
  encoding = match[1]
85
90
  string = match[2].gsub(/_/, '=20')
86
91
  # Remove trailing = if it exists in a Q encoding
87
92
  string = string.sub(/\=$/, '')
88
93
  str = Encodings::QuotedPrintable.decode(string)
89
- str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str)
94
+ str = transcode_charset(str, encoding)
90
95
  end
91
96
  str
92
97
  end
@@ -103,10 +108,16 @@ module Mail
103
108
 
104
109
  private
105
110
 
106
- def Ruby18.fix_encoding(encoding)
111
+ def Ruby18.normalize_iconv_charset_encoding(encoding)
107
112
  case encoding.upcase
108
- when 'UTF8'
113
+ when 'UTF8', 'UTF_8'
109
114
  'UTF-8'
115
+ when 'UTF16', 'UTF-16'
116
+ 'UTF-16BE'
117
+ when 'UTF32', 'UTF-32'
118
+ 'UTF-32BE'
119
+ when 'KS_C_5601-1987'
120
+ 'CP949'
110
121
  else
111
122
  encoding
112
123
  end
@@ -1,7 +1,38 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Mail
4
5
  class Ruby19
6
+ class StrictCharsetEncoder
7
+ def encode(string, charset)
8
+ string.force_encoding(Mail::Ruby19.pick_encoding(charset))
9
+ end
10
+ end
11
+
12
+ class BestEffortCharsetEncoder
13
+ def encode(string, charset)
14
+ string.force_encoding(pick_encoding(charset))
15
+ end
16
+
17
+ private
18
+
19
+ def pick_encoding(charset)
20
+ charset = case charset
21
+ when /ansi_x3.110-1983/
22
+ 'ISO-8859-1'
23
+ when /Windows-?1258/i # Windows-1258 is similar to 1252
24
+ "Windows-1252"
25
+ else
26
+ charset
27
+ end
28
+ Mail::Ruby19.pick_encoding(charset)
29
+ end
30
+ end
31
+
32
+ class << self
33
+ attr_accessor :charset_encoder
34
+ end
35
+ self.charset_encoder = StrictCharsetEncoder.new
5
36
 
6
37
  # Escapes any parenthesis in a string that are unescaped this uses
7
38
  # a Ruby 1.9.1 regexp feature of negative look behind
@@ -43,20 +74,27 @@ module Mail
43
74
  klass.const_get( string )
44
75
  end
45
76
 
77
+ def Ruby19.transcode_charset(str, from_encoding, to_encoding = Encoding::UTF_8)
78
+ charset_encoder.encode(str.dup, from_encoding).encode(to_encoding, :undef => :replace, :invalid => :replace, :replace => '')
79
+ end
80
+
46
81
  def Ruby19.b_value_encode(str, encoding = nil)
47
82
  encoding = str.encoding.to_s
48
83
  [Ruby19.encode_base64(str), encoding]
49
84
  end
50
85
 
51
86
  def Ruby19.b_value_decode(str)
52
- match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
87
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
53
88
  if match
54
- encoding = match[1]
89
+ charset = match[1]
55
90
  str = Ruby19.decode_base64(match[2])
56
- str.force_encoding(fix_encoding(encoding))
91
+ str = charset_encoder.encode(str, charset)
57
92
  end
58
- decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
59
- decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
93
+ decoded = str.encode(Encoding::UTF_8, :invalid => :replace, :replace => "")
94
+ decoded.valid_encoding? ? decoded : decoded.encode(Encoding::UTF_16LE, :invalid => :replace, :replace => "").encode(Encoding::UTF_8)
95
+ rescue Encoding::UndefinedConversionError, ArgumentError, Encoding::ConverterNotFoundError
96
+ warn "Encoding conversion failed #{$!}"
97
+ str.dup.force_encoding(Encoding::UTF_8)
60
98
  end
61
99
 
62
100
  def Ruby19.q_value_encode(str, encoding = nil)
@@ -65,25 +103,29 @@ module Mail
65
103
  end
66
104
 
67
105
  def Ruby19.q_value_decode(str)
68
- match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
106
+ match = str.match(/\=\?(.+)?\?[Qq]\?(.*)\?\=/m)
69
107
  if match
70
- encoding = match[1]
108
+ charset = match[1]
71
109
  string = match[2].gsub(/_/, '=20')
72
110
  # Remove trailing = if it exists in a Q encoding
73
111
  string = string.sub(/\=$/, '')
74
112
  str = Encodings::QuotedPrintable.decode(string)
75
- str.force_encoding(fix_encoding(encoding))
113
+ str = charset_encoder.encode(str, charset)
114
+ # We assume that binary strings hold utf-8 directly to work around
115
+ # jruby/jruby#829 which subtly changes String#encode semantics.
116
+ str.force_encoding(Encoding::UTF_8) if str.encoding == Encoding::ASCII_8BIT
76
117
  end
77
- decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
78
- decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
79
- rescue Encoding::UndefinedConversionError
80
- str.dup.force_encoding("utf-8")
118
+ decoded = str.encode(Encoding::UTF_8, :invalid => :replace, :replace => "")
119
+ decoded.valid_encoding? ? decoded : decoded.encode(Encoding::UTF_16LE, :invalid => :replace, :replace => "").encode(Encoding::UTF_8)
120
+ rescue Encoding::UndefinedConversionError, ArgumentError, Encoding::ConverterNotFoundError
121
+ warn "Encoding conversion failed #{$!}"
122
+ str.dup.force_encoding(Encoding::UTF_8)
81
123
  end
82
124
 
83
125
  def Ruby19.param_decode(str, encoding)
84
- string = uri_parser.unescape(str)
85
- string.force_encoding(encoding) if encoding
86
- string
126
+ str = uri_parser.unescape(str)
127
+ str = charset_encoder.encode(str, encoding) if encoding
128
+ str
87
129
  end
88
130
 
89
131
  def Ruby19.param_encode(str)
@@ -96,23 +138,85 @@ module Mail
96
138
  @uri_parser ||= URI::Parser.new
97
139
  end
98
140
 
99
- # mails somtimes includes invalid encodings like iso885915 or utf8 so we transform them to iso885915 or utf8
100
- # TODO: add this as a test somewhere
101
- # Encoding.list.map{|e| [e.to_s.upcase==fix_encoding(e.to_s.downcase.gsub("-", "")), e.to_s] }.select {|a,b| !b}
102
- # Encoding.list.map{|e| [e.to_s==fix_encoding(e.to_s), e.to_s] }.select {|a,b| !b}
103
- def Ruby19.fix_encoding(encoding)
104
- case encoding
105
- # ISO-8859-15, ISO-2022-JP and alike
106
- when /iso-?(\d{4})-?(\w{1,2})/i then return "ISO-#{$1}-#{$2}"
107
- # "ISO-2022-JP-KDDI" and alike
108
- when /iso-?(\d{4})-?(\w{1,2})-?(\w*)/i then return "ISO-#{$1}-#{$2}-#{$3}"
109
- # UTF-8, UTF-32BE and alike
110
- when /utf-?(\d{1,2})?(\w{1,2})/i then return "UTF-#{$1}#{$2}".gsub(/\A(UTF-(?:16|32))\z/, '\\1BE')
111
- # Windows-1252 and alike
112
- when /Windows-?(.*)/i then return "Windows-#{$1}"
113
- when /^8bit$/ then return "ASCII-8BIT"
114
- #more aliases to be added if needed
115
- else return encoding
141
+ # Pick a Ruby encoding corresponding to the message charset. Most
142
+ # charsets have a Ruby encoding, but some need manual aliasing here.
143
+ #
144
+ # TODO: add this as a test somewhere:
145
+ # Encoding.list.map { |e| [e.to_s.upcase == pick_encoding(e.to_s.downcase.gsub("-", "")), e.to_s] }.select {|a,b| !b}
146
+ # Encoding.list.map { |e| [e.to_s == pick_encoding(e.to_s), e.to_s] }.select {|a,b| !b}
147
+ def Ruby19.pick_encoding(charset)
148
+ charset = charset.to_s
149
+ encoding = case charset.downcase
150
+
151
+ # ISO-8859-8-I etc. http://en.wikipedia.org/wiki/ISO-8859-8-I
152
+ when /^iso[-_]?8859-(\d+)(-i)?$/
153
+ "ISO-8859-#{$1}"
154
+
155
+ # ISO-8859-15, ISO-2022-JP and alike
156
+ when /^iso[-_]?(\d{4})-?(\w{1,2})$/
157
+ "ISO-#{$1}-#{$2}"
158
+
159
+ # "ISO-2022-JP-KDDI" and alike
160
+ when /^iso[-_]?(\d{4})-?(\w{1,2})-?(\w*)$/
161
+ "ISO-#{$1}-#{$2}-#{$3}"
162
+
163
+ # UTF-8, UTF-32BE and alike
164
+ when /^utf[\-_]?(\d{1,2})?(\w{1,2})$/
165
+ "UTF-#{$1}#{$2}".gsub(/\A(UTF-(?:16|32))\z/, '\\1BE')
166
+
167
+ # Windows-1252 and alike
168
+ when /^windows-?(.*)$/
169
+ "Windows-#{$1}"
170
+
171
+ when '8bit'
172
+ Encoding::ASCII_8BIT
173
+
174
+ # alternatives/misspellings of us-ascii seen in the wild
175
+ when /^iso[-_]?646(-us)?$/, 'us=ascii'
176
+ Encoding::ASCII
177
+
178
+ # Microsoft-specific alias for MACROMAN
179
+ when 'macintosh'
180
+ Encoding::MACROMAN
181
+
182
+ # Microsoft-specific alias for CP949 (Korean)
183
+ when 'ks_c_5601-1987'
184
+ Encoding::CP949
185
+
186
+ # Wrongly written Shift_JIS (Japanese)
187
+ when 'shift-jis'
188
+ Encoding::Shift_JIS
189
+
190
+ # GB2312 (Chinese charset) is a subset of GB18030 (its replacement)
191
+ when 'gb2312'
192
+ Encoding::GB18030
193
+
194
+ when 'cp-850'
195
+ Encoding::CP850
196
+
197
+ when 'latin2'
198
+ Encoding::ISO_8859_2
199
+
200
+ else
201
+ charset
202
+ end
203
+
204
+ convert_to_encoding(encoding)
205
+ end
206
+
207
+ class << self
208
+ private
209
+
210
+ def convert_to_encoding(encoding)
211
+ if encoding.is_a?(Encoding)
212
+ encoding
213
+ else
214
+ begin
215
+ Encoding.find(encoding)
216
+ rescue ArgumentError
217
+ Encoding::BINARY
218
+ end
219
+ end
116
220
  end
117
221
  end
118
222
  end
data/lib/mail.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
  module Mail # :doc:
3
4
 
4
5
  require 'date'
@@ -6,7 +7,13 @@ module Mail # :doc:
6
7
 
7
8
  require 'uri'
8
9
  require 'net/smtp'
9
- require 'mime/types'
10
+
11
+ begin
12
+ # Use mime/types/columnar if available, for reduced memory usage
13
+ require 'mime/types/columnar'
14
+ rescue LoadError
15
+ require 'mime/types'
16
+ end
10
17
 
11
18
  if RUBY_VERSION <= '1.8.6'
12
19
  begin
@@ -26,10 +33,7 @@ module Mail # :doc:
26
33
 
27
34
  require 'mail/version'
28
35
 
29
- require 'mail/core_extensions/nil'
30
- require 'mail/core_extensions/object'
31
36
  require 'mail/core_extensions/string'
32
- require 'mail/core_extensions/shell_escape'
33
37
  require 'mail/core_extensions/smtp' if RUBY_VERSION < '1.9.3'
34
38
  require 'mail/indifferent_hash'
35
39
 
@@ -42,7 +46,7 @@ module Mail # :doc:
42
46
  require 'mail/multibyte'
43
47
  end
44
48
 
45
- require 'mail/patterns'
49
+ require 'mail/constants'
46
50
  require 'mail/utilities'
47
51
  require 'mail/configuration'
48
52
 
@@ -77,15 +81,17 @@ module Mail # :doc:
77
81
 
78
82
  require 'mail/envelope'
79
83
 
80
- require 'load_parsers'
84
+ register_autoload :Parsers, "mail/parsers"
81
85
 
82
86
  # Autoload header field elements and transfer encodings.
83
87
  require 'mail/elements'
84
88
  require 'mail/encodings'
85
89
  require 'mail/encodings/base64'
86
90
  require 'mail/encodings/quoted_printable'
91
+ require 'mail/encodings/unix_to_unix'
87
92
 
88
93
  require 'mail/matchers/has_sent_mail'
94
+ require 'mail/matchers/attachment_matchers.rb'
89
95
 
90
96
  # Finally... require all the Mail.methods
91
97
  require 'mail/mail'
metadata CHANGED
@@ -1,64 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
5
- prerelease:
4
+ version: 2.6.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mikel Lindsaar
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mime-types
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.16'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.16'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
30
33
  - !ruby/object:Gem::Dependency
31
- name: treetop
34
+ name: bundler
32
35
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
36
  requirements:
35
- - - ~>
37
+ - - ">="
36
38
  - !ruby/object:Gem::Version
37
- version: 1.4.8
38
- type: :runtime
39
+ version: 1.0.3
40
+ type: :development
39
41
  prerelease: false
40
42
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
43
  requirements:
43
- - - ~>
44
+ - - ">="
44
45
  - !ruby/object:Gem::Version
45
- version: 1.4.8
46
+ version: 1.0.3
46
47
  - !ruby/object:Gem::Dependency
47
- name: i18n
48
+ name: rake
48
49
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ">"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.4.0
54
- type: :runtime
53
+ version: 0.8.7
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.8.7
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rdoc
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
55
83
  prerelease: false
56
84
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
85
  requirements:
59
- - - ! '>='
86
+ - - ">="
60
87
  - !ruby/object:Gem::Version
61
- version: 0.4.0
88
+ version: '0'
62
89
  description: A really Ruby Mail handler.
63
90
  email: raasdnil@gmail.com
64
91
  executables: []
@@ -69,25 +96,25 @@ extra_rdoc_files:
69
96
  - CHANGELOG.rdoc
70
97
  - TODO.rdoc
71
98
  files:
72
- - README.md
73
- - CONTRIBUTING.md
74
99
  - CHANGELOG.rdoc
100
+ - CONTRIBUTING.md
75
101
  - Dependencies.txt
76
102
  - Gemfile
103
+ - MIT-LICENSE
104
+ - README.md
77
105
  - Rakefile
78
106
  - TODO.rdoc
79
- - lib/load_parsers.rb
107
+ - lib/mail.rb
80
108
  - lib/mail/attachments_list.rb
81
109
  - lib/mail/body.rb
82
110
  - lib/mail/check_delivery_params.rb
83
111
  - lib/mail/configuration.rb
84
- - lib/mail/core_extensions/nil.rb
85
- - lib/mail/core_extensions/object.rb
86
- - lib/mail/core_extensions/shell_escape.rb
112
+ - lib/mail/constants.rb
87
113
  - lib/mail/core_extensions/smtp.rb
114
+ - lib/mail/core_extensions/string.rb
88
115
  - lib/mail/core_extensions/string/access.rb
89
116
  - lib/mail/core_extensions/string/multibyte.rb
90
- - lib/mail/core_extensions/string.rb
117
+ - lib/mail/elements.rb
91
118
  - lib/mail/elements/address.rb
92
119
  - lib/mail/elements/address_list.rb
93
120
  - lib/mail/elements/content_disposition_element.rb
@@ -100,17 +127,18 @@ files:
100
127
  - lib/mail/elements/mime_version_element.rb
101
128
  - lib/mail/elements/phrase_list.rb
102
129
  - lib/mail/elements/received_element.rb
103
- - lib/mail/elements.rb
130
+ - lib/mail/encodings.rb
104
131
  - lib/mail/encodings/7bit.rb
105
132
  - lib/mail/encodings/8bit.rb
106
133
  - lib/mail/encodings/base64.rb
107
134
  - lib/mail/encodings/binary.rb
108
135
  - lib/mail/encodings/quoted_printable.rb
109
136
  - lib/mail/encodings/transfer_encoding.rb
110
- - lib/mail/encodings.rb
137
+ - lib/mail/encodings/unix_to_unix.rb
111
138
  - lib/mail/envelope.rb
112
139
  - lib/mail/field.rb
113
140
  - lib/mail/field_list.rb
141
+ - lib/mail/fields.rb
114
142
  - lib/mail/fields/bcc_field.rb
115
143
  - lib/mail/fields/cc_field.rb
116
144
  - lib/mail/fields/comments_field.rb
@@ -149,17 +177,18 @@ files:
149
177
  - lib/mail/fields/subject_field.rb
150
178
  - lib/mail/fields/to_field.rb
151
179
  - lib/mail/fields/unstructured_field.rb
152
- - lib/mail/fields.rb
153
180
  - lib/mail/header.rb
154
181
  - lib/mail/indifferent_hash.rb
155
182
  - lib/mail/mail.rb
183
+ - lib/mail/matchers/attachment_matchers.rb
156
184
  - lib/mail/matchers/has_sent_mail.rb
157
185
  - lib/mail/message.rb
186
+ - lib/mail/multibyte.rb
158
187
  - lib/mail/multibyte/chars.rb
159
188
  - lib/mail/multibyte/exceptions.rb
160
189
  - lib/mail/multibyte/unicode.rb
161
190
  - lib/mail/multibyte/utils.rb
162
- - lib/mail/multibyte.rb
191
+ - lib/mail/network.rb
163
192
  - lib/mail/network/delivery_methods/exim.rb
164
193
  - lib/mail/network/delivery_methods/file_delivery.rb
165
194
  - lib/mail/network/delivery_methods/sendmail.rb
@@ -170,69 +199,78 @@ files:
170
199
  - lib/mail/network/retriever_methods/imap.rb
171
200
  - lib/mail/network/retriever_methods/pop3.rb
172
201
  - lib/mail/network/retriever_methods/test_retriever.rb
173
- - lib/mail/network.rb
174
- - lib/mail/parsers/address_lists.rb
175
- - lib/mail/parsers/address_lists.treetop
176
- - lib/mail/parsers/content_disposition.rb
177
- - lib/mail/parsers/content_disposition.treetop
178
- - lib/mail/parsers/content_location.rb
179
- - lib/mail/parsers/content_location.treetop
180
- - lib/mail/parsers/content_transfer_encoding.rb
181
- - lib/mail/parsers/content_transfer_encoding.treetop
182
- - lib/mail/parsers/content_type.rb
183
- - lib/mail/parsers/content_type.treetop
184
- - lib/mail/parsers/date_time.rb
185
- - lib/mail/parsers/date_time.treetop
186
- - lib/mail/parsers/envelope_from.rb
187
- - lib/mail/parsers/envelope_from.treetop
188
- - lib/mail/parsers/message_ids.rb
189
- - lib/mail/parsers/message_ids.treetop
190
- - lib/mail/parsers/mime_version.rb
191
- - lib/mail/parsers/mime_version.treetop
192
- - lib/mail/parsers/phrase_lists.rb
193
- - lib/mail/parsers/phrase_lists.treetop
194
- - lib/mail/parsers/received.rb
195
- - lib/mail/parsers/received.treetop
196
- - lib/mail/parsers/rfc2045.rb
197
- - lib/mail/parsers/rfc2045.treetop
198
- - lib/mail/parsers/rfc2822.rb
199
- - lib/mail/parsers/rfc2822.treetop
200
- - lib/mail/parsers/rfc2822_obsolete.rb
201
- - lib/mail/parsers/rfc2822_obsolete.treetop
202
+ - lib/mail/parsers.rb
203
+ - lib/mail/parsers/address_lists_parser.rb
204
+ - lib/mail/parsers/content_disposition_parser.rb
205
+ - lib/mail/parsers/content_location_parser.rb
206
+ - lib/mail/parsers/content_transfer_encoding_parser.rb
207
+ - lib/mail/parsers/content_type_parser.rb
208
+ - lib/mail/parsers/date_time_parser.rb
209
+ - lib/mail/parsers/envelope_from_parser.rb
210
+ - lib/mail/parsers/message_ids_parser.rb
211
+ - lib/mail/parsers/mime_version_parser.rb
212
+ - lib/mail/parsers/phrase_lists_parser.rb
213
+ - lib/mail/parsers/ragel.rb
214
+ - lib/mail/parsers/ragel/common.rl
215
+ - lib/mail/parsers/ragel/date_time.rl
216
+ - lib/mail/parsers/ragel/parser_info.rb
217
+ - lib/mail/parsers/ragel/ruby.rb
218
+ - lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb
219
+ - lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl
220
+ - lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb
221
+ - lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl
222
+ - lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb
223
+ - lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl
224
+ - lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb
225
+ - lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl
226
+ - lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb
227
+ - lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl
228
+ - lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb
229
+ - lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl
230
+ - lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb
231
+ - lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl
232
+ - lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb
233
+ - lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl
234
+ - lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb
235
+ - lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl
236
+ - lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb
237
+ - lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl
238
+ - lib/mail/parsers/ragel/ruby/machines/rb_actions.rl
239
+ - lib/mail/parsers/ragel/ruby/machines/received_machine.rb
240
+ - lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl
241
+ - lib/mail/parsers/ragel/ruby/parser.rb.rl.erb
242
+ - lib/mail/parsers/received_parser.rb
202
243
  - lib/mail/part.rb
203
244
  - lib/mail/parts_list.rb
204
- - lib/mail/patterns.rb
205
245
  - lib/mail/utilities.rb
206
246
  - lib/mail/values/unicode_tables.dat
207
247
  - lib/mail/version.rb
208
248
  - lib/mail/version_specific/ruby_1_8.rb
209
249
  - lib/mail/version_specific/ruby_1_9.rb
210
- - lib/mail.rb
211
- - lib/tasks/corpus.rake
212
- - lib/tasks/treetop.rake
213
- - lib/VERSION
214
- homepage: http://github.com/mikel/mail
215
- licenses: []
250
+ homepage: https://github.com/mikel/mail
251
+ licenses:
252
+ - MIT
253
+ metadata: {}
216
254
  post_install_message:
217
- rdoc_options: []
255
+ rdoc_options:
256
+ - "--exclude"
257
+ - lib/mail/values/unicode_tables.dat
218
258
  require_paths:
219
259
  - lib
220
260
  required_ruby_version: !ruby/object:Gem::Requirement
221
- none: false
222
261
  requirements:
223
- - - ! '>='
262
+ - - ">="
224
263
  - !ruby/object:Gem::Version
225
264
  version: '0'
226
265
  required_rubygems_version: !ruby/object:Gem::Requirement
227
- none: false
228
266
  requirements:
229
- - - ! '>='
267
+ - - ">="
230
268
  - !ruby/object:Gem::Version
231
269
  version: '0'
232
270
  requirements: []
233
271
  rubyforge_project:
234
- rubygems_version: 1.8.24
272
+ rubygems_version: 2.5.1
235
273
  signing_key:
236
- specification_version: 3
274
+ specification_version: 4
237
275
  summary: Mail provides a nice Ruby DSL for making, sending and reading emails.
238
276
  test_files: []
data/lib/VERSION DELETED
@@ -1,4 +0,0 @@
1
- major:2
2
- minor:5
3
- patch:2
4
- build: