mail 2.7.1 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +59 -28
  3. data/lib/mail/attachments_list.rb +2 -5
  4. data/lib/mail/body.rb +24 -47
  5. data/lib/mail/check_delivery_params.rb +21 -16
  6. data/lib/mail/constants.rb +27 -5
  7. data/lib/mail/elements/address.rb +27 -27
  8. data/lib/mail/elements/address_list.rb +1 -1
  9. data/lib/mail/elements/content_disposition_element.rb +1 -1
  10. data/lib/mail/elements/content_location_element.rb +1 -1
  11. data/lib/mail/elements/content_transfer_encoding_element.rb +1 -1
  12. data/lib/mail/elements/content_type_element.rb +8 -4
  13. data/lib/mail/elements/date_time_element.rb +1 -1
  14. data/lib/mail/elements/envelope_from_element.rb +13 -7
  15. data/lib/mail/elements/message_ids_element.rb +14 -5
  16. data/lib/mail/elements/mime_version_element.rb +1 -1
  17. data/lib/mail/elements/phrase_list.rb +7 -2
  18. data/lib/mail/elements/received_element.rb +20 -6
  19. data/lib/mail/encodings/7bit.rb +5 -0
  20. data/lib/mail/encodings/base64.rb +2 -2
  21. data/lib/mail/encodings/quoted_printable.rb +2 -2
  22. data/lib/mail/encodings.rb +30 -59
  23. data/lib/mail/envelope.rb +11 -14
  24. data/lib/mail/field.rb +37 -53
  25. data/lib/mail/field_list.rb +60 -7
  26. data/lib/mail/fields/bcc_field.rb +34 -52
  27. data/lib/mail/fields/cc_field.rb +28 -49
  28. data/lib/mail/fields/comments_field.rb +27 -37
  29. data/lib/mail/fields/common_address_field.rb +170 -0
  30. data/lib/mail/fields/common_date_field.rb +58 -0
  31. data/lib/mail/fields/common_field.rb +77 -0
  32. data/lib/mail/fields/common_message_id_field.rb +42 -0
  33. data/lib/mail/fields/content_description_field.rb +7 -14
  34. data/lib/mail/fields/content_disposition_field.rb +13 -38
  35. data/lib/mail/fields/content_id_field.rb +24 -51
  36. data/lib/mail/fields/content_location_field.rb +11 -25
  37. data/lib/mail/fields/content_transfer_encoding_field.rb +31 -31
  38. data/lib/mail/fields/content_type_field.rb +46 -71
  39. data/lib/mail/fields/date_field.rb +23 -51
  40. data/lib/mail/fields/from_field.rb +28 -49
  41. data/lib/mail/fields/in_reply_to_field.rb +38 -49
  42. data/lib/mail/fields/keywords_field.rb +18 -31
  43. data/lib/mail/fields/message_id_field.rb +25 -71
  44. data/lib/mail/fields/mime_version_field.rb +19 -30
  45. data/lib/mail/fields/named_structured_field.rb +11 -0
  46. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  47. data/lib/mail/fields/optional_field.rb +5 -6
  48. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +12 -10
  49. data/lib/mail/fields/received_field.rb +43 -57
  50. data/lib/mail/fields/references_field.rb +35 -49
  51. data/lib/mail/fields/reply_to_field.rb +28 -49
  52. data/lib/mail/fields/resent_bcc_field.rb +28 -49
  53. data/lib/mail/fields/resent_cc_field.rb +28 -49
  54. data/lib/mail/fields/resent_date_field.rb +5 -29
  55. data/lib/mail/fields/resent_from_field.rb +28 -49
  56. data/lib/mail/fields/resent_message_id_field.rb +5 -29
  57. data/lib/mail/fields/resent_sender_field.rb +27 -56
  58. data/lib/mail/fields/resent_to_field.rb +28 -49
  59. data/lib/mail/fields/return_path_field.rb +50 -54
  60. data/lib/mail/fields/sender_field.rb +34 -55
  61. data/lib/mail/fields/structured_field.rb +3 -30
  62. data/lib/mail/fields/subject_field.rb +9 -11
  63. data/lib/mail/fields/to_field.rb +28 -49
  64. data/lib/mail/fields/unstructured_field.rb +16 -48
  65. data/lib/mail/header.rb +69 -110
  66. data/lib/mail/matchers/attachment_matchers.rb +15 -0
  67. data/lib/mail/message.rb +52 -66
  68. data/lib/mail/multibyte/chars.rb +8 -166
  69. data/lib/mail/multibyte/utils.rb +26 -43
  70. data/lib/mail/multibyte.rb +1 -11
  71. data/lib/mail/network/delivery_methods/exim.rb +5 -4
  72. data/lib/mail/network/delivery_methods/file_delivery.rb +11 -10
  73. data/lib/mail/network/delivery_methods/logger_delivery.rb +2 -5
  74. data/lib/mail/network/delivery_methods/sendmail.rb +56 -18
  75. data/lib/mail/network/delivery_methods/smtp.rb +25 -9
  76. data/lib/mail/network/delivery_methods/smtp_connection.rb +3 -12
  77. data/lib/mail/network/delivery_methods/test_mailer.rb +4 -2
  78. data/lib/mail/network/retriever_methods/base.rb +8 -8
  79. data/lib/mail/network/retriever_methods/imap.rb +2 -2
  80. data/lib/mail/network/retriever_methods/pop3.rb +2 -2
  81. data/lib/mail/network/retriever_methods/test_retriever.rb +2 -1
  82. data/lib/mail/parsers/address_lists_parser.rb +33070 -33064
  83. data/lib/mail/parsers/address_lists_parser.rl +7 -0
  84. data/lib/mail/parsers/content_disposition_parser.rb +833 -827
  85. data/lib/mail/parsers/content_disposition_parser.rl +7 -0
  86. data/lib/mail/parsers/content_location_parser.rb +770 -764
  87. data/lib/mail/parsers/content_location_parser.rl +7 -0
  88. data/lib/mail/parsers/content_transfer_encoding_parser.rb +474 -468
  89. data/lib/mail/parsers/content_transfer_encoding_parser.rl +7 -0
  90. data/lib/mail/parsers/content_type_parser.rb +971 -965
  91. data/lib/mail/parsers/content_type_parser.rl +7 -0
  92. data/lib/mail/parsers/date_time_parser.rb +838 -832
  93. data/lib/mail/parsers/date_time_parser.rl +7 -0
  94. data/lib/mail/parsers/envelope_from_parser.rb +3623 -3529
  95. data/lib/mail/parsers/envelope_from_parser.rl +7 -0
  96. data/lib/mail/parsers/message_ids_parser.rb +5107 -2800
  97. data/lib/mail/parsers/message_ids_parser.rl +12 -1
  98. data/lib/mail/parsers/mime_version_parser.rb +463 -457
  99. data/lib/mail/parsers/mime_version_parser.rl +7 -0
  100. data/lib/mail/parsers/phrase_lists_parser.rb +836 -830
  101. data/lib/mail/parsers/phrase_lists_parser.rl +8 -1
  102. data/lib/mail/parsers/received_parser.rb +8688 -8682
  103. data/lib/mail/parsers/received_parser.rl +7 -0
  104. data/lib/mail/parsers/rfc5322.rl +28 -13
  105. data/lib/mail/parsers.rb +11 -17
  106. data/lib/mail/part.rb +5 -9
  107. data/lib/mail/parts_list.rb +57 -0
  108. data/lib/mail/smtp_envelope.rb +57 -0
  109. data/lib/mail/utilities.rb +307 -69
  110. data/lib/mail/version.rb +1 -1
  111. data/lib/mail/yaml.rb +30 -0
  112. data/lib/mail.rb +3 -20
  113. metadata +72 -18
  114. data/lib/mail/core_extensions/smtp.rb +0 -28
  115. data/lib/mail/core_extensions/string.rb +0 -17
  116. data/lib/mail/fields/common/address_container.rb +0 -17
  117. data/lib/mail/fields/common/common_address.rb +0 -161
  118. data/lib/mail/fields/common/common_date.rb +0 -36
  119. data/lib/mail/fields/common/common_field.rb +0 -52
  120. data/lib/mail/fields/common/common_message_id.rb +0 -49
  121. data/lib/mail/version_specific/ruby_1_8.rb +0 -163
  122. data/lib/mail/version_specific/ruby_1_9.rb +0 -278
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikel Lindsaar
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-13 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_mime
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-smtp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-imap
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-pop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: bundler
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +108,20 @@ dependencies:
66
108
  - - "~>"
