@Test public void testFixupCharset() throws Exception { String charsetOnMail; String expect; charsetOnMail = "CP932"; expect = "shift_jis"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, new MimeMessage())); MimeMessage message; message = new MimeMessage(); message.setHeader("From", "aaa@docomo.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@dwmail.jp"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@pdx.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@willcom.com"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@emnet.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@emobile.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-docomo-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@softbank.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-softbank-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@vodafone.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-softbank-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@disney.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-softbank-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@vertuclub.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-softbank-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@ezweb.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-kddi-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); message = new MimeMessage(); message.setHeader("From", "aaa@ido.ne.jp"); charsetOnMail = "shift_jis"; expect = "x-kddi-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); }
static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022-jp")) { String variant = JisSupport.getJisVariantFromMessage(message); if (variant != null) charset = "x-" + variant + "-" + charset + "-2007"; } return charset; }
CharsetSupport { static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022-jp")) { String variant = JisSupport.getJisVariantFromMessage(message); if (variant != null) charset = "x-" + variant + "-" + charset + "-2007"; } return charset; } }
CharsetSupport { static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022-jp")) { String variant = JisSupport.getJisVariantFromMessage(message); if (variant != null) charset = "x-" + variant + "-" + charset + "-2007"; } return charset; }  }
CharsetSupport { static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022-jp")) { String variant = JisSupport.getJisVariantFromMessage(message); if (variant != null) charset = "x-" + variant + "-" + charset + "-2007"; } return charset; }  static void setCharset(String charset, Part part); static String getCharsetFromAddress(String address); }
CharsetSupport { static String fixupCharset(String charset, Message message) throws MessagingException { if (charset == null || "0".equals(charset)) charset = "US-ASCII"; charset = charset.toLowerCase(Locale.US); if (charset.equals("cp932")) charset = SHIFT_JIS; if (charset.equals(SHIFT_JIS) || charset.equals("iso-2022-jp")) { String variant = JisSupport.getJisVariantFromMessage(message); if (variant != null) charset = "x-" + variant + "-" + charset + "-2007"; } return charset; }  static void setCharset(String charset, Part part); static String getCharsetFromAddress(String address);  }