Author: norman
Date: Sun Aug  2 18:39:29 2009
New Revision: 800125

URL: http://svn.apache.org/viewvc?rev=800125&view=rev
Log:
Add handler for forwarding messages

Added:
    
labs/hupa/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
    labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java
Modified:
    labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
    
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
    
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java
    labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java

Modified: labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java?rev=800125&r1=800124&r2=800125&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java 
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java Sun 
Aug  2 18:39:29 2009
@@ -33,10 +33,12 @@
 import org.apache.hupa.server.handler.ExposeMessageHandler;
 import org.apache.hupa.server.handler.FetchFoldersHandler;
 import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.handler.ForwardMessageHandler;
 import org.apache.hupa.server.handler.LoginSessionHandler;
 import org.apache.hupa.server.handler.LoginUserHandler;
 import org.apache.hupa.server.handler.LogoutUserHandler;
 import org.apache.hupa.server.handler.NoopHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
 import org.apache.hupa.server.handler.SendMessageHandler;
 import org.apache.hupa.server.servlet.DownloadAttachmentServlet;
 import org.apache.hupa.server.servlet.UploadAttachmentServlet;
@@ -61,6 +63,8 @@
                bindHandler(ExposeMessageHandler.class);
                bindHandler(DeleteMessageHandler.class);
                bindHandler(SendMessageHandler.class);
+               bindHandler(ReplyMessageHandler.class);
+               bindHandler(ForwardMessageHandler.class);
                bindHandler(NoopHandler.class);
                bindHandler(LoginSessionHandler.class);
                

Modified: 
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java?rev=800125&r1=800124&r2=800125&view=diff
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
 (original)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
 Sun Aug  2 18:39:29 2009
