当前位置: 代码迷 >> J2EE >> :jmail 中java.io.UnsupportedEncodingException: unicode-1-1-utf-7 解决办法
  详细解决方案

:jmail 中java.io.UnsupportedEncodingException: unicode-1-1-utf-7 解决办法

热度:752   发布时间:2016-04-22 01:32:13.0
求救:jmail 中java.io.UnsupportedEncodingException: unicode-1-1-utf-7 解决方法
我在apche james的mailet写了这样几句代码:
  if(part.isMimeType("multipart/report")){
  Multipart multipart = (Multipart)part.getContent(); 
  email_content=multipart.getBodyPart(0).getContent().toString();
  }
在运行的时候出现:java.io.UnsupportedEncodingException: unicode-1-1-utf-7

高手请教我解决的办法,james中设置的编码是utf-8,而过滤邮件的时候有unicode-1-1-utf-7编码的邮件?

------解决方案--------------------
Java code
public String getMessageText(Message message) throws java.io.IOException,javax.mail.MessagingException  {    String body = null;    Object o = message.getContent();    if (o instanceof MimeMultipart)    {      MimeMultipart mm = (MimeMultipart)o;      mm = (MimeMultipart)o;      BodyPart bp = null;        for(int j = 0; j < mm.getCount(); j++)        {          bp = mm.getBodyPart(j);          try          {            o = bp.getContent();          }          catch (IOException e)          {            if (bp.getContentType().equals("text/plain; charset=unicode-1-1-utf-7"))            {              ByteArrayOutputStream bao = new ByteArrayOutputStream();              bp.writeTo(bao);              body = bao.toString();            }            break;          }          if (o instanceof MimeMessage)          {           body = ((MimeMessage)o).getContent().toString();           break;          }          else if (o instanceof String)          {            body = (String)o;            break;          }        }    }    else    {      body = message.getContent().toString();    }    return body;  }
  相关解决方案