-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add a test for MessageChangedListener
#481
base: master
Are you sure you want to change the base?
Add a test for MessageChangedListener
#481
Conversation
@boris-petrov , try ...
inboxFolder.addMessageChangedListener(listener);
inboxFolder.getMessages()[0].setFlag(DELETED, true); // Triggers the listener The mail listeners need e.g. an IMAP operation (IDLE, FETCH ....) as trigger. If you access an email via GreenMail server reference, you directly manipulate the mail 'on the server side' and 'raw', circumventing clients: greenMail.getReceivedMessages()[0].setFlag(DELETED, true); This is more of a GreenMail helper, and very limited as all the mail API objects were designed for client side usage. |
4c36d75
to
ffd290e
Compare
@marcelmay thanks for the answer! You're right that doing |
A loop issuing IMAP IDLE in a thread should trigger any listener |
@marcelmay I pushed a new commit that does what you're suggesting. I still can't make it work. Do you mind taking a look? |
// Ignore | ||
} | ||
|
||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented, using the internal (server-side) API won't trigger any listeners. Because you directly manipulate the message in memory, and work around any JavaMail listener mechanism.
Instead, use IMAP / JavaMail:
inboxFolder.getMessages()[0].setFlag(DELETED, true); // Triggers the listener, as this results in an IMAP command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelmay I added another commit that does what you suggest. First I try with the same variable on which I've added the listener - that works as expected. Then I try with a new variable - then it doesn't. That's what I meant before by "external" event. Sorry, I should have removed the "server-side" setting of flags before. But please check the test now.
b832049
to
8ab7b8c
Compare
@boris-petrov , your test succeeds . I would close this PR for now, unless you still have issues? If you have still issues, you you please rebase? Sorry I cleaned up/moved some tests. |
8ab7b8c
to
0ee0af1
Compare
@marcelmay the test still doesn't pass on my side... I rebased on |
@boris-petrov : You're right, the test still fails. Thx for being persistent! |
@marcelmay - this is a test that
MessageChangedListener
is called when flags are changed. It isn't though. I'm not sure if I'm doing something wrong or this is not supported by Greenmail?As for the test itself:
saveChanges
is needed?CountDownLatch
to wait for the event to be triggered. That's fine but it might be better to use theidle
mechanism as in the test before this one. I'm not sure it would work, however, I'm not very familiar with IMAP's protocol.