loose_mail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b6e60e13d7f02445cf141fa30114a77170d990a3c701dbec17c1f8eb9a9522f
4
+ data.tar.gz: f13ea8f285f75e410ef765e1ebfa91a0841d8124b881f0b822b2f71156f65640
5
+ SHA512:
6
+ metadata.gz: c85d0547c89a30469c285d8b6ce399727a586f0ce0000c41980033c0669e5b852ba4b73c545dae2eb8204c8e8b089240da218dadb0d794f115c9b17680af42e0
7
+ data.tar.gz: 2c0f41110f35213566ed293e8df7cf6470a6e266f7c39806e2c84411ae685d63be4a1af83a50761d250567280d909974feca1972d0a898b773e71abebbc2ceba
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TOMITA Masahiro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/lib/loose_mail.rb ADDED
@@ -0,0 +1,61 @@
1
+ require_relative 'loose_mail/version'
2
+ require 'mail'
3
+ require 'mail/parser_tools'
4
+
5
+ module LooseMail
6
+ ENCODED_VALUE = /\A=\?([^?]+)\?([QB])\?([^?]*)\?=\z/i
7
+
8
+ def self.decode_words(words)
9
+ results = []
10
+ while (word = words.shift)
11
+ if (m = word.match(ENCODED_VALUE))
12
+ charset = m[1].downcase
13
+ word = decode_data(m[2], m[3])
14
+ while (m = words.first&.match(ENCODED_VALUE)) && m[1].downcase == charset
15
+ word.concat decode_data(m[2], m[3])
16
+ words.shift
17
+ end
18
+ word = Mail::Ruby19.charset_encoder.encode(word, charset).encode(Encoding::UTF_8, undef: :replace, invalid: :replace)
19
+ end
20
+ results.push word
21
+ end
22
+ results.join
23
+ end
24
+
25
+ def self.decode_data(type, data)
26
+ case type
27
+ when 'q', 'Q' then data.gsub(/_/, ' ').unpack1('M')
28
+ when 'b', 'B' then data.unpack1('m')
29
+ end
30
+ end
31
+ end
32
+
33
+ module Mail
34
+ module Encodings
35
+ def self.value_decode(str)
36
+ return str unless str.match? ENCODED_VALUE
37
+ words = collapse_adjacent_encodings(str)
38
+ LooseMail.decode_words(words)
39
+ end
40
+ end
41
+
42
+ module ParserTools
43
+ def chars(data, from_bytes, to_bytes)
44
+ s = data.slice(from_bytes..to_bytes)
45
+ if from_bytes != 0 && data[from_bytes - 1] == '"' && data[to_bytes + 1] == '"' # quoted string
46
+ s.gsub!(/\\(.)/) { $1 }
47
+ end
48
+ s.force_encoding(Encoding::UTF_8)
49
+ end
50
+ end
51
+
52
+ class Ruby19
53
+ class << self
54
+ alias orig_pick_encoding pick_encoding
55
+ def pick_encoding(charset)
56
+ charset = 'cp50221' if charset =~ /\Aiso-2022-jp/i
57
+ orig_pick_encoding(charset)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LooseMail
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/loose_mail/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "loose_mail"
7
+ spec.version = LooseMail::VERSION
8
+ spec.authors = ["TOMITA Masahiro"]
9
+ spec.email = ["tommy@tmtm.org"]
10
+ spec.summary = "loose_mail"
11
+ spec.description = "loose_mail"
12
+ spec.homepage = "https://github.com/tmtm/loose_mail"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/tmtm/loose_mail"
17
+ spec.metadata["changelog_uri"] = "https://github.com/tmtm/loose_mail"
18
+ spec.files = ['LICENSE.txt', 'loose_mail.gemspec', 'lib/loose_mail.rb', 'lib/loose_mail/version.rb']
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.add_dependency "mail", '2.7.1'
23
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loose_mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TOMITA Masahiro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.1
27
+ description: loose_mail
28
+ email:
29
+ - tommy@tmtm.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - lib/loose_mail.rb
36
+ - lib/loose_mail/version.rb
37
+ - loose_mail.gemspec
38
+ homepage: https://github.com/tmtm/loose_mail
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://github.com/tmtm/loose_mail
43
+ source_code_uri: https://github.com/tmtm/loose_mail
44
+ changelog_uri: https://github.com/tmtm/loose_mail
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.7.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.2.15
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: loose_mail
64
+ test_files: []