0.08
No commit activity in last 3 years
No release in over 3 years
A set of patches for mikel's mail gem. With this, you can easily send and receive mails with ISO-2022-JP enconding (so-called 'JIS-CODE').
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.0.0, < 7.0
>= 3.12, < 5.0

Runtime

>= 2.2.6, <= 2.7.1
 Project Readme

mail-iso-2022-jp

A patch that provides 'mail' gem with iso-2022-jp conversion capability.

Overview

  • (en)

    mail-iso-2022-jp is a patch for mikel/mail. With this patch, you can easily send mails with ISO-2022-JP enconding (so-called "JIS-CODE").

  • (ja)

    mail-iso-2022-jp は、mikel/mail に対するパッチです。 これを利用すると ISO-2022-JP(いわゆる「JISコード」)でのメール送信が容易になります。

Feature

  • (en)

    • If you set the charset header to ISO-2022-JP, the values of From, Sender, To, Cc, Reply-To, Subject, Resent-From, Resent-Sender, Resent-To and Resent-Cc headers and the text of body will be automatically converted to ISO-2022-JP.

    • The text part of multipart mail is also encoded with iso-2022-jp.

    • When the charset header has other values, this patch has no effect.

  • (ja)

    • chasetヘッダの値が ISO-2022-JP である場合、差出人(From)、Sender、宛先(To)、Cc、Reply-To、件名(Subject)、 Resent-From、Resent-Sender、Resent-To、Resent-Cc の各ヘッダの値および本文(Body)が 自動的に ISO-2022-JP に変換されます。

    • マルチパートメールのテキストパートもiso-2022-jpでエンコードされます。

    • charsetヘッダの値が ISO-2022-JP でない場合、このパッチには何の効果もありません。

Requirements

Ruby

  • 2.2, 2.3, 2.4, 2.5, 2.6

Gems

  • mail 2.2.6 or higher, but lower than or equal to 2.7.1

ActionMailer (Optional)

  • 3.0 or higher (including 6.x)

Getting Start

Install as a gem

Add to your Gemfile:

gem 'mail-iso-2022-jp'

or run this command:

gem install mail-iso-2022-jp

Install as a Rails plugin

$ cd RAILS_ROOT
$ rails plugin install git://github.com/kuroda/mail-iso-2022-jp.git

Usage

mail = Mail.new(:charset => 'ISO-2022-JP') do
  from    '山田太郎 <taro@example.com>'
  to      '佐藤花子 <hanako@example.com>'
  cc      '事務局 <info@example.com>'
  subject '日本語件名'
  body    '日本語本文'
end

mail['from'].encoded
  => "From: =?ISO-2022-JP?B?GyRCOzNFREJATzobKEI=?= <taro@example.com>\r\n"
mail['to'].encoded
  => "To: =?ISO-2022-JP?B?GyRCOjRGIzJWO1IbKEI=?= <hanako@example.com>\r\n"
mail.subject
 => "=?ISO-2022-JP?B?GyRCRnxLXDhsN29MPhsoQg==?="
NKF.nkf('-mw', mail.subject)
 => "日本語件名"
mail.body.encoded
 => "\e$BF|K\\8lK\\J8\e(B"
NKF.nkf('-w', mail.body.encoded)
 => "日本語本文"

Usage with ActionMailer

class UserMailer < ActionMailer::Base
  default  :charset => 'ISO-2022-JP',
    :from => "山田太郎 <bar@example.com>",
    :cc => '事務局 <info@example.com>'

  def notice
    mail(:to => '佐藤花子 <foo@example.com>', :subject => '日本語件名') do |format|
      format.text { render :inline => '日本語本文' }
    end
  end
end

Remarks

  • (en)

    • NEC special characters like and IBM extended characters like , are allowed in the subject, recipient names and mail body.
    • FULLWIDTH TILDE (U+FF5E) and WAVE DASH (U+301C, ) are converted to the fullwidth tilde (0x2141, ).
    • FULLWIDTH HYPHEN MINUS (U+FF0D) and MINUS SIGN (U+2212) are converted to the fullwidth minus (0x215d, ).
    • EM DASH (U+2014) and HORIZONTAL BAR (U+2015) are converted to the dash sign (0x213d, ).
    • DOUBLE VERTICAL LINE (U+2016, ) and PARALLEL TO (U+2225, ) to the double vertical line (0x2142, ).
    • Halfwidth (Hankaku) katakanas are maintained intact.
    • Characters that cannot be translated into iso-2022-jp encoding are substituted with question marks (?).
    • A pull request mikel/mail#534 has been sent to the mikel/mail repository but not yet accepted.
  • (ja)

    • などのNEC特殊文字や といったIBM拡張文字を件名、宛先、本文などに含めることができます。
    • 全角チルダ(U+FF5E, )と波ダッシュ(U+301C, )は、全角チルダ(0x2141, )に変換されます。
    • 全角ハイフンマイナス(U+ff0D)とマイナス記号(U+2212)は、全角マイナス(0x215d, )に変換されます。
    • 長い(em)ダッシュ(U+2014, )と水平線(U+2015, )は、ダッシュ(0x213d, )に変換されます。
    • 二重縦線(U+2016, )と平行記号(U+2225, )は、二重縦線(0x2142, )に変換されます。
    • 半角カタカナはそのまま維持されます。
    • 変換できない文字は疑問符(?)で置換されます。
    • mikel/mail リポジトリにプルリクエスト mikel/mail#534 が送られていますが、まだアクセプトされていません。

References

License

(en) mail-iso-2022-jp is distributed under the MIT license. (MIT-LICENSE)

(ja) mail-iso-2022-jp はMITライセンスで配布されています。 (MIT-LICENSE)

Special thanks

Kohei Matsushita -- Initial creator of this patch.