james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From man...@apache.org
Subject svn commit: r1364950 - in /james/hupa/trunk: client/src/main/java/org/apache/hupa/client/mvp/ server/src/main/java/org/apache/hupa/server/handler/ shared/src/main/java/org/apache/hupa/shared/ shared/src/main/java/org/apache/hupa/shared/data/ shared/src...
Date Tue, 24 Jul 2012 09:09:40 GMT
Author: manolo
Date: Tue Jul 24 09:09:40 2012
New Revision: 1364950

URL: http://svn.apache.org/viewvc?rev=1364950&view=rev
Log:
Fixes HUPA-96 : pass reference ids when replying. Patch by Zsombor Gegesy

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/handler/AbstractSendMessageHandler.java
    james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java
    james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/SendMessage.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=1364950&r1=1364949&r2=1364950&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
Tue Jul 24 09:09:40 2012
@@ -41,6 +41,7 @@ import net.customware.gwt.presenter.clie
 
 import org.apache.hupa.client.HupaCallback;
 import org.apache.hupa.client.validation.EmailListValidator;
+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;
@@ -81,7 +82,6 @@ public class MessageSendPresenter extend
     
     protected SMTPMessage message = null;
     
-    @SuppressWarnings("unused")
     private MessageDetails oldDetails;
 
     private OnFinishUploaderHandler onFinishUploadHandler = new OnFinishUploaderHandler()
{
@@ -210,13 +210,29 @@ public class MessageSendPresenter extend
                 if (type == Type.NEW) {
                     command = new SendMessage(message);
                 } else if (type == Type.FORWARD) {
-                    command = new ForwardMessage(message, folder, oldmessage.getUid());
+                    command = addMessageIds(new ForwardMessage(message, folder, oldDetails.getUid()));
                 } else {
-                    command = new ReplyMessage(message, folder, oldmessage.getUid());
+                    command = addMessageIds(new ReplyMessage(message, folder, oldDetails.getUid()));
                 }
                 dispatchMessage(dispatcher, eventBus, command);
             }
         }
+
+        private ForwardMessage addMessageIds(ForwardMessage msg) {
+            String msgId = oldDetails.getMessageId();
+            msg.setInReplyTo(msgId);
+            
+            if (msgId != null) {
+                String oldRefs = oldDetails.getReferences();
+                if (oldRefs != null) {
+                    msg.setReferences(msgId.trim() + SConsts.HEADER_REFERENCES_SEPARATOR
+ oldRefs);
+                } else {
+                    msg.setReferences(msgId.trim());
+                }
+            }
+            return msg;
+        }
+        
     };
 
     protected ArrayList<String> emailTextToArray(String emails) {

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=1364950&r1=1364949&r2=1364950&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
Tue Jul 24 09:09:40 2012
@@ -56,6 +56,7 @@ import org.apache.hupa.server.preference
 import org.apache.hupa.server.utils.MessageUtils;
 import org.apache.hupa.server.utils.RegexPatterns;
 import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.shared.SConsts;
 import org.apache.hupa.shared.data.MessageAttachment;
 import org.apache.hupa.shared.data.SMTPMessage;
 import org.apache.hupa.shared.data.User;
@@ -148,10 +149,29 @@ public abstract class AbstractSendMessag
         message.setRecipients(RecipientType.CC, MessageUtils.getRecipients(m.getCc()));
         message.setRecipients(RecipientType.BCC, MessageUtils.getRecipients(m.getBcc()));
         message.setSubject(MessageUtils.encodeTexts(m.getSubject()));
+        updateHeaders(message, action);
         message.saveChanges();
         return message;
     }
-    /**
+    
+    protected void updateHeaders(MimeMessage message, A action) {
+        if (action.getInReplyTo() != null) {
+            try {
+                message.addHeader(SConsts.HEADER_IN_REPLY_TO, action.getInReplyTo());
+            } catch (MessagingException e) {
+                logger.error("Error while setting header:" + e.getMessage(), e);
+            }
+        }
+        if (action.getReferences() != null) {
+            try {
+                message.addHeader(SConsts.HEADER_REFERENCES, action.getReferences());
+            } catch (MessagingException e) {
+                logger.error("Error while setting header:" + e.getMessage(), e);
+            }
+        }
+    }
+
+	/**
      * Fill the body of the given message with data which the given action contain
      * 
      * @param message the message

Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java?rev=1364950&r1=1364949&r2=1364950&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
(original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/GetMessageDetailsHandler.java
Tue Jul 24 09:09:40 2012
@@ -19,16 +19,20 @@
 
 package org.apache.hupa.server.handler;
 
+import static org.apache.hupa.server.utils.RegexPatterns.*;
+
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
+import java.util.Enumeration;
 
 import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+import javax.mail.Header;
 import javax.mail.Message;
 import javax.mail.MessagingException;
 import javax.mail.Multipart;
 import javax.mail.Part;
-import javax.mail.Flags.Flag;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeUtility;
 import javax.servlet.http.HttpSession;
@@ -38,7 +42,6 @@ import net.customware.gwt.dispatch.share
 
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.IMAPStoreCache;
-import static org.apache.hupa.server.utils.RegexPatterns.*;
 import org.apache.hupa.shared.data.IMAPFolder;
 import org.apache.hupa.shared.data.MessageAttachment;
 import org.apache.hupa.shared.data.MessageDetails;
@@ -144,7 +147,11 @@ public class GetMessageDetailsHandler ex
 
         mDetails.setMessageAttachments(attachmentList);
 
-        mDetails.setRawHeader(message.getAllHeaders().toString());
+        for (@SuppressWarnings("unchecked")
+        Enumeration<Header> en = message.getAllHeaders(); en.hasMoreElements();) {
+            Header header = en.nextElement();
+            mDetails.addHeader(header.getName(), header.getValue());
+        }
         
         return mDetails;
     }

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java?rev=1364950&r1=1364949&r2=1364950&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java Tue Jul 24 09:09:40
2012
@@ -34,4 +34,10 @@ public class SConsts {
     
     public static final String USER_SESS_ATTR = "user";
     public static final String CONTACTS_SESS_ATTR = "contacts";
+    
+    public static final String HEADER_IN_REPLY_TO = "In-Reply-To";
+    public static final String HEADER_REFERENCES = "References";
+    public static final String HEADER_MESSAGE_ID = "Message-ID";
+    public static final String HEADER_REFERENCES_SEPARATOR = "\r\n ";
+    
 }
\ No newline at end of file

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java?rev=1364950&r1=1364949&r2=1364950&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java
(original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/MessageDetails.java
Tue Jul 24 09:09:40 2012
@@ -21,22 +21,31 @@ package org.apache.hupa.shared.data;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hupa.shared.SConsts;
 
 public class MessageDetails implements Serializable{
     /**
-     * 
-     */
-    private static final long serialVersionUID = 7611536915564919521L;
-    private String text;
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private String text;
     private ArrayList<MessageAttachment> aList;
     private long uid;
     private String raw;
+    private Map<String, List<String>> headers = new HashMap<String, List<String>>();
 
+    
     public String toString() {
         return "uid=" + String.valueOf(getUid()) +
         " text.length=" + (text != null ? text.length() : 0) + 
         " raw.length=" + (raw != null ? raw.length() : 0) + 
-        " attachments=" + (aList != null ? aList.size() : 0); 
+        " attachments=" + (aList != null ? aList.size() : 0) + 
+        " headers=" + (headers != null ? headers.size() : 0); 
     }
     
     
@@ -66,6 +75,21 @@ public class MessageDetails implements S
         return raw;
     }
     
+    public Map<String, List<String>> getHeaders() {
+		return headers;
+	}
+    
+    public void addHeader(String name, String value) {
+    	List<String> list = headers.get(name);
+    	if (list == null) {
+    		list = new ArrayList<String>();
+    		headers.put(name, list);
+    	}
+    	list.add(value);
+    }
+    
+    
+    
     /**
      * Set the body text of the content
      * 
@@ -93,6 +117,31 @@ public class MessageDetails implements S
     }
 
     /**
+     * 
+     * @return the In-Reply-To header field.
+     */
+    public String getInReplyTo() {
+        return getHeaderValue(SConsts.HEADER_IN_REPLY_TO);
+    }
+
+    public String getHeaderValue(String key) {
+        List<String> h = headers.get(key);
+        return h != null && !h.isEmpty() ? h.get(0) : null;
+    }
+
+    /**
+     * 
+     * @return the References header field.
+     */
+    public String getReferences() {
+        return getHeaderValue(SConsts.HEADER_REFERENCES);
+    }
+
+    public String getMessageId() {
+        return getHeaderValue(SConsts.HEADER_MESSAGE_ID);
+    }    
+    
+    /**
      * Return the attachments 
      * 
      * @return aList

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java?rev=1364950&r1=1364949&r2=1364950&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java Tue
Jul 24 09:09:40 2012
@@ -25,15 +25,28 @@ import org.apache.hupa.shared.data.SMTPM
 
 public class ForwardMessage extends SendMessage {
 
-    private static final long serialVersionUID = 1656671247843122192L;
+    private static final long serialVersionUID = 1L;
+    
     private long uid;
     private IMAPFolder folder;
+    private String inReplyTo;
+    private String references;
 
     public ForwardMessage(SMTPMessage msg, IMAPFolder folder, long uid) {
         super(msg);
-        this.uid = uid;
         this.folder = folder;
+        this.uid = uid;
     }
+
+    public ForwardMessage setInReplyTo(String inReplyTo) {
+		this.inReplyTo = inReplyTo;
+		return this;
+	}
+    
+    public ForwardMessage setReferences(String references) {
+		this.references = references;
+		return this;
+	}
     
     protected ForwardMessage() {
     }
@@ -45,4 +58,14 @@ public class ForwardMessage extends Send
     public IMAPFolder getFolder() {
         return folder;
     }
+    
+    @Override
+    public String getInReplyTo() {
+		return inReplyTo;
+	}
+
+    @Override
+    public String getReferences() {
+		return references;
+	}
 }

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=1364950&r1=1364949&r2=1364950&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 Tue
Jul 24 09:09:40 2012
@@ -29,7 +29,7 @@ public class ReplyMessage extends Forwar
 
     
     public ReplyMessage(SMTPMessage msg, IMAPFolder folder, long uid) {
-        super(msg, folder, uid);
+    	super(msg, folder, uid);
     }
 
     protected ReplyMessage() {

Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java?rev=1364950&r1=1364949&r2=1364950&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java Tue
Jul 24 09:09:40 2012
@@ -48,4 +48,12 @@ public class SendMessage implements Acti
         this.msg = msg;
     }
     
+    public String getInReplyTo() {
+		return null;
+	}
+
+    public String getReferences() {
+		return null;
+	}
+
 }



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