Hello Eric,
That was quite the code I tested yesterday, but I got still the same
exception, because the MailboxManager is not initialized (null pointer
exception).
I tried the @Resource annotation, I got 'null pointer' and I tried the
BeanFactory way but I got a 'bean creation exception'...
I think the first method is the good one, but I'm still looking after the
magic method to instantiate my MailboxManager.

Thx,
Luc.


2011/1/20 Eric Charles <e...@apache.org>

> Hi,
>
> Probably you did not instantiate spring context.
>
> As first shot, you could copy Main to YourMain
>
> https://svn.apache.org/repos/asf/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/Main.java
>
> and hack it with for example with code sample in [1].
>
> You can also hack the spring context xml files if you don't want to load
> all the beans, but you will still need a few of them to access the mailbox.
>
> Obviously, we could discuss the following:
> 1. Add some code simple samples for basic operations on mailbox.
> 2. Have a spring context for mailbox that could be used as a stand-alone
> (and also be imported in server).
>
> Tks,
>
> Eric
>
> [1] code sample (non compiling).
>
> public class YourMain {
>
>    private static Log log = LogFactory.getLog(Main.class.getName());
>
>    @Ressource(name="mailboxmanager")
>    private static MailboxManager;
>
>    public static void main(String[] args) throws IOException {
>
>        final JamesServerApplicationContext context = new
> JamesServerApplicationContext(new String[] {
> "context/james-server-context.xml" });
>        context.registerShutdownHook();
>
>        // Bad code practice - Refactor it!!!
>
>        MailboxPath mailboxPath = MailboxPath.inbox("userName");
>
>        MailboxSession mailboxSession =
> mailboxManager.createSystemSession(userName30, log)
>        mailboxManager.startProcessingRequest(mailboxSession);
>        try {
>                mailboxManager.createMailbox(mailboxPath, mailboxSession);
>        }
>        catch (MailboxExistsException e) {
>                // Do nothing, the mailbox already exists.
>        }
>
>        mailboxManager.endProcessingRequest(mailboxSession);
>
>
>        MessageManager messageManager =
> mailboxManager.getMailbox("mailboxPath", mailboxSession);
>
>       // instanciate an input stream that contains your email content
> (body, header,...)
>
>        messageManager.appendMessage(your-input-stream,
>                       new Date(),
>                       mailboxSession,
>                       isRecent,
>                       flags);
>               mailboxManager.endProcessingRequest(mailboxSession);
>           }
>
>    }
>
> }
>
>
>
> On 19/01/2011 20:07, Luc Saulière wrote:
>
>> Thx for answering so quickly, I tried this in a new package inside
>> james-server-container-spring project...
>> I have a public static void main(String[] args) containing my private
>> staticMailboxManager mailboxManager which
>>
>> is injected with the annotation @Resource(name="mailboxmanager") from the
>> spring-bean.xml.
>> But it does not succeed in initializing the variable and I get a
>> NullPointerException as soon as I use it...
>> How can I initialize my beans without running the entire James app?
>>
>> Tks.
>>
>>
>> 2011/1/19 Eric Charles<e...@apache.org>
>>
>>  Hi Luc,
>>>
>>> Yes, code has changed in trunk since M2 (we don't use MailServer
>>> anymore).
>>> In M2, or in trunk, the way to store mail is the same.
>>> If you are deploying the your code/class in the james spring container,
>>> you
>>> need to inject the mailboxmanager (with @Resources(name="mailboxmanager")
>>> and have a block of code such as:
>>>
>>> MailboxPath mailboxPath = MailboxPath.inbox(userName30);
>>> MailboxSession mailboxSession =
>>> mailboxManager.createSystemSession(userName30, log)
>>> MessageManager messageManager = mailboxManager.getMailbox(mailboxPath,
>>> mailboxSession);
>>> messageManager.appendMessage(your-input-stream,
>>>                        new Date(),
>>>                        mailboxSession,
>>>                        isRecent,
>>>                        flags);
>>>                mailboxManager.endProcessingRequest(mailboxSession);
>>>            }
>>>
>>> I just realize I can't find a simple test case to in trunk to show this
>>> (or
>>> maybe I didn't look good).
>>> If we don't have this, maybe you could open a jira so we can further
>>> provide test samples.
>>> (this comes from  the fact that all our tests were made from an "imap
>>> perspective", we moved the imap test to another  project, but we probably
>>> should further enrich the pure mailbox test cases/samples).
>>>
>>> Tks,
>>>
>>> Eric
>>>
>>>
>>>
>>>
>>> On 19/01/2011 18:04, Luc Sauličre wrote:
>>>
>>>  Hello,
>>>> I'm developing with Math on the same mail app. We didn't succeed in
>>>> storing
>>>> mail as james3 does. In fact the SieveMailet class does not have a
>>>> setUsersRepo method, I think you're dealing with a newer version of
>>>> James3...
>>>> We are developing with the M2 one and SieveMailet have a setMailserver
>>>> method instead.
>>>> So, is there any way to store a mail (from another IMAP connection for
>>>> instance) in the James3 mySQL db, as James3 does (i.e. filling correctly
>>>> all
>>>> the appropriate tables...)?
>>>>
>>>> Thx for helping.
>>>> Luc.
>>>>
>>>> 2011/1/17 Eric Charles<e...@apache.org>
>>>>
>>>>  Hi,
>>>>
>>>>> The mails store magic occurs in LocalDelivery where the MailboxManager
>>>>> is
>>>>> injected.
>>>>> (more precise, LocalDelivery uses the SieveMailet initialized with the
>>>>> MailboxManager)
>>>>>        sieveMailet.setUsersRepository(usersRepository);
>>>>>        sieveMailet.setMailboxManager(mailboxManager);
>>>>>        sieveMailet.init(m);
>>>>>        sieveMailet.setQuiet(true);
>>>>> ...
>>>>>        if (mail.getState() != Mail.GHOST) {
>>>>>            sieveMailet.service(mail);
>>>>>        }
>>>>>
>>>>> You only need to know that *MailRepository is not for users' mail
>>>>> storage
>>>>> http://james.apache.org/server/3/feature-persistence.html
>>>>>
>>>>> Both topics (mailet usage for delivery + separate mail stores) are
>>>>> subject
>>>>> to discussion will certainly change.
>>>>>
>>>>> Tks,
>>>>>
>>>>> Eric
>>>>>
>>>>>
>>>>>
>>>>> On 17/01/2011 11:43, math math wrote:
>>>>>
>>>>>  Hello everybody,
>>>>>
>>>>>> I am developping a web mail project using james 3M2. I'm trying to
>>>>>> store
>>>>>> mails in a "james3" way with an external application using MySql DB.
>>>>>> I've
>>>>>> tried to store mails using mysq database repositories for a few days
>>>>>> now
>>>>>> but
>>>>>> i didn't succeed to do so... I 've traced the store method of
>>>>>> JDBCMailRepository class and also the ToRepository one. But still
>>>>>> don't
>>>>>> know
>>>>>> how James 3 is storing mails in the DB.
>>>>>>
>>>>>> I would be very glad if someone could help me in this task.
>>>>>>
>>>>>> Thanks,
>>>>>> Mat
>>>>>>
>>>>>>
>>>>>>  ---------------------------------------------------------------------
>>>>>>
>>>>> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
>>>>> For additional commands, e-mail: server-dev-h...@james.apache.org
>>>>>
>>>>>
>>>>>
>>>>>  ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
>>> For additional commands, e-mail: server-dev-h...@james.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
> For additional commands, e-mail: server-dev-h...@james.apache.org
>
>

Reply via email to