@@ -1,3 +1,21 @@
+/****************************************************************
+ * 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;
 
@@ -68,8 +86,9 @@
 
        protected abstract Message createMessage(Session session, A action) 
throws AddressException, MessagingException,ActionException;
        
-       protected void fillBody(Message message, 
org.apache.hupa.shared.data.Message m) throws MessagingException {
+       protected Message fillBody(Message message, A action) throws 
MessagingException, ActionException {
 
+               org.apache.hupa.shared.data.Message m = action.getMessage();
                ArrayList<MessageAttachment> attachments = m.getMessageContent()
                                .getMessageAttachments();
                // check if there are any attachments to include
@@ -84,24 +103,33 @@
 
                        Multipart multipart = new MimeMultipart();
                        multipart.addBodyPart(messageBodyPart);
-
-                       // lopp over the attachments
-                       for (int i = 0; i < attachments.size(); i++) {
-                               // get the attachment from the registry
-                               FileItem fItem = 
registry.get(attachments.get(i).getName());
-                               // Part two is attachment
-                               messageBodyPart = new MimeBodyPart();
-                               DataSource source = new 
FileItemDataStore(fItem);
-                               messageBodyPart.setDataHandler(new 
DataHandler(source));
-                               messageBodyPart.setFileName(source.getName());
-                               multipart.addBodyPart(messageBodyPart);
-                       }
+                       
+                       multipart = handleAttachments(multipart, attachments);
+                       
                        // Put parts in message
                        message.setContent(multipart);
 
                }
                // save message 
                message.saveChanges();
+               return message;
+       }
+       
+       protected Multipart handleAttachments(Multipart multipart, 
ArrayList<MessageAttachment> attachments) throws MessagingException {
+               if (attachments != null) {
+               // lopp over the attachments
+               for (int i = 0; i < attachments.size(); i++) {
+                       // get the attachment from the registry
+                       FileItem fItem = 
registry.get(attachments.get(i).getName());
+                       // Part two is attachment
+                       MimeBodyPart messageBodyPart = new MimeBodyPart();
+                       DataSource source = new FileItemDataStore(fItem);
+                       messageBodyPart.setDataHandler(new DataHandler(source));
+                       messageBodyPart.setFileName(source.getName());
+                       multipart.addBodyPart(messageBodyPart);
+               }
+               }
+               return multipart;
        }
        protected void sendMessage(User user, Session session, Message message) 
throws MessagingException {
                Transport transport = session.getTransport("smtp");
@@ -195,7 +223,7 @@
                        Session session = Session.getDefaultInstance(props);
 
                        Message message = createMessage(session, action);
-                       fillBody(message,action.getMessage());
+                       message = fillBody(message,action);
                        
                        sendMessage(getUser(action.getSessionId()),session, 
message);
                        

Added: 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java?rev=800125&view=auto
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
 (added)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java
 Sun Aug  2 18:39:29 2009
@@ -0,0 +1,118 @@
+/****************************************************************
+ * 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 java.util.ArrayList;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Session;
+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.shared.ActionException;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.annotations.SMTPAuth;
+import org.apache.hupa.server.annotations.SMTPServerAddress;
+import org.apache.hupa.server.annotations.SMTPServerPort;
+import org.apache.hupa.shared.rpc.ForwardMessage;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class ForwardMessageHandler extends 
AbstractSendMessageHandler<ForwardMessage>{
+
+       @Inject
+       public ForwardMessageHandler(Log logger, FileItemRegistry registry,
+                       IMAPStoreCache store, Provider<HttpSession> provider,
+                       @SMTPServerAddress String address,  @SMTPServerPort int 
port, @SMTPAuth boolean auth) {
+               super(logger, registry, store, provider, address, port, auth);
+       }
+
+       @Override
+       protected Message createMessage(Session session, ForwardMessage action)
+                       throws AddressException, MessagingException, 
ActionException {
+                       MimeMessage message = new MimeMessage(session);
+                       org.apache.hupa.shared.data.Message m = 
action.getMessage();
+                       message.setFrom(new 
InternetAddress(m.getHeader().getFrom()));
+                       ArrayList<String> to = m.getHeader().getTo();
+                       for (int i = 0; i < to.size(); i++) {
+                               message.addRecipient(RecipientType.TO, new 
InternetAddress(to
+                                               .get(i)));
+                       }
+
+                       ArrayList<String> cc = m.getHeader().getCc();
+                       for (int i = 0; i < cc.size(); i++) {
+                               message.addRecipient(RecipientType.CC, new 
InternetAddress(cc
+                                               .get(i)));
+                       }
+                       message.setSubject("Fwd: " + 
m.getHeader().getSubject());
+                       return message;
+       }
+
+       @Override
+       protected Message fillBody(Message message,
+                       ForwardMessage action) throws MessagingException, 
ActionException {
+               org.apache.hupa.shared.data.Message m = action.getMessage();
+
+               // create the message part
+               MimeBodyPart messageBodyPart = new MimeBodyPart();
+
+               // fill message
+               messageBodyPart.setText(m.getMessageContent().getText());
+
+               Multipart multipart = new MimeMultipart();
+               multipart.addBodyPart(messageBodyPart);
+               
+               IMAPStore store = cache.get(getUser(action.getSessionId()));
+               
+               IMAPFolder folder = (IMAPFolder) 
store.getFolder(action.getFolder().getFullName());
+               Message fMessage = 
folder.getMessageByUID(action.getReplyMessageUid());
+               
+               // Create and fill part for the forwarded content
+               messageBodyPart = new MimeBodyPart();
+               messageBodyPart.setDataHandler(fMessage.getDataHandler());
+               multipart.addBodyPart(messageBodyPart);
+
+               multipart = handleAttachments(multipart, 
m.getMessageContent().getMessageAttachments());
+               
+               
+               // Put parts in message
+               message.setContent(multipart);
+               message.saveChanges();
+               return message;
+       }
+
+       public Class<ForwardMessage> getActionType() {
+               return ForwardMessage.class;
+       }
+
+}

Modified: 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java?rev=800125&r1=800124&r2=800125&view=diff
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java 
(original)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java 
Sun Aug  2 18:39:29 2009
@@ -30,17 +30,22 @@
 import org.apache.commons.logging.Log;
 import org.apache.hupa.server.FileItemRegistry;
 import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.annotations.SMTPAuth;
+import org.apache.hupa.server.annotations.SMTPServerAddress;
+import org.apache.hupa.server.annotations.SMTPServerPort;
 import org.apache.hupa.shared.rpc.ReplyMessage;
 
+import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.sun.mail.imap.IMAPFolder;
 import com.sun.mail.imap.IMAPStore;
 
 public class ReplyMessageHandler extends 
AbstractSendMessageHandler<ReplyMessage>{
 
+       @Inject
        public ReplyMessageHandler(Log logger, FileItemRegistry registry,
                        IMAPStoreCache store, Provider<HttpSession> provider,
-                       String address, int port, boolean auth) {
+                       @SMTPServerAddress String address, @SMTPServerPort int 
port, @SMTPAuth boolean auth) {
                super(logger, registry, store, provider, address, port, auth);
        }
 

Added: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java?rev=800125&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java 
(added)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ForwardMessage.java Sun 
Aug  2 18:39:29 2009
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.shared.rpc;
+
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.Message;
+
+public class ForwardMessage extends SendMessage{
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1656671247843122192L;
+       private long uid;
+       private IMAPFolder folder;
+
+       public ForwardMessage(String sessionId, Message msg, IMAPFolder folder, 
long uid) {
+               super(sessionId, msg);
+               this.uid = uid;
+               this.folder = folder;
+       }
+       
+       protected ForwardMessage() {
+               
+       }
+
+       public long getReplyMessageUid() {
+               return uid;
+       }
+       
+       public IMAPFolder getFolder() {
+               return folder;
+       }
+}

Modified: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java?rev=800125&r1=800124&r2=800125&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java 
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java Sun 
Aug  2 18:39:29 2009
@@ -1,4 +1,3 @@
-package org.apache.hupa.shared.rpc;
 /****************************************************************
  * Licensed to the Apache Software Foundation (ASF) under one   *
  * or more contributor license agreements.  See the NOTICE file *
@@ -19,39 +18,31 @@
  ****************************************************************/
 
 
+package org.apache.hupa.shared.rpc;
+
 import org.apache.hupa.shared.data.IMAPFolder;
 import org.apache.hupa.shared.data.Message;
 
-public class ReplyMessage extends SendMessage{
+public class ReplyMessage extends ForwardMessage{
 
        /**
         * 
         */
        private static final long serialVersionUID = -383135476236902779L;
        private boolean replyAll;
-       private long uid;
-       private IMAPFolder folder;
        
        public ReplyMessage(String sessionId, Message msg, IMAPFolder folder, 
long uid, boolean replyAll) {
-               super(sessionId, msg);
+               super(sessionId, msg, folder, uid);
                this.replyAll = replyAll;
-               this.uid = uid;
-               this.folder = folder;
        }
 
        protected ReplyMessage() {
                
        }
+       
        public boolean getReplyAll() {
                return replyAll;
        }
        
-       public long getReplyMessageUid() {
-               return uid;
-       }
-       
-       public IMAPFolder getFolder() {
-               return folder;
-       }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to