Author: norman
Date: Sun Aug  2 13:49:24 2009
New Revision: 800079

URL: http://svn.apache.org/viewvc?rev=800079&view=rev
Log:
Start to work on reply/reply all

Added:
    
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
      - copied, changed from r799680, 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.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/handler/SendMessageHandler.java
    labs/hupa/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java

Copied: 
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
 (from r799680, 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java)
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java?p2=labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java&p1=labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java&r1=799680&r2=800079&rev=800079&view=diff
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java 
(original)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java
 Sun Aug  2 13:49:24 2009
@@ -1,21 +1,3 @@
-/****************************************************************
- * 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;
 
@@ -36,9 +18,7 @@
 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;
@@ -67,7 +47,7 @@
  * Handle sending of email messages
  * 
  */
-public class SendMessageHandler extends AbstractSessionHandler<SendMessage, 
EmptyResult> {
+public abstract class AbstractSendMessageHandler<A extends SendMessage> 
extends AbstractSessionHandler<A,EmptyResult> {
 
        private final FileItemRegistry registry;
        private final Properties props = new Properties();
@@ -76,7 +56,7 @@
        private final int port;
 
        @Inject
-       public SendMessageHandler(Log logger, FileItemRegistry 
registry,IMAPStoreCache store, Provider<HttpSession> 
provider,@SMTPServerAddress String address, @SMTPServerPort int port, @SMTPAuth 
boolean auth) {
+       public AbstractSendMessageHandler(Log logger, FileItemRegistry 
registry,IMAPStoreCache store, Provider<HttpSession> 
provider,@SMTPServerAddress String address, @SMTPServerPort int port, @SMTPAuth 
boolean auth) {
                super(store,logger,provider);
                this.registry = registry;
                this.auth = auth;
@@ -85,117 +65,72 @@
                props.put("mail.smtp.auth", auth);
        }
 
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.hupa.server.handler.AbstractSessionHandler#executeInternal(org.apache.hupa.shared.rpc.Session,
 net.customware.gwt.dispatch.server.ExecutionContext)
-        */
-       public EmptyResult executeInternal(SendMessage action, ExecutionContext 
context)
-                       throws ActionException {
-               try {
-
-                       Session session = Session.getDefaultInstance(props);
-                       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(m.getHeader().getSubject());
 
-                       ArrayList<MessageAttachment> attachments = 
m.getMessageContent()
-                                       .getMessageAttachments();
-                       // check if there are any attachments to include
-                       if (attachments == null || attachments.isEmpty()) {
-                               
message.setText(m.getMessageContent().getText());
-                       } else {
-                               // create the message part
-                               MimeBodyPart messageBodyPart = new 
MimeBodyPart();
-
-                               // fill message
-                               
messageBodyPart.setText(m.getMessageContent().getText());
-
-                               Multipart multipart = new MimeMultipart();
+       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 {
+
+               ArrayList<MessageAttachment> attachments = m.getMessageContent()
+                               .getMessageAttachments();
+               // check if there are any attachments to include
+               if (attachments == null || attachments.isEmpty()) {
+                       message.setText(m.getMessageContent().getText());
+               } else {
+                       // create the message part
+                       MimeBodyPart messageBodyPart = new MimeBodyPart();
+
+                       // fill message
+                       
messageBodyPart.setText(m.getMessageContent().getText());
+
+                       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);
-
-                               // 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);
-                               }
-                               // Put parts in message
-                               message.setContent(multipart);
-
                        }
-                       // save message 
-                       message.saveChanges();
-                       
-                       User user = getUser(action.getSessionId());
-                       Transport transport = session.getTransport("smtp");
-                       // check if smtp auth is needed
-                       if (auth) {
-                               logger.debug("Use auth for smtp connection");
+                       // Put parts in message
+                       message.setContent(multipart);
 
-                               transport.connect(address,port,user.getName(), 
user.getPassword());
-                       } else {
-                               transport.connect(address, port, null,null);
-                       }
-                       logger.info("Send message from " + 
m.getHeader().getFrom()+ " to " + message.getRecipients(RecipientType.TO));
-                       transport.sendMessage(message, 
message.getAllRecipients());
-                       
-                       // store message in sent folder
-                       IMAPStore iStore = cache.get(user);
-                       IMAPFolder folder = (IMAPFolder) 
iStore.getFolder(org.apache.hupa.shared.data.IMAPFolder.DEFAULT_SENT);
-                       if (folder.exists() == false) {
-                               folder.create(IMAPFolder.READ_WRITE);
-                       }
-                       if (folder.isOpen() == false) {
-                               folder.open(Folder.READ_WRITE);
-                       }
-                       message.setFlag(Flag.SEEN, true);
-                       folder.appendMessages(new Message[] {message});
-                       folder.close(false);
-               } catch (AddressException e) {
-                       logger.error("Error while parsing recipient", e);
-                       throw new ActionException("Error while parsing 
recipient");
-               } catch (MessagingException e) {
-                       logger.error("Error while sending message", e);
-                       throw new ActionException("Error while sending 
message");
                }
-               return new EmptyResult();
+               // save message 
+               message.saveChanges();
        }
-
-       /*
-        * (non-Javadoc)
-        * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
-        */
-       public Class<SendMessage> getActionType() {
-               return SendMessage.class;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
net.customware.gwt.dispatch.server.ActionHandler#rollback(net.customware.gwt.dispatch.shared.Action,
 net.customware.gwt.dispatch.shared.Result, 
net.customware.gwt.dispatch.server.ExecutionContext)
-        */
-       public void rollback(SendMessage arg0, EmptyResult arg1,
-                       ExecutionContext arg2) throws ActionException {
-               // not implemented
+       protected void sendMessage(User user, Session session, Message message) 
throws MessagingException {
+               Transport transport = session.getTransport("smtp");
+               // check if smtp auth is needed
+               if (auth) {
+                       logger.debug("Use auth for smtp connection");
+
+                       transport.connect(address,port,user.getName(), 
user.getPassword());
+               } else {
+                       transport.connect(address, port, null,null);
+               }
+               logger.info("Send message from " + 
message.getFrom()[0].toString()+ " to " + 
message.getRecipients(RecipientType.TO).toString());
+               transport.sendMessage(message, message.getAllRecipients());
+               
+               // store message in sent folder
+               IMAPStore iStore = cache.get(user);
+               IMAPFolder folder = (IMAPFolder) 
iStore.getFolder(org.apache.hupa.shared.data.IMAPFolder.DEFAULT_SENT);
+               if (folder.exists() == false) {
+                       folder.create(IMAPFolder.READ_WRITE);
+               }
+               if (folder.isOpen() == false) {
+                       folder.open(Folder.READ_WRITE);
+               }
+               message.setFlag(Flag.SEEN, true);
+               folder.appendMessages(new Message[] {message});
+               folder.close(false);
        }
+       
+       
 
        /**
         * DataStore which wrap a FileItem
@@ -251,4 +186,35 @@
 
        }
 
+
+
+       @Override
+       protected EmptyResult executeInternal(A action, ExecutionContext 
context)
+                       throws ActionException {
+               try {
+                       Session session = Session.getDefaultInstance(props);
+
+                       Message message = createMessage(session, action);
+                       fillBody(message,action.getMessage());
+                       
+                       sendMessage(getUser(action.getSessionId()),session, 
message);
+                       
+               
+               } catch (AddressException e) {
+                       logger.error("Error while parsing recipient", e);
+                       throw new ActionException("Error while parsing 
recipient");
+               } catch (MessagingException e) {
+                       logger.error("Error while sending message", e);
+                       throw new ActionException("Error while sending 
message");
+               }
+               return new EmptyResult();
+       }
+
+       public void rollback(A arg0, EmptyResult arg1, ExecutionContext arg2)
+                       throws ActionException {
+               // TODO Auto-generated method stub
+               
+       }
+       
+
 }

Added: 
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=800079&view=auto
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java 
(added)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java 
Sun Aug  2 13:49:24 2009
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.AddressException;
+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.shared.rpc.ReplyMessage;
+
+import com.google.inject.Provider;
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class ReplyMessageHandler extends 
AbstractSendMessageHandler<ReplyMessage>{
+
+       public ReplyMessageHandler(Log logger, FileItemRegistry registry,
+                       IMAPStoreCache store, Provider<HttpSession> provider,
+                       String address, int port, boolean auth) {
+               super(logger, registry, store, provider, address, port, auth);
+       }
+
+       @Override
+       protected Message createMessage(Session session, ReplyMessage action)
+                       throws AddressException, MessagingException, 
ActionException {
+               IMAPStore store = cache.get(getUser(action.getSessionId()));
+               IMAPFolder folder = (IMAPFolder) 
store.getFolder(action.getFolder().getFullName());
+               Message m = folder.getMessageByUID(action.getReplyMessageUid());
+               return m.reply(action.getReplyAll());
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
+        */
+       public Class<ReplyMessage> getActionType() {
+               return ReplyMessage.class;
+       }
+
+}

Modified: 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java?rev=800079&r1=800078&r2=800079&view=diff
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java 
(original)
+++ 
labs/hupa/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java 
Sun Aug  2 13:49:24 2009
@@ -1,254 +1,74 @@
-/****************************************************************
- * 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.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Properties;
-
-import javax.activation.DataHandler;
-import javax.activation.DataSource;
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Session;
-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;
-import net.customware.gwt.dispatch.shared.ActionException;
-
-import org.apache.commons.fileupload.FileItem;
-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.data.MessageAttachment;
-import org.apache.hupa.shared.data.User;
-import org.apache.hupa.shared.rpc.EmptyResult;
-import org.apache.hupa.shared.rpc.SendMessage;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPStore;
-
-/**
- * Handle sending of email messages
- * 
- */
-public class SendMessageHandler extends AbstractSessionHandler<SendMessage, 
EmptyResult> {
-
-       private final FileItemRegistry registry;
-       private final Properties props = new Properties();
-       private final boolean auth;
-       private final String address;
-       private final int port;
-
-       @Inject
-       public SendMessageHandler(Log logger, FileItemRegistry 
registry,IMAPStoreCache store, Provider<HttpSession> 
provider,@SMTPServerAddress String address, @SMTPServerPort int port, @SMTPAuth 
boolean auth) {
-               super(store,logger,provider);
-               this.registry = registry;
-               this.auth = auth;
-               this.address = address;
-               this.port = port;
-               props.put("mail.smtp.auth", auth);
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.hupa.server.handler.AbstractSessionHandler#executeInternal(org.apache.hupa.shared.rpc.Session,
 net.customware.gwt.dispatch.server.ExecutionContext)
-        */
-       public EmptyResult executeInternal(SendMessage action, ExecutionContext 
context)
-                       throws ActionException {
-               try {
-
-                       Session session = Session.getDefaultInstance(props);
-                       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(m.getHeader().getSubject());
-
-                       ArrayList<MessageAttachment> attachments = 
m.getMessageContent()
-                                       .getMessageAttachments();
-                       // check if there are any attachments to include
-                       if (attachments == null || attachments.isEmpty()) {
-                               
message.setText(m.getMessageContent().getText());
-                       } else {
-                               // create the message part
-                               MimeBodyPart messageBodyPart = new 
MimeBodyPart();
-
-                               // fill message
-                               
messageBodyPart.setText(m.getMessageContent().getText());
-
-                               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);
-                               }
-                               // Put parts in message
-                               message.setContent(multipart);
-
-                       }
-                       // save message 
-                       message.saveChanges();
-                       
-                       User user = getUser(action.getSessionId());
-                       Transport transport = session.getTransport("smtp");
-                       // check if smtp auth is needed
-                       if (auth) {
-                               logger.debug("Use auth for smtp connection");
-
-                               transport.connect(address,port,user.getName(), 
user.getPassword());
-                       } else {
-                               transport.connect(address, port, null,null);
-                       }
-                       logger.info("Send message from " + 
m.getHeader().getFrom()+ " to " + message.getRecipients(RecipientType.TO));
-                       transport.sendMessage(message, 
message.getAllRecipients());
-                       
-                       // store message in sent folder
-                       IMAPStore iStore = cache.get(user);
-                       IMAPFolder folder = (IMAPFolder) 
iStore.getFolder(org.apache.hupa.shared.data.IMAPFolder.DEFAULT_SENT);
-                       if (folder.exists() == false) {
-                               folder.create(IMAPFolder.READ_WRITE);
-                       }
-                       if (folder.isOpen() == false) {
-                               folder.open(Folder.READ_WRITE);
-                       }
-                       message.setFlag(Flag.SEEN, true);
-                       folder.appendMessages(new Message[] {message});
-                       folder.close(false);
-               } catch (AddressException e) {
-                       logger.error("Error while parsing recipient", e);
-                       throw new ActionException("Error while parsing 
recipient");
-               } catch (MessagingException e) {
-                       logger.error("Error while sending message", e);
-                       throw new ActionException("Error while sending 
message");
-               }
-               return new EmptyResult();
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
-        */
-       public Class<SendMessage> getActionType() {
-               return SendMessage.class;
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see 
net.customware.gwt.dispatch.server.ActionHandler#rollback(net.customware.gwt.dispatch.shared.Action,
 net.customware.gwt.dispatch.shared.Result, 
net.customware.gwt.dispatch.server.ExecutionContext)
-        */
-       public void rollback(SendMessage arg0, EmptyResult arg1,
-                       ExecutionContext arg2) throws ActionException {
-               // not implemented
-       }
-
-       /**
-        * DataStore which wrap a FileItem
-        * 
-        */
-       private class FileItemDataStore implements DataSource {
-
-               private FileItem item;
-
-               public FileItemDataStore(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;
-               }
-
-       }
-
-}
+/****************************************************************
+ * 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.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.FileItemRegistry;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.shared.rpc.SendMessage;
+
+import com.google.inject.Provider;
+
+public class SendMessageHandler extends 
AbstractSendMessageHandler<SendMessage> {
+
+       public SendMessageHandler(Log logger, FileItemRegistry registry,
+                       IMAPStoreCache store, Provider<HttpSession> provider,
+                       String address, int port, boolean auth) {
+               super(logger, registry, store, provider, address, port, auth);
+       }
+
+       @Override
+       protected Message createMessage(Session session, SendMessage action)
+                       throws AddressException, MessagingException {
+               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(m.getHeader().getSubject());
+               return message;
+       }
+
+       public Class<SendMessage> getActionType() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+}

Added: 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=800079&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java (added)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/ReplyMessage.java Sun 
Aug  2 13:49:24 2009
@@ -0,0 +1,57 @@
+package org.apache.hupa.shared.rpc;
+/****************************************************************
+ * 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.                                           *
+ ****************************************************************/
+
+
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.Message;
+
+public class ReplyMessage extends SendMessage{
+
+       /**
+        * 
+        */
+       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);
+               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;
+       }
+
+}

Modified: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java?rev=800079&r1=800078&r2=800079&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java 
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/SendMessage.java Sun Aug 
 2 13:49:24 2009
@@ -36,8 +36,7 @@
                this.msg = msg;
        }
        
-       @SuppressWarnings("unused")
-       private SendMessage() {
+       protected SendMessage() {
                
        }
        



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

Reply via email to