mail-jenc 1.0.10 → 1.2.0
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.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/mail/jenc/attachments_list_patch.rb +4 -4
- data/lib/mail/jenc/b_encoder.rb +3 -1
- data/lib/mail/jenc/config.rb +24 -0
- data/lib/mail/jenc/fields/address_field_patch.rb +5 -5
- data/lib/mail/jenc/fields/unstructured_field_patch.rb +3 -3
- data/lib/mail/jenc/message_patch.rb +15 -5
- data/lib/mail/jenc/percent_encoder.rb +2 -0
- data/lib/mail/jenc/rfc2231_encoder.rb +2 -0
- data/lib/mail/jenc/utilities_patch.rb +24 -0
- data/lib/mail/jenc/version.rb +3 -1
- data/lib/mail/jenc.rb +34 -17
- metadata +9 -15
- data/lib/mail/jenc/fields/content_type_field_patch.rb +0 -19
- data/lib/mail/jenc/ruby_1_9_patch.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f4d09dee3b6fcb41a2c89d36fa5d03612996fe805e2c641c2aef579056a37e6
|
4
|
+
data.tar.gz: c6ccc4f85aa7c1ac09cbaee529e1da56fd7404eca00a03a3191e66b53b93a591
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab7f00be8087ab1300bb239112885cdb5b3135fe18fdeab33bf2c86e82baa3130e2756268c0296feb9fff609f64d7c3a721ce96259dbb9fd42dae57f5882cc7
|
7
|
+
data.tar.gz: e3cf8443136b5fe92bfdfaf5ffd5891c03151b65d96edc1a641414609d5e5edfb7b12008e93902e1b87e4830d432df0e372ae5ca54bc9de0233891f87c6f9b15
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@ A mail patch for encoding conventional mail.
|
|
4
4
|
|
5
5
|
## Dependencies
|
6
6
|
|
7
|
-
* ruby 2.
|
8
|
-
* mail 2.
|
7
|
+
* ruby 2.5+
|
8
|
+
* mail 2.8
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -25,10 +25,10 @@ Use mail as usual. You can enable/disable patched features as follows:
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
# disable patch
|
28
|
-
Mail::Jenc.disable
|
28
|
+
Mail::Jenc.disable!
|
29
29
|
|
30
30
|
# enable patch
|
31
|
-
Mail::Jenc.enable
|
31
|
+
Mail::Jenc.enable!
|
32
32
|
```
|
33
33
|
|
34
34
|
## Contributing
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jenc
|
3
5
|
module AttachmentsListPatch
|
4
6
|
def []=(name, value)
|
5
7
|
if Jenc.enabled? && value.is_a?(Hash)
|
6
8
|
charset = value.delete(:header_charset)
|
7
|
-
rfc2231 = value.key?(:rfc2231) ? value.delete(:rfc2231) : Jenc.rfc2231
|
9
|
+
rfc2231 = value.key?(:rfc2231) ? value.delete(:rfc2231) : Jenc.config.rfc2231
|
8
10
|
|
9
11
|
if name && name.encoding == Encoding::UTF_8 && charset
|
10
12
|
mime_type = set_mime_type(name)
|
@@ -27,6 +29,4 @@ module Mail
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
Mail::AttachmentsList.prepend Mail::Jenc::AttachmentsListPatch
|
32
|
-
end
|
32
|
+
Mail::AttachmentsList.prepend Mail::Jenc::AttachmentsListPatch
|
data/lib/mail/jenc/b_encoder.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jenc
|
3
5
|
class BEncoder
|
4
6
|
class << self
|
5
7
|
def encode(str, charset)
|
6
|
-
if Jenc.escape_sequence_charsets.include?(charset.to_s.downcase)
|
8
|
+
if Jenc.config.escape_sequence_charsets.include?(charset.to_s.downcase)
|
7
9
|
split(str).map { |s| transcode_and_encode(s, charset) }.join(' ')
|
8
10
|
else
|
9
11
|
transcode_and_encode(str, charset)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Jenc
|
5
|
+
class Config
|
6
|
+
NAMES = [:enabled, :rfc2231, :escape_sequence_charsets, :preferred_charsets]
|
7
|
+
NAMES.each do |name|
|
8
|
+
attr_accessor name
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(attrs = {})
|
12
|
+
attrs.each do |key, val|
|
13
|
+
send("#{key}=", val)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
NAMES.each_with_object({}) do |name, hash|
|
19
|
+
hash[name] = send(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jenc
|
3
|
-
module
|
5
|
+
module CommonAddressFieldPatch
|
4
6
|
def initialize(value, charset = nil)
|
5
7
|
if Jenc.enabled?
|
6
8
|
if value.is_a?(String) && !value.ascii_only? && value.encoding == Encoding::UTF_8 && charset && charset.downcase != 'utf-8'
|
@@ -19,9 +21,7 @@ module Mail
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::
|
24
|
+
klasses = ObjectSpace.each_object(Class).select { |klass| klass < Mail::CommonAddressField }
|
23
25
|
klasses.each do |klass|
|
24
|
-
|
25
|
-
klass.prepend Mail::Jenc::AddressFieldPatch
|
26
|
-
end
|
26
|
+
klass.prepend Mail::Jenc::CommonAddressFieldPatch
|
27
27
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jenc
|
3
5
|
module UnstructuredFieldPatch
|
@@ -17,6 +19,4 @@ module Mail
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
Mail::UnstructuredField.prepend Mail::Jenc::UnstructuredFieldPatch
|
22
|
-
end
|
22
|
+
Mail::UnstructuredField.prepend Mail::Jenc::UnstructuredFieldPatch
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mail
|
2
4
|
module Jenc
|
3
5
|
module MessagePatch
|
@@ -14,16 +16,24 @@ module Mail
|
|
14
16
|
|
15
17
|
def add_file(values)
|
16
18
|
if Jenc.enabled?
|
17
|
-
if values.is_a?(Hash)
|
18
|
-
values[:
|
19
|
+
if values.is_a?(Hash)
|
20
|
+
values[:charset] ||= nil
|
21
|
+
values[:header_charset] = header.charset if header.charset
|
19
22
|
end
|
20
23
|
end
|
21
24
|
super
|
22
25
|
end
|
26
|
+
|
27
|
+
def convert_to_multipart
|
28
|
+
unless has_content_type?
|
29
|
+
content_type = 'text/plain'
|
30
|
+
content_type += "; charset=#{charset}" if charset
|
31
|
+
self.content_type = content_type
|
32
|
+
end
|
33
|
+
super
|
34
|
+
end
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
26
38
|
|
27
|
-
|
28
|
-
Mail::Message.prepend Mail::Jenc::MessagePatch
|
29
|
-
end
|
39
|
+
Mail::Message.prepend Mail::Jenc::MessagePatch
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mail
|
4
|
+
module Jenc
|
5
|
+
module UtilitiesPatch
|
6
|
+
def transcode_charset(str, from_encoding, to_encoding = Encoding::UTF_8)
|
7
|
+
if Jenc.enabled?
|
8
|
+
coded = super(str, from_encoding, UtilitiesPatch.preferred_charset(to_encoding))
|
9
|
+
coded.force_encoding(to_encoding)
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def preferred_charset(charset)
|
17
|
+
Jenc.config.preferred_charsets[charset.to_s.downcase] || charset
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Mail::Utilities.singleton_class.prepend Mail::Jenc::UtilitiesPatch
|
data/lib/mail/jenc/version.rb
CHANGED
data/lib/mail/jenc.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mail'
|
2
4
|
|
3
5
|
Dir["#{__dir__}/jenc/**/*.rb"].each do |file|
|
@@ -7,30 +9,45 @@ end
|
|
7
9
|
module Mail
|
8
10
|
module Jenc
|
9
11
|
class << self
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
@@config = Config.new(
|
13
|
+
enabled: true,
|
14
|
+
rfc2231: false,
|
15
|
+
escape_sequence_charsets: ['iso-2022-jp'],
|
16
|
+
preferred_charsets: {
|
17
|
+
'iso-2022-jp' => 'cp50221',
|
18
|
+
'shift_jis' => 'cp932'
|
19
|
+
}
|
20
|
+
)
|
21
|
+
|
22
|
+
def configure
|
23
|
+
yield @@config
|
24
|
+
end
|
25
|
+
|
26
|
+
THREAD_KEY = :_mail_jenc
|
27
|
+
|
28
|
+
def config
|
29
|
+
Thread.current[THREAD_KEY] || @@config
|
30
|
+
end
|
31
|
+
|
32
|
+
def with_config(hash = {})
|
33
|
+
old = Thread.current[THREAD_KEY]
|
34
|
+
Thread.current[THREAD_KEY] = Config.new(config.attributes.merge(hash))
|
35
|
+
yield
|
36
|
+
ensure
|
37
|
+
Thread.current[THREAD_KEY] = old
|
38
|
+
end
|
14
39
|
|
15
40
|
def enabled?
|
16
|
-
|
41
|
+
config.enabled
|
17
42
|
end
|
18
43
|
|
19
|
-
def enable
|
20
|
-
|
44
|
+
def enable!
|
45
|
+
config.enabled = true
|
21
46
|
end
|
22
47
|
|
23
|
-
def disable
|
24
|
-
|
48
|
+
def disable!
|
49
|
+
config.enabled = false
|
25
50
|
end
|
26
51
|
end
|
27
|
-
|
28
|
-
self.enable
|
29
|
-
self.rfc2231 = false
|
30
|
-
self.escape_sequence_charsets = ['iso-2022-jp']
|
31
|
-
self.preferred_charsets = {
|
32
|
-
'iso-2022-jp' => 'cp50221',
|
33
|
-
'shift_jis' => 'cp932'
|
34
|
-
}
|
35
52
|
end
|
36
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail-jenc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-18 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: rake
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,19 +78,19 @@ files:
|
|
84
78
|
- lib/mail/jenc.rb
|
85
79
|
- lib/mail/jenc/attachments_list_patch.rb
|
86
80
|
- lib/mail/jenc/b_encoder.rb
|
81
|
+
- lib/mail/jenc/config.rb
|
87
82
|
- lib/mail/jenc/fields/address_field_patch.rb
|
88
|
-
- lib/mail/jenc/fields/content_type_field_patch.rb
|
89
83
|
- lib/mail/jenc/fields/unstructured_field_patch.rb
|
90
84
|
- lib/mail/jenc/message_patch.rb
|
91
85
|
- lib/mail/jenc/percent_encoder.rb
|
92
86
|
- lib/mail/jenc/rfc2231_encoder.rb
|
93
|
-
- lib/mail/jenc/
|
87
|
+
- lib/mail/jenc/utilities_patch.rb
|
94
88
|
- lib/mail/jenc/version.rb
|
95
89
|
homepage: https://github.com/kanety/mail-jenc
|
96
90
|
licenses:
|
97
91
|
- MIT
|
98
92
|
metadata: {}
|
99
|
-
post_install_message:
|
93
|
+
post_install_message:
|
100
94
|
rdoc_options: []
|
101
95
|
require_paths:
|
102
96
|
- lib
|
@@ -112,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
106
|
version: '0'
|
113
107
|
requirements: []
|
114
108
|
rubygems_version: 3.3.3
|
115
|
-
signing_key:
|
109
|
+
signing_key:
|
116
110
|
specification_version: 4
|
117
111
|
summary: A mail patch for encoding conventional mail
|
118
112
|
test_files: []
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Mail
|
2
|
-
module Jenc
|
3
|
-
module ContentTypeFieldPatch
|
4
|
-
def parameters
|
5
|
-
if Jenc.enabled?
|
6
|
-
super.tap do |parameters|
|
7
|
-
parameters.delete('charset') if parameters.key?('boundary') || parameters.key?('name')
|
8
|
-
end
|
9
|
-
else
|
10
|
-
super
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
unless Mail::ContentTypeField.included_modules.include?(Mail::Jenc::ContentTypeFieldPatch)
|
18
|
-
Mail::ContentTypeField.prepend Mail::Jenc::ContentTypeFieldPatch
|
19
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Mail
|
2
|
-
module Jenc
|
3
|
-
module Ruby19Patch
|
4
|
-
def transcode_charset(str, from_encoding, to_encoding = Encoding::UTF_8)
|
5
|
-
if Jenc.enabled?
|
6
|
-
coded = super(str, from_encoding, Ruby19Patch.preferred_charset(to_encoding))
|
7
|
-
coded.force_encoding(to_encoding)
|
8
|
-
else
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def preferred_charset(charset)
|
15
|
-
Jenc.preferred_charsets[charset.to_s.downcase] || charset
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
unless Mail::Ruby19.singleton_class.included_modules.include?(Mail::Jenc::Ruby19Patch)
|
23
|
-
Mail::Ruby19.singleton_class.prepend Mail::Jenc::Ruby19Patch
|
24
|
-
end
|