Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java mail can't tell whether a mail has an attachment or not correctly?

960799Sep 7 2012 — edited Sep 12 2012
i send mail through my progress with no attachment name, as a result, the 163 mail server rename the attachment to a bin file with no name property in the contenttype.
when i receive the mail and try to Part.getDisposition(), and i got null as the return. but as i see, the mail surely has an attachment and it's mimetype is application/octet-stream.
i was confused whether i coded wrong or not. and my code are as below:
	public Vector<Mail> receive(String folderName) throws MessagingException, IOException, InterruptedException {
		Vector<Mail> mail_v = new Vector<Mail>();
		
		MailParser mailParser;
		Mail mail;
		
		Session session = Session.getDefaultInstance(server.getMailServer(), user);
		Store store = session.getStore(this.urlName.getMailURLName());
		store.connect();
		Folder folder = store.getFolder(folderName);
		folder.open(Folder.READ_ONLY);
		
		Message message[] = folder.getMessages();
		int message_size = message.length;
		// System.out.println(message[310].getContentType());
		for(int i = 0; i < message_size; i++) {
			if(message.isMimeType("multipart/*")) {
System.out.println(i);
Multipart mu = (Multipart) message[i].getContent();
int mu_size = mu.getCount();
for(int j = 0; j < mu_size; j++) {
BodyPart mu_t = mu.getBodyPart(j);
if(! mu_t.isMimeType("multipart/*")) {
System.out.println("第" + i + "封邮件:" + message[i].getSubject() + " 第" + j + "个BodyPart的内容格式:" + mu_t.getContentType());
String dis = mu_t.getDisposition();
System.out.println(dis);
}
else {
// System.out.println("第" + i + "封邮件:" + message[i].getSubject() + " 第" + j + "个BodyPart的内容格式:" + mu_t.getContentType());
}
}
}
else {
// System.out.println("第" + i + "封邮件:" + message[i].getSubject() + " 的内容格式:" + message[i].getContentType());
}
Thread.sleep(150);
}

folder.close(true);
store.close();

return mail_v;
}
Edited by: EJP on 8/09/2012 15:15: added {noformat}
{noformat} tags. Please use them.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2012
Added on Sep 7 2012
6 comments
2,045 views