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: [email protected]<[email protected]>
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:<[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]
--
eric | http://about.echarles.net | @echarles
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]