67
109
  - !ruby/object:Gem::Version
68
110
  version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-benchmark
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  - !ruby/object:Gem::Dependency
70
126
  name: rdoc
71
127
  requirement: !ruby/object:Gem::Requirement
@@ -109,8 +165,6 @@ files:
109
165
  - lib/mail/check_delivery_params.rb
110
166
  - lib/mail/configuration.rb
111
167
  - lib/mail/constants.rb
112
- - lib/mail/core_extensions/smtp.rb
113
- - lib/mail/core_extensions/string.rb
114
168
  - lib/mail/elements.rb
115
169
  - lib/mail/elements/address.rb
116
170
  - lib/mail/elements/address_list.rb
@@ -140,12 +194,10 @@ files:
140
194
  - lib/mail/fields/bcc_field.rb
141
195
  - lib/mail/fields/cc_field.rb
142
196
  - lib/mail/fields/comments_field.rb
143
- - lib/mail/fields/common/address_container.rb
144
- - lib/mail/fields/common/common_address.rb
145
- - lib/mail/fields/common/common_date.rb
146
- - lib/mail/fields/common/common_field.rb
147
- - lib/mail/fields/common/common_message_id.rb
148
- - lib/mail/fields/common/parameter_hash.rb
197
+ - lib/mail/fields/common_address_field.rb
198
+ - lib/mail/fields/common_date_field.rb
199
+ - lib/mail/fields/common_field.rb
200
+ - lib/mail/fields/common_message_id_field.rb
149
201
  - lib/mail/fields/content_description_field.rb
