Hi everyone!
I'm currently in the process of developing a simple IMAP Email client as part of a larger Spring MVC web application. The mail-related stuff is handled by the
Java Mail API.
I am neither a Java pro nor am I very experienced with the Spring framework, so please bare with me. I'm having this 'project' as a hobby and try to learn from and grow with it.
I was already able to send mail and read IMAP messages from a server, so this is not the real issue here. I'm having a hard time to figure out how to properly and cleanly integrate the mail functionality into the mvc environment.
The goal front-end-wise, is to enable the user to get a list with messages and then be able to set certain flags (read, deleted, etc.) on them.
Now there are some conceptional things that I can't really figure out. I'll just describe how I imagine this to work and what problems I have with it. Maybe I'm just overthinking this...
I imagine a Controller with a request mapping to /mail. The method should return the view and add the messages to the model. To have a reference point on the messages I think about using a custom Wrapper object around each javax.mail.Message object. These wrapper objects should then have an ID, that I could pass back and forth between back- and front-end since the Message itself doesn't have any identifying property except for the mail-header (?).
When the user deletes or marks a message with some other flag, an AJAX post request to a second request mapping in the controller should be called, passing the wrapper object id that I use to get the real message from some list.
This is where I get stuck... How would I properly store a collection of those message-wrapper objects so that I can access them from different mapping methods in the controller?
Populate a list in the controller constructor? What's the lifespan of a controller instance?
I'm also unsure about the IMAP connection here. To get the messages I have to open the store and the folder. Once the store is closed, the connection between the received Message objects and the server is lost so I can't modify them anymore...
Can I open the store on application startup and leave it open until shutdown? How would I do that?
Then again, if I opened the store and got the messages each time in the '/mail' request mapping method, I guess my IMAP server wouldn't like the amount of new connections so much, - so the connection should in fact be handled somewhere centralized and in the background, instead of inside the controller?
That's an insane amount of questions there
I'd be really glad if someone could maybe just point me in the right direction with this.
If anything is unclear, please let me know and I'll try to clarify.
Thanks a lot in advance!!!