001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.fukurou.mail;
017
018import javax.mail.internet.InternetAddress;
019import javax.mail.internet.MimeMessage;
020
021/**
022 * MailCharset は、E-Mail 送信時のエンコードに応じた処理を行う為の、
023 * インターフェースです。
024 *
025 * E-Mail で日本語を送信する場合、ISO-2022-JP(JISコード)化して、7bit で
026 * エンコードして送信する必要がありますが、Windows系の特殊文字や、unicodeと
027 * 文字のマッピングが異なる文字などが、文字化けします。
028 * 対応方法としては、
029 * 『1.Windows-31J + 8bit 送信』
030 * 『2.ISO-2022-JP に独自変換 + 7bit 送信』
031 * の方法があります。
032 * 今回、この2つの方法について、それぞれサブクラス化を行い、処理できるように
033 * したのが、このインターフェース、および、サブクラスです。
034 *
035 * 『1.Windows-31J + 8bit 送信』の方法は、通常の JavaMail API に準拠して
036 * 処理を行う、Mail_Windows31J_Charset サブクラスで実装しています。
037 * 古いメイラーおよび、古いメールサーバーではメール転送できない為、
038 * この方式は、社内で使用する場合のみに、利用できますが、主としてWindows系の
039 * 社内システムにおいては、こちらの方が、なにかとトラブルは少ないと思います。
040 *
041 * 『2.ISO-2022-JP に独自変換 + 7bit 送信』の実装は、
042 * JAVA PRESS Vol.37 (http://www.gihyo.co.jp/magazines/javapress)の
043 * 【特集1】 決定版! サーバサイドJavaの日本語処理
044 *  第3章:JavaMailの日本語処理プログラミング……木下信
045 *“マルチプラットフォーム”な日本語メール送信術 完全解説
046 * でのサンプルアプリケーション
047 * http://www.gihyo.co.jp/book/2004/225371/download/toku1_3.zip
048 * を、使用して、Mail_ISO2022JP_Charset サブクラスで実装しています。
049 *
050 * これらのサブクラスは、MailCharsetFactory ファクトリクラスより、作成されます。
051 * その場合、引数のキャラクタセット名は、Windows-31J 、MS932 か、それ以外となっています。
052 * それ以外が指定された場合は、ISO-2022-JP を使用します。
053 *
054 * @version  4.0
055 * @author   Kazuhiko Hasegawa
056 * @since    JDK5.0,
057 */
058public interface MailCharset {
059
060        /**
061         * テキストをセットします。
062         * Part#setText() の代わりにこちらを使うようにします。
063         *
064         * ※ 内部で、MessagingException が発生した場合は、RuntimeException に変換されて throw されます。
065         *
066         * @param mimeMsg MimeMessage最大取り込み件数
067         * @param text    設定するテキスト
068         */
069        void setTextContent( MimeMessage mimeMsg, String text ) ;
070
071        /**
072         * 日本語を含むヘッダ用テキストを生成します。
073         * 変換結果は ASCII なので、これをそのまま setSubject や InternetAddress
074         * のパラメタとして使用してください。
075         *
076         * ※ 内部で、UnsupportedEncodingException が発生した場合は、RuntimeException に変換されて throw されます。
077         *
078         * @param text    設定するテキスト
079         *
080         * @return      日本語を含むヘッダ用テキスト
081         */
082        String encodeWord( String text ) ;
083
084        /**
085         * 日本語を含むアドレスを生成します。
086         * personal に、日本語が含まれると想定しています。
087         * サブクラスで、日本語処理を行う場合の方法は、それぞれ異なります。
088         *
089         * ※ 内部で、UnsupportedEncodingException が発生した場合は、RuntimeException に変換されて throw されます。
090         *
091         * @param address    アドレス部分
092         * @param personal   日本語の説明部分
093         *
094         * @return      日本語を含むアドレス
095         */
096        InternetAddress getAddress( String address,String personal ) ;
097
098        /**
099         * Content-Transfer-Encoding を指定する場合の ビット数を返します。
100         *
101         * Windows系は、8bit / ISO-2022-JP 系は、7bit になります。
102         *
103         * @return      ビット数
104         */
105        String getBit() ;
106}