You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Jerry Tian <je...@gmail.com> on 2012/05/30 17:20:44 UTC

How to use MailboxManager to insert a "fake" mail?

Hi, Jame developers,

I am building a proxy/gateway using james-imap-processor sub-module.
Currently I directly put my testing logic into the actual processor.

In org.apache.james.imap.processor.SearchProcessor, before the actual
searching happening, I am trying to insert/save some fake mails into
mailbox using the provided MailboxManager.

This is the code, more of a hack, which is borrowed from the  AppendProcessor.

=========================================
			//add this message into mailbox.
			String msgContent = this.getNewMsgStreamContent(noteData.getNoteTitle(),
					noteData.getNoteTitle(),//noteData.getNoteContent(),
					new Date(noteData.getCreatedAt()),
					inoteUID,
					null,
					userId,
					userDomain);
			
			logger.info("using raw msg content generated: " + msgContent);
				
			final MailboxPath mailboxPath = ...;
			final SelectedMailbox selectedMailbox = imapSession.getSelected();
			final boolean isSelectedMailbox = selectedMailbox != null &&
selectedMailbox.getPath().equals(mailboxPath);
			
			mailbox.appendMessage(new
ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
					new Date(noteData.getCreatedAt()),
					mailboxSession,
					!isSelectedMailbox,
					new Flags());
=========================================

And the referred getNewMsgStreamContent method is as below(the
template used is dumped before using the same client and server):

=========================================
	private String getNewMsgStreamContent(String title, String content,
Date cDate, String inoteUUID, String msgUUID, String userId, String
domain) {
		final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy
HH:mm:ss Z");
		
		if (cDate == null) {
			cDate = new Date();
		}
		String currDate = sdf.format(cDate);
		
		if (inoteUUID == null) {
			inoteUUID = UUID.randomUUID().toString();
		}
		
		if (msgUUID == null) {
			msgUUID = UUID.randomUUID().toString() + "@" + domain;
		}
		
		String syncUser = userId + "@" + domain;
		
		return NEW_MSG_TPL.replaceAll("__TITLE__", title)
				.replaceAll("__SYNC_USER__", syncUser)
				.replaceAll("__INOTE_UUID__", inoteUUID)
				.replaceAll("__MSG_UUID__", msgUUID)
				.replaceAll("__CDATE__", currDate)
				.replaceAll("__BODY__", content);
	}

=========================================

>From my test, the above method will produce a message as this:

=========================================

Subject: Coming soon
From: abc@def.com <ab...@def.com>
X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
Content-Type: text/html;
	charset=utf-8
X-Uniform-Type-Identifier: com.apple.mail-note
Message-Id: <a9...@def.com>
Date: Thu, 24 May 2012 16:19:31 +0800
X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (1.0)

Coming soon

=========================================

Although the invoking of appendMessage generates no exception so far,
it turns out only an empty mail record is stored in this mail box.
That is, the messageManager.getMessages(MessageRange,
FetchGroup.HEADERS, mailboxSession) does returns newly added records
in search result, but only MessageResult.getUid() returns a valid
value, and all other header values are missing(different from the
normal mail records from real clients).

Any clue why this is happening? And is there a more developer friendly
way to directly save a "fake" mail into user's mailbox?

Thanks a lot.

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@gmail.com>.
Hi Jerry,

To help on documentation, you can read
http://james.apache.org/contribute.html#Documentation

For code you can browse open JIRA via [1].
Helping closing/resolving a few of those will be very helpful:
JAMES-1350
JAMES-881
JAMES-1413
...

Thx, Eric


On 06/22/2012 05:50 AM, Jerry Tian wrote:
> Hi, Eric,
>
> https://issues.apache.org/jira/browse/JAMES would be better.
>
> I think if I can start the migration guide. But maybe a mentor is
> needed, since I am not familiar with your workflow on this
> documentation tasks.
>
> For some background information, I am working in a startup, mainly
> developing J2EE with Spring for years, and have done a lot of
> deployments with various kinds of servers, mostly with Linux,
> sometimes Windows.
>
> Regards.
>
> Jerry Tian
>
> On Sat, Jun 16, 2012 at 9:02 AM, Eric Charles<er...@apache.org>  wrote:
>> The default conf is something we build based on users/dev inputs.
>> There is room for improvement, but it should already be good enough...
>>
>> Sure, we have some work for you :) see open jiras in [1], [2], [3].
>>
>> Tell us which type of task would you like, we'll try to guide you to one you
>> will love.
>>
>> Thx, Eric
>>
>> [1] https://issues.apache.org/jira/browse/JAMES
>> [2] https://issues.apache.org/jira/browse/MAILBOX
>> [3] https://issues.apache.org/jira/browse/PROTOCOLS
>>
>>
>> On 06/16/2012 05:39 PM, Jerry Tian wrote:
>>>
>>> Got it. Seems the default configuration is good enough for my case.
>>>
>>> Again, thanks for the guidance, Eric.
>>>
>>> BTW, if I want to help with the  development and documentation,
>>> anything I can do?
>>>
>>> Regards.
>>>
>>> On 6/16/12, Eric Charles<er...@apache.org>    wrote:
>>>>
>>>> Document on http://james.apache.org/server/3/config-system.html
>>>>
>>>> "In combination with james-database.properties and
>>>> META-INF/persistence.xml, the datasource to access the database is
>>>> defined in spring-server.xml"
>>>>
>>>> Eric
>>>>
>>>> On 06/15/2012 09:07 AM, Eric Charles wrote:
>>>>>
>>>>> Hi Jerry,
>>>>>
>>>>> Glad you made it work :)
>>>>>
>>>>> You can find the datasource definition in the spring-server.xml located
>>>>> in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the
>>>>> bottom of the file, section "Database DataSource", it is indeed defined
>>>>> as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding
>>>>> the eviction... parameters).
>>>>>
>>>>> Obviously, this should be further documented on
>>>>> http://james.apache.org/server/3/config-system.html where we although
>>>>> describe the james-database.properties and link to the spring-server.xml
>>>>> file...
>>>>>
>>>>> Thx, Eric
>>>>>
>>>>>
>>>>> On 06/15/2012 01:21 AM, Jerry Tian wrote:
>>>>>>
>>>>>> Hi, Eric,
>>>>>>
>>>>>> Thanks for your hint. This bug finally turned out to be my mistake on
>>>>>> new line characters("\r\n", not "\n") used in mail body stream.
>>>>>>
>>>>>> Now the server is switched to MySQL as backend mail storage. There is
>>>>>> one thing I can't find out myself with respect to this deployment
>>>>>> configuration.
>>>>>>
>>>>>> There is only one collection opened by James after starting it up. I
>>>>>> am guessing James is using Apache's common DBCP as its database
>>>>>> connection pool(since I found this JAR in "lib" directory), but how do
>>>>>> I configure it? A grep within the James directory doen't yield useful
>>>>>> search results, and the manual on website also doesn't mention it.
>>>>>>
>>>>>> Regards.
>>>>>>
>>>>>> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org>    wrote:
>>>>>>>
>>>>>>> Hi Jerry,
>>>>>>>
>>>>>>> Not sure what's happening there. The String you give is not empty, so
>>>>>>> it
>>>>>>> should work.
>>>>>>>
>>>>>>> Kickoff your debuger and follow the path all the way down... Check
>>>>>>> also what
>>>>>>> is stored in your Derby database (database files are located under
>>>>>>> ${your.james.home}/var/store/derby - you will have to stop james and
>>>>>>> connect
>>>>>>> via a jdbc client with the correct connect string
>>>>>>> jdbc:derby:/${your.james.home}/var/store/derby).
>>>>>>>
>>>>>>> Thx, Eric
>>>>>>>
>>>>>>>
>>>>>>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> Hi, Eric,
>>>>>>>>
>>>>>>>> Thanks for your help, kinda on the move these days, sorry for the
>>>>>>>> late
>>>>>>>> reply.
>>>>>>>>
>>>>>>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>>>>>>> store, this seems more "safe" but less efficient. So, for better
>>>>>>>> efficiency, I still prefer the direct way.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>
>>>>>>>>   wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi Jerry,
>>>>>>>>>
>>>>>>>>> Why do you want to store anything if you want to act as a proxy?
>>>>>>>>> Shouldn't
>>>>>>>>> you always delegate the request to the remote imap server?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> You are right, it do include 2-way data transfer, and the James
>>>>>>>> server
>>>>>>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>>>>>>
>>>>>>>> It is used to bring a legacy client and a third party service
>>>>>>>> together.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> To try to answer your question:
>>>>>>>>> - which mailstore do you use: memory?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Now, the test and debug installation is using the default Derby
>>>>>>>> database, which should be the memory mail store you mentioned. In
>>>>>>>> production env, MySQL
>>>>>>>> is our choice.
>>>>>>>>
>>>>>>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Yes.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Print also the content of the msgContent string before callen
>>>>>>>>> append().
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>> Subject: Coming soon
>>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>>> Content-Type: text/html;
>>>>>>>> charset=utf-8
>>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>>> Message-Id:<a9...@def.com>
>>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>>
>>>>>>>> Coming soon
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>> This is the message I dumped before append(). Hope it helps.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thx, Eric
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hi, Jame developers,
>>>>>>>>>>
>>>>>>>>>> I am building a proxy/gateway using james-imap-processor
>>>>>>>>>> sub-module.
>>>>>>>>>> Currently I directly put my testing logic into the actual
>>>>>>>>>> processor.
>>>>>>>>>>
>>>>>>>>>> In org.apache.james.imap.processor.SearchProcessor, before the
>>>>>>>>>> actual
>>>>>>>>>> searching happening, I am trying to insert/save some fake mails
>>>>>>>>>> into
>>>>>>>>>> mailbox using the provided MailboxManager.
>>>>>>>>>>
>>>>>>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>>>>>> AppendProcessor.
>>>>>>>>>>
>>>>>>>>>> =========================================
>>>>>>>>>> //add this message into mailbox.
>>>>>>>>>> String msgContent =
>>>>>>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>>>>>>
>>>>>>>>>> noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>>>>>> new
>>>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>>>> inoteUID,
>>>>>>>>>> null,
>>>>>>>>>> userId,
>>>>>>>>>> userDomain);
>>>>>>>>>>
>>>>>>>>>> logger.info("using raw msg content generated: " +
>>>>>>>>>> msgContent);
>>>>>>>>>>
>>>>>>>>>> final MailboxPath mailboxPath = ...;
>>>>>>>>>> final SelectedMailbox selectedMailbox =
>>>>>>>>>> imapSession.getSelected();
>>>>>>>>>> final boolean isSelectedMailbox = selectedMailbox
>>>>>>>>>> != null&&
>>>>>>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>>>>>>
>>>>>>>>>> mailbox.appendMessage(new
>>>>>>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>>>>>> new
>>>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>>>> mailboxSession,
>>>>>>>>>> !isSelectedMailbox,
>>>>>>>>>> new Flags());
>>>>>>>>>> =========================================
>>>>>>>>>>
>>>>>>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>>>>>>> template used is dumped before using the same client and server):
>>>>>>>>>>
>>>>>>>>>> =========================================
>>>>>>>>>> private String getNewMsgStreamContent(String title, String
>>>>>>>>>> content,
>>>>>>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>>>>>>> domain) {
>>>>>>>>>> final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>>>>>>> MMM yyyy
>>>>>>>>>> HH:mm:ss Z");
>>>>>>>>>>
>>>>>>>>>> if (cDate == null) {
>>>>>>>>>> cDate = new Date();
>>>>>>>>>> }
>>>>>>>>>> String currDate = sdf.format(cDate);
>>>>>>>>>>
>>>>>>>>>> if (inoteUUID == null) {
>>>>>>>>>> inoteUUID = UUID.randomUUID().toString();
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> if (msgUUID == null) {
>>>>>>>>>> msgUUID = UUID.randomUUID().toString() + "@" +
>>>>>>>>>> domain;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> String syncUser = userId + "@" + domain;
>>>>>>>>>>
>>>>>>>>>> return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>>>>>> .replaceAll("__SYNC_USER__", syncUser)
>>>>>>>>>> .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>>>>>> .replaceAll("__MSG_UUID__", msgUUID)
>>>>>>>>>> .replaceAll("__CDATE__", currDate)
>>>>>>>>>> .replaceAll("__BODY__", content);
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> =========================================
>>>>>>>>>>
>>>>>>>>>>   From my test, the above method will produce a message as this:
>>>>>>>>>>
>>>>>>>>>> =========================================
>>>>>>>>>>
>>>>>>>>>> Subject: Coming soon
>>>>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>>>>> X-Universally-Unique-Identifier:
>>>>>>>>>> 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>>>>> Content-Type: text/html;
>>>>>>>>>> charset=utf-8
>>>>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>>>>> Message-Id:<a9...@def.com>
>>>>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>>>>
>>>>>>>>>> Coming soon
>>>>>>>>>>
>>>>>>>>>> =========================================
>>>>>>>>>>
>>>>>>>>>> Although the invoking of appendMessage generates no exception so
>>>>>>>>>> far,
>>>>>>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>>>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>>>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added
>>>>>>>>>> records
>>>>>>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>>>>>>> value, and all other header values are missing(different from the
>>>>>>>>>> normal mail records from real clients).
>>>>>>>>>>
>>>>>>>>>> Any clue why this is happening? And is there a more developer
>>>>>>>>>> friendly
>>>>>>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>>>>>>
>>>>>>>>>> Thanks a lot.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>
>>>>>
>>>>
>>>> --
>>>> eric | http://about.echarles.net | @echarles
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>>
>>>
>>>
>>
>> --
>> eric | http://about.echarles.net | @echarles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Jerry Tian <je...@gmail.com>.
Hi, Eric,

https://issues.apache.org/jira/browse/JAMES would be better.

I think if I can start the migration guide. But maybe a mentor is
needed, since I am not familiar with your workflow on this
documentation tasks.

For some background information, I am working in a startup, mainly
developing J2EE with Spring for years, and have done a lot of
deployments with various kinds of servers, mostly with Linux,
sometimes Windows.

Regards.

Jerry Tian

On Sat, Jun 16, 2012 at 9:02 AM, Eric Charles <er...@apache.org> wrote:
> The default conf is something we build based on users/dev inputs.
> There is room for improvement, but it should already be good enough...
>
> Sure, we have some work for you :) see open jiras in [1], [2], [3].
>
> Tell us which type of task would you like, we'll try to guide you to one you
> will love.
>
> Thx, Eric
>
> [1] https://issues.apache.org/jira/browse/JAMES
> [2] https://issues.apache.org/jira/browse/MAILBOX
> [3] https://issues.apache.org/jira/browse/PROTOCOLS
>
>
> On 06/16/2012 05:39 PM, Jerry Tian wrote:
>>
>> Got it. Seems the default configuration is good enough for my case.
>>
>> Again, thanks for the guidance, Eric.
>>
>> BTW, if I want to help with the  development and documentation,
>> anything I can do?
>>
>> Regards.
>>
>> On 6/16/12, Eric Charles<er...@apache.org>  wrote:
>>>
>>> Document on http://james.apache.org/server/3/config-system.html
>>>
>>> "In combination with james-database.properties and
>>> META-INF/persistence.xml, the datasource to access the database is
>>> defined in spring-server.xml"
>>>
>>> Eric
>>>
>>> On 06/15/2012 09:07 AM, Eric Charles wrote:
>>>>
>>>> Hi Jerry,
>>>>
>>>> Glad you made it work :)
>>>>
>>>> You can find the datasource definition in the spring-server.xml located
>>>> in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the
>>>> bottom of the file, section "Database DataSource", it is indeed defined
>>>> as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding
>>>> the eviction... parameters).
>>>>
>>>> Obviously, this should be further documented on
>>>> http://james.apache.org/server/3/config-system.html where we although
>>>> describe the james-database.properties and link to the spring-server.xml
>>>> file...
>>>>
>>>> Thx, Eric
>>>>
>>>>
>>>> On 06/15/2012 01:21 AM, Jerry Tian wrote:
>>>>>
>>>>> Hi, Eric,
>>>>>
>>>>> Thanks for your hint. This bug finally turned out to be my mistake on
>>>>> new line characters("\r\n", not "\n") used in mail body stream.
>>>>>
>>>>> Now the server is switched to MySQL as backend mail storage. There is
>>>>> one thing I can't find out myself with respect to this deployment
>>>>> configuration.
>>>>>
>>>>> There is only one collection opened by James after starting it up. I
>>>>> am guessing James is using Apache's common DBCP as its database
>>>>> connection pool(since I found this JAR in "lib" directory), but how do
>>>>> I configure it? A grep within the James directory doen't yield useful
>>>>> search results, and the manual on website also doesn't mention it.
>>>>>
>>>>> Regards.
>>>>>
>>>>> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org>  wrote:
>>>>>>
>>>>>> Hi Jerry,
>>>>>>
>>>>>> Not sure what's happening there. The String you give is not empty, so
>>>>>> it
>>>>>> should work.
>>>>>>
>>>>>> Kickoff your debuger and follow the path all the way down... Check
>>>>>> also what
>>>>>> is stored in your Derby database (database files are located under
>>>>>> ${your.james.home}/var/store/derby - you will have to stop james and
>>>>>> connect
>>>>>> via a jdbc client with the correct connect string
>>>>>> jdbc:derby:/${your.james.home}/var/store/derby).
>>>>>>
>>>>>> Thx, Eric
>>>>>>
>>>>>>
>>>>>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>>>>>
>>>>>>>
>>>>>>> Hi, Eric,
>>>>>>>
>>>>>>> Thanks for your help, kinda on the move these days, sorry for the
>>>>>>> late
>>>>>>> reply.
>>>>>>>
>>>>>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>>>>>> store, this seems more "safe" but less efficient. So, for better
>>>>>>> efficiency, I still prefer the direct way.
>>>>>>>
>>>>>>>
>>>>>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>
>>>>>>>  wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> Hi Jerry,
>>>>>>>>
>>>>>>>> Why do you want to store anything if you want to act as a proxy?
>>>>>>>> Shouldn't
>>>>>>>> you always delegate the request to the remote imap server?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> You are right, it do include 2-way data transfer, and the James
>>>>>>> server
>>>>>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>>>>>
>>>>>>> It is used to bring a legacy client and a third party service
>>>>>>> together.
>>>>>>>
>>>>>>>>
>>>>>>>> To try to answer your question:
>>>>>>>> - which mailstore do you use: memory?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Now, the test and debug installation is using the default Derby
>>>>>>> database, which should be the memory mail store you mentioned. In
>>>>>>> production env, MySQL
>>>>>>> is our choice.
>>>>>>>
>>>>>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Yes.
>>>>>>>
>>>>>>>>
>>>>>>>> Print also the content of the msgContent string before callen
>>>>>>>> append().
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> =========================================
>>>>>>>
>>>>>>> Subject: Coming soon
>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>> Content-Type: text/html;
>>>>>>> charset=utf-8
>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>> Message-Id:<a9...@def.com>
>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>
>>>>>>> Coming soon
>>>>>>>
>>>>>>> =========================================
>>>>>>>
>>>>>>> This is the message I dumped before append(). Hope it helps.
>>>>>>>
>>>>>>>>
>>>>>>>> Thx, Eric
>>>>>>>>
>>>>>>>>
>>>>>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi, Jame developers,
>>>>>>>>>
>>>>>>>>> I am building a proxy/gateway using james-imap-processor
>>>>>>>>> sub-module.
>>>>>>>>> Currently I directly put my testing logic into the actual
>>>>>>>>> processor.
>>>>>>>>>
>>>>>>>>> In org.apache.james.imap.processor.SearchProcessor, before the
>>>>>>>>> actual
>>>>>>>>> searching happening, I am trying to insert/save some fake mails
>>>>>>>>> into
>>>>>>>>> mailbox using the provided MailboxManager.
>>>>>>>>>
>>>>>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>>>>> AppendProcessor.
>>>>>>>>>
>>>>>>>>> =========================================
>>>>>>>>> //add this message into mailbox.
>>>>>>>>> String msgContent =
>>>>>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>>>>>
>>>>>>>>> noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>>>>> new
>>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>>> inoteUID,
>>>>>>>>> null,
>>>>>>>>> userId,
>>>>>>>>> userDomain);
>>>>>>>>>
>>>>>>>>> logger.info("using raw msg content generated: " +
>>>>>>>>> msgContent);
>>>>>>>>>
>>>>>>>>> final MailboxPath mailboxPath = ...;
>>>>>>>>> final SelectedMailbox selectedMailbox =
>>>>>>>>> imapSession.getSelected();
>>>>>>>>> final boolean isSelectedMailbox = selectedMailbox
>>>>>>>>> != null&&
>>>>>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>>>>>
>>>>>>>>> mailbox.appendMessage(new
>>>>>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>>>>> new
>>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>>> mailboxSession,
>>>>>>>>> !isSelectedMailbox,
>>>>>>>>> new Flags());
>>>>>>>>> =========================================
>>>>>>>>>
>>>>>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>>>>>> template used is dumped before using the same client and server):
>>>>>>>>>
>>>>>>>>> =========================================
>>>>>>>>> private String getNewMsgStreamContent(String title, String
>>>>>>>>> content,
>>>>>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>>>>>> domain) {
>>>>>>>>> final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>>>>>> MMM yyyy
>>>>>>>>> HH:mm:ss Z");
>>>>>>>>>
>>>>>>>>> if (cDate == null) {
>>>>>>>>> cDate = new Date();
>>>>>>>>> }
>>>>>>>>> String currDate = sdf.format(cDate);
>>>>>>>>>
>>>>>>>>> if (inoteUUID == null) {
>>>>>>>>> inoteUUID = UUID.randomUUID().toString();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> if (msgUUID == null) {
>>>>>>>>> msgUUID = UUID.randomUUID().toString() + "@" +
>>>>>>>>> domain;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> String syncUser = userId + "@" + domain;
>>>>>>>>>
>>>>>>>>> return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>>>>> .replaceAll("__SYNC_USER__", syncUser)
>>>>>>>>> .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>>>>> .replaceAll("__MSG_UUID__", msgUUID)
>>>>>>>>> .replaceAll("__CDATE__", currDate)
>>>>>>>>> .replaceAll("__BODY__", content);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> =========================================
>>>>>>>>>
>>>>>>>>>  From my test, the above method will produce a message as this:
>>>>>>>>>
>>>>>>>>> =========================================
>>>>>>>>>
>>>>>>>>> Subject: Coming soon
>>>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>>>> X-Universally-Unique-Identifier:
>>>>>>>>> 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>>>> Content-Type: text/html;
>>>>>>>>> charset=utf-8
>>>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>>>> Message-Id:<a9...@def.com>
>>>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>>>
>>>>>>>>> Coming soon
>>>>>>>>>
>>>>>>>>> =========================================
>>>>>>>>>
>>>>>>>>> Although the invoking of appendMessage generates no exception so
>>>>>>>>> far,
>>>>>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added
>>>>>>>>> records
>>>>>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>>>>>> value, and all other header values are missing(different from the
>>>>>>>>> normal mail records from real clients).
>>>>>>>>>
>>>>>>>>> Any clue why this is happening? And is there a more developer
>>>>>>>>> friendly
>>>>>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>>>>>
>>>>>>>>> Thanks a lot.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>
>>>>
>>>
>>> --
>>> eric | http://about.echarles.net | @echarles
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>>
>>
>>
>
> --
> eric | http://about.echarles.net | @echarles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@apache.org>.
The default conf is something we build based on users/dev inputs.
There is room for improvement, but it should already be good enough...

Sure, we have some work for you :) see open jiras in [1], [2], [3].

Tell us which type of task would you like, we'll try to guide you to one 
you will love.

Thx, Eric

[1] https://issues.apache.org/jira/browse/JAMES
[2] https://issues.apache.org/jira/browse/MAILBOX
[3] https://issues.apache.org/jira/browse/PROTOCOLS

On 06/16/2012 05:39 PM, Jerry Tian wrote:
> Got it. Seems the default configuration is good enough for my case.
>
> Again, thanks for the guidance, Eric.
>
> BTW, if I want to help with the  development and documentation,
> anything I can do?
>
> Regards.
>
> On 6/16/12, Eric Charles<er...@apache.org>  wrote:
>> Document on http://james.apache.org/server/3/config-system.html
>>
>> "In combination with james-database.properties and
>> META-INF/persistence.xml, the datasource to access the database is
>> defined in spring-server.xml"
>>
>> Eric
>>
>> On 06/15/2012 09:07 AM, Eric Charles wrote:
>>> Hi Jerry,
>>>
>>> Glad you made it work :)
>>>
>>> You can find the datasource definition in the spring-server.xml located
>>> in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the
>>> bottom of the file, section "Database DataSource", it is indeed defined
>>> as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding
>>> the eviction... parameters).
>>>
>>> Obviously, this should be further documented on
>>> http://james.apache.org/server/3/config-system.html where we although
>>> describe the james-database.properties and link to the spring-server.xml
>>> file...
>>>
>>> Thx, Eric
>>>
>>>
>>> On 06/15/2012 01:21 AM, Jerry Tian wrote:
>>>> Hi, Eric,
>>>>
>>>> Thanks for your hint. This bug finally turned out to be my mistake on
>>>> new line characters("\r\n", not "\n") used in mail body stream.
>>>>
>>>> Now the server is switched to MySQL as backend mail storage. There is
>>>> one thing I can't find out myself with respect to this deployment
>>>> configuration.
>>>>
>>>> There is only one collection opened by James after starting it up. I
>>>> am guessing James is using Apache's common DBCP as its database
>>>> connection pool(since I found this JAR in "lib" directory), but how do
>>>> I configure it? A grep within the James directory doen't yield useful
>>>> search results, and the manual on website also doesn't mention it.
>>>>
>>>> Regards.
>>>>
>>>> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org>  wrote:
>>>>> Hi Jerry,
>>>>>
>>>>> Not sure what's happening there. The String you give is not empty, so
>>>>> it
>>>>> should work.
>>>>>
>>>>> Kickoff your debuger and follow the path all the way down... Check
>>>>> also what
>>>>> is stored in your Derby database (database files are located under
>>>>> ${your.james.home}/var/store/derby - you will have to stop james and
>>>>> connect
>>>>> via a jdbc client with the correct connect string
>>>>> jdbc:derby:/${your.james.home}/var/store/derby).
>>>>>
>>>>> Thx, Eric
>>>>>
>>>>>
>>>>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>>>>
>>>>>> Hi, Eric,
>>>>>>
>>>>>> Thanks for your help, kinda on the move these days, sorry for the late
>>>>>> reply.
>>>>>>
>>>>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>>>>> store, this seems more "safe" but less efficient. So, for better
>>>>>> efficiency, I still prefer the direct way.
>>>>>>
>>>>>>
>>>>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>  wrote:
>>>>>>>
>>>>>>> Hi Jerry,
>>>>>>>
>>>>>>> Why do you want to store anything if you want to act as a proxy?
>>>>>>> Shouldn't
>>>>>>> you always delegate the request to the remote imap server?
>>>>>>
>>>>>>
>>>>>> You are right, it do include 2-way data transfer, and the James server
>>>>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>>>>
>>>>>> It is used to bring a legacy client and a third party service
>>>>>> together.
>>>>>>
>>>>>>>
>>>>>>> To try to answer your question:
>>>>>>> - which mailstore do you use: memory?
>>>>>>
>>>>>>
>>>>>> Now, the test and debug installation is using the default Derby
>>>>>> database, which should be the memory mail store you mentioned. In
>>>>>> production env, MySQL
>>>>>> is our choice.
>>>>>>
>>>>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>>>>
>>>>>>
>>>>>> Yes.
>>>>>>
>>>>>>>
>>>>>>> Print also the content of the msgContent string before callen
>>>>>>> append().
>>>>>>
>>>>>>
>>>>>> =========================================
>>>>>>
>>>>>> Subject: Coming soon
>>>>>> From: abc@def.com<ab...@def.com>
>>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>> Content-Type: text/html;
>>>>>> charset=utf-8
>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>> Message-Id:<a9...@def.com>
>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>> Content-Transfer-Encoding: 7bit
>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>
>>>>>> Coming soon
>>>>>>
>>>>>> =========================================
>>>>>>
>>>>>> This is the message I dumped before append(). Hope it helps.
>>>>>>
>>>>>>>
>>>>>>> Thx, Eric
>>>>>>>
>>>>>>>
>>>>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> Hi, Jame developers,
>>>>>>>>
>>>>>>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>>>>>>> Currently I directly put my testing logic into the actual processor.
>>>>>>>>
>>>>>>>> In org.apache.james.imap.processor.SearchProcessor, before the
>>>>>>>> actual
>>>>>>>> searching happening, I am trying to insert/save some fake mails into
>>>>>>>> mailbox using the provided MailboxManager.
>>>>>>>>
>>>>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>>>> AppendProcessor.
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>> //add this message into mailbox.
>>>>>>>> String msgContent =
>>>>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>>>>
>>>>>>>> noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>>>> new
>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>> inoteUID,
>>>>>>>> null,
>>>>>>>> userId,
>>>>>>>> userDomain);
>>>>>>>>
>>>>>>>> logger.info("using raw msg content generated: " +
>>>>>>>> msgContent);
>>>>>>>>
>>>>>>>> final MailboxPath mailboxPath = ...;
>>>>>>>> final SelectedMailbox selectedMailbox =
>>>>>>>> imapSession.getSelected();
>>>>>>>> final boolean isSelectedMailbox = selectedMailbox
>>>>>>>> != null&&
>>>>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>>>>
>>>>>>>> mailbox.appendMessage(new
>>>>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>>>> new
>>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>>> mailboxSession,
>>>>>>>> !isSelectedMailbox,
>>>>>>>> new Flags());
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>>>>> template used is dumped before using the same client and server):
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>> private String getNewMsgStreamContent(String title, String
>>>>>>>> content,
>>>>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>>>>> domain) {
>>>>>>>> final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>>>>> MMM yyyy
>>>>>>>> HH:mm:ss Z");
>>>>>>>>
>>>>>>>> if (cDate == null) {
>>>>>>>> cDate = new Date();
>>>>>>>> }
>>>>>>>> String currDate = sdf.format(cDate);
>>>>>>>>
>>>>>>>> if (inoteUUID == null) {
>>>>>>>> inoteUUID = UUID.randomUUID().toString();
>>>>>>>> }
>>>>>>>>
>>>>>>>> if (msgUUID == null) {
>>>>>>>> msgUUID = UUID.randomUUID().toString() + "@" +
>>>>>>>> domain;
>>>>>>>> }
>>>>>>>>
>>>>>>>> String syncUser = userId + "@" + domain;
>>>>>>>>
>>>>>>>> return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>>>> .replaceAll("__SYNC_USER__", syncUser)
>>>>>>>> .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>>>> .replaceAll("__MSG_UUID__", msgUUID)
>>>>>>>> .replaceAll("__CDATE__", currDate)
>>>>>>>> .replaceAll("__BODY__", content);
>>>>>>>> }
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>>  From my test, the above method will produce a message as this:
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>> Subject: Coming soon
>>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>>> X-Universally-Unique-Identifier:
>>>>>>>> 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>>> Content-Type: text/html;
>>>>>>>> charset=utf-8
>>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>>> Message-Id:<a9...@def.com>
>>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>>
>>>>>>>> Coming soon
>>>>>>>>
>>>>>>>> =========================================
>>>>>>>>
>>>>>>>> Although the invoking of appendMessage generates no exception so
>>>>>>>> far,
>>>>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>>>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>>>>> value, and all other header values are missing(different from the
>>>>>>>> normal mail records from real clients).
>>>>>>>>
>>>>>>>> Any clue why this is happening? And is there a more developer
>>>>>>>> friendly
>>>>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>>>>
>>>>>>>> Thanks a lot.
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>
>>>>>
>>>>> --
>>>>> eric | http://about.echarles.net | @echarles
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>
>>
>> --
>> eric | http://about.echarles.net | @echarles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>>
>
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Jerry Tian <je...@gmail.com>.
Got it. Seems the default configuration is good enough for my case.

Again, thanks for the guidance, Eric.

BTW, if I want to help with the  development and documentation,
anything I can do?

Regards.

On 6/16/12, Eric Charles <er...@apache.org> wrote:
> Document on http://james.apache.org/server/3/config-system.html
>
> "In combination with james-database.properties and
> META-INF/persistence.xml, the datasource to access the database is
> defined in spring-server.xml"
>
> Eric
>
> On 06/15/2012 09:07 AM, Eric Charles wrote:
>> Hi Jerry,
>>
>> Glad you made it work :)
>>
>> You can find the datasource definition in the spring-server.xml located
>> in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the
>> bottom of the file, section "Database DataSource", it is indeed defined
>> as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding
>> the eviction... parameters).
>>
>> Obviously, this should be further documented on
>> http://james.apache.org/server/3/config-system.html where we although
>> describe the james-database.properties and link to the spring-server.xml
>> file...
>>
>> Thx, Eric
>>
>>
>> On 06/15/2012 01:21 AM, Jerry Tian wrote:
>>> Hi, Eric,
>>>
>>> Thanks for your hint. This bug finally turned out to be my mistake on
>>> new line characters("\r\n", not "\n") used in mail body stream.
>>>
>>> Now the server is switched to MySQL as backend mail storage. There is
>>> one thing I can't find out myself with respect to this deployment
>>> configuration.
>>>
>>> There is only one collection opened by James after starting it up. I
>>> am guessing James is using Apache's common DBCP as its database
>>> connection pool(since I found this JAR in "lib" directory), but how do
>>> I configure it? A grep within the James directory doen't yield useful
>>> search results, and the manual on website also doesn't mention it.
>>>
>>> Regards.
>>>
>>> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org> wrote:
>>>> Hi Jerry,
>>>>
>>>> Not sure what's happening there. The String you give is not empty, so
>>>> it
>>>> should work.
>>>>
>>>> Kickoff your debuger and follow the path all the way down... Check
>>>> also what
>>>> is stored in your Derby database (database files are located under
>>>> ${your.james.home}/var/store/derby - you will have to stop james and
>>>> connect
>>>> via a jdbc client with the correct connect string
>>>> jdbc:derby:/${your.james.home}/var/store/derby).
>>>>
>>>> Thx, Eric
>>>>
>>>>
>>>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>>>
>>>>> Hi, Eric,
>>>>>
>>>>> Thanks for your help, kinda on the move these days, sorry for the late
>>>>> reply.
>>>>>
>>>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>>>> store, this seems more "safe" but less efficient. So, for better
>>>>> efficiency, I still prefer the direct way.
>>>>>
>>>>>
>>>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org> wrote:
>>>>>>
>>>>>> Hi Jerry,
>>>>>>
>>>>>> Why do you want to store anything if you want to act as a proxy?
>>>>>> Shouldn't
>>>>>> you always delegate the request to the remote imap server?
>>>>>
>>>>>
>>>>> You are right, it do include 2-way data transfer, and the James server
>>>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>>>
>>>>> It is used to bring a legacy client and a third party service
>>>>> together.
>>>>>
>>>>>>
>>>>>> To try to answer your question:
>>>>>> - which mailstore do you use: memory?
>>>>>
>>>>>
>>>>> Now, the test and debug installation is using the default Derby
>>>>> database, which should be the memory mail store you mentioned. In
>>>>> production env, MySQL
>>>>> is our choice.
>>>>>
>>>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>>>
>>>>>
>>>>> Yes.
>>>>>
>>>>>>
>>>>>> Print also the content of the msgContent string before callen
>>>>>> append().
>>>>>
>>>>>
>>>>> =========================================
>>>>>
>>>>> Subject: Coming soon
>>>>> From: abc@def.com<ab...@def.com>
>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>> Content-Type: text/html;
>>>>> charset=utf-8
>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>> Message-Id:<a9...@def.com>
>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>> Content-Transfer-Encoding: 7bit
>>>>> Mime-Version: 1.0 (1.0)
>>>>>
>>>>> Coming soon
>>>>>
>>>>> =========================================
>>>>>
>>>>> This is the message I dumped before append(). Hope it helps.
>>>>>
>>>>>>
>>>>>> Thx, Eric
>>>>>>
>>>>>>
>>>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>>>
>>>>>>>
>>>>>>> Hi, Jame developers,
>>>>>>>
>>>>>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>>>>>> Currently I directly put my testing logic into the actual processor.
>>>>>>>
>>>>>>> In org.apache.james.imap.processor.SearchProcessor, before the
>>>>>>> actual
>>>>>>> searching happening, I am trying to insert/save some fake mails into
>>>>>>> mailbox using the provided MailboxManager.
>>>>>>>
>>>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>>> AppendProcessor.
>>>>>>>
>>>>>>> =========================================
>>>>>>> //add this message into mailbox.
>>>>>>> String msgContent =
>>>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>>>
>>>>>>> noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>>> new
>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>> inoteUID,
>>>>>>> null,
>>>>>>> userId,
>>>>>>> userDomain);
>>>>>>>
>>>>>>> logger.info("using raw msg content generated: " +
>>>>>>> msgContent);
>>>>>>>
>>>>>>> final MailboxPath mailboxPath = ...;
>>>>>>> final SelectedMailbox selectedMailbox =
>>>>>>> imapSession.getSelected();
>>>>>>> final boolean isSelectedMailbox = selectedMailbox
>>>>>>> != null&&
>>>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>>>
>>>>>>> mailbox.appendMessage(new
>>>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>>> new
>>>>>>> Date(noteData.getCreatedAt()),
>>>>>>> mailboxSession,
>>>>>>> !isSelectedMailbox,
>>>>>>> new Flags());
>>>>>>> =========================================
>>>>>>>
>>>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>>>> template used is dumped before using the same client and server):
>>>>>>>
>>>>>>> =========================================
>>>>>>> private String getNewMsgStreamContent(String title, String
>>>>>>> content,
>>>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>>>> domain) {
>>>>>>> final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>>>> MMM yyyy
>>>>>>> HH:mm:ss Z");
>>>>>>>
>>>>>>> if (cDate == null) {
>>>>>>> cDate = new Date();
>>>>>>> }
>>>>>>> String currDate = sdf.format(cDate);
>>>>>>>
>>>>>>> if (inoteUUID == null) {
>>>>>>> inoteUUID = UUID.randomUUID().toString();
>>>>>>> }
>>>>>>>
>>>>>>> if (msgUUID == null) {
>>>>>>> msgUUID = UUID.randomUUID().toString() + "@" +
>>>>>>> domain;
>>>>>>> }
>>>>>>>
>>>>>>> String syncUser = userId + "@" + domain;
>>>>>>>
>>>>>>> return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>>> .replaceAll("__SYNC_USER__", syncUser)
>>>>>>> .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>>> .replaceAll("__MSG_UUID__", msgUUID)
>>>>>>> .replaceAll("__CDATE__", currDate)
>>>>>>> .replaceAll("__BODY__", content);
>>>>>>> }
>>>>>>>
>>>>>>> =========================================
>>>>>>>
>>>>>>> From my test, the above method will produce a message as this:
>>>>>>>
>>>>>>> =========================================
>>>>>>>
>>>>>>> Subject: Coming soon
>>>>>>> From: abc@def.com<ab...@def.com>
>>>>>>> X-Universally-Unique-Identifier:
>>>>>>> 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>>> Content-Type: text/html;
>>>>>>> charset=utf-8
>>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>>> Message-Id:<a9...@def.com>
>>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>>> Content-Transfer-Encoding: 7bit
>>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>>
>>>>>>> Coming soon
>>>>>>>
>>>>>>> =========================================
>>>>>>>
>>>>>>> Although the invoking of appendMessage generates no exception so
>>>>>>> far,
>>>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>>>> value, and all other header values are missing(different from the
>>>>>>> normal mail records from real clients).
>>>>>>>
>>>>>>> Any clue why this is happening? And is there a more developer
>>>>>>> friendly
>>>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>>>
>>>>>>> Thanks a lot.
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>>
>>>>>>
>>>>>> --
>>>>>> eric | http://about.echarles.net | @echarles
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>
>>>>
>>>> --
>>>> eric | http://about.echarles.net | @echarles
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>
> --
> eric | http://about.echarles.net | @echarles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
>


