mail-jdec 1.0.10 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.gitignore +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/gemfiles/{mail27.gemfile → mail28.gemfile} +1 -2
- data/lib/mail/jdec/body_patch.rb +2 -0
- data/lib/mail/jdec/decoder.rb +4 -2
- data/lib/mail/jdec/detector.rb +2 -0
- data/lib/mail/jdec/elements/content_disposition_element_patch.rb +2 -0
- data/lib/mail/jdec/elements/content_type_element_patch.rb +2 -0
- data/lib/mail/jdec/encodings_patch.rb +2 -0
- data/lib/mail/jdec/fields/common_address_field_patch.rb +33 -0
- data/lib/mail/jdec/fields/common_date_field_patch.rb +46 -0
- data/lib/mail/jdec/fields/parameter_hash_patch.rb +12 -10
- data/lib/mail/jdec/fields/structured_field_patch.rb +2 -0
- data/lib/mail/jdec/fields/unstructured_field_patch.rb +2 -0
- data/lib/mail/jdec/message_patch.rb +2 -0
- data/lib/mail/jdec/{ruby_1_9_patch.rb → utilities_patch.rb} +5 -3
- data/lib/mail/jdec/version.rb +3 -1
- data/lib/mail/jdec.rb +2 -0
- data/mail-jdec.gemspec +1 -1
- metadata +9 -16
- data/lib/mail/jdec/fields/address_field_patch.rb +0 -27
- data/lib/mail/jdec/fields/date_field_patch.rb +0 -54
- data/lib/mail/jdec/fields/references_field_patch.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ab2c096a186f73beaaa84de6c3e857359d65f50e5bc7ed333450624e6d77f7
|
4
|
+
data.tar.gz: c8b624b4155eb04d18864d8fe9bd586dd6e58492e1126aaed056d24615dc04c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7daf270c25730a7e2bc0876889f2900e2ad86b06cc21310dba5434e2d525ef82128d27c5abbf5b83fd3a2609f94d27ee8c06d6d236b2172fd19361f4221bbed6
|
7
|
+
data.tar.gz: befc1dfd40761b72c6a7a06993f667fa2396b65cf5a28b0043f2b92b270d8269770628ae37576fa97b93ab6166228a84bbc7f842b30966c7c082c58085ed3861
|
data/.github/workflows/ci.yml
CHANGED
@@ -8,8 +8,8 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
ruby: [2.
|
12
|
-
gemfile: ['
|
11
|
+
ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2]
|
12
|
+
gemfile: ['mail28']
|
13
13
|
|
14
14
|
name: ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}
|
15
15
|
|
@@ -17,7 +17,7 @@ jobs:
|
|
17
17
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
18
18
|
|
19
19
|
steps:
|
20
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v3
|
21
21
|
- uses: ruby/setup-ruby@v1
|
22
22
|
with:
|
23
23
|
ruby-version: ${{ matrix.ruby }}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/mail/jdec/body_patch.rb
CHANGED
data/lib/mail/jdec/decoder.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jdec
|
3
5
|
class Decoder
|
4
6
|
class << self
|
5
7
|
def decode_if_needed(text)
|
6
|
-
return text if text.nil? || text.encoding == Encoding::UTF_8
|
8
|
+
return text if text.nil? || !text.respond_to?(:encoding) || text.encoding == Encoding::UTF_8
|
7
9
|
|
8
10
|
detected = Detector.detect(text)
|
9
11
|
|
@@ -57,7 +59,7 @@ module Mail
|
|
57
59
|
if content =~ ENCODED_VALUE
|
58
60
|
bytes = content.scan(/\=\?([^?]+)\?([QB])\?([^?]*?)\?\=/mi).map do |_, encoding, encoded|
|
59
61
|
case encoding
|
60
|
-
when *B_VALUES then Mail::
|
62
|
+
when *B_VALUES then Mail::Utilities.decode_base64(encoded)
|
61
63
|
when *Q_VALUES then Mail::Encodings::QuotedPrintable.decode(encoded.gsub(/_/, '=20').sub(/\=$/, ''))
|
62
64
|
end
|
63
65
|
end.join('')
|
data/lib/mail/jdec/detector.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Jdec
|
5
|
+
module CommonAddressFieldPatch
|
6
|
+
def element
|
7
|
+
super
|
8
|
+
rescue Mail::Field::ParseError => e
|
9
|
+
if Jdec.enabled?
|
10
|
+
@errors = [name, value, e]
|
11
|
+
@element = AddressList.new('')
|
12
|
+
else
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def errors
|
18
|
+
@errors
|
19
|
+
end
|
20
|
+
|
21
|
+
def address_list
|
22
|
+
element
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::CommonAddressField }
|
29
|
+
klasses.each do |klass|
|
30
|
+
unless klass.included_modules.include?(Mail::Jdec::CommonAddressFieldPatch)
|
31
|
+
klass.prepend Mail::Jdec::CommonAddressFieldPatch
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Jdec
|
5
|
+
module CommonDateFieldPatch
|
6
|
+
def element
|
7
|
+
super
|
8
|
+
rescue Mail::Field::ParseError => e
|
9
|
+
if Jdec.enabled?
|
10
|
+
@errors = [name, value, e]
|
11
|
+
@element = nil
|
12
|
+
else
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def date_time
|
18
|
+
if Jdec.enabled?
|
19
|
+
if element
|
20
|
+
begin
|
21
|
+
::DateTime.parse("#{element.date_string} #{element.time_string}")
|
22
|
+
rescue ArgumentError => e
|
23
|
+
require 'time'
|
24
|
+
begin
|
25
|
+
Time.parse(value).to_datetime
|
26
|
+
rescue ArgumentError => e
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::CommonDateField }
|
42
|
+
klasses.each do |klass|
|
43
|
+
unless klass.included_modules.include?(Mail::Jdec::CommonDateFieldPatch)
|
44
|
+
klass.prepend Mail::Jdec::CommonDateFieldPatch
|
45
|
+
end
|
46
|
+
end
|
@@ -1,31 +1,33 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
3
|
+
require 'mail/constants'
|
4
|
+
require 'mail/indifferent_hash'
|
5
|
+
require 'mail/encodings'
|
4
6
|
|
7
|
+
module Mail
|
5
8
|
# ParameterHash is an intelligent Hash that allows you to add
|
6
9
|
# parameter values including the MIME extension paramaters that
|
7
10
|
# have the name*0="blah", name*1="bleh" keys, and will just return
|
8
11
|
# a single key called name="blahbleh" and do any required un-encoding
|
9
12
|
# to make that happen
|
10
|
-
#
|
11
|
-
|
12
|
-
class ParameterHash < IndifferentHash
|
13
|
-
|
14
|
-
include Mail::Utilities
|
15
|
-
|
13
|
+
#
|
14
|
+
# Parameters are defined in RFC2045. Split keys are in RFC2231.
|
15
|
+
class ParameterHash < IndifferentHash #:nodoc:
|
16
16
|
def [](key_name)
|
17
17
|
key_pattern = Regexp.escape(key_name.to_s)
|
18
18
|
pairs = []
|
19
19
|
exact = nil
|
20
|
+
|
20
21
|
each do |k,v|
|
21
22
|
if k =~ /^#{key_pattern}(\*|$)/i
|
22
|
-
if $1 == ASTERISK
|
23
|
+
if $1 == Constants::ASTERISK
|
23
24
|
pairs << [k, v]
|
24
25
|
else
|
25
26
|
exact = k
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
29
31
|
if pairs.empty? # Just dealing with a single value pair
|
30
32
|
super(exact || key_name)
|
31
33
|
else # Dealing with a multiple value pair or a single encoded value pair
|
@@ -46,13 +48,13 @@ module Mail
|
|
46
48
|
value = Mail::Encodings.param_encode(value)
|
47
49
|
key_name = "#{key_name}*"
|
48
50
|
end
|
49
|
-
%Q{#{key_name}=#{quote_token(value)}}
|
51
|
+
%Q{#{key_name}=#{Utilities.quote_token(value)}}
|
50
52
|
end.join(";\r\n\s")
|
51
53
|
end
|
52
54
|
|
53
55
|
def decoded
|
54
56
|
map.sort_by { |a| a.first.to_s =~ /^([^*]+)\*(\d+)/ ? [$1, $2.to_i] : [a.first.to_s, 0] }.map! do |key_name, value|
|
55
|
-
%Q{#{key_name}=#{quote_token(value)}}
|
57
|
+
%Q{#{key_name}=#{Utilities.quote_token(value)}}
|
56
58
|
end.join("; ")
|
57
59
|
end
|
58
60
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jdec
|
3
|
-
module
|
5
|
+
module UtilitiesPatch
|
4
6
|
def pick_encoding(charset)
|
5
7
|
if Jdec.enabled?
|
6
8
|
Jdec.preferred_charsets.each do |from, to|
|
@@ -33,6 +35,6 @@ module Mail
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
unless Mail::
|
37
|
-
Mail::
|
38
|
+
unless Mail::Utilities.singleton_class.included_modules.include?(Mail::Jdec::UtilitiesPatch)
|
39
|
+
Mail::Utilities.singleton_class.prepend Mail::Jdec::UtilitiesPatch
|
38
40
|
end
|
data/lib/mail/jdec/version.rb
CHANGED
data/lib/mail/jdec.rb
CHANGED
data/mail-jdec.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "mail", ">= 2.
|
20
|
+
spec.add_dependency "mail", ">= 2.8.1"
|
21
21
|
spec.add_dependency "charlock_holmes", ">= 0.7.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "rake"
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.8.0
|
19
|
+
version: 2.8.1
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 2.8.0
|
26
|
+
version: 2.8.1
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: charlock_holmes
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,7 +97,7 @@ files:
|
|
103
97
|
- Rakefile
|
104
98
|
- bin/console
|
105
99
|
- bin/setup
|
106
|
-
- gemfiles/
|
100
|
+
- gemfiles/mail28.gemfile
|
107
101
|
- lib/mail/jdec.rb
|
108
102
|
- lib/mail/jdec/body_patch.rb
|
109
103
|
- lib/mail/jdec/decoder.rb
|
@@ -111,14 +105,13 @@ files:
|
|
111
105
|
- lib/mail/jdec/elements/content_disposition_element_patch.rb
|
112
106
|
- lib/mail/jdec/elements/content_type_element_patch.rb
|
113
107
|
- lib/mail/jdec/encodings_patch.rb
|
114
|
-
- lib/mail/jdec/fields/
|
115
|
-
- lib/mail/jdec/fields/
|
108
|
+
- lib/mail/jdec/fields/common_address_field_patch.rb
|
109
|
+
- lib/mail/jdec/fields/common_date_field_patch.rb
|
116
110
|
- lib/mail/jdec/fields/parameter_hash_patch.rb
|
117
|
-
- lib/mail/jdec/fields/references_field_patch.rb
|
118
111
|
- lib/mail/jdec/fields/structured_field_patch.rb
|
119
112
|
- lib/mail/jdec/fields/unstructured_field_patch.rb
|
120
113
|
- lib/mail/jdec/message_patch.rb
|
121
|
-
- lib/mail/jdec/
|
114
|
+
- lib/mail/jdec/utilities_patch.rb
|
122
115
|
- lib/mail/jdec/version.rb
|
123
116
|
- mail-jdec.gemspec
|
124
117
|
homepage: https://github.com/kanety/mail-jdec
|
@@ -139,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
132
|
- !ruby/object:Gem::Version
|
140
133
|
version: '0'
|
141
134
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
135
|
+
rubygems_version: 3.2.22
|
143
136
|
signing_key:
|
144
137
|
specification_version: 4
|
145
138
|
summary: A mail patch for decoding some improper mails
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Mail
|
2
|
-
module Jdec
|
3
|
-
module AddressFieldPatch
|
4
|
-
def parse(val = value)
|
5
|
-
super
|
6
|
-
rescue Mail::Field::ParseError => e
|
7
|
-
if Jdec.enabled?
|
8
|
-
@errors = [name, val, e]
|
9
|
-
@address_list = AddressList.new('')
|
10
|
-
else
|
11
|
-
raise e
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def errors
|
16
|
-
@errors
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::CommonAddress }
|
23
|
-
klasses.each do |klass|
|
24
|
-
unless klass.included_modules.include?(Mail::Jdec::AddressFieldPatch)
|
25
|
-
klass.prepend Mail::Jdec::AddressFieldPatch
|
26
|
-
end
|
27
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Mail
|
2
|
-
module Jdec
|
3
|
-
module DateFieldPatch
|
4
|
-
def date_time
|
5
|
-
super
|
6
|
-
rescue ArgumentError, Mail::Field::ParseError => e
|
7
|
-
if Jdec.enabled?
|
8
|
-
begin
|
9
|
-
require 'time'
|
10
|
-
Time.parse(value).to_datetime
|
11
|
-
rescue ArgumentError => e
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
else
|
15
|
-
raise e
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module Mail
|
23
|
-
class DateField < StructuredField
|
24
|
-
def initialize(value = nil, charset = nil)
|
25
|
-
super(CAPITALIZED_FIELD, self.class.normalize_datetime(value), charset)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.normalize_datetime(string)
|
29
|
-
if Utilities.blank?(string)
|
30
|
-
datetime = ::DateTime.now
|
31
|
-
else
|
32
|
-
stripped = string.to_s.gsub(/\(.*?\)/, '').squeeze(' ')
|
33
|
-
begin
|
34
|
-
datetime = ::DateTime.parse(stripped)
|
35
|
-
rescue ArgumentError => e
|
36
|
-
raise unless 'invalid date' == e.message
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
if datetime
|
41
|
-
datetime.strftime('%a, %d %b %Y %H:%M:%S %z')
|
42
|
-
else
|
43
|
-
string
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::CommonDate }
|
50
|
-
klasses.each do |klass|
|
51
|
-
unless klass.included_modules.include?(Mail::Jdec::DateFieldPatch)
|
52
|
-
klass.prepend Mail::Jdec::DateFieldPatch
|
53
|
-
end
|
54
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Mail
|
2
|
-
module Jdec
|
3
|
-
module ReferencesFieldPatch
|
4
|
-
def initialize(value = nil, charset = 'utf-8')
|
5
|
-
if Jdec.enabled?
|
6
|
-
if value.is_a?(String)
|
7
|
-
value = value.gsub(/>\s*,\s*</, ">\r\n <")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
super
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
unless Mail::ReferencesField.included_modules.include?(Mail::Jdec::ReferencesFieldPatch)
|
17
|
-
Mail::ReferencesField.prepend Mail::Jdec::ReferencesFieldPatch
|
18
|
-
end
|