You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ma...@apache.org on 2009/12/02 11:32:25 UTC

svn commit: r886105 - in /james/hupa/trunk: client/src/main/java/org/apache/hupa/client/mvp/ server/src/main/java/org/apache/hupa/server/ server/src/main/java/org/apache/hupa/server/handler/ server/src/main/java/org/apache/hupa/server/utils/ server/src...

Author: manolo
Date: Wed Dec  2 10:32:05 2009
New Revision: 886105

URL: http://svn.apache.org/viewvc?rev=886105&view=rev
Log:
Now replying messages handles correctly: inline images present in original message, and new attachments added by the user.
Re-factoring in MessageHandlers: now they share the same code for createMessage and fillMessage, being different the getAttachments
Partially applied HUPA-58 patch.

Added:
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java
Modified:
    james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/FileItemRegistry.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/MessageUtils.java
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaTestCase.java
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceTestModule.java
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java
    james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/FetchFoldersResult.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java

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=886105&r1=886104&r2=886105&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 Dec  2 10:32:05 2009
@@ -267,8 +267,7 @@
                     } else if(type.equals(Type.REPLY) || type.equals(Type.REPLY_ALL)) {
                         display.setLoading(true);
 
-                        boolean replyAll = type.equals(Type.REPLY_ALL);
-                        dispatcher.execute(new ReplyMessage(message, folder, oldmessage.getUid(), replyAll), new HupaCallback<GenericResult>(dispatcher, eventBus) {
+                        dispatcher.execute(new ReplyMessage(message, folder, oldmessage.getUid()), new HupaCallback<GenericResult>(dispatcher, eventBus) {
                             public void callback(GenericResult result) {
                                 if (result.isSuccess()) {
                                     eventBus.fireEvent(new SentMessageEvent());

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/FileItemRegistry.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/FileItemRegistry.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/FileItemRegistry.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/FileItemRegistry.java Wed Dec  2 10:32:05 2009
@@ -32,10 +32,18 @@
 
     public Map<String,FileItem> map = new HashMap<String, FileItem>();
     private Log logger;
+    static int idCounter = 0;
+    int registryId;
+    
+    public String toString() {
+        return "registryId=" + registryId +
+               " nItems=" + map.size();
+    }
     
     @Inject
     public FileItemRegistry(Log logger) {
         this.logger = logger;
+        registryId  = idCounter++;
     }
     
     public void add(FileItem item) {

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java Wed Dec  2 10:32:05 2009
@@ -27,7 +27,6 @@
 import java.util.List;
 import java.util.Properties;
 
-import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.mail.Address;
 import javax.mail.AuthenticationFailedException;
@@ -40,9 +39,11 @@
 import javax.mail.Transport;
 import javax.mail.Flags.Flag;
 import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimeMessage.RecipientType;
 import javax.servlet.http.HttpSession;
 
 import net.customware.gwt.dispatch.server.ExecutionContext;
@@ -135,8 +136,17 @@
      * @throws MessagingException
      * @throws ActionException
      */
-    protected abstract Message createMessage(Session session, A action) throws AddressException, MessagingException,ActionException;
-
+    protected Message createMessage(Session session, A action) throws AddressException, MessagingException {
+        MimeMessage message = new MimeMessage(session);
+        SMTPMessage m = action.getMessage();
+        message.setFrom(new InternetAddress(m.getFrom()));
+        message.setRecipients(RecipientType.TO, MessageUtils.getRecipients(m.getTo()));
+        message.setRecipients(RecipientType.CC, MessageUtils.getRecipients(m.getCc()));
+        message.setRecipients(RecipientType.BCC, MessageUtils.getRecipients(m.getBcc()));
+        message.setSubject(m.getSubject());
+        message.saveChanges();
+        return message;
+    }
     /**
      * Fill the body of the given message with data which the given action contain
      * 
@@ -151,9 +161,9 @@
 
         String html = restoreInlineLinks(action.getMessage().getText());
         
-        // TODO: client sends the message as html right now, 
+        // TODO: client sends the message as a html document right now, 
         // the idea is that it should be sent in both formats because
-        // it is easier to do the handle html in the browser. 
+        // it is easier to handle html in the browser. 
         String text = htmlToText(html);
         
         @SuppressWarnings("unchecked")
@@ -166,6 +176,7 @@
         return RegexPatterns.replaceAll(s, RegexPatterns.regex_revertInlineImg, RegexPatterns.repl_revertInlineImg);
     }
     
+    // TODO: just temporary stuff because it has to be done in the client side
     protected String htmlToText(String s){
         s=s.replaceAll("\n", " ");
         s=s.replaceAll("(?si)<br\\s*?/?>", "\n");
@@ -184,8 +195,9 @@
      */
     @SuppressWarnings("unchecked")
     protected List getAttachments(A action) throws MessagingException, ActionException {
-        FileItemRegistry registry = MessageUtils.getSessionRegistry(httpSessionProvider.get(), logger); 
+        FileItemRegistry registry = MessageUtils.getSessionRegistry(logger, httpSessionProvider.get());
         List<MessageAttachment> attachments = action.getMessage().getMessageAttachments();
+        
         ArrayList<FileItem> items = new ArrayList<FileItem>();
         for (MessageAttachment attachment: attachments) {
             FileItem fItem = registry.get(attachment.getName());
@@ -208,7 +220,7 @@
         ArrayList<MessageAttachment> attachments = msg.getMessageAttachments();
         if (attachments != null && ! attachments.isEmpty()) {
             for(MessageAttachment attach : attachments) 
-                MessageUtils.getSessionRegistry(httpSessionProvider.get(), logger).remove(attach.getName());
+                MessageUtils.getSessionRegistry(logger, httpSessionProvider.get()).remove(attach.getName());
         }
     }
     
@@ -351,7 +363,7 @@
             multipart.addBodyPart(bodyPart);
             for (Object attachment: parts) {
                 if (attachment instanceof FileItem) {
-                    multipart.addBodyPart(fileitemToBodypart((FileItem)attachment));
+                    multipart.addBodyPart(MessageUtils.fileitemToBodypart((FileItem)attachment));
                 } else {
                     multipart.addBodyPart((BodyPart)attachment);
                 }
@@ -364,20 +376,11 @@
 
     }
     
-    private static BodyPart fileitemToBodypart(FileItem item) throws MessagingException {
-        MimeBodyPart messageBodyPart = new MimeBodyPart();
-        DataSource source = new AbstractSendMessageHandler.FileItemDataStore(item);
-        messageBodyPart.setDataHandler(new DataHandler(source));
-        messageBodyPart.setFileName(source.getName());
-        return messageBodyPart;
-    }
-    
-
     /**
      * DataStore which wrap a FileItem
      * 
      */
-    protected static class FileItemDataStore implements DataSource {
+    public static class FileItemDataStore implements DataSource {
 
         private FileItem item;
 

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java Wed Dec  2 10:32:05 2009
@@ -19,32 +19,21 @@
 
 package org.apache.hupa.server.handler;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.activation.DataSource;
 import javax.mail.BodyPart;
 import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMessage.RecipientType;
 import javax.servlet.http.HttpSession;
 
 import net.customware.gwt.dispatch.shared.ActionException;
 
-import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.IMAPStoreCache;
 import org.apache.hupa.server.utils.MessageUtils;
-import org.apache.hupa.shared.data.SMTPMessage;
 import org.apache.hupa.shared.rpc.ForwardMessage;
 
 import com.google.inject.Inject;
@@ -66,26 +55,6 @@
     }
 
     @Override
-    protected Message createMessage(Session session, ForwardMessage action) throws AddressException, MessagingException, ActionException {
-        MimeMessage message = new MimeMessage(session);
-        SMTPMessage m = action.getMessage();
-        message.setFrom(new InternetAddress(m.getFrom()));
-        List<String> to = m.getTo();
-        for (int i = 0; i < to.size(); i++) {
-            message.addRecipient(RecipientType.TO, new InternetAddress(to.get(i)));
-        }
-
-        List<String> cc = m.getCc();
-        for (int i = 0; cc != null && i < cc.size(); i++) {
-            message.addRecipient(RecipientType.CC, new InternetAddress(cc.get(i)));
-        }
-        message.setSubject(m.getSubject());
-        message.saveChanges();
-        return message;
-    }
-
-
-    @Override
     @SuppressWarnings("unchecked")
     protected List getAttachments(ForwardMessage action) throws MessagingException, ActionException {
         List<BodyPart> items = new ArrayList<BodyPart>();
@@ -117,62 +86,4 @@
         return ForwardMessage.class;
     }
 
-    /**
-     * DataStore which wrap a FileItem
-     * 
-     */
-    protected static class PartDataStore implements DataSource {
-
-        private FileItem item;
-
-        public PartDataStore(FileItem item) {
-            this.item = item;
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.activation.DataSource#getContentType()
-         */
-        public String getContentType() {
-            return item.getContentType();
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.activation.DataSource#getInputStream()
-         */
-        public InputStream getInputStream() throws IOException {
-            return item.getInputStream();
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.activation.DataSource#getName()
-         */
-        public String getName() {
-            String fullName = item.getName();
-
-            // Strip path from file
-            int index = fullName.lastIndexOf(File.separator);
-            if (index == -1) {
-                return fullName;
-            } else {
-                return fullName.substring(index + 1, fullName.length());
-            }
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see javax.activation.DataSource#getOutputStream()
-         */
-        public OutputStream getOutputStream() throws IOException {
-            return null;
-        }
-
-    }
-
 }

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java Wed Dec  2 10:32:05 2009
@@ -19,13 +19,14 @@
 
 package org.apache.hupa.server.handler;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.BodyPart;
 import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage.RecipientType;
 import javax.servlet.http.HttpSession;
 
 import net.customware.gwt.dispatch.shared.ActionException;
@@ -33,7 +34,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.IMAPStoreCache;
 import org.apache.hupa.server.utils.MessageUtils;
-import org.apache.hupa.shared.data.SMTPMessage;
 import org.apache.hupa.shared.rpc.ReplyMessage;
 
 import com.google.inject.Inject;
@@ -47,7 +47,7 @@
  * 
  *
  */
-public class ReplyMessageHandler extends AbstractSendMessageHandler<ReplyMessage>{
+public class ReplyMessageHandler extends AbstractSendMessageHandler<ReplyMessage> {
 
     @Inject
     public ReplyMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider,
@@ -55,30 +55,34 @@
         super(logger, store, provider, address, port, auth, useSSL);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.hupa.server.handler.AbstractSendMessageHandler#createMessage(javax.mail.Session, org.apache.hupa.shared.rpc.SendMessage)
-     */
-    protected Message createMessage(Session session, ReplyMessage action)
-            throws AddressException, MessagingException, ActionException {
+    @Override
+    @SuppressWarnings("unchecked")
+    protected List getAttachments(ReplyMessage action) throws MessagingException, ActionException {
+        List<BodyPart> items = new ArrayList<BodyPart>();
         IMAPStore store = cache.get(getUser());
+
         IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName());
         if (folder.isOpen() == false) {
             folder.open(Folder.READ_ONLY);
         }
-        Message rMessage =  folder.getMessageByUID(action.getReplyMessageUid()).reply(action.getReplyAll());
-        SMTPMessage m = action.getMessage();
-        // Use the new recipient list, maybe it has changed
-        rMessage.setRecipients(RecipientType.TO, MessageUtils.getRecipients(m.getTo()));
-        rMessage.setRecipients(RecipientType.CC, MessageUtils.getRecipients(m.getCc()));
-        rMessage.setRecipients(RecipientType.BCC, MessageUtils.getRecipients(m.getBcc()));
-        rMessage.setFrom(new InternetAddress(m.getFrom()));
-        // replace subject
-        rMessage.setSubject(m.getSubject());
-        rMessage.saveChanges();
-        return rMessage;
+
+        // Only original inline images have to be added to the list 
+        Message msg = folder.getMessageByUID(action.getReplyMessageUid());
+        try {
+            items = MessageUtils.extractInlineImages(logger, msg.getContent());
+            if (items.size() > 0)
+                logger.debug("Replying a message, extracted: " + items.size() + " inline image from");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        
+        // Put into the list the attachments uploaded by the user
+        items.addAll(super.getAttachments(action));
+        
+        return items;
     }
 
+
     /*
      * (non-Javadoc)
      * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java Wed Dec  2 10:32:05 2009
@@ -19,19 +19,10 @@
 
 package org.apache.hupa.server.handler;
 
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.AddressException;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMessage.RecipientType;
 import javax.servlet.http.HttpSession;
 
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.IMAPStoreCache;
-import org.apache.hupa.server.utils.MessageUtils;
-import org.apache.hupa.shared.data.SMTPMessage;
 import org.apache.hupa.shared.rpc.SendMessage;
 
 import com.google.inject.Inject;
@@ -53,22 +44,6 @@
 
     /*
      * (non-Javadoc)
-     * @see org.apache.hupa.server.handler.AbstractSendMessageHandler#createMessage(javax.mail.Session, org.apache.hupa.shared.rpc.SendMessage)
-     */
-    protected Message createMessage(Session session, SendMessage action)
-            throws AddressException, MessagingException {
-        MimeMessage message = new MimeMessage(session);
-        SMTPMessage m = action.getMessage();
-        message.setFrom(new InternetAddress(m.getFrom()));
-        message.setRecipients(RecipientType.TO, MessageUtils.getRecipients(m.getTo()));
-        message.setRecipients(RecipientType.CC, MessageUtils.getRecipients(m.getCc()));
-        message.setRecipients(RecipientType.BCC, MessageUtils.getRecipients(m.getBcc()));
-        message.setSubject(m.getSubject());
-        return message;
-    }
-
-    /*
-     * (non-Javadoc)
      * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
      */
     public Class<SendMessage> getActionType() {

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/MessageUtils.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/MessageUtils.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/MessageUtils.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/MessageUtils.java Wed Dec  2 10:32:05 2009
@@ -24,6 +24,8 @@
 import java.util.Arrays;
 import java.util.List;
 
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
 import javax.mail.Address;
 import javax.mail.BodyPart;
 import javax.mail.MessagingException;
@@ -31,11 +33,14 @@
 import javax.mail.Part;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeUtility;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.handler.AbstractSendMessageHandler;
 
 
 
@@ -104,7 +109,16 @@
         return ret;
     }
 
-    public static FileItemRegistry getSessionRegistry(HttpSession session, Log logger) {
+    static public List<BodyPart> extractInlineImages(Log logger, Object content) throws MessagingException, IOException {
+        ArrayList<BodyPart> ret = new ArrayList<BodyPart>();
+        for (BodyPart attach : extractMessageAttachments(logger, content)) {
+            if (attach.getHeader("Content-ID") != null && attach.getContentType().startsWith("image/"))
+                ret.add(attach);
+        }
+        return ret;
+    }
+
+    public static FileItemRegistry getSessionRegistry(Log logger, HttpSession session) {
         FileItemRegistry registry = (FileItemRegistry)session.getAttribute("registry");
         if (registry == null) {
             registry = new FileItemRegistry(logger);
@@ -157,5 +171,20 @@
         }
         return null;
     }
+
+    /**
+     * Convert a FileItem to a BodyPart
+     * 
+     * @param item
+     * @return
+     * @throws MessagingException
+     */
+    public static BodyPart fileitemToBodypart(FileItem item) throws MessagingException {
+        MimeBodyPart messageBodyPart = new MimeBodyPart();
+        DataSource source = new AbstractSendMessageHandler.FileItemDataStore(item);
+        messageBodyPart.setDataHandler(new DataHandler(source));
+        messageBodyPart.setFileName(source.getName());
+        return messageBodyPart;
+    }
     
 }
\ No newline at end of file

Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaTestCase.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaTestCase.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaTestCase.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaTestCase.java Wed Dec  2 10:32:05 2009
@@ -29,6 +29,7 @@
 import org.apache.hupa.server.handler.AbstractSendMessageHandler;
 import org.apache.hupa.server.handler.ForwardMessageHandler;
 import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
 import org.apache.hupa.shared.rpc.SendMessage;
 
 import com.google.inject.Injector;
@@ -46,6 +47,7 @@
     protected AbstractSendMessageHandler<SendMessage> abstSendMsgHndl = injector.getInstance(AbstractSendMessageHandler.class);
     
     protected ForwardMessageHandler fwdMsgHndl = injector.getInstance(ForwardMessageHandler.class);
+    protected ReplyMessageHandler reMsgHndl = injector.getInstance(ReplyMessageHandler.class);
     
     protected GetMessageDetailsHandler getDetailsMsgHndl = injector.getInstance(GetMessageDetailsHandler.class);
     

Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceTestModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceTestModule.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceTestModule.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceTestModule.java Wed Dec  2 10:32:05 2009
@@ -27,6 +27,7 @@
 import org.apache.hupa.server.handler.AbstractSendMessageHandler;
 import org.apache.hupa.server.handler.ForwardMessageHandler;
 import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
 import org.apache.hupa.server.handler.SendMessageHandler;
 import org.apache.hupa.server.mock.MockHttpSession;
 import org.apache.hupa.server.mock.MockIMAPStore;
@@ -59,6 +60,7 @@
         
         bind(AbstractSendMessageHandler.class).to(SendMessageHandler.class);
         bind(SendMessageHandler.class);
+        bind(ReplyMessageHandler.class);
         bind(ForwardMessageHandler.class);
 
     }

Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/AbtractSendMessageHandlerTest.java Wed Dec  2 10:32:05 2009
@@ -45,8 +45,8 @@
                             + " multipart/alternative\n"
                             + "  text/plain\n"
                             + "  text/html\n"
-                            + " mock/attachment => file_1.bin\n"
-                            + " mock/attachment => file_2.bin\n";
+                            + " mock/attachment => uploadedFile_1.bin\n"
+                            + " mock/attachment => uploadedFile_2.bin\n";
 
     public void testComposeMessage() throws Exception{
 
@@ -112,7 +112,7 @@
         
         MockIMAPFolder sentbox = (MockIMAPFolder) store.getFolder(DemoModeConstants.DEMO_MODE_SENT_FOLDER);
         
-        SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(MessageUtils.getSessionRegistry(httpSession, logger), 2);
+        SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(MessageUtils.getSessionRegistry(logger, httpSession), 2);
         SendMessage action = new SendMessage(smtpmsg);
         
         Message message = abstSendMsgHndl.createMessage(session, action);
@@ -122,7 +122,9 @@
 
         abstSendMsgHndl.sendMessage(session, demouser, message);
 
-        Part part = MessageUtils.handleMultiPart(logger, message.getContent(), "file_1.bin");
+        
+        // The reported size is wrong before the message has been saved
+        Part part = MessageUtils.handleMultiPart(logger, message.getContent(), "uploadedFile_1.bin");
         assertTrue(part.getSize() < 0);
 
         assertTrue(sentbox.getMessages().length == 0);
@@ -132,8 +134,9 @@
         message = sentbox.getMessage(0);
         assertNotNull(message);
         assertEquals(contentTwoAttach, TestUtils.summaryzeContent(message).toString());
-        
-        part = MessageUtils.handleMultiPart(logger, message.getContent(), "file_1.bin");
+
+        // After saving the message, the reported size has to be OK
+        part = MessageUtils.handleMultiPart(logger, message.getContent(), "uploadedFile_1.bin");
         assertTrue(part.getSize() > 0);
         
     }
@@ -148,7 +151,7 @@
         
         MockIMAPFolder sentbox = (MockIMAPFolder) store.getFolder(DemoModeConstants.DEMO_MODE_SENT_FOLDER);
         
-        SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(MessageUtils.getSessionRegistry(httpSession, logger), 2);
+        SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(MessageUtils.getSessionRegistry(logger, httpSession), 2);
         SendMessage action = new SendMessage(smtpmsg);
         
         assertTrue(sentbox.getMessages().length == 0);
@@ -157,7 +160,7 @@
         assertNotNull(message);
         assertEquals(contentTwoAttach, TestUtils.summaryzeContent(message).toString());
         
-        Part part = MessageUtils.handleMultiPart(logger, message.getContent(), "file_1.bin");
+        Part part = MessageUtils.handleMultiPart(logger, message.getContent(), "uploadedFile_1.bin");
         assertTrue(part.getSize() > 0);
         
     }

Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java?rev=886105&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java Wed Dec  2 10:32:05 2009
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.handler;
+
+
+import javax.mail.Message;
+import javax.servlet.http.HttpSession;
+
+import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.HupaTestCase;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.guice.DemoModeConstants;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStoreCache;
+import org.apache.hupa.server.utils.MessageUtils;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.rpc.ReplyMessage;
+
+import com.sun.mail.imap.IMAPStore;
+
+public class ReplyMessageHandlerTest extends HupaTestCase {
+
+    public void testForwardMessage() throws Exception {
+        User demouser = DemoModeConstants.demoUser;
+
+        HttpSession httpSession = injector.getInstance(HttpSession.class);
+        httpSession.setAttribute("user", demouser);
+
+        IMAPStoreCache storeCache = injector.getInstance(IMAPStoreCache.class);
+        IMAPStore store = injector.getInstance(IMAPStore.class);
+        ((MockIMAPStoreCache)storeCache).addValidUser(demouser, store);
+
+        FileItemRegistry registry = MessageUtils.getSessionRegistry(logger, httpSession);
+        
+        
+        MockIMAPFolder sentbox = (MockIMAPFolder) store.getFolder(DemoModeConstants.DEMO_MODE_SENT_FOLDER);
+        assertTrue(sentbox.getMessages().length == 0);
+
+        MockIMAPFolder inbox = (MockIMAPFolder) store.getFolder(DemoModeConstants.DEMO_MODE_INBOX_FOLDER);
+        assertTrue(inbox.getMessages().length >= 0);
+
+        // Create a mime message with 2 attachments and 1 inline image, and put it in the inbox
+        Message message = TestUtils.createMockMimeMessage(session, 2);
+        TestUtils.addMockAttachment(message, "inlineImage.jpg", true);
+        
+        inbox.appendMessages(new Message[]{message});
+        long msgUid = inbox.getUID(message);
+        message = inbox.getMessageByUID(msgUid);
+        assertNotNull(message);
+        
+        String expected = "multipart/mixed\n"
+                        + " multipart/alternative\n"
+                        + "  text/plain\n"
+                        + "  text/html\n"
+                        + " mock/attachment => file_1.bin\n"
+                        + " mock/attachment => file_2.bin\n"
+                        + " image/mock => inlineImage.jpg\n";
+        assertEquals(expected, TestUtils.summaryzeContent(message).toString());
+        
+        // Create a reply user action with an uploaded message
+        SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(registry, 1);
+        ReplyMessage action = new ReplyMessage(smtpmsg, new IMAPFolder(inbox.getFullName()), msgUid);
+        
+        message = reMsgHndl.createMessage(session, action);
+        message = reMsgHndl.fillBody(message, action);
+        
+        // The final message has to include the file uploaded by the user and the inline image
+        expected = "multipart/mixed\n"
+                 + " multipart/alternative\n"
+                 + "  text/plain\n"
+                 + "  text/html\n"
+                 + " image/mock => inlineImage.jpg\n"
+                 + " mock/attachment => uploadedFile_1.bin\n";
+        
+        assertEquals(expected, TestUtils.summaryzeContent(message).toString());
+
+    }
+}

Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java Wed Dec  2 10:32:05 2009
@@ -7,16 +7,9 @@
 import javax.mail.Session;
 
 import org.apache.commons.logging.Log;
-import org.apache.hupa.server.guice.GuiceTestModule;
+import org.apache.hupa.server.HupaTestCase;
 
-import com.google.inject.Injector;
-
-import junit.framework.TestCase;
-
-public class MessageUtilsTest extends TestCase {
-
-    GuiceTestModule module = new GuiceTestModule();
-    Injector injector = module.getInjector();
+public class MessageUtilsTest extends HupaTestCase {
     
     public void testExtractMessageAttachments() throws Exception {
         Session session = injector.getInstance(Session.class);
@@ -25,4 +18,30 @@
         List<BodyPart> parts = MessageUtils.extractMessageAttachments(logger, message.getContent());
         assertEquals(2, parts.size());
     }
+
+    public void testExtractInlineAttachments() throws Exception {
+        Session session = injector.getInstance(Session.class);
+        Log logger = injector.getInstance(Log.class);
+
+        Message message = TestUtils.createMockMimeMessage(session, 1);
+        
+        List<BodyPart> attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
+        List<BodyPart> inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
+        assertEquals(1, attachments.size());
+        assertEquals(0, inlineImgs.size());
+        
+        TestUtils.addMockAttachment(message, "mfile.bin", false);
+        
+        attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
+        inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
+        assertEquals(2, attachments.size());
+        assertEquals(0, inlineImgs.size());
+
+        TestUtils.addMockAttachment(message, "mfile.jpg", true);
+        
+        attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
+        inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
+        assertEquals(3, attachments.size());
+        assertEquals(1, inlineImgs.size());
+    }
 }
\ No newline at end of file

Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java Wed Dec  2 10:32:05 2009
@@ -26,6 +26,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import javax.mail.BodyPart;
 import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.Multipart;
@@ -73,19 +74,18 @@
         }
 
         private String ident(int spaces, String text) {
-            String ret = "";
-            for (int i = 0; i < spaces; i++)
-                ret += " ";
-            return ret + text;
+            char[] padding = new char[spaces];
+            Arrays.fill(padding, ' ');
+            return new String(padding) + text;
         }
-
+        
         public String toString() {
-            String ret = "";
-            for (String s : this) {
-                ret += s + "\n";
-            }
-            return ret;
+            StringBuilder ret = new StringBuilder();
+            for (String s : this) 
+                ret.append(s).append("\n");
+            return ret.toString();
         }
+
     }
 
     /**
@@ -95,20 +95,25 @@
      * @return a new item
      * @throws IOException
      */
-    public static FileItem createMockFileItem(String filename) throws IOException {
+    public static FileItem createMockFileItem(String filename, String contentType) throws IOException {
         FileItemFactory f = new DiskFileItemFactory();
-        FileItem item = f.createItem("fieldname_" + filename, "mock/attachment", false, filename);
+        FileItem item = f.createItem("fieldname_" + filename, contentType, false, filename);
         OutputStream os = item.getOutputStream();
         os.write("ABCDEFGHIJK\n".getBytes());
         os.close();
         return item;
     }
+
+    public static FileItem createMockFileItem(String filename) throws IOException {
+        return createMockFileItem(filename, "mock/attachment");
+    }
     
     public void testCreateMockFileItem() throws Exception {
         FileItem item = createMockFileItem("filename.jpg");
         assertEquals("ABCDEFGHIJK\n", item.getString());
     }
 
+    
     /**
      * Create a new mime-message from a file stored in the fixtures folder
      * 
@@ -120,8 +125,7 @@
     public static MimeMessage loadMessageFromFile(Session session, String msgFile) throws Exception {
         msgFile = DemoModeConstants.DEMO_MODE_MESSAGES_LOCATION + msgFile;
         URL url = Thread.currentThread().getContextClassLoader().getResource(msgFile);
-        assertNotNull("Check that the file " + msgFile + " is in the classpath", url);
-    
+
         FileInputStream is = new FileInputStream(url.getFile());
         return new MimeMessage(session, is);
     }
@@ -175,7 +179,7 @@
 
         for (int i = 1; i <= nfiles; i++) {
             FileItem fileItem;
-            fileItem = TestUtils.createMockFileItem("file_" + i + ".bin");
+            fileItem = TestUtils.createMockFileItem("uploadedFile_" + i + ".bin");
             registry.add(fileItem);
 
             MessageAttachment msgAttach = new MessageAttachment();
@@ -243,4 +247,26 @@
         return ret;
     }
 
+    /**
+     * Add a mock attachment to a mime message, you can specify whether the attachment
+     * is an in-line image, and the file name
+     * 
+     * @param message
+     * @param fileName
+     * @param isInline
+     * @throws IOException
+     * @throws MessagingException
+     */
+    public static void addMockAttachment(Message message, String fileName, boolean isInline) throws IOException, MessagingException {
+        FileItem item = createMockFileItem(fileName, isInline ? "image/mock" : "mock/attachment");
+            
+        BodyPart part = MessageUtils.fileitemToBodypart(item);
+        if (isInline)
+            part.addHeader("Content-ID", "any-id");
+        
+        Multipart mpart = (Multipart) message.getContent();
+        mpart.addBodyPart(part);
+        message.saveChanges();
+    }
+ 
 }
\ No newline at end of file

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/FetchFoldersResult.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/FetchFoldersResult.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/FetchFoldersResult.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/FetchFoldersResult.java Wed Dec  2 10:32:05 2009
@@ -39,18 +39,17 @@
     
     @SuppressWarnings("unused")
     private FetchFoldersResult() {
-        
     }
     
     public ArrayList<IMAPFolder> getFolders() {
         return folders;
     }
-    
+
     public String toString() {
-        String ret = "";
-        for (IMAPFolder f: folders) {
-            ret += f.getFullName() + " ";
-        }
-        return ret;
+        StringBuilder ret = new StringBuilder();
+        for (IMAPFolder f : folders)
+            ret.append(f.getFullName()).append(" ");
+        return ret.toString();
     }
+    
 }

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java?rev=886105&r1=886104&r2=886105&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java Wed Dec  2 10:32:05 2009
@@ -27,19 +27,12 @@
 
     private static final long serialVersionUID = -383135476236902779L;
 
-    private boolean replyAll;
     
-    public ReplyMessage(SMTPMessage msg, IMAPFolder folder, long uid, boolean replyAll) {
+    public ReplyMessage(SMTPMessage msg, IMAPFolder folder, long uid) {
         super(msg, folder, uid);
-        this.replyAll = replyAll;
     }
 
     protected ReplyMessage() {
-        
-    }
-    
-    public boolean getReplyAll() {
-        return replyAll;
     }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org