-- 
Jerry Tian

http://www.jerrysgadget.com
http://www.3gtb.com

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@apache.org>.
Document on http://james.apache.org/server/3/config-system.html

"In combination with james-database.properties and 
META-INF/persistence.xml, the datasource to access the database is 
defined in spring-server.xml"

Eric

On 06/15/2012 09:07 AM, Eric Charles wrote:
> Hi Jerry,
>
> Glad you made it work :)
>
> You can find the datasource definition in the spring-server.xml located
> in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the
> bottom of the file, section "Database DataSource", it is indeed defined
> as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding
> the eviction... parameters).
>
> Obviously, this should be further documented on
> http://james.apache.org/server/3/config-system.html where we although
> describe the james-database.properties and link to the spring-server.xml
> file...
>
> Thx, Eric
>
>
> On 06/15/2012 01:21 AM, Jerry Tian wrote:
>> Hi, Eric,
>>
>> Thanks for your hint. This bug finally turned out to be my mistake on
>> new line characters("\r\n", not "\n") used in mail body stream.
>>
>> Now the server is switched to MySQL as backend mail storage. There is
>> one thing I can't find out myself with respect to this deployment
>> configuration.
>>
>> There is only one collection opened by James after starting it up. I
>> am guessing James is using Apache's common DBCP as its database
>> connection pool(since I found this JAR in "lib" directory), but how do
>> I configure it? A grep within the James directory doen't yield useful
>> search results, and the manual on website also doesn't mention it.
>>
>> Regards.
>>
>> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org> wrote:
>>> Hi Jerry,
>>>
>>> Not sure what's happening there. The String you give is not empty, so it
>>> should work.
>>>
>>> Kickoff your debuger and follow the path all the way down... Check
>>> also what
>>> is stored in your Derby database (database files are located under
>>> ${your.james.home}/var/store/derby - you will have to stop james and
>>> connect
>>> via a jdbc client with the correct connect string
>>> jdbc:derby:/${your.james.home}/var/store/derby).
>>>
>>> Thx, Eric
>>>
>>>
>>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>>
>>>> Hi, Eric,
>>>>
>>>> Thanks for your help, kinda on the move these days, sorry for the late
>>>> reply.
>>>>
>>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>>> store, this seems more "safe" but less efficient. So, for better
>>>> efficiency, I still prefer the direct way.
>>>>
>>>>
>>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org> wrote:
>>>>>
>>>>> Hi Jerry,
>>>>>
>>>>> Why do you want to store anything if you want to act as a proxy?
>>>>> Shouldn't
>>>>> you always delegate the request to the remote imap server?
>>>>
>>>>
>>>> You are right, it do include 2-way data transfer, and the James server
>>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>>
>>>> It is used to bring a legacy client and a third party service together.
>>>>
>>>>>
>>>>> To try to answer your question:
>>>>> - which mailstore do you use: memory?
>>>>
>>>>
>>>> Now, the test and debug installation is using the default Derby
>>>> database, which should be the memory mail store you mentioned. In
>>>> production env, MySQL
>>>> is our choice.
>>>>
>>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>>
>>>>
>>>> Yes.
>>>>
>>>>>
>>>>> Print also the content of the msgContent string before callen
>>>>> append().
>>>>
>>>>
>>>> =========================================
>>>>
>>>> Subject: Coming soon
>>>> From: abc@def.com<ab...@def.com>
>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>> Content-Type: text/html;
>>>> charset=utf-8
>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>> Message-Id:<a9...@def.com>
>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>> Content-Transfer-Encoding: 7bit
>>>> Mime-Version: 1.0 (1.0)
>>>>
>>>> Coming soon
>>>>
>>>> =========================================
>>>>
>>>> This is the message I dumped before append(). Hope it helps.
>>>>
>>>>>
>>>>> Thx, Eric
>>>>>
>>>>>
>>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>>
>>>>>>
>>>>>> Hi, Jame developers,
>>>>>>
>>>>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>>>>> Currently I directly put my testing logic into the actual processor.
>>>>>>
>>>>>> In org.apache.james.imap.processor.SearchProcessor, before the actual
>>>>>> searching happening, I am trying to insert/save some fake mails into
>>>>>> mailbox using the provided MailboxManager.
>>>>>>
>>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>> AppendProcessor.
>>>>>>
>>>>>> =========================================
>>>>>> //add this message into mailbox.
>>>>>> String msgContent =
>>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>>
>>>>>> noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>> new
>>>>>> Date(noteData.getCreatedAt()),
>>>>>> inoteUID,
>>>>>> null,
>>>>>> userId,
>>>>>> userDomain);
>>>>>>
>>>>>> logger.info("using raw msg content generated: " +
>>>>>> msgContent);
>>>>>>
>>>>>> final MailboxPath mailboxPath = ...;
>>>>>> final SelectedMailbox selectedMailbox =
>>>>>> imapSession.getSelected();
>>>>>> final boolean isSelectedMailbox = selectedMailbox
>>>>>> != null&&
>>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>>
>>>>>> mailbox.appendMessage(new
>>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>> new
>>>>>> Date(noteData.getCreatedAt()),
>>>>>> mailboxSession,
>>>>>> !isSelectedMailbox,
>>>>>> new Flags());
>>>>>> =========================================
>>>>>>
>>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>>> template used is dumped before using the same client and server):
>>>>>>
>>>>>> =========================================
>>>>>> private String getNewMsgStreamContent(String title, String
>>>>>> content,
>>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>>> domain) {
>>>>>> final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>>> MMM yyyy
>>>>>> HH:mm:ss Z");
>>>>>>
>>>>>> if (cDate == null) {
>>>>>> cDate = new Date();
>>>>>> }
>>>>>> String currDate = sdf.format(cDate);
>>>>>>
>>>>>> if (inoteUUID == null) {
>>>>>> inoteUUID = UUID.randomUUID().toString();
>>>>>> }
>>>>>>
>>>>>> if (msgUUID == null) {
>>>>>> msgUUID = UUID.randomUUID().toString() + "@" +
>>>>>> domain;
>>>>>> }
>>>>>>
>>>>>> String syncUser = userId + "@" + domain;
>>>>>>
>>>>>> return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>> .replaceAll("__SYNC_USER__", syncUser)
>>>>>> .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>> .replaceAll("__MSG_UUID__", msgUUID)
>>>>>> .replaceAll("__CDATE__", currDate)
>>>>>> .replaceAll("__BODY__", content);
>>>>>> }
>>>>>>
>>>>>> =========================================
>>>>>>
>>>>>> From my test, the above method will produce a message as this:
>>>>>>
>>>>>> =========================================
>>>>>>
>>>>>> Subject: Coming soon
>>>>>> From: abc@def.com<ab...@def.com>
>>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>>> Content-Type: text/html;
>>>>>> charset=utf-8
>>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>>> Message-Id:<a9...@def.com>
>>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>>> Content-Transfer-Encoding: 7bit
>>>>>> Mime-Version: 1.0 (1.0)
>>>>>>
>>>>>> Coming soon
>>>>>>
>>>>>> =========================================
>>>>>>
>>>>>> Although the invoking of appendMessage generates no exception so far,
>>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>>> value, and all other header values are missing(different from the
>>>>>> normal mail records from real clients).
>>>>>>
>>>>>> Any clue why this is happening? And is there a more developer
>>>>>> friendly
>>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>>
>>>>>> Thanks a lot.
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>>
>>>>>
>>>>> --
>>>>> eric | http://about.echarles.net | @echarles
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>
>>> --
>>> eric | http://about.echarles.net | @echarles
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@apache.org>.
Hi Jerry,

