On 25.10.2012 08:52, Eric Charles wrote:
in our environment, we need to synchronize the state of messages within
James (using JPA mailbox) with an external system. This means that (i)
when messages get fetched/deleted using IMAP, I want to call some Java
code that updates an external database and (ii) when changes to the
external database are made, the corresponding message flags should be
set in the James database.
In order to achieve that, I thought about the following approaches:
Regarding (i) the MessageListener may be of help, since it allows to
provide hooks for flags such as SEEN and DELETED. In this respect, my
question would be how to register my own MessageListener implementation?
Look at the imap processor implementations. That's where the listeners
are registered. Search for addListener in
https://svn.apache.org/repos/asf/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
https://svn.apache.org/repos/asf/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
...
Thanks for that. I will create a spring-managed MessageListener
implementation, which registers with the OpenJPAStoreMailboxManager.
In terms of (ii), the cleanest approach would be store the messageId of
the external system within a custom JPA entity inheriting from
JPAMessage. The corresponding messageId would be transferred as a header
of the MimeMessage to store. This means, I would require to add some
custom code, when the JPAMessage is created based on the MimeMessage. Is
this possible in James, and if so, could someone provide me with a hint
how to do this?
Not sure to understand what you want. In your introduction, you say that
you want to update james based on a change in an external database. Can
you confirm?
Yes. For syncing the messages between the two databases (the external
one and the James JPA database), I need to somehow maintain a link
between those two databases. This link could be the UUID of the message
in the original database.
In our environment, messages are fed into James by wrapping the original
message of the external database in a MimeMessage and putting it into
the spool queue. This works already well.
In order to create the link using the UUID, I thought about adding the
UUID as a header to the MimeMessage. In my custom JPAMessageEntity, I
parse the header in the constructor, extract the UUID, and set it as a
property on my custom JPAMessageEntity.
Does this sound feasible or is there any better approach how to achieve
this?
Thanks and best regards,
Marco
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]