Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy Messages Function wont work with Greenmail MimeMessage #495

Open
ajayaviyyapu opened this issue Oct 7, 2022 · 2 comments
Open

Copy Messages Function wont work with Greenmail MimeMessage #495

ajayaviyyapu opened this issue Oct 7, 2022 · 2 comments

Comments

@ajayaviyyapu
Copy link

ajayaviyyapu commented Oct 7, 2022

I am attaching my piece of code at the end (Test.zip). This code fails at copymessages line pasted below with an exception.

folderInbox.getMailFolder().copyMessages(receivedMessages, folderArchive.getMailFolder());

Exception:-

java.lang.ClassCastException: com.icegreen.greenmail.store.StoredMessage$UidAwareMimeMessage cannot be cast to com.sun.mail.imap.IMAPMessage
at com.sun.mail.imap.Utility.toMessageSet(Utility.java:85)
at com.sun.mail.imap.IMAPFolder.copymoveMessages(IMAPFolder.java:2109)
at com.sun.mail.imap.IMAPFolder.copyMessages(IMAPFolder.java:2018)
at de.tnt.innight.ttms.mail.CheckMailBoxServiceTest.read_EP_Results_With_New_Unprocessed_Email_To_Route_Mail_To_Archiv_Test(CheckMailBoxServiceTest.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at com.icegreen.greenmail.junit.GreenMailRule$1.evaluate(GreenMailRule.java:63)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Test.zip

@marcelmay
Copy link
Member

You use client-side IMAP API with GreenMail server-side messages:

L78: final MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); // Direct access to server-side instances 
...
L82: folderInbox.getMailFolder().copyMessages(receivedMessages, folderArchive.getMailFolder()); // folderInbox wrapping JavaMail-fetched folder? 

Fetch the messages via JavaMail, as JavaMail can only work on JavaMail-'managed' instances:

finalMessage[] receivedMessages  =   folderInbox.getMessages(); // Fetch via JavaMail

@ajayaviyyapu
Copy link
Author

Thanks Marcel for responding.

  1. Yes folderInbox is nothing but a wrapper on the javax.mail.Folder.

  2. I tried to do in the way recommended by you by using the following line.

finalMessage[] receivedMessages = folderInbox.getMessages();

Now i dont even receive messages. When i was using the previous line as mentioned below, I was atleast able to receive the messages. Only the copymessages method was failing.

final MimeMessage[] receivedMessages = greenMail.getReceivedMessages();

Is there anything that needs to be changed when i am using Javax Mail Message instead of Green Mail Message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants