You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Marco Zapletal <ma...@gmail.com> on 2012/10/24 10:12:22 UTC
Syncing Message Status / Flags with external system
Hi folks,
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?
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?
Thanks and best regards,
Marco
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: Syncing Message Status / Flags with external system
Posted by Eric Charles <er...@apache.org>.
(see inline)
On 25/10/2012 10:54, Marco Zapletal wrote:
> 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.
>
Sounds good.
>
>>
>>> 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.
>
The James database does not have a UUID, but a UID which is unique per
mailbox. Maybe you can generate a UUID in the external one?
> 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.
Really cool!
> 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?
>
That's feasible sure.
The only drawback with this approach is that you are quite intrusive
with the current code and will be impacted on any future change (this
will happen soon in trunk).
> Thanks and best regards,
>
> Marco
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: Syncing Message Status / Flags with external system
Posted by Marco Zapletal <ma...@gmail.com>.
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: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: Syncing Message Status / Flags with external system
Posted by Eric Charles <er...@apache.org>.
(see inline)
On 24/10/2012 09:12, Marco Zapletal wrote:
> Hi folks,
>
>
> 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
...
> 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?
> Thanks and best regards,
> Marco
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org