150
202
  - lib/mail/fields/content_disposition_field.rb
151
203
  - lib/mail/fields/content_id_field.rb
@@ -158,7 +210,10 @@ files:
158
210
  - lib/mail/fields/keywords_field.rb
159
211
  - lib/mail/fields/message_id_field.rb
160
212
  - lib/mail/fields/mime_version_field.rb
213
+ - lib/mail/fields/named_structured_field.rb
214
+ - lib/mail/fields/named_unstructured_field.rb
161
215
  - lib/mail/fields/optional_field.rb
216
+ - lib/mail/fields/parameter_hash.rb
162
217
  - lib/mail/fields/received_field.rb
163
218
  - lib/mail/fields/references_field.rb
164
219
  - lib/mail/fields/reply_to_field.rb
@@ -233,16 +288,16 @@ files:
233
288
  - lib/mail/parsers/rfc5322_lexical_tokens.rl
234
289
  - lib/mail/part.rb
235
290
  - lib/mail/parts_list.rb
291
+ - lib/mail/smtp_envelope.rb
236
292
  - lib/mail/utilities.rb
237
293
  - lib/mail/values/unicode_tables.dat
238
294
  - lib/mail/version.rb
239
- - lib/mail/version_specific/ruby_1_8.rb
240
- - lib/mail/version_specific/ruby_1_9.rb
295
+ - lib/mail/yaml.rb
241
296
  homepage: https://github.com/mikel/mail
242
297
  licenses:
243
298
  - MIT
244
299
  metadata: {}
245
- post_install_message:
300
+ post_install_message:
246
301
  rdoc_options:
247
302
  - "--exclude"
248
303
  - lib/mail/values/unicode_tables.dat
