mail-jdec 1.1.0 → 1.1.2

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: 4b79e3c592167bea0b81f1f92959a728b253f27b9a4ac84cbfca9c24af70bf44
4
+ data.tar.gz: 5c2205ef8533ade4e48367f0b72cea2a7c39b41e470aa6925bda3122cf8da0b6
5
5
  SHA512:
6
- metadata.gz: 7daf270c25730a7e2bc0876889f2900e2ad86b06cc21310dba5434e2d525ef82128d27c5abbf5b83fd3a2609f94d27ee8c06d6d236b2172fd19361f4221bbed6
7
- data.tar.gz: befc1dfd40761b72c6a7a06993f667fa2396b65cf5a28b0043f2b92b270d8269770628ae37576fa97b93ab6166228a84bbc7f842b30966c7c082c58085ed3861
6
+ metadata.gz: a900a989980cd0d098dd5376ddd0c58f02e51b8b781194978d34e6b5febaf4b144ce0c0a2dea4269dad77d27c870780ad901e4e4d9c205d70e806dd525716571
7
+ data.tar.gz: 200f37329d5a89d19a8690f13f07dac5eb96d32aba0ee5a4e4f893c75c5ff7dcdfdb3a0b58fcf4cea2077ae83c1dcc4d991861592a3ff10fb580499f8b3e6da9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.2
4
+
5
+ * Remove tab characters in references header.
6
+
7
+ ## 1.1.1
8
+
9
+ * Support charset detection including message parts.
10
+
3
11
  ## 1.1.0
4
12
 
5
13
  * Change supported mail version to 2.8.
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mail
4
+ module Jdec
5
+ module MessageIdsElementPatch
6
+ private
7
+
8
+ def parse(string)
9
+ if Jdec.enabled? && string.is_a?(String)
10
+ string = string.gsub(/\t/, ' ')
11
+ end
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ unless Mail::MessageIdsElement.included_modules.include?(Mail::Jdec::MessageIdsElementPatch)
19
+ Mail::MessageIdsElement.prepend Mail::Jdec::MessageIdsElementPatch
20
+ end
@@ -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.2'
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.2
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-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -104,6 +104,7 @@ files:
104
104
  - lib/mail/jdec/detector.rb
105
105
  - lib/mail/jdec/elements/content_disposition_element_patch.rb
106
106
  - lib/mail/jdec/elements/content_type_element_patch.rb
107
+ - lib/mail/jdec/elements/message_ids_element_patch.rb
107
108
  - lib/mail/jdec/encodings_patch.rb
108
109
  - lib/mail/jdec/fields/common_address_field_patch.rb
109
110
  - lib/mail/jdec/fields/common_date_field_patch.rb
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  requirements: []
135
- rubygems_version: 3.2.22
136
+ rubygems_version: 3.3.3
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: A mail patch for decoding some improper mails