mail-jdec 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60ab2c096a186f73beaaa84de6c3e857359d65f50e5bc7ed333450624e6d77f7
4
- data.tar.gz: c8b624b4155eb04d18864d8fe9bd586dd6e58492e1126aaed056d24615dc04c9
3
+ metadata.gz: f4cba29f251d5a8fe9a696f6e965b9fd2b52c622f64aedb23f63567e3ebc15d0
4
+ data.tar.gz: ae6a610eee21b581f474fedf651a90e54bc9e5dde5d613daeebd621c0520da86
5
5
  SHA512:
6
- metadata.gz: 7daf270c25730a7e2bc0876889f2900e2ad86b06cc21310dba5434e2d525ef82128d27c5abbf5b83fd3a2609f94d27ee8c06d6d236b2172fd19361f4221bbed6
7
- data.tar.gz: befc1dfd40761b72c6a7a06993f667fa2396b65cf5a28b0043f2b92b270d8269770628ae37576fa97b93ab6166228a84bbc7f842b30966c7c082c58085ed3861
6
+ metadata.gz: c5a8e19b16e943c41890c0652433f1607b15c08108440dbbe0fbe4ca6e3360f3aed4d43328e46aa4230b390bac46b9566db890b123f675444972054231af7514
7
+ data.tar.gz: 9cd358e45c80af8aab96e8d995d16720028ec657c224a0faeb07ba2eec12b39be15b76f2c778524f4a420b499c7649eea13e751eeefdf55deb53dbf083f1549b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.1
4
+
5
+ * Support charset detection including message parts.
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  * Change supported mail version to 2.8.
@@ -6,13 +6,13 @@ module Mail
6
6
  def decoded
7
7
  decoded = super
8
8
 
9
- if Jdec.enabled? && (!has_content_type? || (text? && !has_charset? && !attachment? && !multipart?))
9
+ if Jdec.enabled? && MessagePatch.autodetect?(self)
10
10
  detected = Detector.detect(decoded)
11
11
  if detected && detected[:type] == :text
12
12
  charset = detected[:encoding].downcase
13
13
  decoded = Mail::Encodings.transcode_charset(decoded.dup.force_encoding(charset), charset, 'utf-8')
14
- header[:content_type] = 'text/plain'
15
- header[:content_type].parameters[:charset] = charset
14
+ header[:content_type] = 'text/plain' unless has_content_type?
15
+ header[:content_type].parameters[:charset] = charset unless has_charset?
16
16
  else
17
17
  decoded = Mail::Encodings.transcode_charset(decoded, decoded.encoding, 'utf-8')
18
18
  end
@@ -20,6 +20,23 @@ module Mail
20
20
 
21
21
  decoded
22
22
  end
23
+
24
+ class << self
25
+ def autodetect?(message)
26
+ !message.has_content_type? ||
27
+ (mime_types_for_autodetect?(message.mime_type) && !message.has_charset? && !message.attachment? && !message.multipart?)
28
+ end
29
+
30
+ def mime_types_for_autodetect?(mime_type)
31
+ Jdec.mime_types_for_autodetect.any? do |type|
32
+ if type.is_a?(Regexp)
33
+ type.match?(mime_type)
34
+ else
35
+ type == mime_type
36
+ end
37
+ end
38
+ end
39
+ end
23
40
  end
24
41
  end
25
42
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mail
4
4
  module Jdec
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.1'
6
6
  end
7
7
  end
data/lib/mail/jdec.rb CHANGED
@@ -13,6 +13,7 @@ module Mail
13
13
  attr_reader :enabled
14
14
  attr_accessor :autodetect_confidence
15
15
  attr_accessor :autodetect_skip_charsets
16
+ attr_accessor :mime_types_for_autodetect
16
17
  attr_accessor :preferred_charsets
17
18
 
18
19
  def enabled?
@@ -31,6 +32,7 @@ module Mail
31
32
  self.enable
32
33
  self.autodetect_confidence = 50
33
34
  self.autodetect_skip_charsets = %w()
35
+ self.mime_types_for_autodetect = [%r{^text/}, 'message/delivery-status', 'message/disposition-notification']
34
36
  self.preferred_charsets = {
35
37
  'iso-2022-jp' => 'cp50221',
36
38
  'iso-2022-jp-1' => 'cp50221',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-jdec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshikazu Kaneta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-12 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.2.22
135
+ rubygems_version: 3.3.3
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: A mail patch for decoding some improper mails