james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r834853 [1/2] - in /james/hupa/trunk: ./ client/src/main/java/org/apache/hupa/client/mvp/ client/src/main/java/org/apache/hupa/client/mvp/place/ server/src/main/java/org/apache/hupa/server/guice/ server/src/main/java/org/apache/hupa/server/...
Date Wed, 11 Nov 2009 12:38:14 GMT
Author: norman
Date: Wed Nov 11 12:38:13 2009
New Revision: 834853

URL: http://svn.apache.org/viewvc?rev=834853&view=rev
Log:
Better displaying of email messages (HUPA-47). Thx to Manuel Carrasco !

Added:
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java
Modified:
    james/hupa/trunk/README.txt
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/IMAPMessageListPresenterPlace.java
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MainPresenterPlace.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DispatchServletModule.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/MessageSourceServlet.java
    james/hupa/trunk/server/src/main/resources/mime/0.msg
    james/hupa/trunk/server/src/main/resources/mime/2.msg
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java

Modified: james/hupa/trunk/README.txt
URL: http://svn.apache.org/viewvc/james/hupa/trunk/README.txt?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/README.txt (original)
+++ james/hupa/trunk/README.txt Wed Nov 11 12:38:13 2009
@@ -48,3 +48,10 @@
        copy 'client/src/main/webapp/WEB-INF/web.xml' to 'war/WEB-INF'
   Then, set project's output directory to: /hupa/war/WEB-INF/classes
        properties -> Java Build Path -> Source -> Default output folder
+
+- If you compile hupa with google's eclipse plugin and you get the message:
+  >> 'GWT module hupa needs to be (re)compiled, please run a compile or use the Compile/Browse button in hosted mode'
+ 
+  Configure the plugin to compile only the 'Hupa' module.
+  Properties -> Google -> Web Toolkit -> Entry Point Modules -> Hupa - org.apache.hupa
+ 

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListPresenter.java Wed Nov 11 12:38:13 2009
@@ -81,14 +81,12 @@
         public HasClickHandlers getDeleteClick();
         public HasClickHandlers getDeleteAllClick();
         public HasEnable getDeleteEnable();
-
         public void reloadData();
         public void removeMessages(ArrayList<Message> messages);
         public ArrayList<Message> getSelectedMessages();
         public void reset();
         public HasDialog getConfirmDeleteDialog();
         public HasDialog getConfirmDeleteAllDialog();
-
         public HasClickHandlers getConfirmDeleteDialogClick();
         public HasClickHandlers getConfirmDeleteAllDialogClick();
         public void selectAllMessages();

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageListView.java Wed Nov 11 12:38:13 2009
@@ -21,7 +21,9 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.hupa.client.HupaConstants;
 import org.apache.hupa.client.HupaMessages;
@@ -69,6 +71,8 @@
 import com.google.gwt.gen2.table.event.client.PageLoadHandler;
 import com.google.gwt.gen2.table.event.client.RowCountChangeEvent;
 import com.google.gwt.gen2.table.event.client.RowCountChangeHandler;
+import com.google.gwt.gen2.table.event.client.RowSelectionEvent;
+import com.google.gwt.gen2.table.event.client.RowSelectionHandler;
 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Composite;
@@ -730,4 +734,5 @@
     public HasChangeHandlers getRowsPerPageChange() {
         return pageBox;
     }
+    
 }

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessagePresenter.java Wed Nov 11 12:38:13 2009
@@ -30,6 +30,7 @@
 import org.apache.hupa.client.HupaCallback;
 import org.apache.hupa.client.widgets.HasDialog;
 import org.apache.hupa.client.widgets.HasURL;
+import org.apache.hupa.shared.SConsts;
 import org.apache.hupa.shared.Util;
 import org.apache.hupa.shared.data.IMAPFolder;
 import org.apache.hupa.shared.data.Message;
@@ -101,13 +102,7 @@
         display.getCc().setText(Util.arrayToString(message.getCc()));
         display.getTo().setText(Util.arrayToString(message.getTo()));
         display.getSubject().setText(message.getSubject());
-        String con = messageDetails.getText();
-        // TODO: do this in the server so it is easier to test.
-        // The server should send all the messages as html.
-        if (messageDetails.isHTML() == false) {
-        	con = "<pre>" + Util.escapeHtmlTags(con) + "</pre>";
-        }
-        display.getContent().setHTML(con);
+        display.getContent().setHTML(messageDetails.getText());
         display.setAttachments(messageDetails.getMessageAttachments(), folder.getFullName(),message.getUid());
     }
 