@@ -252,16 +307,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
307
  requirements:
253
308
  - - ">="
254
309
  - !ruby/object:Gem::Version
255
- version: '0'
310
+ version: '2.5'
256
311
  required_rubygems_version: !ruby/object:Gem::Requirement
257
312
  requirements:
258
313
  - - ">="
259
314
  - !ruby/object:Gem::Version
260
315
  version: '0'
261
316
  requirements: []
262
- rubyforge_project:
263
- rubygems_version: 2.7.6
264
- signing_key:
317
+ rubygems_version: 3.1.6
318
+ signing_key:
265
319
  specification_version: 4
266
320
  summary: Mail provides a nice Ruby DSL for making, sending and reading emails.
267
321
  test_files: []
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # This is a backport of r30294 from ruby trunk because of a bug in net/smtp.
5
- # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30294
6
- #
7
- # Fixed in Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
8
- if RUBY_VERSION < '1.9.3'
9
- module Net
10
- class SMTP
11
- begin
12
- alias_method :original_tlsconnect, :tlsconnect
13
-
14
- def tlsconnect(s)
15
- verified = false
16
- begin
17
- original_tlsconnect(s).tap { verified = true }
18
- ensure
19
- unless verified
20
- s.close rescue nil
21
- end
22
- end
23
- end
24
- rescue NameError
25
- end
26
- end
27
- end
28
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- class String #:nodoc:
4
-
5
- unless method_defined?(:ascii_only?)
6
- # Backport from Ruby 1.9 checks for non-us-ascii characters.
7
- def ascii_only?
8
- self !~ MATCH_NON_US_ASCII
9
- end
10
-
11
- MATCH_NON_US_ASCII = /[^\x00-\x7f]/
12
- end
13
-
14
- unless method_defined?(:bytesize)
15
- alias :bytesize :length
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
- module Mail
3
-
4
- class AddressContainer < Array
5
-
6
- def initialize(field, list = [])
7
- @field = field
8
- super(list)
9
- end
10
-
11
- def <<(address)
12
- @field << address
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,161 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'mail/fields/common/address_container'
4
-
5
- module Mail
6
- module CommonAddress # :nodoc:
7
- def parse(val = value)
8
- unless Utilities.blank?(val)
9
- @address_list = AddressList.new(encode_if_needed(val))
10
- else
11
- nil
12
- end
13
- end
14
-
15
- def charset
16
- @charset
17
- end
18
-
19
- def encode_if_needed(val) #:nodoc:
20
- # Need to join arrays of addresses into a single value
21
- if val.kind_of?(Array)
22
- val.compact.map { |a| encode_if_needed a }.join(', ')
23
-
24
- # Pass through UTF-8; encode non-UTF-8.
25
- else
26
- utf8_if_needed(val) || Encodings.encode_non_usascii(val, charset)
27
- end
28
- end
29
-
30
- # Allows you to iterate through each address object in the address_list
31
- def each
32
- address_list.addresses.each do |address|
33
- yield(address)
34
- end
35
- end
36
-
37
- # Returns the address string of all the addresses in the address list
38
- def addresses
39
- list = address_list.addresses.map { |a| a.address }
40
- Mail::AddressContainer.new(self, list)
41
- end
42
-
43
- # Returns the formatted string of all the addresses in the address list
44
- def formatted
45
- list = address_list.addresses.map { |a| a.format }
46
- Mail::AddressContainer.new(self, list)
47
- end
48
-
49
- # Returns the display name of all the addresses in the address list
50
- def display_names
51
- list = address_list.addresses.map { |a| a.display_name }
52
- Mail::AddressContainer.new(self, list)
53
- end
54
-
55
- # Returns the actual address objects in the address list
56
- def addrs
57
- list = address_list.addresses
58
- Mail::AddressContainer.new(self, list)
59
- end
60
-
61
- # Returns a hash of group name => address strings for the address list
62
- def groups
63
- address_list.addresses_grouped_by_group
64
- end
65
-
66
- # Returns the addresses that are part of groups
67
- def group_addresses
68
- decoded_group_addresses
69
- end
70
-
71
- # Returns a list of decoded group addresses
72
- def decoded_group_addresses
73
- groups.map { |k,v| v.map { |a| a.decoded } }.flatten
74
- end
75
-
76
- # Returns a list of encoded group addresses
77
- def encoded_group_addresses
78
- groups.map { |k,v| v.map { |a| a.encoded } }.flatten
79
- end
80
-
81
- # Returns the name of all the groups in a string
82
- def group_names # :nodoc:
83
- address_list.group_names
84
- end
85
-
86
- def default
87
- addresses
88
- end
89
-
90
- def <<(val)
91
- case
92
- when val.nil?
93
- raise ArgumentError, "Need to pass an address to <<"
94
- when Utilities.blank?(val)
95
- parse(encoded)
96
- else
97
- self.value = [self.value, val].reject {|a| Utilities.blank?(a) }.join(", ")
98
- end
99
- end
100
-
101
- def value=(val)
102
- super
103
- parse(self.value)
104
- end
105
-
106
- private
107
-
108
- if 'string'.respond_to?(:encoding)
109
- # Pass through UTF-8 addresses
110
- def utf8_if_needed(val)
111
- if charset =~ /\AUTF-?8\z/i
112
- val
113
- elsif val.encoding == Encoding::UTF_8
114
- val
115
- elsif (utf8 = val.dup.force_encoding(Encoding::UTF_8)).valid_encoding?
116
- utf8
117
- end
118
- end
119
- else
120
- def utf8_if_needed(val)
121
- if charset =~ /\AUTF-?8\z/i
122
- val
123
- end
124
- end
125
- end
126
-
127
- def do_encode(field_name)
128
- return '' if Utilities.blank?(value)
129
- address_array = address_list.addresses.reject { |a| encoded_group_addresses.include?(a.encoded) }.compact.map { |a| a.encoded }
130
- address_text = address_array.join(", \r\n\s")
131
- group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.encoded }.join(", \r\n\s")};" }
132
- group_text = group_array.join(" \r\n\s")
133
- return_array = [address_text, group_text].reject { |a| Utilities.blank?(a) }
134
- "#{field_name}: #{return_array.join(", \r\n\s")}\r\n"
135
- end
136
-
137
- def do_decode
138
- return nil if Utilities.blank?(value)
139
- address_array = address_list.addresses.reject { |a| decoded_group_addresses.include?(a.decoded) }.map { |a| a.decoded }
140
- address_text = address_array.join(", ")
141
- group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.decoded }.join(", ")};" }
142
- group_text = group_array.join(" ")
143
- return_array = [address_text, group_text].reject { |a| Utilities.blank?(a) }
144
- return_array.join(", ")
145
- end
146
-
147
- def address_list # :nodoc:
148
- @address_list ||= AddressList.new(value)
149
- end
150
-
151
- def get_group_addresses(group_list)
152
- if group_list.respond_to?(:addresses)
153
- group_list.addresses.map do |address|
154
- Mail::Address.new(address)
155
- end
156
- else
157
- []
158
- end
159
- end
160
- end
161
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- module Mail
4
- module CommonDate # :nodoc:
5
- # Returns a date time object of the parsed date
6
- def date_time
7
- ::DateTime.parse("#{element.date_string} #{element.time_string}")
8
- end
9
-
10
- def default
11
- date_time
12
- end
13
-
14
- def parse(val = value)
15
- unless Utilities.blank?(val)
16
- @element = Mail::DateTimeElement.new(val)
17
- else
18
- nil
19
- end
20
- end
21
-
22
- private
23
-
24
- def do_encode(field_name)
25
- "#{field_name}: #{value}\r\n"
26
- end
27
-
28
- def do_decode
29
- "#{value}"
30
- end
31
-
32
- def element
33
- @element ||= Mail::DateTimeElement.new(value)
34
- end
35
- end
36
- end
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- module Mail
4
- module CommonField # :nodoc:
5
- include Mail::Constants
6
-
7
- def name=(value)
8
- @name = value
9
- end
10
-
11
- def name
12
- @name ||= nil
13
- end
14
-
15
- def value=(value)
16
- @length = nil
17
- @element = nil
18
- @value = value.is_a?(Array) ? value : value.to_s
19
- end
20
-
21
- def value
22
- @value
23
- end
24
-
25
- def to_s
26
- decoded.to_s
27
- end
28
-
29
- def default
30
- decoded
31
- end
32
-
33
- def field_length
34
- @length ||= "#{name}: #{encode(decoded)}".length
35
- end
36
-
37
- def responsible_for?( val )
38
- name.to_s.casecmp(val.to_s) == 0
39
- end
40
-
41
- private
42
-
43
- FILENAME_RE = /\b(filename|name)=([^;"\r\n]+\s[^;"\r\n]+)/
44
- def ensure_filename_quoted(value)
45
- if value.is_a?(String)
46
- value.sub FILENAME_RE, '\1="\2"'
47
- else
48
- value
49
- end
50
- end
51
- end
52
- end
@@ -1,49 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- module Mail
4
- module CommonMessageId # :nodoc:
5
- def element
6
- @element ||= Mail::MessageIdsElement.new(value) unless Utilities.blank?(value)
7
- end
8
-
9
- def parse(val = value)
10
- unless Utilities.blank?(val)
11
- @element = Mail::MessageIdsElement.new(val)
12
- else
13
- nil
14
- end
15
- end
16
-
17
- def message_id
18
- element.message_id if element
19
- end
20
-
21
- def message_ids
22
- element.message_ids if element
23
- end
24
-
25
- def default
26
- return nil unless message_ids
27
- if message_ids.length == 1
28
- message_ids[0]
29
- else
30
- message_ids
31
- end
32
- end
33
-
34
- private
35
-
36
- def do_encode(field_name)
37
- %Q{#{field_name}: #{formated_message_ids("\r\n ")}\r\n}
38
- end
39
-
40
- def do_decode
41
- formated_message_ids(' ')
42
- end
43
-
44
- def formated_message_ids(join)
45
- message_ids.map{ |m| "<#{m}>" }.join(join) if message_ids
46
- end
47
-
48
- end
49
- end
@@ -1,163 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require 'net/imap' # for decode_utf7
4
-
5
- module Mail
6
- class Ruby18
7
- require 'base64'
8
- require 'iconv'
9
-
10
- # Escapes any parenthesis in a string that are unescaped. This can't
11
- # use the Ruby 1.9.1 regexp feature of negative look behind so we have
12
- # to do two replacement, first unescape everything, then re-escape it
13
- def Ruby18.escape_paren( str )
14
- re = /\\\)/
15
- str = str.gsub(re) { |s| ')'}
16
- re = /\\\(/
17
- str = str.gsub(re) { |s| '('}
18
- re = /([\(\)])/ # Only match unescaped parens
19
- str.gsub(re) { |s| '\\' + s }
20
- end
21
-
22
- def Ruby18.paren( str )
23
- str = $1 if str =~ /^\((.*)?\)$/
24
- str = escape_paren( str )
25
- '(' + str + ')'
26
- end
27
-
28
- def Ruby18.escape_bracket( str )
29
- re = /\\\>/
30
- str = str.gsub(re) { |s| '>'}
31
- re = /\\\</
32
- str = str.gsub(re) { |s| '<'}
33
- re = /([\<\>])/ # Only match unescaped parens
34
- str.gsub(re) { |s| '\\' + s }
35
- end
36
-
37
- def Ruby18.bracket( str )
38
- str = $1 if str =~ /^\<(.*)?\>$/
39
- str = escape_bracket( str )
40
- '<' + str + '>'
41
- end
42
-
43
- def Ruby18.decode_base64(str)
44
- Base64.decode64(str) if str
45
- end
46
-
47
- def Ruby18.encode_base64(str)
48
- Base64.encode64(str)
49
- end
50
-
51
- def Ruby18.has_constant?(klass, string)
52
- klass.constants.include?( string )
53
- end
54
-
55
- def Ruby18.get_constant(klass, string)
56
- klass.const_get( string )
57
- end
58
-
59
- def Ruby18.transcode_charset(str, from_encoding, to_encoding = 'UTF-8')
60
- case from_encoding
61
- when /utf-?7/i
62
- decode_utf7(str)
63
- else
64
- retried = false
65
- begin
66
- Iconv.conv("#{normalize_iconv_charset_encoding(to_encoding)}//IGNORE", normalize_iconv_charset_encoding(from_encoding), str)
67
- rescue Iconv::InvalidEncoding
68
- if retried
69
- raise
70
- else
71
- from_encoding = 'ASCII'
72
- retried = true
73
- retry
74
- end
75
- end
76
- end
77
- end
78
-
79
- def Ruby18.decode_utf7(str)
80
- Net::IMAP.decode_utf7(str)
81
- end
82
-
83
- def Ruby18.b_value_encode(str, encoding)
84
- # Ruby 1.8 requires an encoding to work
85
- raise ArgumentError, "Must supply an encoding" if encoding.nil?
86
- encoding = encoding.to_s.upcase.gsub('_', '-')
87
- [Encodings::Base64.encode(str), normalize_iconv_charset_encoding(encoding)]
88
- end
89
-
90
- def Ruby18.b_value_decode(str)
91
- match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
92
- if match
93
- encoding = match[1]
94
- str = Ruby18.decode_base64(match[2])
95
- str = transcode_charset(str, encoding)
96
- end
97
- str
98
- end
99
-
100
- def Ruby18.q_value_encode(str, encoding)
101
- # Ruby 1.8 requires an encoding to work
102
- raise ArgumentError, "Must supply an encoding" if encoding.nil?
103
- encoding = encoding.to_s.upcase.gsub('_', '-')
104
- [Encodings::QuotedPrintable.encode(str), encoding]
105
- end
106
-
107
- def Ruby18.q_value_decode(str)
108
- match = str.match(/\=\?(.+)?\?[Qq]\?(.*)\?\=/m)
109
- if match
110
- encoding = match[1]
111
- string = match[2].gsub(/_/, '=20')
112
- # Remove trailing = if it exists in a Q encoding
113
- string = string.sub(/\=$/, '')
114
- str = Encodings::QuotedPrintable.decode(string)
115
- str = transcode_charset(str, encoding)
116
- end
117
- str
118
- end
119
-
120
- def Ruby18.param_decode(str, encoding)
121
- str = URI.unescape(str)
122
- if encoding
123
- transcode_charset(str, encoding)
124
- else
125
- str
126
- end
127
- end
128
-
129
- def Ruby18.param_encode(str)
130
- encoding = $KCODE.to_s.downcase
131
- language = Configuration.instance.param_encode_language
132
- "#{encoding}'#{language}'#{URI.escape(str)}"
133
- end
134
-
135
- def Ruby18.string_byteslice(str, *args)
136
- str.slice(*args)
137
- end
138
-
139
- private
140
-
141
- def Ruby18.normalize_iconv_charset_encoding(encoding)
142
- case encoding.upcase
143
- when 'UTF8', 'UTF_8'
144
- 'UTF-8'
145
- when 'UTF16', 'UTF-16'
146
- 'UTF-16BE'
147
- when 'UTF32', 'UTF-32'
148
- 'UTF-32BE'
149
- when 'KS_C_5601-1987'
150
- 'CP949'
151
- else
152
- # Fall back to ASCII for charsets that Iconv doesn't recognize
153
- begin
154
- Iconv.new('UTF-8', encoding)
155
- rescue Iconv::InvalidEncoding => e
156
- 'ASCII'
157
- else
158
- encoding
159
- end
160
- end
161
- end
162
- end
163
- end