james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Tian <jerr...@gmail.com>
Subject Re: How to use MailboxManager to insert a "fake" mail?
Date Sun, 03 Jun 2012 14:00:19 GMT
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 <eric@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<abc@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:<a95c1844-a3cb-4726-9c3d-d8c9031a6c0b@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<abc@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:<a95c1844-a3cb-4726-9c3d-d8c9031a6c0b@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


Mime
View raw message