mail-iso-2022-jp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/README.md +109 -0
- data/Rakefile +23 -0
- data/lib/mail-iso-2022-jp.rb +1 -0
- data/lib/mail-iso-2022-jp/patches.rb +49 -0
- metadata +85 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
A patch that provides 'mail' gem with iso-2022-jp conversion capability.
|
2
|
+
========================================================================
|
3
|
+
|
4
|
+
Overview
|
5
|
+
--------
|
6
|
+
|
7
|
+
* (en)
|
8
|
+
|
9
|
+
`mail-iso-2022-jp` is a patch for [mikel/mail](https://github.com/mikel/mail).
|
10
|
+
With this patch, you can easily send mails with `ISO-2022-JP` enconding (so-called "JIS-CODE").
|
11
|
+
|
12
|
+
* (ja)
|
13
|
+
|
14
|
+
`mail-iso-2022-jp` は、[mikel/mail](https://github.com/mikel/mail) に対するパッチです。
|
15
|
+
これを利用すると `ISO-2022-JP`(いわゆる「JISコード」)でのメール送信が容易になります。
|
16
|
+
|
17
|
+
|
18
|
+
Feature
|
19
|
+
-------
|
20
|
+
|
21
|
+
* (en)
|
22
|
+
|
23
|
+
If you set the `charset` header to `ISO-2022-JP`, the values of `From`, `To`, and `Subject` headers
|
24
|
+
and the text of body will be automatically converted to `ISO-2022-JP` by `NKF` module.
|
25
|
+
|
26
|
+
When the `charset` header has other values, this patch has no effect.
|
27
|
+
|
28
|
+
* (ja)
|
29
|
+
|
30
|
+
chasetヘッダの値が `ISO-2022-JP` である場合、送信者(From)、宛先(To)、件名(Subject)の各ヘッダの値および
|
31
|
+
本文(Body)が`NKF`モジュールによって自動的に `ISO-2022-JP` に変換されます。
|
32
|
+
|
33
|
+
charsetヘッダの値が `ISO-2022-JP` でない場合、このパッチは何の効果もありません。
|
34
|
+
|
35
|
+
|
36
|
+
Environments
|
37
|
+
------------
|
38
|
+
|
39
|
+
### Requirements ###
|
40
|
+
|
41
|
+
* `ruby` 1.8.7 or higher
|
42
|
+
* `mail` 2.2.5 or higher
|
43
|
+
|
44
|
+
|
45
|
+
Getting Start
|
46
|
+
-------------
|
47
|
+
|
48
|
+
### Install as a gem ###
|
49
|
+
|
50
|
+
Add to your Gemfile:
|
51
|
+
|
52
|
+
gem 'mail-iso-2022-jp'
|
53
|
+
|
54
|
+
or run this command:
|
55
|
+
|
56
|
+
gem install mail-iso-2022-jp
|
57
|
+
|
58
|
+
### Install as a Rails plugin ###
|
59
|
+
|
60
|
+
$ cd RAILS_ROOT
|
61
|
+
$ rails plugin install http://github.com/kuroda/mail-iso-2022-jp.git
|
62
|
+
|
63
|
+
### Example ###
|
64
|
+
|
65
|
+
mail = Mail.new(:charset => 'ISO-2022-JP') do
|
66
|
+
from '山田太郎 <taro@example.com>'
|
67
|
+
to '佐藤花子 <hanako@example.com>'
|
68
|
+
subject '日本語件名'
|
69
|
+
body '日本語本文'
|
70
|
+
end
|
71
|
+
|
72
|
+
mail['from'].encoded
|
73
|
+
=> "From: =?ISO-2022-JP?B?GyRCOzNFREJATzobKEI=?= <taro@example.com>\r\n"
|
74
|
+
mail['to'].encoded
|
75
|
+
=> "To: =?ISO-2022-JP?B?GyRCOjRGIzJWO1IbKEI=?= <hanako@example.com>\r\n"
|
76
|
+
mail.subject
|
77
|
+
=> "=?ISO-2022-JP?B?GyRCRnxLXDhsN29MPhsoQg==?="
|
78
|
+
NKF.nkf('-mw', mail.subject)
|
79
|
+
=> "日本語件名"
|
80
|
+
mail.body.encoded
|
81
|
+
=> "\e$BF|K\\8lK\\J8\e(B"
|
82
|
+
NKF.nkf('-w', mail.body.encoded)
|
83
|
+
=> "日本語本文"
|
84
|
+
|
85
|
+
### Example for ActionMailer ###
|
86
|
+
|
87
|
+
class UserMailer < ActionMailer::Base
|
88
|
+
default :from => "山田太郎 <bar@example.com>", :charset => 'ISO-2022-JP'
|
89
|
+
def notice
|
90
|
+
mail(:to => '佐藤花子 <foo@example.com>', :subject => '日本語件名') do |format|
|
91
|
+
format.text { render :inline => '日本語本文' }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
License
|
99
|
+
-------
|
100
|
+
|
101
|
+
(en) "mail-iso-2022-jp" released under the MIT license (MIT-LICENSE.txt)
|
102
|
+
|
103
|
+
(ja) "mail-iso-2022-jp" は MITライセンスで配布しています。 (MIT-LICENSE.txt)
|
104
|
+
|
105
|
+
|
106
|
+
Special thanks
|
107
|
+
--------------
|
108
|
+
|
109
|
+
[Kohei Matsushita](https://github.com/ma2shita) -- Initial creator of this patch.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the mail_ja plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the mail_ja plugin.'
|
17
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'MailJa'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mail-iso-2022-jp/patches'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Mail
|
2
|
+
class Message
|
3
|
+
def process_body_raw_with_iso_2022_jp_encoding
|
4
|
+
if @charset.to_s.downcase == 'iso-2022-jp'
|
5
|
+
@body_raw = NKF.nkf('-j', @body_raw)
|
6
|
+
end
|
7
|
+
process_body_raw_without_iso_2022_jp_encoding
|
8
|
+
end
|
9
|
+
alias_method :process_body_raw_without_iso_2022_jp_encoding, :process_body_raw
|
10
|
+
alias_method :process_body_raw, :process_body_raw_with_iso_2022_jp_encoding
|
11
|
+
end
|
12
|
+
|
13
|
+
module FieldWithIso2022JpEncoding
|
14
|
+
def self.included(base)
|
15
|
+
base.send :alias_method, :initialize_without_iso_2022_jp_encoding, :initialize
|
16
|
+
base.send :alias_method, :initialize, :initialize_with_iso_2022_jp_encoding
|
17
|
+
base.send :alias_method, :do_decode_without_iso_2022_jp_encoding, :do_decode
|
18
|
+
base.send :alias_method, :do_decode, :do_decode_with_iso_2022_jp_encoding
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_with_iso_2022_jp_encoding(value = nil, charset = 'utf-8')
|
22
|
+
if charset.to_s.downcase == 'iso-2022-jp'
|
23
|
+
value = NKF.nkf('--cp932 -M', NKF.nkf('--cp932 -j', value)).gsub("\n", '').strip
|
24
|
+
end
|
25
|
+
initialize_without_iso_2022_jp_encoding(value, charset)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def do_decode_with_iso_2022_jp_encoding
|
30
|
+
if charset.to_s.downcase == 'iso-2022-jp'
|
31
|
+
value
|
32
|
+
else
|
33
|
+
do_decode_without_iso_2022_jp_encoding
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class SubjectField < UnstructuredField
|
39
|
+
include FieldWithIso2022JpEncoding
|
40
|
+
end
|
41
|
+
|
42
|
+
class FromField < StructuredField
|
43
|
+
include FieldWithIso2022JpEncoding
|
44
|
+
end
|
45
|
+
|
46
|
+
class ToField < StructuredField
|
47
|
+
include FieldWithIso2022JpEncoding
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mail-iso-2022-jp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kohei MATSUHITA
|
14
|
+
- Tsutomu KURODA
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-11-19 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mail
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 5
|
34
|
+
version: 2.2.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: A patch that provides 'mail' gem with iso-2022-jp conversion capability.
|
38
|
+
email: hermes@oiax.jp
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README.md
|
47
|
+
- Gemfile
|
48
|
+
- Rakefile
|
49
|
+
- lib/mail-iso-2022-jp.rb
|
50
|
+
- lib/mail-iso-2022-jp/patches.rb
|
51
|
+
homepage: http://github.com/kuroda/mail_ja
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.10
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: A patch that provides 'mail' gem with iso-2022-jp conversion capability.
|
84
|
+
test_files: []
|
85
|
+
|