
Index: James.java
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/java/org/apache/james/James.java,v
retrieving revision 1.23
diff -r1.23 James.java
26a27,28
> import org.apache.james.imapserver.ACLMailbox;
> import org.apache.james.imapserver.Host;
92a95,98
>     // IMAP related fields
>     private boolean useIMAPstorage = false;
>     private Host imapHost;
>     
187,188d192
<         Configuration inboxConf = conf.getChild("inboxRepository");
<         Configuration inboxRepConf = inboxConf.getChild("repository");
190,193c194,200
<             localInbox = (MailRepository) mailstore.select(inboxRepConf);
<         } catch (Exception e) {
<             getLogger().error("Cannot open private MailRepository");
<             throw e;
---
>         // Get storage system
>             if (conf.getChild("storage").getValue().equals("IMAP")) {
>                 useIMAPstorage = true;
>                 getLogger().info("Using IMAP Store-System");
>             }
>         }catch(Exception e) {
>             // No Storage Entry in Config File found
195,196c202,223
<         inboxRootURL = inboxRepConf.getAttribute("destinationURL");
< 
---
>         
>         // Get the LocalInbox repository
>         if (useIMAPstorage) {
>             try {
>                 // We will need to use a no-args constructor for flexibility
>                 imapHost = (Host) compMgr.lookup( Host.ROLE );
>             } catch (Exception e) {
>                 getLogger().error("Exception in IMAP Storage init: " + e.getMessage());
>                 throw e;
>             }
>         } else {
>             Configuration inboxConf = conf.getChild("inboxRepository");
>             Configuration inboxRepConf = inboxConf.getChild("repository");
>             try {
>                 localInbox = (MailRepository) mailstore.select(inboxRepConf);
>             } catch (Exception e) {
>                 getLogger().error("Cannot open private MailRepository");
>                 throw e;
>             }
>             inboxRootURL = inboxRepConf.getAttribute("destinationURL");
>         }
>         
447,451c474,502
< 
<         Collection recipients = new HashSet();
<         recipients.add(recipient);
<         MailImpl mailImpl = new MailImpl(getId(), sender, recipients, message);
<         getUserInbox(username).store(mailImpl);
---
>         
>         if (useIMAPstorage) {
>             ACLMailbox mbox = null;
>             try {
>                 String folderName = "#user." + username + ".INBOX";
>                 getLogger().debug("Want to store to: " + folderName);
>                 mbox = imapHost.getMailbox(MailServer.MDA, folderName);
>                 if(mbox.store(message,MailServer.MDA)) {
>                     getLogger().info("Message " + message.getMessageID() +" stored in " + folderName);
>                 } else {
>                     throw new RuntimeException("Failed to store mail: ");
>                 }
>                 imapHost.releaseMailbox(MailServer.MDA, mbox);
>                 mbox = null;
>             } catch (Exception e) {
>                 getLogger().error("Exception storing mail: " + e);
>                 e.printStackTrace();
>                 if (mbox != null) {
>                     imapHost.releaseMailbox(MailServer.MDA, mbox);
>                     mbox = null;
>                 }
>                 throw new RuntimeException("Exception storing mail: " + e);
>             }
>         } else {
>             Collection recipients = new HashSet();
>             recipients.add(recipient);
>             MailImpl mailImpl = new MailImpl(getId(), sender, recipients, message);
>             getUserInbox(username).store(mailImpl);
>         }
486c537
< 
---
>    
489a541,542
>      * <p> As we move to IMAP support this will also create mailboxes and
>      * access control lists.
501a555,559
>         if (useIMAPstorage && success) {
>             if ( imapHost.createPrivateMailAccount(userName) ) {
>                 getLogger().info("New MailAccount created for" + userName);
>             }
>         }
