参考以下代码:
public String getsubject(String subject) throws Exception {
boolean bgetstr;
String temps;
String _subject;
if (subject.equals(""))
_subject = subject;
else
_subject = "";
if (_subject.indexOf("=?gb2312") != -1
|| _subject.indexOf("=?GBK") != -1
|| _subject.indexOf("=?utf-8") != -1)
bgetstr = false;
else
bgetstr = true;
try {
temps = MimeUtility.decodeText(_subject);
} catch (UnsupportedEncodingException E) {
return _subject;
}
if (temps.length() == 0) {
temps = "(无主题)";
bgetstr = false;
}
if (bgetstr == false)
return temps;
else
return getstr(temps);
}
public static String getstr(String str) {
try {
String temp_p = str;
byte[] temp_t = temp_p.getBytes("ISO8859-1");
String temp = new String(temp_t);
return temp;
} catch (Exception e) {
return "";
}
}