1、POP3收邮件当然不能
String subject = m.getSubject();
m.setContent(subject, "text/html; charset=gb2312");//用于发邮件2 、
subject = new String(subject.getBytes("iso-8859-1"),"GB2312");3、 public static String getstr(String string){
String returnValue="";
try{
if (string!=null){
returnValue=new String(string.getBytes("iso-8859-1"),"GB2312");
}
}catch(Exception e){}
return null;
}
String subject = m.getSubject();
m.setContent(subject, "text/html; charset=gb2312");//用于发邮件2 、
subject = new String(subject.getBytes("iso-8859-1"),"GB2312");3、 public static String getstr(String string){
String returnValue="";
try{
if (string!=null){
returnValue=new String(string.getBytes("iso-8859-1"),"GB2312");
}
}catch(Exception e){}
return null;
}
你是用哪种方法的呢?好象还是有问题
String subject = m.getSubject();
会自动解码的,需要转化吗?
你看看自己服务器的默认字符集是什么?
----------------------------------------------------------------
public String getAttFileName(String str){
boolean bgetstr = true;
String temps = null;
String _subject = str;
if(_subject == null)
return("无");
boolean tf = true; if (_subject.indexOf("=?gb2312") != -1 ¦¦ _subject.indexOf("=?GBK") != -1 ¦¦ _subject.indexOf("=?utf-8") != -1)
bgetstr = false;
else
bgetstr = true;
try{
if(temps != null){
temps = temps + MimeUtility.decodeText(_subject);
tf = false;
}else{
temps = MimeUtility.decodeText(_subject);
tf = false;
}
}
catch(UnsupportedEncodingException E){
return _subject;
}
if (temps != null && temps.length() == 0){
temps = "无";
bgetstr = false;
}
if (bgetstr == false)
return temps;
else
return getFileNameStr(temps);
}
public String getFileNameStr(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 "";
}
}
我用的是IIS+Resin2.0.0
if (_subject.indexOf("=?gb2312") != -1 ¦¦ _subject.indexOf("=?GBK") != -1 ¦¦ _subject.indexOf("=?utf-8") != -1)
报错!!!expecting ),位置是¦¦ 里的;,这是什么意思呢?
====================================================================
import com.sun.mail.util.*; public static String decodeWord(String s)
{
if(!s.startsWith("=?"))
return s;
int i = 2;
int j;
if((j = s.indexOf(63, i)) == -1)
return s;
String s1 = (s.substring(i, j));
i = j + 1;
if((j = s.indexOf(63, i)) == -1)
return s;
String s2 = s.substring(i, j);
i = j + 1;
if((j = s.indexOf("?=", i)) == -1)
return s;
String s3 = s.substring(i, j);
try
{
ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(s3.getBytes());
Object obj;
if(s2.equalsIgnoreCase("B"))
obj = new BASE64DecoderStream(bytearrayinputstream);
else
if(s2.equalsIgnoreCase("Q"))
obj = new QDecoderStream(bytearrayinputstream);
else
return s;
int k = bytearrayinputstream.available();
byte abyte0[] = new byte[k];
k = ((InputStream) (obj)).read(abyte0, 0, k);
return new String(abyte0, 0, k );
}
catch(Exception ex)
{
return s;
}
}