Android 中利用JAVAMAIL 获取邮件正文出错
求大神给解决,为什么message.getContent 的不到正确的邮件正文,给出的都是java.mail.util.QPDecoderStream@一堆数字代码如下 ,出错的地方用红色标注出了
public class ReceviceMail {
private StringBuffer bodytext = new StringBuffer();
String tomail_text = "";
String subject_text = "";
String body_text = "";
Session session = null;
Store store = null;
Folder folder = null;
public static Message[] message;
int messagelength;
ArrayList<Map<String, Object>> data;
// private Transport transport = null;
private Properties props = null;
public ReceviceMail() {
}// 构造函数
public void receivemaillist() throws Exception {
props = new Properties();
session = Session.getInstance(props, null);
session.setDebug(true);
store = session.getStore("pop3");
store.connect(LoginActivity.get_pop_protocol_text(), -1,
LoginActivity.getusername(), LoginActivity.getpassword());
folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
message = folder.getMessages();
messagelength = message.length;
data = new ArrayList<Map<String, Object>>();
Map<String, Object> item;
for (int i = 0, n = getmessagelength(); i < n; i++) {
item = new HashMap<String, Object>();
try {
item.put("主题", message[i].getSubject());
//item.put("发信人", message[i].getFrom());
item.put("发信人", getmailfrom(i));
//item.put("发信人", message[i].getDisposition().toString());
data.add(item);
//bodytext.append(getmailbody(i));
//System.out.println(getmailbody(i));
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// folder.close(false);
// store.close();
}
public int getmessagelength() {
return messagelength;
}
public ArrayList<Map<String, Object>> getdata() {
return data;
}
public String getmailbody(int i) throws Exception {
// return message[i].getContent().toString();// 正文类型装换有问题
// conte[color=#FF0000]ntText = new String();
getMailContent((Part) message[i]);
return bodytext.toString();
}
public void getMailContent(Part part) throws MessagingException, IOException{
String contentType = part.getContentType();
int nameindex = contentType.indexOf("name");
boolean conname = false;
if(nameindex != -1){
conname = true;
}
System.out.println("CONTENTTYPE:"+contentType);
if(part.isMimeType("text/plain")&&!conname){
bodytext.append(part.getContent());
}else if(part.isMimeType("text/html")&&!conname){
bodytext.append(part.getContent());
}else if(part.isMimeType("multipart/*")){
Multipart multipart = (Multipart) part.getContent();
int count = multipart.getCount();
for(int i=0;i<count;i++){
getMailContent(multipart.getBodyPart(i));
}
}else if(part.isMimeType("message/rfc822")){
getMailContent((Part) part.getContent());
}
}[/color]
public String getmailsubject(int i) throws MessagingException, IOException {
return message[i].getSubject();
}
public String getmailfrom(int i) throws MessagingException, IOException {
// return message[i].getFrom()[0].getType();
InternetAddress[] address = (InternetAddress[]) message[i].getFrom();
String from = address[0].getAddress();
if (from == null) {
from = "";
}
String personal = address[0].getPersonal();
if (personal == null) {
personal = "";
}
String fromaddr = personal + "<" + from + ">";
return fromaddr;
}
}
求大神给解决啊,给小弟的全部分数 --------------------编程问答-------------------- 是编解码的问题吧 --------------------编程问答-------------------- 求详细解释~ 兄弟 --------------------编程问答-------------------- 正文可能包含多媒体文件,要进行解析。而不仅仅是纯文本。 --------------------编程问答-------------------- 这样说吧,在JAVA项目里测试上面的算法,成功的显示邮件内容,但在ANDROID里不能 --------------------编程问答-------------------- java.mail.util.QPDecoderStream@ 表示你getContent获得的是个流对象。
你确定在java项目里收取的邮件是同一封邮件么 --------------------编程问答-------------------- 楼主搞定这个问题了没有啊 我也遇到同样问题搞一周了还没有搞定。求解啊 --------------------编程问答-------------------- 楼主啊,你解决了吗,能告诉我你qq号么,我遇到同样问题 --------------------编程问答-------------------- 楼主问题解决了!我也遇到同样的问题,真心求解。qq:913327171 谢谢~
补充:移动开发 , Android