ImapClient: Try to save email from subfolder and getting wrong message (Java)

Hi,

I want to save email from subfolder on mail server. Ex: Inbox/test
Screenshot from 2020-01-20 14-38-56.png (48.8 KB)

I follow Aspose document but the mail that be saved is not from test folder. It’s a mail from Inbox instead.
As I print it out, data from ImapMessageInfo seem right. But when I try to fetch message from ImapClient by unique id, the list is all messages from Inbox and I cannot find the way to filter the list.
Could you please advice a way to fix this issue?
Here is my JAVA code:

		ImapClient client = new ImapClient();
		client.setHost(host);
		client.setPort(port);
		client.setUsername(username);
		client.setPassword(password);
		client.setSecurityOptions(SecurityOptions.Auto);

		ImapMessageInfoCollection coll = client.listMessages("Inbox/test", true);

		for (ImapMessageInfo msgInfo : coll) {
			System.out.println("Message Subject: " + msgInfo.getSubject());
			System.out.println("From: " + msgInfo.getSender().getAddress());
			System.out.println("Sent Date: " + msgInfo.getDate());
			System.out.println("Mime Message Id: " + msgInfo.getMessageId());
			MailMessage eml = client.fetchMessage(msgInfo.getUniqueId());
			eml.save(new File(folderTarget, eml.getSubject()) + ".eml", SaveOptions.getDefaultEml());
			eml.save(new File(folderTarget, eml.getSubject()) + ".msg", SaveOptions.getDefaultMsg());
		}

regards,
Rapeepan

I have observed your requirements and suggest you to please visit the following thread link for your kind reference. I also like to share that you need to [traverse the mailbox folder wise](https://docs.aspose.com/display/emailjava/Fetching+Messages+and+Saving+to+Disc#FetchingMessagesandSavingtoDisc-ListMessagesfromaFolder) to avoid get the exact folder message.

@mudassir.fayyaz

Thanks for your advice. Actually my code followed these Aspose’s example as your link. Somehow when I run my code again today the previous problem is gone. I’m not sure why.
But I have a new problem. I cannot fetch messages, some of them return null and I got NullPointerException. Same code, I don’t edit anything.

@rcomniscien,

It’s strange that using same code your previous issue is gone and now you are facing other issue of NullPointerException on fetching message. I request you to please provide a working sample project along with test account credentials reproducing the issue so that we may proceed further with investigation on our end.

@mudassir.fayyaz
Here is the sample project as you requested. The zip file is protected, I’ll send the password to your inbox message.
sample.zip (22.9 KB)

@rcomniscien ,

Can you please confirm if the shared project is reproducing the issue related to NullPointerException on fetching messages?

@mudassir.fayyaz
I confirm. I tested it before provided it to you and here is the result when I run it again today, still got NullPointerException.
Screenshot from 2020-01-23 09-33-04.png (451.4 KB)

@rcomniscien,

Thank you for sharing the clarification. An issue with ID EMAILJAVA-34648 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.