Glad you made it work :)

You can find the datasource definition in the spring-server.xml located 
in $JAMES_HOME/conf/META-INF/org/apache/james/spring-server.xml (at the 
bottom of the file, section "Database DataSource", it is indeed defined 
as a org.apache.commons.dbcp.BasicDataSource with best-effort regarding 
the eviction... parameters).

Obviously, this should be further documented on 
http://james.apache.org/server/3/config-system.html where we although 
describe the james-database.properties and link to the spring-server.xml 
file...

Thx, Eric


On 06/15/2012 01:21 AM, Jerry Tian wrote:
> Hi, Eric,
>
> Thanks for your hint. This bug finally turned out to be my mistake on
> new line characters("\r\n", not "\n") used in mail body stream.
>
> Now the server is switched to MySQL as backend mail storage. There is
> one thing I can't find out myself with respect to this deployment
> configuration.
>
> There is only one collection opened by James after starting it up. I
> am guessing James is using Apache's common DBCP as its database
> connection pool(since I found this JAR in "lib" directory), but how do
> I configure it? A grep within the James directory doen't yield useful
> search results, and the manual on website also doesn't mention it.
>
> Regards.
>
> On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles<er...@apache.org>  wrote:
>> Hi Jerry,
>>
>> Not sure what's happening there. The String you give is not empty, so it
>> should work.
>>
>> Kickoff your debuger and follow the path all the way down... Check also what
>> is stored in your Derby database (database files are located under
>> ${your.james.home}/var/store/derby - you will have to stop james and connect
>> via a jdbc client with the correct connect string
>> jdbc:derby:/${your.james.home}/var/store/derby).
>>
>> Thx, Eric
>>
>>
>> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>>
>>> Hi, Eric,
>>>
>>> Thanks for your help, kinda on the move these days, sorry for the late
>>> reply.
>>>
>>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>>> store, this seems more "safe" but less efficient. So, for better
>>> efficiency, I still prefer the direct way.
>>>
>>>
>>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>    wrote:
>>>>
>>>> Hi Jerry,
>>>>
>>>> Why do you want to store anything if you want to act as a proxy?
>>>> Shouldn't
>>>> you always delegate the request to the remote imap server?
>>>
>>>
>>> You are right, it do include 2-way data transfer, and the James server
>>> is acting as a gateway, the previous proxy concept is not accurate.
>>>
>>> It is used to bring a legacy client and a third party service together.
>>>
>>>>
>>>> To try to answer your question:
>>>> - which mailstore do you use: memory?
>>>
>>>
>>> Now, the test and debug installation is using the default Derby
>>> database, which should be the memory mail store you mentioned. In
>>> production env, MySQL
>>> is our choice.
>>>
>>>> - are you accessing the same mailstore when invoke getMessages()?
>>>
>>>
>>> Yes.
>>>
>>>>
>>>> Print also the content of the msgContent string before callen append().
>>>
>>>
>>> =========================================
>>>
>>> Subject: Coming soon
>>> From: abc@def.com<ab...@def.com>
>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>> Content-Type: text/html;
>>>         charset=utf-8
>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>> Message-Id:<a9...@def.com>
>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>> Content-Transfer-Encoding: 7bit
>>> Mime-Version: 1.0 (1.0)
>>>
>>> Coming soon
>>>
>>> =========================================
>>>
>>> This is the message I dumped before append(). Hope it helps.
>>>
>>>>
>>>> Thx, Eric
>>>>
>>>>
>>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>>
>>>>>
>>>>> Hi, Jame developers,
>>>>>
>>>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>>>> Currently I directly put my testing logic into the actual processor.
>>>>>
>>>>> In org.apache.james.imap.processor.SearchProcessor, before the actual
>>>>> searching happening, I am trying to insert/save some fake mails into
>>>>> mailbox using the provided MailboxManager.
>>>>>
>>>>> This is the code, more of a hack, which is borrowed from the
>>>>>   AppendProcessor.
>>>>>
>>>>> =========================================
>>>>>                         //add this message into mailbox.
>>>>>                         String msgContent =
>>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>>
>>>>>   noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>>                                         new
>>>>> Date(noteData.getCreatedAt()),
>>>>>                                         inoteUID,
>>>>>                                         null,
>>>>>                                         userId,
>>>>>                                         userDomain);
>>>>>
>>>>>                         logger.info("using raw msg content generated: " +
>>>>> msgContent);
>>>>>
>>>>>                         final MailboxPath mailboxPath = ...;
>>>>>                         final SelectedMailbox selectedMailbox =
>>>>> imapSession.getSelected();
>>>>>                         final boolean isSelectedMailbox = selectedMailbox
>>>>> != null&&
>>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>>
>>>>>                         mailbox.appendMessage(new
>>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>>                                         new
>>>>> Date(noteData.getCreatedAt()),
>>>>>                                         mailboxSession,
>>>>>                                         !isSelectedMailbox,
>>>>>                                         new Flags());
>>>>> =========================================
>>>>>
>>>>> And the referred getNewMsgStreamContent method is as below(the
>>>>> template used is dumped before using the same client and server):
>>>>>
>>>>> =========================================
>>>>>         private String getNewMsgStreamContent(String title, String
>>>>> content,
>>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>>> domain) {
>>>>>                 final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>>> MMM yyyy
>>>>> HH:mm:ss Z");
>>>>>
>>>>>                 if (cDate == null) {
>>>>>                         cDate = new Date();
>>>>>                 }
>>>>>                 String currDate = sdf.format(cDate);
>>>>>
>>>>>                 if (inoteUUID == null) {
>>>>>                         inoteUUID = UUID.randomUUID().toString();
>>>>>                 }
>>>>>
>>>>>                 if (msgUUID == null) {
>>>>>                         msgUUID = UUID.randomUUID().toString() + "@" +
>>>>> domain;
>>>>>                 }
>>>>>
>>>>>                 String syncUser = userId + "@" + domain;
>>>>>
>>>>>                 return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>>                                 .replaceAll("__SYNC_USER__", syncUser)
>>>>>                                 .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>>                                 .replaceAll("__MSG_UUID__", msgUUID)
>>>>>                                 .replaceAll("__CDATE__", currDate)
>>>>>                                 .replaceAll("__BODY__", content);
>>>>>         }
>>>>>
>>>>> =========================================
>>>>>
>>>>>   From my test, the above method will produce a message as this:
>>>>>
>>>>> =========================================
>>>>>
>>>>> Subject: Coming soon
>>>>> From: abc@def.com<ab...@def.com>
>>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>>> Content-Type: text/html;
>>>>>         charset=utf-8
>>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>>> Message-Id:<a9...@def.com>
>>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>>> Content-Transfer-Encoding: 7bit
>>>>> Mime-Version: 1.0 (1.0)
>>>>>
>>>>> Coming soon
>>>>>
>>>>> =========================================
>>>>>
>>>>> Although the invoking of appendMessage generates no exception so far,
>>>>> it turns out only an empty mail record is stored in this mail box.
>>>>> That is, the messageManager.getMessages(MessageRange,
>>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>>>> in search result, but only MessageResult.getUid() returns a valid
>>>>> value, and all other header values are missing(different from the
>>>>> normal mail records from real clients).
>>>>>
>>>>> Any clue why this is happening? And is there a more developer friendly
>>>>> way to directly save a "fake" mail into user's mailbox?
>>>>>
>>>>> Thanks a lot.
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>>
>>>>
>>>> --
>>>> eric | http://about.echarles.net | @echarles
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>> --
>> eric | http://about.echarles.net | @echarles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Jerry Tian <je...@gmail.com>.
Hi, Eric,

Thanks for your hint. This bug finally turned out to be my mistake on
new line characters("\r\n", not "\n") used in mail body stream.

Now the server is switched to MySQL as backend mail storage. There is
one thing I can't find out myself with respect to this deployment
configuration.

There is only one collection opened by James after starting it up. I
am guessing James is using Apache's common DBCP as its database
connection pool(since I found this JAR in "lib" directory), but how do
I configure it? A grep within the James directory doen't yield useful
search results, and the manual on website also doesn't mention it.

Regards.

On Mon, Jun 4, 2012 at 1:26 AM, Eric Charles <er...@apache.org> wrote:
> Hi Jerry,
>
> Not sure what's happening there. The String you give is not empty, so it
> should work.
>
> Kickoff your debuger and follow the path all the way down... Check also what
> is stored in your Derby database (database files are located under
> ${your.james.home}/var/store/derby - you will have to stop james and connect
> via a jdbc client with the correct connect string
> jdbc:derby:/${your.james.home}/var/store/derby).
>
> Thx, Eric
>
>
> On 06/03/2012 04:00 PM, Jerry Tian wrote:
>>
>> Hi, Eric,
>>
>> Thanks for your help, kinda on the move these days, sorry for the late
>> reply.
>>
>> BTW, I am also thinking of using a IMAP client to manipulate the mail
>> store, this seems more "safe" but less efficient. So, for better
>> efficiency, I still prefer the direct way.
>>
>>
>> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>  wrote:
>>>
>>> Hi Jerry,
>>>
>>> Why do you want to store anything if you want to act as a proxy?
>>> Shouldn't
>>> you always delegate the request to the remote imap server?
>>
>>
>> You are right, it do include 2-way data transfer, and the James server
>> is acting as a gateway, the previous proxy concept is not accurate.
>>
>> It is used to bring a legacy client and a third party service together.
>>
>>>
>>> To try to answer your question:
>>> - which mailstore do you use: memory?
>>
>>
>> Now, the test and debug installation is using the default Derby
>> database, which should be the memory mail store you mentioned. In
>> production env, MySQL
>> is our choice.
>>
>>> - are you accessing the same mailstore when invoke getMessages()?
>>
>>
>> Yes.
>>
>>>
>>> Print also the content of the msgContent string before callen append().
>>
>>
>> =========================================
>>
>> Subject: Coming soon
>> From: abc@def.com<ab...@def.com>
>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>> Content-Type: text/html;
>>        charset=utf-8
>> X-Uniform-Type-Identifier: com.apple.mail-note
>> Message-Id:<a9...@def.com>
>> Date: Thu, 24 May 2012 16:19:31 +0800
>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>> Content-Transfer-Encoding: 7bit
>> Mime-Version: 1.0 (1.0)
>>
>> Coming soon
>>
>> =========================================
>>
>> This is the message I dumped before append(). Hope it helps.
>>
>>>
>>> Thx, Eric
>>>
>>>
>>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>>
>>>>
>>>> Hi, Jame developers,
>>>>
>>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>>> Currently I directly put my testing logic into the actual processor.
>>>>
>>>> In org.apache.james.imap.processor.SearchProcessor, before the actual
>>>> searching happening, I am trying to insert/save some fake mails into
>>>> mailbox using the provided MailboxManager.
>>>>
>>>> This is the code, more of a hack, which is borrowed from the
>>>>  AppendProcessor.
>>>>
>>>> =========================================
>>>>                        //add this message into mailbox.
>>>>                        String msgContent =
>>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>>
>>>>  noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>>                                        new
>>>> Date(noteData.getCreatedAt()),
>>>>                                        inoteUID,
>>>>                                        null,
>>>>                                        userId,
>>>>                                        userDomain);
>>>>
>>>>                        logger.info("using raw msg content generated: " +
>>>> msgContent);
>>>>
>>>>                        final MailboxPath mailboxPath = ...;
>>>>                        final SelectedMailbox selectedMailbox =
>>>> imapSession.getSelected();
>>>>                        final boolean isSelectedMailbox = selectedMailbox
>>>> != null&&
>>>> selectedMailbox.getPath().equals(mailboxPath);
>>>>
>>>>                        mailbox.appendMessage(new
>>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>>                                        new
>>>> Date(noteData.getCreatedAt()),
>>>>                                        mailboxSession,
>>>>                                        !isSelectedMailbox,
>>>>                                        new Flags());
>>>> =========================================
>>>>
>>>> And the referred getNewMsgStreamContent method is as below(the
>>>> template used is dumped before using the same client and server):
>>>>
>>>> =========================================
>>>>        private String getNewMsgStreamContent(String title, String
>>>> content,
>>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>>> domain) {
>>>>                final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>>> MMM yyyy
>>>> HH:mm:ss Z");
>>>>
>>>>                if (cDate == null) {
>>>>                        cDate = new Date();
>>>>                }
>>>>                String currDate = sdf.format(cDate);
>>>>
>>>>                if (inoteUUID == null) {
>>>>                        inoteUUID = UUID.randomUUID().toString();
>>>>                }
>>>>
>>>>                if (msgUUID == null) {
>>>>                        msgUUID = UUID.randomUUID().toString() + "@" +
>>>> domain;
>>>>                }
>>>>
>>>>                String syncUser = userId + "@" + domain;
>>>>
>>>>                return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>>                                .replaceAll("__SYNC_USER__", syncUser)
>>>>                                .replaceAll("__INOTE_UUID__", inoteUUID)
>>>>                                .replaceAll("__MSG_UUID__", msgUUID)
>>>>                                .replaceAll("__CDATE__", currDate)
>>>>                                .replaceAll("__BODY__", content);
>>>>        }
>>>>
>>>> =========================================
>>>>
>>>>  From my test, the above method will produce a message as this:
>>>>
>>>> =========================================
>>>>
>>>> Subject: Coming soon
>>>> From: abc@def.com<ab...@def.com>
>>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>>> Content-Type: text/html;
>>>>        charset=utf-8
>>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>>> Message-Id:<a9...@def.com>
>>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>>> Content-Transfer-Encoding: 7bit
>>>> Mime-Version: 1.0 (1.0)
>>>>
>>>> Coming soon
>>>>
>>>> =========================================
>>>>
>>>> Although the invoking of appendMessage generates no exception so far,
>>>> it turns out only an empty mail record is stored in this mail box.
>>>> That is, the messageManager.getMessages(MessageRange,
>>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>>> in search result, but only MessageResult.getUid() returns a valid
>>>> value, and all other header values are missing(different from the
>>>> normal mail records from real clients).
>>>>
>>>> Any clue why this is happening? And is there a more developer friendly
>>>> way to directly save a "fake" mail into user's mailbox?
>>>>
>>>> Thanks a lot.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>>
>>>
>>> --
>>> eric | http://about.echarles.net | @echarles
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> --
> eric | http://about.echarles.net | @echarles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@apache.org>.
Hi Jerry,

Not sure what's happening there. The String you give is not empty, so it 
should work.

Kickoff your debuger and follow the path all the way down... Check also 
what is stored in your Derby database (database files are located under 
${your.james.home}/var/store/derby - you will have to stop james and 
connect via a jdbc client with the correct connect string 
jdbc:derby:/${your.james.home}/var/store/derby).

Thx, Eric

On 06/03/2012 04:00 PM, Jerry Tian wrote:
> Hi, Eric,
>
> Thanks for your help, kinda on the move these days, sorry for the late reply.
>
> BTW, I am also thinking of using a IMAP client to manipulate the mail
> store, this seems more "safe" but less efficient. So, for better
> efficiency, I still prefer the direct way.
>
>
> On Thu, May 31, 2012 at 1:32 AM, Eric Charles<er...@apache.org>  wrote:
>> Hi Jerry,
>>
>> Why do you want to store anything if you want to act as a proxy? Shouldn't
>> you always delegate the request to the remote imap server?
>
> You are right, it do include 2-way data transfer, and the James server
> is acting as a gateway, the previous proxy concept is not accurate.
>
> It is used to bring a legacy client and a third party service together.
>
>>
>> To try to answer your question:
>> - which mailstore do you use: memory?
>
> Now, the test and debug installation is using the default Derby
> database, which should be the memory mail store you mentioned. In
> production env, MySQL
> is our choice.
>
>> - are you accessing the same mailstore when invoke getMessages()?
>
> Yes.
>
>>
>> Print also the content of the msgContent string before callen append().
>
> =========================================
>
> Subject: Coming soon
> From: abc@def.com<ab...@def.com>
> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
> Content-Type: text/html;
>         charset=utf-8
> X-Uniform-Type-Identifier: com.apple.mail-note
> Message-Id:<a9...@def.com>
> Date: Thu, 24 May 2012 16:19:31 +0800
> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
> Content-Transfer-Encoding: 7bit
> Mime-Version: 1.0 (1.0)
>
> Coming soon
>
> =========================================
>
> This is the message I dumped before append(). Hope it helps.
>
>>
>> Thx, Eric
>>
>>
>> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>>
>>> Hi, Jame developers,
>>>
>>> I am building a proxy/gateway using james-imap-processor sub-module.
>>> Currently I directly put my testing logic into the actual processor.
>>>
>>> In org.apache.james.imap.processor.SearchProcessor, before the actual
>>> searching happening, I am trying to insert/save some fake mails into
>>> mailbox using the provided MailboxManager.
>>>
>>> This is the code, more of a hack, which is borrowed from the
>>>   AppendProcessor.
>>>
>>> =========================================
>>>                         //add this message into mailbox.
>>>                         String msgContent =
>>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>>
>>>   noteData.getNoteTitle(),//noteData.getNoteContent(),
>>>                                         new Date(noteData.getCreatedAt()),
>>>                                         inoteUID,
>>>                                         null,
>>>                                         userId,
>>>                                         userDomain);
>>>
>>>                         logger.info("using raw msg content generated: " +
>>> msgContent);
>>>
>>>                         final MailboxPath mailboxPath = ...;
>>>                         final SelectedMailbox selectedMailbox =
>>> imapSession.getSelected();
>>>                         final boolean isSelectedMailbox = selectedMailbox
>>> != null&&
>>> selectedMailbox.getPath().equals(mailboxPath);
>>>
>>>                         mailbox.appendMessage(new
>>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>>                                         new Date(noteData.getCreatedAt()),
>>>                                         mailboxSession,
>>>                                         !isSelectedMailbox,
>>>                                         new Flags());
>>> =========================================
>>>
>>> And the referred getNewMsgStreamContent method is as below(the
>>> template used is dumped before using the same client and server):
>>>
>>> =========================================
>>>         private String getNewMsgStreamContent(String title, String content,
>>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>>> domain) {
>>>                 final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>>> MMM yyyy
>>> HH:mm:ss Z");
>>>
>>>                 if (cDate == null) {
>>>                         cDate = new Date();
>>>                 }
>>>                 String currDate = sdf.format(cDate);
>>>
>>>                 if (inoteUUID == null) {
>>>                         inoteUUID = UUID.randomUUID().toString();
>>>                 }
>>>
>>>                 if (msgUUID == null) {
>>>                         msgUUID = UUID.randomUUID().toString() + "@" +
>>> domain;
>>>                 }
>>>
>>>                 String syncUser = userId + "@" + domain;
>>>
>>>                 return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>>                                 .replaceAll("__SYNC_USER__", syncUser)
>>>                                 .replaceAll("__INOTE_UUID__", inoteUUID)
>>>                                 .replaceAll("__MSG_UUID__", msgUUID)
>>>                                 .replaceAll("__CDATE__", currDate)
>>>                                 .replaceAll("__BODY__", content);
>>>         }
>>>
>>> =========================================
>>>
>>>   From my test, the above method will produce a message as this:
>>>
>>> =========================================
>>>
>>> Subject: Coming soon
>>> From: abc@def.com<ab...@def.com>
>>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>>> Content-Type: text/html;
>>>         charset=utf-8
>>> X-Uniform-Type-Identifier: com.apple.mail-note
>>> Message-Id:<a9...@def.com>
>>> Date: Thu, 24 May 2012 16:19:31 +0800
>>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>>> Content-Transfer-Encoding: 7bit
>>> Mime-Version: 1.0 (1.0)
>>>
>>> Coming soon
>>>
>>> =========================================
>>>
>>> Although the invoking of appendMessage generates no exception so far,
>>> it turns out only an empty mail record is stored in this mail box.
>>> That is, the messageManager.getMessages(MessageRange,
>>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>>> in search result, but only MessageResult.getUid() returns a valid
>>> value, and all other header values are missing(different from the
>>> normal mail records from real clients).
>>>
>>> Any clue why this is happening? And is there a more developer friendly
>>> way to directly save a "fake" mail into user's mailbox?
>>>
>>> Thanks a lot.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>> --
>> eric | http://about.echarles.net | @echarles
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Jerry Tian <je...@gmail.com>.
Hi, Eric,

Thanks for your help, kinda on the move these days, sorry for the late reply.

BTW, I am also thinking of using a IMAP client to manipulate the mail
store, this seems more "safe" but less efficient. So, for better
efficiency, I still prefer the direct way.


On Thu, May 31, 2012 at 1:32 AM, Eric Charles <er...@apache.org> wrote:
> Hi Jerry,
>
> Why do you want to store anything if you want to act as a proxy? Shouldn't
> you always delegate the request to the remote imap server?

You are right, it do include 2-way data transfer, and the James server
is acting as a gateway, the previous proxy concept is not accurate.

It is used to bring a legacy client and a third party service together.

>
> To try to answer your question:
> - which mailstore do you use: memory?

Now, the test and debug installation is using the default Derby
database, which should be the memory mail store you mentioned. In
production env, MySQL
is our choice.

> - are you accessing the same mailstore when invoke getMessages()?

Yes.

>
> Print also the content of the msgContent string before callen append().

=========================================

Subject: Coming soon
From: abc@def.com<ab...@def.com>
X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
Content-Type: text/html;
       charset=utf-8
X-Uniform-Type-Identifier: com.apple.mail-note
Message-Id:<a9...@def.com>
Date: Thu, 24 May 2012 16:19:31 +0800
X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (1.0)

Coming soon

=========================================

This is the message I dumped before append(). Hope it helps.

>
> Thx, Eric
>
>
> On 05/30/2012 05:20 PM, Jerry Tian wrote:
>>
>> Hi, Jame developers,
>>
>> I am building a proxy/gateway using james-imap-processor sub-module.
>> Currently I directly put my testing logic into the actual processor.
>>
>> In org.apache.james.imap.processor.SearchProcessor, before the actual
>> searching happening, I am trying to insert/save some fake mails into
>> mailbox using the provided MailboxManager.
>>
>> This is the code, more of a hack, which is borrowed from the
>>  AppendProcessor.
>>
>> =========================================
>>                        //add this message into mailbox.
>>                        String msgContent =
>> this.getNewMsgStreamContent(noteData.getNoteTitle(),
>>
>>  noteData.getNoteTitle(),//noteData.getNoteContent(),
>>                                        new Date(noteData.getCreatedAt()),
>>                                        inoteUID,
>>                                        null,
>>                                        userId,
>>                                        userDomain);
>>
>>                        logger.info("using raw msg content generated: " +
>> msgContent);
>>
>>                        final MailboxPath mailboxPath = ...;
>>                        final SelectedMailbox selectedMailbox =
>> imapSession.getSelected();
>>                        final boolean isSelectedMailbox = selectedMailbox
>> != null&&
>> selectedMailbox.getPath().equals(mailboxPath);
>>
>>                        mailbox.appendMessage(new
>> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
>>                                        new Date(noteData.getCreatedAt()),
>>                                        mailboxSession,
>>                                        !isSelectedMailbox,
>>                                        new Flags());
>> =========================================
>>
>> And the referred getNewMsgStreamContent method is as below(the
>> template used is dumped before using the same client and server):
>>
>> =========================================
>>        private String getNewMsgStreamContent(String title, String content,
>> Date cDate, String inoteUUID, String msgUUID, String userId, String
>> domain) {
>>                final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d
>> MMM yyyy
>> HH:mm:ss Z");
>>
>>                if (cDate == null) {
>>                        cDate = new Date();
>>                }
>>                String currDate = sdf.format(cDate);
>>
>>                if (inoteUUID == null) {
>>                        inoteUUID = UUID.randomUUID().toString();
>>                }
>>
>>                if (msgUUID == null) {
>>                        msgUUID = UUID.randomUUID().toString() + "@" +
>> domain;
>>                }
>>
>>                String syncUser = userId + "@" + domain;
>>
>>                return NEW_MSG_TPL.replaceAll("__TITLE__", title)
>>                                .replaceAll("__SYNC_USER__", syncUser)
>>                                .replaceAll("__INOTE_UUID__", inoteUUID)
>>                                .replaceAll("__MSG_UUID__", msgUUID)
>>                                .replaceAll("__CDATE__", currDate)
>>                                .replaceAll("__BODY__", content);
>>        }
>>
>> =========================================
>>
>>  From my test, the above method will produce a message as this:
>>
>> =========================================
>>
>> Subject: Coming soon
>> From: abc@def.com<ab...@def.com>
>> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
>> Content-Type: text/html;
>>        charset=utf-8
>> X-Uniform-Type-Identifier: com.apple.mail-note
>> Message-Id:<a9...@def.com>
>> Date: Thu, 24 May 2012 16:19:31 +0800
>> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
>> Content-Transfer-Encoding: 7bit
>> Mime-Version: 1.0 (1.0)
>>
>> Coming soon
>>
>> =========================================
>>
>> Although the invoking of appendMessage generates no exception so far,
>> it turns out only an empty mail record is stored in this mail box.
>> That is, the messageManager.getMessages(MessageRange,
>> FetchGroup.HEADERS, mailboxSession) does returns newly added records
>> in search result, but only MessageResult.getUid() returns a valid
>> value, and all other header values are missing(different from the
>> normal mail records from real clients).
>>
>> Any clue why this is happening? And is there a more developer friendly
>> way to directly save a "fake" mail into user's mailbox?
>>
>> Thanks a lot.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> --
> eric | http://about.echarles.net | @echarles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: How to use MailboxManager to insert a "fake" mail?

Posted by Eric Charles <er...@apache.org>.
Hi Jerry,

Why do you want to store anything if you want to act as a proxy? 
Shouldn't you always delegate the request to the remote imap server?

To try to answer your question:
- which mailstore do you use: memory?
- are you accessing the same mailstore when invoke getMessages()?

Print also the content of the msgContent string before callen append().

Thx, Eric

On 05/30/2012 05:20 PM, Jerry Tian wrote:
> Hi, Jame developers,
>
> I am building a proxy/gateway using james-imap-processor sub-module.
> Currently I directly put my testing logic into the actual processor.
>
> In org.apache.james.imap.processor.SearchProcessor, before the actual
> searching happening, I am trying to insert/save some fake mails into
> mailbox using the provided MailboxManager.
>
> This is the code, more of a hack, which is borrowed from the  AppendProcessor.
>
> =========================================
> 			//add this message into mailbox.
> 			String msgContent = this.getNewMsgStreamContent(noteData.getNoteTitle(),
> 					noteData.getNoteTitle(),//noteData.getNoteContent(),
> 					new Date(noteData.getCreatedAt()),
> 					inoteUID,
> 					null,
> 					userId,
> 					userDomain);
> 			
> 			logger.info("using raw msg content generated: " + msgContent);
> 				
> 			final MailboxPath mailboxPath = ...;
> 			final SelectedMailbox selectedMailbox = imapSession.getSelected();
> 			final boolean isSelectedMailbox = selectedMailbox != null&&
> selectedMailbox.getPath().equals(mailboxPath);
> 			
> 			mailbox.appendMessage(new
> ByteArrayInputStream(msgContent.getBytes("ISO-8859-1")),
> 					new Date(noteData.getCreatedAt()),
> 					mailboxSession,
> 					!isSelectedMailbox,
> 					new Flags());
> =========================================
>
> And the referred getNewMsgStreamContent method is as below(the
> template used is dumped before using the same client and server):
>
> =========================================
> 	private String getNewMsgStreamContent(String title, String content,
> Date cDate, String inoteUUID, String msgUUID, String userId, String
> domain) {
> 		final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy
> HH:mm:ss Z");
> 		
> 		if (cDate == null) {
> 			cDate = new Date();
> 		}
> 		String currDate = sdf.format(cDate);
> 		
> 		if (inoteUUID == null) {
> 			inoteUUID = UUID.randomUUID().toString();
> 		}
> 		
> 		if (msgUUID == null) {
> 			msgUUID = UUID.randomUUID().toString() + "@" + domain;
> 		}
> 		
> 		String syncUser = userId + "@" + domain;
> 		
> 		return NEW_MSG_TPL.replaceAll("__TITLE__", title)
> 				.replaceAll("__SYNC_USER__", syncUser)
> 				.replaceAll("__INOTE_UUID__", inoteUUID)
> 				.replaceAll("__MSG_UUID__", msgUUID)
> 				.replaceAll("__CDATE__", currDate)
> 				.replaceAll("__BODY__", content);
> 	}
>
> =========================================
>
>  From my test, the above method will produce a message as this:
>
> =========================================
>
> Subject: Coming soon
> From: abc@def.com<ab...@def.com>
> X-Universally-Unique-Identifier: 3f4e6172-042b-4363-8edb-a366751f8163
> Content-Type: text/html;
> 	charset=utf-8
> X-Uniform-Type-Identifier: com.apple.mail-note
> Message-Id:<a9...@def.com>
> Date: Thu, 24 May 2012 16:19:31 +0800
> X-Mail-Created-Date: Thu, 24 May 2012 16:19:31 +0800
> Content-Transfer-Encoding: 7bit
> Mime-Version: 1.0 (1.0)
>
> Coming soon
>
> =========================================
>
> Although the invoking of appendMessage generates no exception so far,
> it turns out only an empty mail record is stored in this mail box.
> That is, the messageManager.getMessages(MessageRange,
> FetchGroup.HEADERS, mailboxSession) does returns newly added records
> in search result, but only MessageResult.getUid() returns a valid
> value, and all other header values are missing(different from the
> normal mail records from real clients).
>
> Any clue why this is happening? And is there a more developer friendly
> way to directly save a "fake" mail into user's mailbox?
>
> Thanks a lot.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

-- 
eric | http://about.echarles.net | @echarles

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org