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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

About backup mail in eml format

user4074040Jan 21 2023

Hi,
I want to use javamail to backup my email account and save it in eml format. but my programme always throw an error: "error loading POP3 headers" when it has saved several mails. the code may have some problems. What is the reason and how to resolve the problem? The follow code is my programme:
public void loadMailListFromServer() {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "pop3");
props.setProperty("mail.pop3.host", "pop.qq.com");
props.setProperty("mail.pop3.port", "995");
props.setProperty("mail.pop3.ssl.enable", "true");
props.put("mail.debug", "false");
Session session = Session.getDefaultInstance(props, new Authenticator(){
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("166505261@qq.com", "MY_PASSWORD");
}
});

try {  
Store store = session.getStore("pop3");   
store.connect();   
Folder folder   = store.getFolder("INBOX");  
folder.open(Folder.READ\_ONLY);  
int total = folder.getMessageCount();  
for(int i=1; i\<=total; i++) {  
 try {  
 MimeMessage msg = (MimeMessage)folder.getMessage(i);  
 loadMail(session, i, msg);  
 } catch(Exception e) {  
 e.printStackTrace();  
 System.out.println("exception and reset...");  
 if(!store.isConnected()) {  
 store.close();  
 }  
 if(folder.isOpen()) folder.close();  
 store = session.getStore("pop3");  
 store.connect();  
 folder = store.getFolder("INBOX");  
 folder.open(Folder.READ\_ONLY);  
 total = folder.getMessageCount();  
 i--;  
 }  
}  
store.close();  
} catch(Exception e) {  
 e.printStackTrace();  
}  

}
protected void loadMail(Session session, int messageNo, MimeMessage message) throws Exception {

SimpleDateFormat sdtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String subject = message.getSubject();
Date recvDate = message.getSentDate();
String messageId = message.getMessageID();

String uid = UUID.randomUUID().toString();
File dir = new File("D:/mail_backup/");
File file = new File(String.format("D:/mail_backup/%s.eml", uid));
if(!dir.exists()) dir.mkdirs();
if(!file.exists()) dir.createNewFile();
OutputStream ips = new FileOutputStream(file);
message.writeTo(ips);
ips.close();
System.out.println(sdtf.format(recvDate) + " mail subject:"
+ subject + "|messageID="+ messageId);
}

Comments

Answer

I'm afraid this is a known bug - https://bugs.openjdk.java.net/browse/JMC-4946  (this is an Oracle internal bug so you can't see it)

I would suggest that you use JMC from an older JDK 8 version, it's the same version of JMC (5.5)

Sorry for the trouble.

Marked as Answer by Isuru Perera · Sep 27 2020
Isuru Perera

Thanks for confirming!

I am using jdk1.8.0_77 when I want to view the help. Will that issue be resolved in next JDK version?

It should definitely be resolved in the next major JDK version, not sure about the next JDK 8 update.

Isuru Perera

Thanks for the prompt reply!

I'm just happy that the issue is reported and it'll be fixed in a future release. I didn't know where to report for these kinds of JMC related issues, that's why I posted in this form.

Thanks again for providing me the details.

If you're not Oracle internal, I think this forum is the best way to report JMC issues.

Thanks for doing so

Hirt-Oracle

It will be fixed in JDK 9 for sure. We are currently looking into providing an update for JDK8 (a fix in the JDK necessitates an upgrade of our RCP platform for this to be fixed, in effect requiring us to release a 5.5.1 release).

Isuru Perera

Thanks Marcus for the information!

So, in JDK 9, we will get Oracle Java Mission Control 6, right? I heard that it'll be completely different when comparing with current JMC. Is there any public website to download a pre-release of JMC 6?

user8785303

It is nice to see that you acknowledge this as a bug. This related bug report, https://bugs.openjdk.java.net/browse/JDK-8155588, was quickly dismissed as "not an issue".

Something happened in Java 8 Update 91 that affected many projects and applications in a bad way. See this Stack Overflow answer: http://stackoverflow.com/a/38444118.

Do you have any comments on that answer? Where can I find more details about how and when this will be fixed?

They dismissed JDK-8155588 because "this version of tomcat really should not be used together with JDK 8".

Which is why we need to upgrade the RCP platform we use to build JMC, like Hirt says above.

As a JMC developer, I don't have any other comments or insights about the general issue.

Hirt-Oracle

Hi Isuru,

If you want to start playing with JMC 6.0, and your company is either a Java SE Advanced customer or owns one of the WebLogic suites, your company can enter the commercial Early Access program. Just e-mail me and I will help get you started.

Kind regards,

Marcus

Hirt-Oracle

And yep, JMC 6 is quite different to JMC 5.5.

1 - 11

Post Details

Added on Jan 21 2023
1 comment
501 views