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     */
016    package org.opengion.fukurou.mail;
017    
018    // import java.io.InputStream;
019    // import java.io.OutputStream;
020    // import java.io.ByteArrayOutputStream;
021    // import java.io.ByteArrayInputStream;
022    // import java.io.UnsupportedEncodingException;
023    // import java.io.IOException;
024    
025    // import javax.activation.DataHandler;
026    // import javax.activation.DataSource;
027    // import javax.mail.internet.InternetAddress;
028    // import javax.mail.internet.MimeMessage;
029    // import javax.mail.internet.MimeUtility;
030    // import javax.mail.MessagingException;
031    // import com.sun.mail.util.BASE64EncoderStream;
032    
033    // import java.nio.charset.Charset;             // 5.5.2.6 (2012/05/25)
034    
035    /**
036     * unicode ã¨ã€JIS ã¨ã®æ–?­—コードã?関係ã§ã€å¤‰æ›ã—ã¦ã?¾ã™ã?
037     * <pre>
038     * http://www.ingrid.org/java/i18n/encoding/ja-conv.html
039     *
040     * 0x00a2 �0xffe0       ??(1-81, CENT SIGN)
041     * 0x00a3 â‡?0xffe1       ?¡ (1-82, POUND SIGN)
042     * 0x00a5 �0x005c       \ (D/12, YEN SIGN)
043     * 0x00ac â‡?0xffe2       ?¢ (2-44, NOT SIGN)
044     * 0x2016 �0x2225       ∥ (1-34, DOUBLE VERTICAL LINE)
045     * 0x203e �0x007e       ~ (F/14, OVERLINE)
046     * 0x2212 �0xff0d       ??(1-61, MINUS SIGN)
047     * 0x301c �0xff5e       ??(1-33, WAVE DASH)
048     *
049     * ãれãžã‚Œã‚³ãƒ¼ãƒ‰å¤‰æ›ã—ã¾ã™ã?
050     * </pre>
051     *
052     * @version  4.0
053     * @author   Kazuhiko Hasegawa
054     * @since    JDK5.0,
055     */
056    class UnicodeCorrecter {
057    
058            /**
059             * インスタンスã®ç”Ÿæ?を抑止ã—ã¾ã™ã?
060             */
061            private UnicodeCorrecter() {
062                    // 何もã‚りã¾ã›ã‚“ã€?PMD エラー回é¿)
063            }
064    
065            /**
066             * Unicode æ–?­—å?ã®è£œæ­£ã‚’行ã„ã¾ã™ã?
067             * "MS932" コンãƒã?ã‚¿ã§ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰ã—よã†ã¨ã—ãŸéš›ã«
068             * 正常ã«å¤‰æ›ã§ããªã?ƒ¨åˆ?‚’補正ã—ã¾ã™ã?
069             *
070             * @param       str 入力文字å?
071             * @return      Unicode æ–?­—å?ã®è£œæ­£çµæžœ
072             */
073            public static String correctToCP932( final String str ) {
074                    String rtn = "";
075    
076                    if( str != null ) {
077                            int cnt = str.length();
078                            StringBuilder buf = new StringBuilder( cnt );
079                            for(int i=0; i<cnt; i++) {
080                                    buf.append(correctToCP932(str.charAt(i)));
081                            }
082                            rtn = buf.toString() ;
083                    }
084                    return rtn ;
085            }
086    
087            /**
088             * キャラクタå˜ä½ã«ã€Unicode æ–?­—ã?補正を行ã„ã¾ã™ã?
089             *
090             * 風間殿ã®ãƒšã?ジをå‚è€?«ã—ã¦ã?¾ã™ã?
091             * @see <a href="http://www.ingrid.org/java/i18n/encoding/ja-conv.html" target="_blank">
092             * http://www.ingrid.org/java/i18n/encoding/ja-conv.html</a>
093             *
094             * @param       ch 入力文�
095             * @return      Unicode æ–?­—ã?è£œæ­£çµæžœ
096             */
097            public static char correctToCP932( final char ch ) {
098                    char rtn = ch;
099    
100                    switch (ch) {
101            //              case 0x00a2:    return 0xffe0;          // ≪
102            //              case 0x00a3:    return 0xffe1;          // ?£
103            //              case 0x00ac:    return 0xffe2;          // μ
104            //              case 0x03bc:    return 0x00b5;          // ・
105            //              case 0x2014:    return 0x2015;          // ??
106            //              case 0x2016:    return 0x2225;          // ≫
107            //              case 0x2212:    return 0xff0d;          // �
108            //              case 0x226a:    return 0x00ab;          // ∥
109            //              case 0x226b:    return 0x00bb;          // ヴ
110            //              case 0x301c:    return 0xff5e;          // ??
111            //              case 0x30f4:    return 0x3094;          // ??
112            //              case 0x30fb:    return 0x00b7;          // ??
113            //              case 0xff0c:    return 0x00b8;          // ?¡
114            //              case 0xffe3:    return 0x00af;          // ?¢
115    
116                            case 0x00a2:    rtn = 0xffe0; break;            // ??(1-81, CENT SIGN)
117                            case 0x00a3:    rtn = 0xffe1; break;            // ?¡ (1-82, POUND SIGN)
118                            case 0x00a5:    rtn = 0x005c; break;            // \ (D/12, YEN SIGN)
119                            case 0x00ac:    rtn = 0xffe2; break;            // ?¢ (2-44, NOT SIGN)
120                            case 0x2016:    rtn = 0x2225; break;            // ∥ (1-34, DOUBLE VERTICAL LINE)
121                            case 0x203e:    rtn = 0x007e; break;            // ~ (F/14, OVERLINE)
122                            case 0x2212:    rtn = 0xff0d; break;            // ??(1-61, MINUS SIGN)
123                            case 0x301c:    rtn = 0xff5e; break;            // ??(1-33, WAVE DASH)
124    
125            //              case 0x301c:    return 0xff5e;
126            //              case 0x2016:    return 0x2225;
127            //              case 0x2212:    return 0xff0d;
128                            default:                break;                  // 4.0.0 (2005/01/31)
129                    }
130                    return rtn;
131            }
132    }