我已经开发了用于读取消息的代码,如下所示
else if (p.isMimeType("multipart/*")) {
Log.i("snt", "22");
System.out.println("This is a Multipart");
System.out.println("---------------------------");
Multipart mp = (Multipart) p.getContent();
int count = mp.getCount();
//for (int i = 0; i < count; i++)
{
System.out.println("Count is : " + String.valueOf(count));
Multipart multipart = mp;//(Multipart) msg[i].getContent();
for (int x = 0; x < multipart.getCount(); x++) {
BodyPart bodyPart = multipart.getBodyPart(x);
Integer ctr = MainActivity.maxSlno();
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
System.out.println("Mail have some attachment : ");
Log.i("snt", "33");
DataHandler handler = bodyPart.getDataHandler();
File root = Environment.getExternalStorageDirectory();
String path = root.getPath() + "/" + handler.getName();//+ "/PSattachment.psz";
File savedFile = new File(path);
String destFilePath = path;//.getFileName();
FileOutputStream output = new FileOutputStream(destFilePath);
InputStream input = bodyPart.getInputStream();
byte[] buffer = new byte[4096];
int byteRead;
while ((byteRead = input.read(buffer)) != -1) {
output.write(buffer, 0, byteRead);
}
output.close();
MainActivity.addAttachment(String.valueOf(ctr), path);//handler.getName()
System.out.println("file name : " + handler.getName());
} else {
Log.i("snt", "44");
String str;//=bodyPart.toString();//(bodyPart.getContent());
str = bodyPart.getContent().toString();
Log.i("snt", str);
detail_mail.mbody.setText(str);
}
以上代码正在下载附件,但邮件正文未打印。它具有类似于javax.mail.internet.MimeMultipart@f3f0d6c的赋予值,而不是电子邮件正文。请帮助我阅读正文部分Multipart电子邮件。预先感谢您的帮助。
问题可能是您没有处理嵌套的多部分。有关如何处理嵌套多部分的示例,请参见msgshow.java demo program。