@@ -160,7 +155,10 @@
         registerHandler(display.getShowRawMessageClick().addClickHandler(new ClickHandler() {
 
             public void onClick(ClickEvent event) {
-                String message_url = GWT.getModuleBaseURL() + "messageSourceServlet?uid=" + message.getUid() + "&folder=" + folder.getFullName();
+                String message_url = GWT.getModuleBaseURL() + SConsts.SERVLET_SOURCE + 
+                "?" + SConsts.PARAM_UID + "=" + message.getUid() + 
+                "&" + SConsts.PARAM_FOLDER + "=" + folder.getFullName();
+                
                 display.getRawMessageURL().setUrl(message_url);
                 display.getRawMessageDialog().center();
             }

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/IMAPMessageView.java Wed Nov 11 12:38:13 2009
@@ -29,6 +29,7 @@
 import org.apache.hupa.client.widgets.Iframe;
 import org.apache.hupa.client.widgets.Loading;
 import org.apache.hupa.client.widgets.MyDialogBox;
+import org.apache.hupa.shared.SConsts;
 import org.apache.hupa.shared.data.MessageAttachment;
 import org.cobogw.gwt.user.client.ui.Button;
 import org.cobogw.gwt.user.client.ui.ButtonBar;
@@ -230,10 +231,11 @@
 
                     public void onClick(ClickEvent event) {
                          DOM.setElementAttribute(RootPanel.get("__download")
-                                 .getElement(), "src", GWT.getModuleBaseURL()
-                                 + "downloadAttachmentServlet?attachment_name="
-                                 + a.getName() + "&folder_name=" + folder
-                                 + "&message_uuid=" + uid);
+                                 .getElement(), "src", 
+                                 GWT.getModuleBaseURL() + SConsts.SERVLET_DOWNLOAD 
+                                 + "?" + SConsts.PARAM_NAME + "=" + a.getName() 
+                                 + "&" + SConsts.PARAM_FOLDER + "=" + folder
+                                 + "&" + SConsts.PARAM_UID + "=" + uid);
                     }
 
                 });

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java Wed Nov 11 12:38:13 2009
@@ -1,539 +1,566 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.hupa.client.mvp;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-
-import net.customware.gwt.presenter.client.EventBus;
-import net.customware.gwt.presenter.client.widget.WidgetContainerDisplay;
-import net.customware.gwt.presenter.client.widget.WidgetContainerPresenter;
-
-import org.apache.hupa.client.CachingDispatchAsync;
-import org.apache.hupa.client.HupaCallback;
-import org.apache.hupa.client.mvp.MessageSendPresenter.Type;
-import org.apache.hupa.client.widgets.HasDialog;
-import org.apache.hupa.client.widgets.IMAPTreeItem;
-import org.apache.hupa.shared.data.IMAPFolder;
-import org.apache.hupa.shared.data.Message;
-import org.apache.hupa.shared.data.MessageDetails;
-import org.apache.hupa.shared.data.User;
-import org.apache.hupa.shared.data.Message.IMAPFlag;
-import org.apache.hupa.shared.events.BackEvent;
-import org.apache.hupa.shared.events.BackEventHandler;
-import org.apache.hupa.shared.events.DecreaseUnseenEvent;
-import org.apache.hupa.shared.events.DecreaseUnseenEventHandler;
-import org.apache.hupa.shared.events.ExpandMessageEvent;
-import org.apache.hupa.shared.events.ExpandMessageEventHandler;
-import org.apache.hupa.shared.events.FolderSelectionEvent;
-import org.apache.hupa.shared.events.FolderSelectionEventHandler;
-import org.apache.hupa.shared.events.ForwardMessageEvent;
-import org.apache.hupa.shared.events.ForwardMessageEventHandler;
-import org.apache.hupa.shared.events.IncreaseUnseenEvent;
-import org.apache.hupa.shared.events.IncreaseUnseenEventHandler;
-import org.apache.hupa.shared.events.LoadMessagesEvent;
-import org.apache.hupa.shared.events.LoadMessagesEventHandler;
-import org.apache.hupa.shared.events.LoginEvent;
-import org.apache.hupa.shared.events.LoginEventHandler;
-import org.apache.hupa.shared.events.MessagesReceivedEvent;
-import org.apache.hupa.shared.events.MessagesReceivedEventHandler;
-import org.apache.hupa.shared.events.NewMessageEvent;
-import org.apache.hupa.shared.events.NewMessageEventHandler;
-import org.apache.hupa.shared.events.ReplyMessageEvent;
-import org.apache.hupa.shared.events.ReplyMessageEventHandler;
-import org.apache.hupa.shared.events.SentMessageEvent;
-import org.apache.hupa.shared.events.SentMessageEventHandler;
-import org.apache.hupa.shared.rpc.CreateFolder;
-import org.apache.hupa.shared.rpc.DeleteFolder;
-import org.apache.hupa.shared.rpc.FetchFolders;
-import org.apache.hupa.shared.rpc.FetchFoldersResult;
-import org.apache.hupa.shared.rpc.GenericResult;
-import org.apache.hupa.shared.rpc.GetMessageDetails;
-import org.apache.hupa.shared.rpc.GetMessageDetailsResult;
-import org.apache.hupa.shared.rpc.RenameFolder;
-import org.apache.hupa.widgets.event.EditEvent;
-import org.apache.hupa.widgets.event.EditHandler;
-import org.apache.hupa.widgets.ui.HasEditable;
-import org.apache.hupa.widgets.ui.HasEnable;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.HasClickHandlers;
-import com.google.gwt.event.logical.shared.HasSelectionHandlers;
-import com.google.gwt.event.logical.shared.SelectionEvent;
-import com.google.gwt.event.logical.shared.SelectionHandler;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.HasValue;
-import com.google.gwt.user.client.ui.TreeItem;
-import com.google.inject.Inject;
-
-/**
- *
- */
-public class MainPresenter extends WidgetContainerPresenter<MainPresenter.Display> {
-
-    public interface Display extends WidgetContainerDisplay {
-        
-        public HasClickHandlers getSearchClick();
-
-        public HasValue<String> getSearchValue();
-
-        public void fillSearchOracle(ArrayList<Message> messages);
-
-        public HasSelectionHandlers<TreeItem> getTree();
-
-        public void bindTreeItems(ArrayList<IMAPTreeItem> treeList);
-
-        public HasClickHandlers getRenameClick();
-
-        public HasClickHandlers getDeleteClick();
-
-        public HasClickHandlers getNewClick();
-
-        public HasDialog getDeleteConfirmDialog();
-
-        public HasClickHandlers getDeleteConfirmClick();
-
-        public HasEnable getRenameEnable();
-
-        public HasEnable getDeleteEnable();
-
-        public HasEnable getNewEnable();
-
-        public void updateTreeItem(IMAPFolder folder);
-
-        public void deleteSelectedFolder();
-
-        public HasEditable createFolder(EditHandler handler);
-
-        public void increaseUnseenMessageCount(IMAPFolder folder, int amount);
-
-        public void decreaseUnseenMessageCount(IMAPFolder folder, int amount);
-        
-        public void setLoadingFolders(boolean loading);
-        public void setLoadingMessage(boolean loading);
-
-    }
-
-    private CachingDispatchAsync cachingDispatcher;
-    private User user;
-    private IMAPFolder folder;
-    private IMAPMessageListPresenter messageListPresenter;
-    private IMAPMessagePresenter messagePresenter;
-    private MessageSendPresenter sendPresenter;
-    private IMAPTreeItem tItem;
-    private HasEditable editableTreeItem;
-    
-    @Inject
-    public MainPresenter(MainPresenter.Display display, EventBus bus, CachingDispatchAsync cachingDispatcher, IMAPMessageListPresenter messageListPresenter, IMAPMessagePresenter messagePresenter,
-            MessageSendPresenter sendPresenter) {
-        super(display, bus, messageListPresenter, messagePresenter, sendPresenter);
-        this.cachingDispatcher = cachingDispatcher;
-        this.messageListPresenter = messageListPresenter;
-        this.messagePresenter = messagePresenter;
-        this.sendPresenter = sendPresenter;
-    }
-
-    protected void loadTreeItems() {
-        display.setLoadingFolders(true);
-        cachingDispatcher.execute(new FetchFolders(), new HupaCallback<FetchFoldersResult>(cachingDispatcher, eventBus, display) {
-            public void callback(FetchFoldersResult result) {
-                display.bindTreeItems(createTreeNodes(result.getFolders()));
-                // disable
-                display.getDeleteEnable().setEnabled(false);
-                display.getRenameEnable().setEnabled(false);
-                display.setLoadingFolders(false);
-
-            }
-        });
-    }
-
-    /**
-     * Create recursive the TreeNodes with all childs
-     * 
-     * @param list
-     * @return
-     */
-    private ArrayList<IMAPTreeItem> createTreeNodes(ArrayList<IMAPFolder> list) {
-        ArrayList<IMAPTreeItem> tList = new ArrayList<IMAPTreeItem>();
-
-        for (int i = 0; i < list.size(); i++) {
-            IMAPFolder iFolder = list.get(i);
-
-            final IMAPTreeItem record = new IMAPTreeItem(iFolder);
-            record.addEditHandler(new EditHandler() {
-
-                public void onEditEvent(EditEvent event) {
-                    if (event.getEventType().equals(EditEvent.EventType.Stop)) {
-                        IMAPFolder iFolder = new IMAPFolder((String) event.getOldValue());
-                        final String newName = (String) event.getNewValue();
-                        if (iFolder.getFullName().equalsIgnoreCase(newName) == false) {
-                            cachingDispatcher.execute(new RenameFolder(iFolder, newName), new HupaCallback<GenericResult>(cachingDispatcher, eventBus) {
-                                public void callback(GenericResult result) {
-                                    folder.setFullName(newName);
-                                }
-                                public void callbackError(Throwable caught) {
-                                    record.cancelEdit();
-                                }
-                            }); 
-                        }
-                    }
-                }
-
-            });
-            record.setUserObject(iFolder);
-
-            ArrayList<IMAPFolder> childFolders = iFolder.getChildIMAPFolders();
-            if (childFolders != null && childFolders.isEmpty() == false) {
-                ArrayList<IMAPTreeItem> items = createTreeNodes(childFolders);
-                for (int a = 0; a < items.size(); a++) {
-                    record.addItem(items.get(a));
-                }
-            }
-
-            // Store the INBOX as starting point after first loading
-            if (iFolder.getFullName().equals(user.getSettings().getInboxFolderName())) {
-                folder = iFolder;
-                tItem = record;
-            }
-
-            tList.add(record);
-        }
-
-        // Sort tree
-        Collections.sort(tList, new Comparator<TreeItem>() {
-
-            public int compare(TreeItem o1, TreeItem o2) {
-                return o1.getText().compareTo(o2.getText());
-            }
-
-        });
-        return tList;
-    }
-
-    private void showMessageTable(User user, IMAPFolder folder) {
-        this.user = user;
-        this.folder = folder;
-        messageListPresenter.revealDisplay(user, folder);
-    }
-
-    private void showMessage(User user, IMAPFolder folder, Message message, MessageDetails details) {
-        messagePresenter.revealDisplay(user, folder, message, details);
-    }
-
-    private void showNewMessage() {
-        sendPresenter.revealDisplay(user);
-    }
-
-    private void showForwardMessage(ForwardMessageEvent event) {
-        sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.FORWARD);
-    }
-
-    private void showReplyMessage(ReplyMessageEvent event) {
-        if (event.getReplyAll()) {
-            sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.REPLY_ALL);
-        } else {
-            sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.REPLY);
-
-        }
-        sendPresenter.revealDisplay();
-    }
-
-    /**
-     * Reset the presenter and display
-     */
-    private void reset() {
-        display.getSearchValue().setValue("");
-        // clear the cache
-        cachingDispatcher.clear();
-    }
-
-
-    @Override
-    protected void onBind() {
-        super.onBind();
-        registerHandler(eventBus.addHandler(LoadMessagesEvent.TYPE, new LoadMessagesEventHandler() {
-
-            public void onLoadMessagesEvent(LoadMessagesEvent loadMessagesEvent) {
-                showMessageTable(loadMessagesEvent.getUser(), loadMessagesEvent.getFolder());
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(MessagesReceivedEvent.TYPE, new MessagesReceivedEventHandler() {
-
-            public void onMessagesReceived(MessagesReceivedEvent event) {
-
-                // fill the oracle
-                display.fillSearchOracle(event.getMessages());
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(ExpandMessageEvent.TYPE, new ExpandMessageEventHandler() {
-
-            public void onExpandMessage(ExpandMessageEvent event) {
-                final boolean decreaseUnseen;
-                final Message message = event.getMessage();
-                // check if the message was already seen in the past
-                if (event.getMessage().getFlags().contains(IMAPFlag.SEEN) == false) {
-                    decreaseUnseen = true;
-                } else {
-                    decreaseUnseen = false;
-                }
-
-                display.setLoadingMessage(true);
-                cachingDispatcher.executeWithCache(new GetMessageDetails(event.getFolder(), message.getUid()), new HupaCallback<GetMessageDetailsResult>(cachingDispatcher, eventBus, display) {
-                    public void callback(GetMessageDetailsResult result) {
-                        if (decreaseUnseen) {
-                            eventBus.fireEvent(new DecreaseUnseenEvent(user, folder));
-                        }
-                        display.setLoadingMessage(false);
-                        showMessage(user, folder, message, result.getMessageDetails());
-                    }
-                });
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(NewMessageEvent.TYPE, new NewMessageEventHandler() {
-
-            public void onNewMessageEvent(NewMessageEvent event) {
-                showNewMessage();
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(SentMessageEvent.TYPE, new SentMessageEventHandler() {
-
-            public void onSentMessageEvent(SentMessageEvent ev) {
-                showMessageTable(user, folder);
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(ForwardMessageEvent.TYPE, new ForwardMessageEventHandler() {
-
-            public void onForwardMessageEvent(ForwardMessageEvent event) {
-                showForwardMessage(event);
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(ReplyMessageEvent.TYPE, new ReplyMessageEventHandler() {
-
-            public void onReplyMessageEvent(ReplyMessageEvent event) {
-                showReplyMessage(event);
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(FolderSelectionEvent.TYPE, new FolderSelectionEventHandler() {
-
-            public void onFolderSelectionEvent(FolderSelectionEvent event) {
-                user = event.getUser();
-                folder = event.getFolder();
-                showMessageTable(user, event.getFolder());
-            }
-
-        }));
-
-        registerHandler(display.getSearchClick().addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                String searchValue = null;
-                if (display.getSearchValue().getValue().trim().length() > 0) {
-                    searchValue = display.getSearchValue().getValue().trim();
-                }
-                eventBus.fireEvent(new LoadMessagesEvent(user, folder, searchValue));
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(BackEvent.TYPE, new BackEventHandler() {
-
-            public void onBackEvent(BackEvent event) {
-                showMessageTable(user, folder);
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(ExpandMessageEvent.TYPE, new ExpandMessageEventHandler() {
-
-            public void onExpandMessage(ExpandMessageEvent event) {
-                if (editableTreeItem != null && editableTreeItem.isEdit()) {
-                    editableTreeItem.cancelEdit();
-                }
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(NewMessageEvent.TYPE, new NewMessageEventHandler() {
-
-            public void onNewMessageEvent(NewMessageEvent event) {
-                if (editableTreeItem != null && editableTreeItem.isEdit()) {
-                    editableTreeItem.cancelEdit();
-                }
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(DecreaseUnseenEvent.TYPE, new DecreaseUnseenEventHandler() {
-
-            public void onDecreaseUnseenEvent(DecreaseUnseenEvent event) {
-                display.decreaseUnseenMessageCount(event.getFolder(), event.getAmount());
-            }
-
-        }));
-        registerHandler(eventBus.addHandler(IncreaseUnseenEvent.TYPE, new IncreaseUnseenEventHandler() {
-
-            public void onIncreaseUnseenEvent(IncreaseUnseenEvent event) {
-                display.increaseUnseenMessageCount(event.getFolder(), event.getAmount());
-            }
-
-        }));
-        registerHandler(display.getTree().addSelectionHandler(new SelectionHandler<TreeItem>() {
-
-            public void onSelection(SelectionEvent<TreeItem> event) {
-                tItem = (IMAPTreeItem) event.getSelectedItem();
-                folder = (IMAPFolder) tItem.getUserObject();
-                eventBus.fireEvent(new LoadMessagesEvent(user, folder));
-            }
-
-        }));
-
-        registerHandler(display.getTree().addSelectionHandler(new SelectionHandler<TreeItem>() {
-
-            public void onSelection(SelectionEvent<TreeItem> event) {
-                tItem = (IMAPTreeItem) event.getSelectedItem();
-                folder = (IMAPFolder) tItem.getUserObject();
-                if (folder.getFullName().equalsIgnoreCase(user.getSettings().getInboxFolderName())) {
-                    display.getDeleteEnable().setEnabled(false);
-                    display.getRenameEnable().setEnabled(false);
-                } else {
-                    display.getDeleteEnable().setEnabled(true);
-                    display.getRenameEnable().setEnabled(true);
-                }
-            }
-
-        }));
-
-        registerHandler(display.getRenameClick().addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                tItem.startEdit();
-            }
-
-        }));
-
-        registerHandler(display.getDeleteClick().addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                display.getDeleteConfirmDialog().show();
-            }
-
-        }));
-
-        registerHandler(display.getDeleteConfirmClick().addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                cachingDispatcher.execute(new DeleteFolder(folder), new AsyncCallback<GenericResult>() {
-
-                    public void onFailure(Throwable caught) {
-                        GWT.log("ERROR while deleting", caught);
-                    }
-
-                    public void onSuccess(GenericResult result) {
-                        display.deleteSelectedFolder();
-                    }
-
-                });
-            }
-
-        }));
-
-        registerHandler(display.getNewClick().addClickHandler(new ClickHandler() {
-
-            public void onClick(ClickEvent event) {
-                editableTreeItem = display.createFolder(new EditHandler() {
-
-                    public void onEditEvent(EditEvent event) {
-                        final IMAPTreeItem item = (IMAPTreeItem) event.getSource();
-                        final String newValue = (String) event.getNewValue();
-                        if (event.getEventType().equals(EditEvent.EventType.Stop)) {
-                            cachingDispatcher.execute(new CreateFolder(new IMAPFolder(newValue.trim())), new AsyncCallback<GenericResult>() {
-
-                                public void onFailure(Throwable caught) {
-                                    GWT.log("Error while create folder", caught);
-                                    item.cancelEdit();
-                                }
-
-                                public void onSuccess(GenericResult result) {
-                                    // Nothing todo
-                                }
-
-                            });
-                        }
-                    }
-
-                });
-            }
-
-        }));
-
-        registerHandler(eventBus.addHandler(MessagesReceivedEvent.TYPE, new MessagesReceivedEventHandler() {
-
-            public void onMessagesReceived(MessagesReceivedEvent event) {
-                IMAPFolder f = event.getFolder();
-                display.updateTreeItem(f);
-            }
-
-        }));
-        
-        registerHandler(eventBus.addHandler(LoginEvent.TYPE,  new LoginEventHandler() {
-
-            public void onLogin(LoginEvent event) {
-                user = event.getUser();
-                folder = new IMAPFolder(user.getSettings().getInboxFolderName());
-            }
-            
-        }));
-
-    }
-
-
-    @Override
-    protected void onUnbind() {
-        reset();
-
-        super.onUnbind();
-    }
-
-    
-    public void revealDisplay(User user) {
-        this.user = user;
-        loadTreeItems();  
-        firePresenterChangedEvent();
-        revealDisplay();
-    }
-    
-    @Override
-    protected void onRevealDisplay() {
-        showMessageTable(user, folder);
-
-        super.onRevealDisplay();
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.hupa.client.mvp;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+import net.customware.gwt.presenter.client.EventBus;
+import net.customware.gwt.presenter.client.widget.WidgetContainerDisplay;
+import net.customware.gwt.presenter.client.widget.WidgetContainerPresenter;
+
+import org.apache.hupa.client.CachingDispatchAsync;
+import org.apache.hupa.client.HupaCallback;
+import org.apache.hupa.client.mvp.MessageSendPresenter.Type;
+import org.apache.hupa.client.widgets.HasDialog;
+import org.apache.hupa.client.widgets.IMAPTreeItem;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.Message;
+import org.apache.hupa.shared.data.MessageDetails;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.data.Message.IMAPFlag;
+import org.apache.hupa.shared.events.BackEvent;
+import org.apache.hupa.shared.events.BackEventHandler;
+import org.apache.hupa.shared.events.DecreaseUnseenEvent;
+import org.apache.hupa.shared.events.DecreaseUnseenEventHandler;
+import org.apache.hupa.shared.events.ExpandMessageEvent;
+import org.apache.hupa.shared.events.ExpandMessageEventHandler;
+import org.apache.hupa.shared.events.FolderSelectionEvent;
+import org.apache.hupa.shared.events.FolderSelectionEventHandler;
+import org.apache.hupa.shared.events.ForwardMessageEvent;
+import org.apache.hupa.shared.events.ForwardMessageEventHandler;
+import org.apache.hupa.shared.events.IncreaseUnseenEvent;
+import org.apache.hupa.shared.events.IncreaseUnseenEventHandler;
+import org.apache.hupa.shared.events.LoadMessagesEvent;
+import org.apache.hupa.shared.events.LoadMessagesEventHandler;
+import org.apache.hupa.shared.events.LoginEvent;
+import org.apache.hupa.shared.events.LoginEventHandler;
+import org.apache.hupa.shared.events.MessagesReceivedEvent;
+import org.apache.hupa.shared.events.MessagesReceivedEventHandler;
+import org.apache.hupa.shared.events.NewMessageEvent;
+import org.apache.hupa.shared.events.NewMessageEventHandler;
+import org.apache.hupa.shared.events.ReplyMessageEvent;
+import org.apache.hupa.shared.events.ReplyMessageEventHandler;
+import org.apache.hupa.shared.events.SentMessageEvent;
+import org.apache.hupa.shared.events.SentMessageEventHandler;
+import org.apache.hupa.shared.rpc.CreateFolder;
+import org.apache.hupa.shared.rpc.DeleteFolder;
+import org.apache.hupa.shared.rpc.FetchFolders;
+import org.apache.hupa.shared.rpc.FetchFoldersResult;
+import org.apache.hupa.shared.rpc.GenericResult;
+import org.apache.hupa.shared.rpc.GetMessageDetails;
+import org.apache.hupa.shared.rpc.GetMessageDetailsResult;
+import org.apache.hupa.shared.rpc.RenameFolder;
+import org.apache.hupa.widgets.event.EditEvent;
+import org.apache.hupa.widgets.event.EditHandler;
+import org.apache.hupa.widgets.ui.HasEditable;
+import org.apache.hupa.widgets.ui.HasEnable;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.HasClickHandlers;
+import com.google.gwt.event.logical.shared.HasSelectionHandlers;
+import com.google.gwt.event.logical.shared.SelectionEvent;
+import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.gwt.user.client.ui.TreeItem;
+import com.google.inject.Inject;
+
+/**
+ *
+ */
+public class MainPresenter extends WidgetContainerPresenter<MainPresenter.Display> {
+
+    public interface Display extends WidgetContainerDisplay {
+        
+        public HasClickHandlers getSearchClick();
+
+        public HasValue<String> getSearchValue();
+
+        public void fillSearchOracle(ArrayList<Message> messages);
+
+        public HasSelectionHandlers<TreeItem> getTree();
+
+        public void bindTreeItems(ArrayList<IMAPTreeItem> treeList);
+
+        public HasClickHandlers getRenameClick();
+
+        public HasClickHandlers getDeleteClick();
+
+        public HasClickHandlers getNewClick();
+
+        public HasDialog getDeleteConfirmDialog();
+
+        public HasClickHandlers getDeleteConfirmClick();
+
+        public HasEnable getRenameEnable();
+
+        public HasEnable getDeleteEnable();
+
+        public HasEnable getNewEnable();
+
+        public void updateTreeItem(IMAPFolder folder);
+
+        public void deleteSelectedFolder();
+
+        public HasEditable createFolder(EditHandler handler);
+
+        public void increaseUnseenMessageCount(IMAPFolder folder, int amount);
+
+        public void decreaseUnseenMessageCount(IMAPFolder folder, int amount);
+        
+        public void setLoadingFolders(boolean loading);
+        public void setLoadingMessage(boolean loading);
+
+    }
+
+    private CachingDispatchAsync cachingDispatcher;
+    private User user;
+    private IMAPFolder folder;
+    private IMAPMessageListPresenter messageListPresenter;
+    private IMAPMessagePresenter messagePresenter;
+    private MessageSendPresenter sendPresenter;
+    private IMAPTreeItem tItem;
+    private HasEditable editableTreeItem;
+    
+    @Inject
+    public MainPresenter(MainPresenter.Display display, EventBus bus, CachingDispatchAsync cachingDispatcher, IMAPMessageListPresenter messageListPresenter, IMAPMessagePresenter messagePresenter,
+            MessageSendPresenter sendPresenter) {
+        super(display, bus, messageListPresenter, messagePresenter, sendPresenter);
+        this.cachingDispatcher = cachingDispatcher;
+        this.messageListPresenter = messageListPresenter;
+        this.messagePresenter = messagePresenter;
+        this.sendPresenter = sendPresenter;
+        
+    }
+
+    protected void loadTreeItems() {
+        display.setLoadingFolders(true);
+        cachingDispatcher.execute(new FetchFolders(), new HupaCallback<FetchFoldersResult>(cachingDispatcher, eventBus, display) {
+            public void callback(FetchFoldersResult result) {
+                display.bindTreeItems(createTreeNodes(result.getFolders()));
+                // disable
+                display.getDeleteEnable().setEnabled(false);
+                display.getRenameEnable().setEnabled(false);
+                display.setLoadingFolders(false);
+
+            }
+        });
+    }
+
+    /**
+     * Create recursive the TreeNodes with all childs
+     * 
+     * @param list
+     * @return
+     */
+    private ArrayList<IMAPTreeItem> createTreeNodes(ArrayList<IMAPFolder> list) {
+        ArrayList<IMAPTreeItem> tList = new ArrayList<IMAPTreeItem>();
+
+        for (int i = 0; i < list.size(); i++) {
+            IMAPFolder iFolder = list.get(i);
+
+            final IMAPTreeItem record = new IMAPTreeItem(iFolder);
+            record.addEditHandler(new EditHandler() {
+
+                public void onEditEvent(EditEvent event) {
+                    if (event.getEventType().equals(EditEvent.EventType.Stop)) {
+                        IMAPFolder iFolder = new IMAPFolder((String) event.getOldValue());
+                        final String newName = (String) event.getNewValue();
+                        if (iFolder.getFullName().equalsIgnoreCase(newName) == false) {
+                            cachingDispatcher.execute(new RenameFolder(iFolder, newName), new HupaCallback<GenericResult>(cachingDispatcher, eventBus) {
+                                public void callback(GenericResult result) {
+                                    folder.setFullName(newName);
+                                }
+                                public void callbackError(Throwable caught) {
+                                    record.cancelEdit();
+                                }
+                            }); 
+                        }
+                    }
+                }
+
+            });
+            record.setUserObject(iFolder);
+
+            ArrayList<IMAPFolder> childFolders = iFolder.getChildIMAPFolders();
+            if (childFolders != null && childFolders.isEmpty() == false) {
+                ArrayList<IMAPTreeItem> items = createTreeNodes(childFolders);
+                for (int a = 0; a < items.size(); a++) {
+                    record.addItem(items.get(a));
+                }
+            }
+
+            // Store the INBOX as starting point after first loading
+            if (iFolder.getFullName().equals(user.getSettings().getInboxFolderName())) {
+                folder = iFolder;
+                tItem = record;
+            }
+
+            tList.add(record);
+        }
+
+        // Sort tree
+        Collections.sort(tList, new Comparator<TreeItem>() {
+
+            public int compare(TreeItem o1, TreeItem o2) {
+                return o1.getText().compareTo(o2.getText());
+            }
+
+        });
+        return tList;
+    }
+
+    private void showMessageTable(User user, IMAPFolder folder) {
+        this.user = user;
+        this.folder = folder;
+        messageListPresenter.revealDisplay(user, folder);
+    }
+
+    private void showMessage(User user, IMAPFolder folder, Message message, MessageDetails details) {
+        messagePresenter.revealDisplay(user, folder, message, details);
+    }
+
+    private void showNewMessage() {
+        sendPresenter.revealDisplay(user);
+    }
+
+    private void showForwardMessage(ForwardMessageEvent event) {
+        sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.FORWARD);
+    }
+
+    private void showReplyMessage(ReplyMessageEvent event) {
+        if (event.getReplyAll()) {
+            sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.REPLY_ALL);
+        } else {
+            sendPresenter.revealDisplay(event.getUser(), event.getFolder(), event.getMessage(), event.getMessageDetails(), Type.REPLY);
+
+        }
+        sendPresenter.revealDisplay();
+    }
+
+    /**
+     * Reset the presenter and display
+     */
+    private void reset() {
+        display.getSearchValue().setValue("");
+        // clear the cache
+        cachingDispatcher.clear();
+    }
+
+
+    @Override
+    protected void onBind() {
+        super.onBind();
+        registerHandler(eventBus.addHandler(LoadMessagesEvent.TYPE, new LoadMessagesEventHandler() {
+
+            public void onLoadMessagesEvent(LoadMessagesEvent loadMessagesEvent) {
+                showMessageTable(loadMessagesEvent.getUser(), loadMessagesEvent.getFolder());
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(MessagesReceivedEvent.TYPE, new MessagesReceivedEventHandler() {
+
+            public void onMessagesReceived(MessagesReceivedEvent event) {
+
+                // fill the oracle
+                display.fillSearchOracle(event.getMessages());
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(ExpandMessageEvent.TYPE, new ExpandMessageEventHandler() {
+
+            public void onExpandMessage(ExpandMessageEvent event) {
+                final boolean decreaseUnseen;
+                final Message message = event.getMessage();
+                // check if the message was already seen in the past
+                if (event.getMessage().getFlags().contains(IMAPFlag.SEEN) == false) {
+                    decreaseUnseen = true;
+                } else {
+                    decreaseUnseen = false;
+                }
+
+                display.setLoadingMessage(true);
+                cachingDispatcher.executeWithCache(new GetMessageDetails(event.getFolder(), message.getUid()), new HupaCallback<GetMessageDetailsResult>(cachingDispatcher, eventBus, display) {
+                    public void callback(GetMessageDetailsResult result) {
+                        if (decreaseUnseen) {
+                            eventBus.fireEvent(new DecreaseUnseenEvent(user, folder));
+                        }
+                        display.setLoadingMessage(false);
+                        showMessage(user, folder, message, result.getMessageDetails());
+                    }
+                });
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(NewMessageEvent.TYPE, new NewMessageEventHandler() {
+
+            public void onNewMessageEvent(NewMessageEvent event) {
+                showNewMessage();
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(SentMessageEvent.TYPE, new SentMessageEventHandler() {
+
+            public void onSentMessageEvent(SentMessageEvent ev) {
+                showMessageTable(user, folder);
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(ForwardMessageEvent.TYPE, new ForwardMessageEventHandler() {
+
+            public void onForwardMessageEvent(ForwardMessageEvent event) {
+                showForwardMessage(event);
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(ReplyMessageEvent.TYPE, new ReplyMessageEventHandler() {
+
+            public void onReplyMessageEvent(ReplyMessageEvent event) {
+                showReplyMessage(event);
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(FolderSelectionEvent.TYPE, new FolderSelectionEventHandler() {
+
+            public void onFolderSelectionEvent(FolderSelectionEvent event) {
+                user = event.getUser();
+                folder = event.getFolder();
+                showMessageTable(user, event.getFolder());
+            }
+
+        }));
+
+        registerHandler(display.getSearchClick().addClickHandler(new ClickHandler() {
+
+            public void onClick(ClickEvent event) {
+                String searchValue = null;
+                if (display.getSearchValue().getValue().trim().length() > 0) {
+                    searchValue = display.getSearchValue().getValue().trim();
+                }
+                eventBus.fireEvent(new LoadMessagesEvent(user, folder, searchValue));
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(BackEvent.TYPE, new BackEventHandler() {
+
+            public void onBackEvent(BackEvent event) {
+                showMessageTable(user, folder);
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(ExpandMessageEvent.TYPE, new ExpandMessageEventHandler() {
+
+            public void onExpandMessage(ExpandMessageEvent event) {
+                if (editableTreeItem != null && editableTreeItem.isEdit()) {
+                    editableTreeItem.cancelEdit();
+                }
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(NewMessageEvent.TYPE, new NewMessageEventHandler() {
+
+            public void onNewMessageEvent(NewMessageEvent event) {
+                if (editableTreeItem != null && editableTreeItem.isEdit()) {
+                    editableTreeItem.cancelEdit();
+                }
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(DecreaseUnseenEvent.TYPE, new DecreaseUnseenEventHandler() {
+
+            public void onDecreaseUnseenEvent(DecreaseUnseenEvent event) {
+                display.decreaseUnseenMessageCount(event.getFolder(), event.getAmount());
+            }
+
+        }));
+        registerHandler(eventBus.addHandler(IncreaseUnseenEvent.TYPE, new IncreaseUnseenEventHandler() {
+
+            public void onIncreaseUnseenEvent(IncreaseUnseenEvent event) {
+                display.increaseUnseenMessageCount(event.getFolder(), event.getAmount());
+            }
+
+        }));
+        registerHandler(display.getTree().addSelectionHandler(new SelectionHandler<TreeItem>() {
+
+            public void onSelection(SelectionEvent<TreeItem> event) {
+                tItem = (IMAPTreeItem) event.getSelectedItem();
+                folder = (IMAPFolder) tItem.getUserObject();
+                eventBus.fireEvent(new LoadMessagesEvent(user, folder));
+            }
+
+        }));
+
+        registerHandler(display.getTree().addSelectionHandler(new SelectionHandler<TreeItem>() {
+
+            public void onSelection(SelectionEvent<TreeItem> event) {
+                tItem = (IMAPTreeItem) event.getSelectedItem();
+                folder = (IMAPFolder) tItem.getUserObject();
+                if (folder.getFullName().equalsIgnoreCase(user.getSettings().getInboxFolderName())) {
+                    display.getDeleteEnable().setEnabled(false);
+                    display.getRenameEnable().setEnabled(false);
+                } else {
+                    display.getDeleteEnable().setEnabled(true);
+                    display.getRenameEnable().setEnabled(true);
+                }
+            }
+
+        }));
+
+        registerHandler(display.getRenameClick().addClickHandler(new ClickHandler() {
+
+            public void onClick(ClickEvent event) {
+                tItem.startEdit();
+            }
+
+        }));
+
+        registerHandler(display.getDeleteClick().addClickHandler(new ClickHandler() {
+
+            public void onClick(ClickEvent event) {
+                display.getDeleteConfirmDialog().show();
+            }
+
+        }));
+
+        registerHandler(display.getDeleteConfirmClick().addClickHandler(new ClickHandler() {
+
+            public void onClick(ClickEvent event) {
+                cachingDispatcher.execute(new DeleteFolder(folder), new AsyncCallback<GenericResult>() {
+
+                    public void onFailure(Throwable caught) {
+                        GWT.log("ERROR while deleting", caught);
+                    }
+
+                    public void onSuccess(GenericResult result) {
+                        display.deleteSelectedFolder();
+                    }
+
+                });
+            }
+
+        }));
+
+        registerHandler(display.getNewClick().addClickHandler(new ClickHandler() {
+
+            public void onClick(ClickEvent event) {
+                editableTreeItem = display.createFolder(new EditHandler() {
+
+                    public void onEditEvent(EditEvent event) {
+                        final IMAPTreeItem item = (IMAPTreeItem) event.getSource();
+                        final String newValue = (String) event.getNewValue();
+                        if (event.getEventType().equals(EditEvent.EventType.Stop)) {
+                            cachingDispatcher.execute(new CreateFolder(new IMAPFolder(newValue.trim())), new AsyncCallback<GenericResult>() {
+
+                                public void onFailure(Throwable caught) {
+                                    GWT.log("Error while create folder", caught);
+                                    item.cancelEdit();
+                                }
+
+                                public void onSuccess(GenericResult result) {
+                                    // Nothing todo
+                                }
+
+                            });
+                        }
+                    }
+
+                });
+            }
+
+        }));
+
+        registerHandler(eventBus.addHandler(MessagesReceivedEvent.TYPE, new MessagesReceivedEventHandler() {
+
+            public void onMessagesReceived(MessagesReceivedEvent event) {
+                IMAPFolder f = event.getFolder();
+                display.updateTreeItem(f);
+            }
+
+        }));
+        
+        registerHandler(eventBus.addHandler(LoginEvent.TYPE,  new LoginEventHandler() {
+
+            public void onLogin(LoginEvent event) {
+                user = event.getUser();
+                folder = new IMAPFolder(user.getSettings().getInboxFolderName());
+            }
+            
+        }));
+        
+        // Export native javascript methods
+        exportJSMethods(this);
+
+    }
+
+
+    @Override
+    protected void onUnbind() {
+        reset();
+
+        super.onUnbind();
+    }
+
+    
+    public void revealDisplay(User user) {
+        this.user = user;
+        loadTreeItems();  
+        firePresenterChangedEvent();
+        revealDisplay();
+    }
+    
+    @Override
+    protected void onRevealDisplay() {
+        showMessageTable(user, folder);
+        super.onRevealDisplay();
+    }
+    
+    public void openLink(String url) {
+        Window.open(url, "_blank", "");
+    }
+
+    public void mailTo(String mailto) {
+        sendPresenter.revealDisplay(user, mailto);
+    }
+    
+    private native void exportJSMethods(MainPresenter presenter) /*-{
+      $wnd.openLink = function(url) {
+        try {
+           presenter.@org.apache.hupa.client.mvp.MainPresenter::openLink(Ljava/lang/String;) (url);
+        } catch(e) {}
+        return false;
+      };
+      $wnd.mailTo = function(mail) {
+        try {
+           presenter.@org.apache.hupa.client.mvp.MainPresenter::mailTo(Ljava/lang/String;) (mail);
+        } catch(e) {}
+        return false;
+      };
+    }-*/;
+}

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java Wed Nov 11 12:38:13 2009
@@ -327,7 +327,7 @@
      * @param oldDetails the olddetails ( if there are any)
      * @param type the type 
      */
-    public void revealDisplay(User user, IMAPFolder folder, Message oldmessage, MessageDetails oldDetails, Type type) {
+    public void revealDisplay(User user, IMAPFolder folder, Message oldmessage, MessageDetails oldDetails, String mailto, Type type) {
         this.oldmessage = oldmessage;
         this.oldDetails = oldDetails;
         this.folder = folder;
@@ -365,9 +365,19 @@
 
             }
         }
+        if (mailto != null)
+            display.getToText().setText(mailto);
         firePresenterChangedEvent();
         revealDisplay();
     }
+
+    public void revealDisplay(User user, IMAPFolder folder, Message oldmessage, MessageDetails oldDetails, Type type) {
+        this.revealDisplay(user, folder, oldmessage, oldDetails, null, type);
+    }
+
+    public void revealDisplay(User user, String mailto) {
+        revealDisplay(user, null, null, null, mailto, Type.NEW);
+    }
     
     /**
      * Bind the given user to the presenter
@@ -375,7 +385,7 @@
      * @param user
      */
     public void revealDisplay(User user) {
-        revealDisplay(user,null,null,null, Type.NEW);
+        revealDisplay(user,null,null,null, null,Type.NEW);
     }
 
     @Override

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendView.java Wed Nov 11 12:38:13 2009
@@ -28,6 +28,7 @@
 import org.apache.hupa.client.widgets.Loading;
 import org.apache.hupa.client.widgets.EnableButton;
 import org.apache.hupa.widgets.ui.EnableHyperlink;
+import org.apache.hupa.shared.SConsts;
 import org.apache.hupa.widgets.ui.HasEnable;
 
 import com.google.gwt.core.client.GWT;
@@ -156,7 +157,7 @@
         text.setVisibleLines(50);
 
         uploadStatus.setCancelConfiguration(IUploadStatus.GMAIL_CANCEL_CFG);
-        uploader.setServletPath(GWT.getModuleBaseURL() + "uploadAttachmentServlet");
+        uploader.setServletPath(GWT.getModuleBaseURL() + SConsts.SERVLET_UPLOAD);
         uploader.avoidRepeatFiles(true);
         uploader.setI18Constants(constants);
         
@@ -275,8 +276,7 @@
     public void resetUploader() {
         uploader.removeFromParent();
         uploader = new MultiUploader();
-        uploader.setServletPath(GWT.getModuleBaseURL()
-                + "uploadAttachmentServlet");
+        uploader.setServletPath(GWT.getModuleBaseURL() + SConsts.SERVLET_UPLOAD);
         uploader.avoidRepeatFiles(true);
         detailGrid.setWidget(5, 1, uploader);        
     }

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/IMAPMessageListPresenterPlace.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/IMAPMessageListPresenterPlace.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/IMAPMessageListPresenterPlace.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/IMAPMessageListPresenterPlace.java Wed Nov 11 12:38:13 2009
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.hupa.client.mvp.place;
 
+
 import org.apache.hupa.client.mvp.IMAPMessageListPresenter;
 
 import com.google.gwt.core.client.GWT;
@@ -67,6 +68,7 @@
     protected PlaceRequest prepareRequest(PlaceRequest request, IMAPMessageListPresenter presenter) {
         request = request.with(PAGE, presenter.getDisplay().getCurrentPage() +"");
         request = request.with(ROWS_PER_PAGE_INDEX, presenter.getDisplay().getRowsPerPageIndex() + "");
+      
         GWT.log("REQ="+request.toString(),null);
 
         return request;

Modified: james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MainPresenterPlace.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MainPresenterPlace.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MainPresenterPlace.java (original)
+++ james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/place/MainPresenterPlace.java Wed Nov 11 12:38:13 2009
@@ -24,6 +24,7 @@
 import com.google.inject.Provider;
 
 import net.customware.gwt.presenter.client.gin.ProvidedPresenterPlace;
+import net.customware.gwt.presenter.client.place.PlaceRequest;
 
 public class MainPresenterPlace extends ProvidedPresenterPlace<MainPresenter>{
 
@@ -37,4 +38,18 @@
         return "Main";
     }
 
+    @Override
+    protected void preparePresenter(PlaceRequest request, MainPresenter presenter) {
+        // TODO Auto-generated method stub
+        super.preparePresenter(request, presenter);
+    }
+
+    @Override
+    protected PlaceRequest prepareRequest(PlaceRequest request, MainPresenter presenter) {
+        // TODO Auto-generated method stub
+        return super.prepareRequest(request, presenter);
+    }
+    
+    
+
 }

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DispatchServletModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DispatchServletModule.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DispatchServletModule.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/DispatchServletModule.java Wed Nov 11 12:38:13 2009
@@ -1,39 +1,40 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.hupa.server.guice;
-
-
-import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
-import org.apache.hupa.server.servlet.HupaDispatchServlet;
-import org.apache.hupa.server.servlet.MessageSourceServlet;
-import org.apache.hupa.server.servlet.UploadAttachmentServlet;
-
-import com.google.inject.servlet.ServletModule;
-
-
-public class DispatchServletModule extends ServletModule{
-     @Override
-        public void configureServlets() {
-             serve("/hupa/dispatch").with(HupaDispatchServlet.class );
-             serve("/hupa/downloadAttachmentServlet").with(DownloadAttachmentServlet.class);
-             serve("/hupa/uploadAttachmentServlet").with(UploadAttachmentServlet.class);
-             serve("/hupa/messageSourceServlet").with(MessageSourceServlet.class);
-        }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.hupa.server.guice;
+
+
+import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
+import org.apache.hupa.server.servlet.HupaDispatchServlet;
+import org.apache.hupa.server.servlet.MessageSourceServlet;
+import org.apache.hupa.server.servlet.UploadAttachmentServlet;
+import org.apache.hupa.shared.SConsts;
+
+import com.google.inject.servlet.ServletModule;
+
+
+public class DispatchServletModule extends ServletModule{
+     @Override
+        public void configureServlets() {
+             serve("/" + SConsts.HUPA + SConsts.SERVLET_DISPATCH).with(HupaDispatchServlet.class );
+             serve("/" + SConsts.HUPA + SConsts.SERVLET_DOWNLOAD).with(DownloadAttachmentServlet.class);
+             serve("/" + SConsts.HUPA + SConsts.SERVLET_UPLOAD).with(UploadAttachmentServlet.class);
+             serve("/" + SConsts.HUPA + SConsts.SERVLET_SOURCE).with(MessageSourceServlet.class);
+        }
+}

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java?rev=834853&r1=834852&r2=834853&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/guice/ServerModul.java Wed Nov 11 12:38:13 2009
@@ -1,195 +1,193 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.hupa.server.guice;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Properties;
-
-import javax.mail.Session;
-
-import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
-
-import org.apache.commons.logging.Log;
-import org.apache.hupa.server.FileItemRegistry;
-import org.apache.hupa.server.IMAPStoreCache;
-import org.apache.hupa.server.InMemoryIMAPStoreCache;
-import org.apache.hupa.server.handler.CheckSessionHandler;
-import org.apache.hupa.server.handler.CreateFolderHandler;
-import org.apache.hupa.server.handler.DeleteAllMessagesHandler;
-import org.apache.hupa.server.handler.DeleteFolderHandler;
-import org.apache.hupa.server.handler.DeleteMessageByUidHandler;
-import org.apache.hupa.server.handler.FetchFoldersHandler;
-import org.apache.hupa.server.handler.FetchMessagesHandler;
-import org.apache.hupa.server.handler.FetchRecentMessagesHandler;
-import org.apache.hupa.server.handler.ForwardMessageHandler;
-import org.apache.hupa.server.handler.GetMessageDetailsHandler;
-import org.apache.hupa.server.handler.GetRawMessageHandler;
-import org.apache.hupa.server.handler.LoginUserHandler;
-import org.apache.hupa.server.handler.LogoutUserHandler;
-import org.apache.hupa.server.handler.MoveMessageHandler;
-import org.apache.hupa.server.handler.NoopHandler;
-import org.apache.hupa.server.handler.RenameFolderHandler;
-import org.apache.hupa.server.handler.ReplyMessageHandler;
-import org.apache.hupa.server.handler.SendMessageHandler;
-import org.apache.hupa.server.handler.SetFlagsHandler;
-import org.apache.hupa.server.handler.TagMessagesHandler;
-import org.apache.hupa.server.mock.MockIMAPFolder;
-import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
-import org.apache.hupa.server.servlet.MessageSourceServlet;
-import org.apache.hupa.server.servlet.UploadAttachmentServlet;
-import org.apache.hupa.shared.data.Settings;
-
-import com.google.inject.Singleton;
-import com.google.inject.name.Names;
-
-/**
- * Module which binds the handlers and configurations
- * 
- * 
- */
-public class ServerModul extends ActionHandlerModule {
-
-    public static final String SYS_PROP_CONFIG_FILE = "hupa.config.file";
-
-    public static final String CONFIG_FILE_NAME = "config.properties";
-    public static final String[] CONFIG_PROPERTIES = {
-            System.getenv("HOME") + "/.hupa/" + CONFIG_FILE_NAME,
-            "/etc/default/hupa"
-            };
-    public static final String CONF_DIR = "WEB-INF/conf/";
-
-    private String configDir;
-    
-    public ServerModul(String rootPath) {
-        configDir = rootPath + "/" + CONF_DIR;
-    }
-
-    @Override
-    protected void configureHandlers() {
-        bindHandler(CheckSessionHandler.class);
-        bindHandler(LoginUserHandler.class);
-        bindHandler(FetchFoldersHandler.class);
-        bindHandler(FetchMessagesHandler.class);
-        bindHandler(FetchRecentMessagesHandler.class);
-        bindHandler(LogoutUserHandler.class);
-        bindHandler(GetMessageDetailsHandler.class);
-        bindHandler(DeleteMessageByUidHandler.class);
-        bindHandler(DeleteAllMessagesHandler.class);
-        bindHandler(SendMessageHandler.class);
-        bindHandler(ReplyMessageHandler.class);
-        bindHandler(ForwardMessageHandler.class);
-        bindHandler(NoopHandler.class);
-        bindHandler(MoveMessageHandler.class);
-        bindHandler(RenameFolderHandler.class);
-        bindHandler(DeleteFolderHandler.class);
-        bindHandler(CreateFolderHandler.class);
-        bindHandler(TagMessagesHandler.class);
-        bindHandler(GetRawMessageHandler.class);
-        bindHandler(SetFlagsHandler.class);
-        bind(FileItemRegistry.class).in(Singleton.class);
-        bind(IMAPStoreCache.class).to(InMemoryIMAPStoreCache.class).in(
-                Singleton.class);
-        bind(Log.class).toProvider(LogProvider.class).in(Singleton.class);
-        bind(Settings.class).toProvider(DefaultUserSettingsProvider.class).in(
-                Singleton.class);
-        bind(DownloadAttachmentServlet.class).in(Singleton.class);
-        bind(UploadAttachmentServlet.class).in(Singleton.class);
-        bind(MessageSourceServlet.class).in(Singleton.class);
-        bind(Session.class).toProvider(SessionProvider.class);
-
-        Properties properties;
-        try {
-            // Bind addresses and ports for imap and smtp
-            properties = loadProperties();
-            Names.bindProperties(binder(), properties);
-        } catch (Exception e) {
-            throw new RuntimeException("Unable to to configure hupa server," +
-                    "\nmake sure that you have a valid /etc/default/hupa file" +
-                    "\nor the web container has been started with the appropriate parameter:" +
-                    " -Dhupa.config.file=your_hupa_properties_file", e);
-        }
-    }
-
-    protected Properties loadProperties() throws Exception {
-        Properties properties = null;
-        properties = loadProperties(configDir + CONFIG_FILE_NAME);
-
-        if (properties == null) {
-            String fileName = System.getProperty(SYS_PROP_CONFIG_FILE);
-            if (fileName != null) {
-                properties = loadProperties(fileName);
-            }
-
-            if (properties == null) {
-                for (String name : CONFIG_PROPERTIES) {
-                    properties = loadProperties(name);
-                    if (properties != null)
-                        break;
-                }
-            }
-        }
-
-        // Configure default parameters for Hupa in demo mode
-        if (properties == null || InMemoryIMAPStoreCache.DEMO_MODE.equals(properties.get("IMAPServerAddress"))) {
-            properties = new Properties();
-			properties.put("IMAPServerAddress", InMemoryIMAPStoreCache.DEMO_MODE);
-			properties.put("IMAPServerPort", "143");
-			properties.put("IMAPS", "false");
-			properties.put("SMTPServerAddress", InMemoryIMAPStoreCache.DEMO_MODE);
-			properties.put("SMTPServerPort", "25");
-			properties.put("SMTPS", "false");
-			properties.put("SMTPAuth", "false");
-			
-			properties.put("DefaultInboxFolder", MockIMAPFolder.mockSettings.getInboxFolderName());
-			properties.put("DefaultTrashFolder", MockIMAPFolder.mockSettings.getTrashFolderName());
-			properties.put("DefaultSentFolder", MockIMAPFolder.mockSettings.getSentFolderName());
-			properties.put("PostFetchMessageCount", "0");
-        }
-        
-        return properties;
-    }
-
-    protected Properties loadProperties(String name) {
-
-        if (name == null)
-            return null;
-
-        Properties properties = null;
-        File file = new File(name);
-        
-        // check if the file is absolute. If not prefix it with the default config dir
-        if (file.isAbsolute() == false) {
-            file = new File(configDir + File.separator + file.getName());
-        }
-        if (file.exists()) {
-            try {
-                properties = new Properties();
-                properties.load(new FileInputStream(file));
-            } catch (Exception e) {
-                properties = null;    
-                e.printStackTrace();
-            }
-        }
-        
-        return properties;
-    }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.hupa.server.guice;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import javax.mail.Session;
+
+import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.InMemoryIMAPStoreCache;
+import org.apache.hupa.server.handler.CheckSessionHandler;
+import org.apache.hupa.server.handler.CreateFolderHandler;
+import org.apache.hupa.server.handler.DeleteAllMessagesHandler;
+import org.apache.hupa.server.handler.DeleteFolderHandler;
+import org.apache.hupa.server.handler.DeleteMessageByUidHandler;
+import org.apache.hupa.server.handler.FetchFoldersHandler;
+import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.handler.FetchRecentMessagesHandler;
+import org.apache.hupa.server.handler.ForwardMessageHandler;
+import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.LoginUserHandler;
+import org.apache.hupa.server.handler.LogoutUserHandler;
+import org.apache.hupa.server.handler.MoveMessageHandler;
+import org.apache.hupa.server.handler.NoopHandler;
+import org.apache.hupa.server.handler.RenameFolderHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
+import org.apache.hupa.server.handler.SendMessageHandler;
+import org.apache.hupa.server.handler.SetFlagsHandler;
+import org.apache.hupa.server.handler.TagMessagesHandler;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
+import org.apache.hupa.server.servlet.MessageSourceServlet;
+import org.apache.hupa.server.servlet.UploadAttachmentServlet;
+import org.apache.hupa.shared.data.Settings;
+
+import com.google.inject.Singleton;
+import com.google.inject.name.Names;
+
+/**
+ * Module which binds the handlers and configurations
+ * 
+ * 
+ */
+public class ServerModul extends ActionHandlerModule {
+
+    public static final String SYS_PROP_CONFIG_FILE = "hupa.config.file";
+
+    public static final String CONFIG_FILE_NAME = "config.properties";
+    public static final String[] CONFIG_PROPERTIES = {
+            System.getenv("HOME") + "/.hupa/" + CONFIG_FILE_NAME,
+            "/etc/default/hupa"
+            };
+    public static final String CONF_DIR = "WEB-INF/conf/";
+
+    private String configDir;
+    
+    public ServerModul(String rootPath) {
+        configDir = rootPath + "/" + CONF_DIR;
+    }
+
+    @Override
+    protected void configureHandlers() {
+        bindHandler(CheckSessionHandler.class);
+        bindHandler(LoginUserHandler.class);
+        bindHandler(FetchFoldersHandler.class);
+        bindHandler(FetchMessagesHandler.class);
+        bindHandler(FetchRecentMessagesHandler.class);
+        bindHandler(LogoutUserHandler.class);
+        bindHandler(GetMessageDetailsHandler.class);
+        bindHandler(DeleteMessageByUidHandler.class);
+        bindHandler(DeleteAllMessagesHandler.class);
+        bindHandler(SendMessageHandler.class);
+        bindHandler(ReplyMessageHandler.class);
+        bindHandler(ForwardMessageHandler.class);
+        bindHandler(NoopHandler.class);
+        bindHandler(MoveMessageHandler.class);
+        bindHandler(RenameFolderHandler.class);
+        bindHandler(DeleteFolderHandler.class);
+        bindHandler(CreateFolderHandler.class);
+        bindHandler(TagMessagesHandler.class);
+        bindHandler(SetFlagsHandler.class);
+        bind(FileItemRegistry.class).in(Singleton.class);
+        bind(IMAPStoreCache.class).to(InMemoryIMAPStoreCache.class).in(
+                Singleton.class);
+        bind(Log.class).toProvider(LogProvider.class).in(Singleton.class);
+        bind(Settings.class).toProvider(DefaultUserSettingsProvider.class).in(
+                Singleton.class);
+        bind(DownloadAttachmentServlet.class).in(Singleton.class);
+        bind(UploadAttachmentServlet.class).in(Singleton.class);
+        bind(MessageSourceServlet.class).in(Singleton.class);
+        bind(Session.class).toProvider(SessionProvider.class);
+
+        Properties properties;
+        try {
+            // Bind addresses and ports for imap and smtp
+            properties = loadProperties();
+            Names.bindProperties(binder(), properties);
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to to configure hupa server," +
+                    "\nmake sure that you have a valid /etc/default/hupa file" +
+                    "\nor the web container has been started with the appropriate parameter:" +
+                    " -Dhupa.config.file=your_hupa_properties_file", e);
+        }
+    }
+
+    protected Properties loadProperties() throws Exception {
+        Properties properties = null;
+        properties = loadProperties(configDir + CONFIG_FILE_NAME);
+
+        if (properties == null) {
+            String fileName = System.getProperty(SYS_PROP_CONFIG_FILE);
+            if (fileName != null) {
+                properties = loadProperties(fileName);
+            }
+
+            if (properties == null) {
+                for (String name : CONFIG_PROPERTIES) {
+                    properties = loadProperties(name);
+                    if (properties != null)
+                        break;
+                }
+            }
+        }
+
+        // Configure default parameters for Hupa in demo mode
+        if (properties == null || InMemoryIMAPStoreCache.DEMO_MODE.equals(properties.get("IMAPServerAddress"))) {
+            properties = new Properties();
+			properties.put("IMAPServerAddress", InMemoryIMAPStoreCache.DEMO_MODE);
+			properties.put("IMAPServerPort", "143");
+			properties.put("IMAPS", "false");
+			properties.put("SMTPServerAddress", InMemoryIMAPStoreCache.DEMO_MODE);
+			properties.put("SMTPServerPort", "25");
+			properties.put("SMTPS", "false");
+			properties.put("SMTPAuth", "false");
+			
+			properties.put("DefaultInboxFolder", MockIMAPFolder.mockSettings.getInboxFolderName());
+			properties.put("DefaultTrashFolder", MockIMAPFolder.mockSettings.getTrashFolderName());
+			properties.put("DefaultSentFolder", MockIMAPFolder.mockSettings.getSentFolderName());
+			properties.put("PostFetchMessageCount", "0");
+        }
+        
+        return properties;
+    }
+
+    protected Properties loadProperties(String name) {
+
+        if (name == null)
+            return null;
+
+        Properties properties = null;
+        File file = new File(name);
+        
+        // check if the file is absolute. If not prefix it with the default config dir
+        if (file.isAbsolute() == false) {
+            file = new File(configDir + File.separator + file.getName());
+        }
+        if (file.exists()) {
+            try {
+                properties = new Properties();
+                properties.load(new FileInputStream(file));
+            } catch (Exception e) {
+                properties = null;    
+                e.printStackTrace();
+            }
+        }
+        
+        return properties;
+    }
+
+}



---------------------------------------------------------------------
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