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 do...@apache.org on 2013/08/21 16:08:29 UTC
svn commit: r1516164 [15/20] - in /james/hupa/trunk: ./ client/
client/src/main/java/com/ client/src/main/java/com/google/
client/src/main/java/com/google/web/
client/src/main/java/com/google/web/bindery/
client/src/main/java/com/google/web/bindery/req...
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LoginUserServiceImpl.java (from r1375909, 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/service/LoginUserServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LoginUserServiceImpl.java&p1=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/SendMessageHandler.java&r1=1375909&r2=1516164&rev=1516164&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/service/LoginUserServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -1,54 +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.server.handler;
-
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.logging.Log;
-import org.apache.hupa.server.IMAPStoreCache;
-import org.apache.hupa.server.preferences.UserPreferencesStorage;
-import org.apache.hupa.shared.rpc.SendMessage;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.name.Named;
-
-/**
- * Handler which handle sending of new messages
- *
- *
- */
-public class SendMessageHandler extends AbstractSendMessageHandler<SendMessage> {
-
- @Inject
- public SendMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider, UserPreferencesStorage preferences,
- @Named("SMTPServerAddress") String address, @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL) {
- super(logger, store, provider, preferences, address, port, auth,useSSL);
- }
-
- /*
- * (non-Javadoc)
- * @see net.customware.gwt.dispatch.server.ActionHandler#getActionType()
- */
- public Class<SendMessage> getActionType() {
- return SendMessage.class;
- }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server.service;
+
+import javax.mail.MessagingException;
+import javax.servlet.http.HttpSession;
+
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.UserImpl;
+import org.apache.hupa.shared.domain.Settings;
+import org.apache.hupa.shared.domain.User;
+import org.apache.hupa.shared.exception.HupaException;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+public class LoginUserServiceImpl extends AbstractService implements LoginUserService {
+
+ @Inject private Provider<Settings> settingsProvider;
+
+ public User login(String username, String password) throws HupaException, MessagingException {
+ HttpSession httpSession = httpSessionProvider.get();
+ SessionUtils.cleanSessionAttributes(httpSession);
+ User user = new UserImpl();
+ user.setName(username);
+ user.setPassword(password);
+ cache.get(user);
+ user.setAuthenticated(true);
+ user.setSettings(settingsProvider.get());
+ httpSession.setAttribute(SConsts.USER_SESS_ATTR, user);
+ logger.debug("Logged user: " + username);
+ return user;
+ }
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserService.java (from r1375909, james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserService.java&p1=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserService.java Wed Aug 21 14:08:19 2013
@@ -1,30 +1,27 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-
-package org.apache.hupa.client.mvp;
-
-public interface NameAwareWidgetDisplay {
-
- /**
- * Return the name for the Display to show
- *
- * @return name
- */
- public String getName();
-}
+/****************************************************************
+ * 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.service;
+
+import org.apache.hupa.shared.domain.LogoutUserResult;
+import org.apache.hupa.shared.exception.HupaException;
+
+public interface LogoutUserService {
+ LogoutUserResult logout() throws HupaException;
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserServiceImpl.java (from r1375909, james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserServiceImpl.java&p1=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/rf/SubjectProxy.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/LogoutUserServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -1,39 +1,44 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-package org.apache.hupa.client.rf;
-
-import org.apache.hupa.server.rf.Subject;
-
-import com.google.web.bindery.requestfactory.shared.EntityProxy;
-import com.google.web.bindery.requestfactory.shared.ProxyFor;
-
-@ProxyFor(Subject.class)
-public interface SubjectProxy extends EntityProxy {
- String getTitle();
-
- Long getId();
-
- Integer getVersion();
-
- void setTitle(String title);
-
- void setId(Long id);
-
- void setVersion(Integer version);
-}
+/****************************************************************
+ * 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.service;
+
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.shared.data.LogoutUserResultImpl;
+import org.apache.hupa.shared.domain.LogoutUserResult;
+import org.apache.hupa.shared.domain.User;
+import org.apache.hupa.shared.exception.HupaException;
+
+public class LogoutUserServiceImpl extends AbstractService implements LogoutUserService {
+ @Override
+ public LogoutUserResult logout() throws HupaException {
+
+ User user = getUser();
+ user.setAuthenticated(false);
+
+ // delete cached store
+ cache.delete(user);
+
+ // remove user attributes from session
+ SessionUtils.cleanSessionAttributes(httpSessionProvider.get());
+
+ return new LogoutUserResultImpl(user);
+
+ }
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageService.java (from r1375909, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageService.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageService.java Wed Aug 21 14:08:19 2013
@@ -17,12 +17,11 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.shared.rpc;
+package org.apache.hupa.server.service;
-import java.io.Serializable;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.MoveMessageAction;
-import net.customware.gwt.dispatch.shared.Action;
-
-public class Contacts implements Action<ContactsResult>, Serializable{
- private static final long serialVersionUID = 1l;
+public interface MoveMessageService {
+ GenericResult move(MoveMessageAction action)throws Exception;
}
Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageServiceImpl.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageServiceImpl.java?rev=1516164&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageServiceImpl.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/MoveMessageServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.service;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+import org.apache.hupa.shared.data.GenericResultImpl;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.MoveMessageAction;
+import org.apache.hupa.shared.domain.User;
+
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class MoveMessageServiceImpl extends AbstractService implements MoveMessageService {
+ public GenericResult move(MoveMessageAction action) throws Exception {
+ User user = getUser();
+ try {
+ IMAPStore store = cache.get(user);
+ IMAPFolder folder = (IMAPFolder) store.getFolder(action.getOldFolder().getFullName());
+ if (folder.isOpen() == false) {
+ folder.open(Folder.READ_WRITE);
+ }
+ Message m = folder.getMessageByUID(action.getMessageUid());
+ Message[] mArray = new Message[] { m };
+ folder.copyMessages(mArray, store.getFolder(action.getNewFolder().getFullName()));
+ folder.setFlags(mArray, new Flags(Flags.Flag.DELETED), true);
+ try {
+ folder.expunge(mArray);
+ folder.close(false);
+ } catch (MessagingException e) {
+ // prolly UID expunge is not supported
+ folder.close(true);
+ }
+ return new GenericResultImpl();
+ } catch (MessagingException e) {
+ logger.error(
+ "Error while moving message " + action.getMessageUid() + " from folder " + action.getOldFolder()
+ + " to " + action.getNewFolder(), e);
+ throw new Exception(e);
+ }
+ }
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderService.java (from r1375909, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderService.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderService.java Wed Aug 21 14:08:19 2013
@@ -17,12 +17,11 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.shared.rpc;
+package org.apache.hupa.server.service;
-import java.io.Serializable;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.RenameFolderAction;
-import net.customware.gwt.dispatch.shared.Action;
-
-public class Contacts implements Action<ContactsResult>, Serializable{
- private static final long serialVersionUID = 1l;
+public interface RenameFolderService {
+ GenericResult rename(RenameFolderAction action) throws Exception;
}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderServiceImpl.java (from r1375909, james/hupa/trunk/server/src/main/java/org/apache/hupa/server/IMAPStoreCache.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderServiceImpl.java&p1=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/IMAPStoreCache.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/IMAPStoreCache.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/RenameFolderServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -17,22 +17,36 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.server;
+package org.apache.hupa.server.service;
-import javax.mail.MessagingException;
-import javax.mail.NoSuchProviderException;
-import javax.mail.Session;
-import javax.mail.Transport;
+import javax.mail.Folder;
-import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.data.GenericResultImpl;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.ImapFolder;
+import org.apache.hupa.shared.domain.RenameFolderAction;
+import org.apache.hupa.shared.domain.User;
import com.sun.mail.imap.IMAPStore;
-public interface IMAPStoreCache {
- public void delete(String username);
- public void delete(User user);
- public IMAPStore get(String username,String password) throws MessagingException;
- public IMAPStore get(User user) throws MessagingException;
- public Transport getMailTransport(boolean useSSL) throws NoSuchProviderException;
- public Session getMailSession();
+public class RenameFolderServiceImpl extends AbstractService implements RenameFolderService {
+
+ @Override
+ public GenericResult rename(RenameFolderAction action) throws Exception {
+ User user = getUser();
+ ImapFolder folder = action.getFolder();
+ String newName = action.getNewName();
+ IMAPStore store = cache.get(user);
+ com.sun.mail.imap.IMAPFolder iFolder = (com.sun.mail.imap.IMAPFolder) store.getFolder(folder.getFullName());
+ Folder newFolder = store.getFolder(newName);
+
+ if (iFolder.isOpen()) {
+ iFolder.close(false);
+ }
+ if (iFolder.renameTo(newFolder)) {
+ return new GenericResultImpl();
+ }
+ throw new Exception("Unable to rename Folder " + folder.getFullName() + " to " + newName + " for user " + user);
+ }
+
}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageService.java (from r1375909, james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageService.java&p1=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageService.java Wed Aug 21 14:08:19 2013
@@ -1,30 +1,27 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-
-package org.apache.hupa.client.mvp;
-
-public interface NameAwareWidgetDisplay {
-
- /**
- * Return the name for the Display to show
- *
- * @return name
- */
- public String getName();
-}
+/****************************************************************
+ * 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.service;
+
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.SendMessageAction;
+
+public interface SendForwardMessageService {
+ GenericResult send(SendMessageAction action)throws Exception;
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageServiceImpl.java (from r1375909, 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/service/SendForwardMessageServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendForwardMessageServiceImpl.java&p1=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ForwardMessageHandler.java&r1=1375909&r2=1516164&rev=1516164&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/service/SendForwardMessageServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -1,89 +1,73 @@
-/****************************************************************
- * 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.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.servlet.http.HttpSession;
-
-import net.customware.gwt.dispatch.shared.ActionException;
-
-import org.apache.commons.logging.Log;
-import org.apache.hupa.server.IMAPStoreCache;
-import org.apache.hupa.server.preferences.UserPreferencesStorage;
-import org.apache.hupa.server.utils.MessageUtils;
-import org.apache.hupa.shared.rpc.ForwardMessage;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.name.Named;
-import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPStore;
-
-/**
- * Handler which handles the forwarding of a message
- *
- */
-public class ForwardMessageHandler extends AbstractSendMessageHandler<ForwardMessage> {
-
- @Inject
- public ForwardMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider, UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address, @Named("SMTPServerPort") int port,
- @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL) {
- super(logger, store, provider, preferences, address, port, auth, useSSL);
- }
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected List getAttachments(ForwardMessage action) throws MessagingException, ActionException {
- List<?> items = new ArrayList();
- IMAPStore store = cache.get(getUser());
-
- IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName());
- if (folder.isOpen() == false) {
- folder.open(Folder.READ_ONLY);
- }
- // Put the original attachments in the list
- Message msg = folder.getMessageByUID(action.getReplyMessageUid());
- try {
- items = MessageUtils.extractMessageAttachments(logger, msg.getContent());
- logger.debug("Forwarding a message, extracted: " + items.size() + " from original.");
- } catch (IOException e) {
- e.printStackTrace();
- }
- // Put in 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()
- */
- public Class<ForwardMessage> getActionType() {
- return ForwardMessage.class;
- }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server.service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.preferences.UserPreferencesStorage;
+import org.apache.hupa.server.utils.MessageUtils;
+import org.apache.hupa.shared.domain.SendForwardMessageAction;
+import org.apache.hupa.shared.domain.SendMessageAction;
+import org.apache.hupa.shared.exception.HupaException;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class SendForwardMessageServiceImpl extends SendMessageBaseServiceImpl implements SendForwardMessageService{
+
+ @Inject
+ public SendForwardMessageServiceImpl(UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address,
+ @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL, IMAPStoreCache cache) {
+ super(preferences, address, port, auth, useSSL,cache);
+ }
+
+ @Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected List getAttachments(SendMessageAction action) throws MessagingException, HupaException {
+ SendForwardMessageAction forwardAction = (SendForwardMessageAction)action;
+ List<?> items = new ArrayList();
+ IMAPStore store = cache.get(getUser());
+
+ IMAPFolder folder = (IMAPFolder) store.getFolder(forwardAction.getFolder().getFullName());
+ if (folder.isOpen() == false) {
+ folder.open(Folder.READ_ONLY);
+ }
+ // Put the original attachments in the list
+ Message msg = folder.getMessageByUID(forwardAction.getUid());
+ try {
+ items = MessageUtils.extractMessageAttachments(logger, msg.getContent());
+ logger.debug("Forwarding a message, extracted: " + items.size() + " from original.");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ // Put in the list the attachments uploaded by the user
+ items.addAll(super.getAttachments(forwardAction));
+ return items;
+ }
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageBaseServiceImpl.java (from r1375909, 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/service/SendMessageBaseServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageBaseServiceImpl.java&p1=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/AbstractSendMessageHandler.java&r1=1375909&r2=1516164&rev=1516164&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/service/SendMessageBaseServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.server.handler;
+package org.apache.hupa.server.service;
import java.io.File;
import java.io.IOException;
@@ -43,13 +43,8 @@ import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
import javax.mail.internet.MimeMultipart;
-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.preferences.UserPreferencesStorage;
@@ -57,47 +52,46 @@ import org.apache.hupa.server.utils.Mess
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;
-import org.apache.hupa.shared.rpc.GenericResult;
-import org.apache.hupa.shared.rpc.SendMessage;
+import org.apache.hupa.shared.data.GenericResultImpl;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.MessageAttachment;
+import org.apache.hupa.shared.domain.SendMessageAction;
+import org.apache.hupa.shared.domain.SmtpMessage;
+import org.apache.hupa.shared.domain.User;
+import org.apache.hupa.shared.exception.HupaException;
import com.google.inject.Inject;
-import com.google.inject.Provider;
import com.google.inject.name.Named;
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPStore;
-/**
- * Handle sending of email messages
- *
- */
-public abstract class AbstractSendMessageHandler<A extends SendMessage> extends AbstractSessionHandler<A,GenericResult> {
-
- private final boolean auth;
- private final String address;
- private final int port;
- private boolean useSSL = false;
- UserPreferencesStorage userPreferences;
- Session session;
-
- @Inject
- public AbstractSendMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider, UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address, @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL) {
- super(store,logger,provider);
- this.auth = auth;
- this.address = address;
- this.port = port;
- this.useSSL = useSSL;
- this.userPreferences = preferences;
- this.session = store.getMailSession();
- session.getProperties().put("mail.smtp.auth", auth);
- }
-
- @Override
- protected GenericResult executeInternal(A action, ExecutionContext context)
- throws ActionException {
- GenericResult result = new GenericResult();
+public class SendMessageBaseServiceImpl extends AbstractService implements SendMessageService{
+
+ private final boolean auth;
+ private final String address;
+ private final int port;
+ private boolean useSSL = false;
+ UserPreferencesStorage userPreferences;
+ Session session;
+
+ @Inject
+ public SendMessageBaseServiceImpl(UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address,
+ @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL, IMAPStoreCache cache) {
+ this.cache = cache;
+ this.auth = auth;
+ this.address = address;
+ this.port = port;
+ this.useSSL = useSSL;
+ this.userPreferences = preferences;
+ this.session = cache.getMailSession();
+ session.getProperties().put("mail.smtp.auth", auth);
+ }
+
+
+
+ public GenericResult send(SendMessageAction action)
+ throws Exception {
+ GenericResult result = new GenericResultImpl();
try {
Message message = createMessage(session, action);
@@ -134,11 +128,10 @@ public abstract class AbstractSendMessag
* @return message
* @throws AddressException
* @throws MessagingException
- * @throws ActionException
*/
- protected Message createMessage(Session session, A action) throws AddressException, MessagingException {
+ protected Message createMessage(Session session, SendMessageAction action) throws AddressException, MessagingException {
MimeMessage message = new MimeMessage(session);
- SMTPMessage m = action.getMessage();
+ SmtpMessage m = action.getMessage();
message.setFrom(new InternetAddress(m.getFrom()));
userPreferences.addContact(m.getTo());
@@ -148,13 +141,14 @@ public abstract class AbstractSendMessag
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(MessageUtils.encodeTexts(m.getSubject()));
+// message.setSubject(MessageUtils.encodeTexts(m.getSubject()));
+ message.setSubject(m.getSubject(), "utf-8");
updateHeaders(message, action);
message.saveChanges();
return message;
}
- protected void updateHeaders(MimeMessage message, A action) {
+ protected void updateHeaders(MimeMessage message, SendMessageAction action) {
if (action.getInReplyTo() != null) {
try {
message.addHeader(SConsts.HEADER_IN_REPLY_TO, action.getInReplyTo());
@@ -178,10 +172,10 @@ public abstract class AbstractSendMessag
* @param action the action
* @return filledMessage
* @throws MessagingException
- * @throws ActionException
* @throws IOException
+ * @throws HupaException
*/
- protected Message fillBody(Message message, A action) throws MessagingException, ActionException, IOException {
+ protected Message fillBody(Message message, SendMessageAction action) throws MessagingException, IOException, HupaException {
String html = restoreInlineLinks(action.getMessage().getText());
@@ -216,9 +210,10 @@ public abstract class AbstractSendMessag
*
* @param action
* @return A list of stored attachments
+ * @throws HupaException
*/
@SuppressWarnings("rawtypes")
- protected List getAttachments(A action) throws MessagingException, ActionException {
+ protected List getAttachments(SendMessageAction action) throws MessagingException, HupaException {
FileItemRegistry registry = SessionUtils.getSessionRegistry(logger, httpSessionProvider.get());
List<MessageAttachment> attachments = action.getMessage().getMessageAttachments();
@@ -241,9 +236,9 @@ public abstract class AbstractSendMessag
* @throws MessagingException
* @throws ActionException
*/
- protected void resetAttachments(A action) throws MessagingException, ActionException {
- SMTPMessage msg = action.getMessage();
- ArrayList<MessageAttachment> attachments = msg.getMessageAttachments();
+ protected void resetAttachments(SendMessageAction action) throws MessagingException {
+ SmtpMessage msg = action.getMessage();
+ List<MessageAttachment> attachments = msg.getMessageAttachments();
if (attachments != null && ! attachments.isEmpty()) {
for(MessageAttachment attach : attachments)
SessionUtils.getSessionRegistry(logger, httpSessionProvider.get()).remove(attach.getName());
@@ -444,4 +439,5 @@ public abstract class AbstractSendMessag
}
+
}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageService.java (from r1375909, james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageService.java&p1=james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/client/src/main/java/org/apache/hupa/client/mvp/NameAwareWidgetDisplay.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendMessageService.java Wed Aug 21 14:08:19 2013
@@ -1,30 +1,27 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one *
- * or more contributor license agreements. See the NOTICE file *
- * distributed with this work for additional information *
- * regarding copyright ownership. The ASF licenses this file *
- * to you under the Apache License, Version 2.0 (the *
- * "License"); you may not use this file except in compliance *
- * with the License. You may obtain a copy of the License at *
- * *
- * http://www.apache.org/licenses/LICENSE-2.0 *
- * *
- * Unless required by applicable law or agreed to in writing, *
- * software distributed under the License is distributed on an *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
- * KIND, either express or implied. See the License for the *
- * specific language governing permissions and limitations *
- * under the License. *
- ****************************************************************/
-
-package org.apache.hupa.client.mvp;
-
-public interface NameAwareWidgetDisplay {
-
- /**
- * Return the name for the Display to show
- *
- * @return name
- */
- public String getName();
-}
+/****************************************************************
+ * 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.service;
+
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.SendMessageAction;
+
+public interface SendMessageService {
+ GenericResult send(SendMessageAction action)throws Exception;
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageService.java (from r1375909, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageService.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageService.java Wed Aug 21 14:08:19 2013
@@ -17,12 +17,11 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.shared.rpc;
+package org.apache.hupa.server.service;
-import java.io.Serializable;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.SendMessageAction;
-import net.customware.gwt.dispatch.shared.Action;
-
-public class Contacts implements Action<ContactsResult>, Serializable{
- private static final long serialVersionUID = 1l;
+public interface SendReplyMessageService {
+ GenericResult send(SendMessageAction action)throws Exception;
}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageServiceImpl.java (from r1375909, 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/service/SendReplyMessageServiceImpl.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SendReplyMessageServiceImpl.java&p1=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/handler/ReplyMessageHandler.java&r1=1375909&r2=1516164&rev=1516164&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/service/SendReplyMessageServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -1,94 +1,79 @@
-/****************************************************************
- * 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.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.mail.Folder;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.servlet.http.HttpSession;
-
-import net.customware.gwt.dispatch.shared.ActionException;
-
-import org.apache.commons.logging.Log;
-import org.apache.hupa.server.IMAPStoreCache;
-import org.apache.hupa.server.preferences.UserPreferencesStorage;
-import org.apache.hupa.server.utils.MessageUtils;
-import org.apache.hupa.shared.rpc.ReplyMessage;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.name.Named;
-import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPStore;
-
-/**
- * Handler which handle replies to a message
- *
- *
- */
-public class ReplyMessageHandler extends AbstractSendMessageHandler<ReplyMessage> {
-
- @Inject
- public ReplyMessageHandler(Log logger, IMAPStoreCache store, Provider<HttpSession> provider, UserPreferencesStorage preferences,
- @Named("SMTPServerAddress") String address, @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL) {
- super(logger, store, provider, preferences, address, port, auth, useSSL);
- }
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected List getAttachments(ReplyMessage action) throws MessagingException, ActionException {
- List<?> items = new ArrayList();
- IMAPStore store = cache.get(getUser());
-
- IMAPFolder folder = (IMAPFolder) store.getFolder(action.getFolder().getFullName());
- if (folder.isOpen() == false) {
- folder.open(Folder.READ_ONLY);
- }
-
- // 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()
- */
- public Class<ReplyMessage> getActionType() {
- return ReplyMessage.class;
- }
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server.service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.preferences.UserPreferencesStorage;
+import org.apache.hupa.server.utils.MessageUtils;
+import org.apache.hupa.shared.domain.SendMessageAction;
+import org.apache.hupa.shared.domain.SendReplyMessageAction;
+import org.apache.hupa.shared.exception.HupaException;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class SendReplyMessageServiceImpl extends SendMessageBaseServiceImpl implements SendReplyMessageService{
+
+ @Inject
+ public SendReplyMessageServiceImpl(UserPreferencesStorage preferences, @Named("SMTPServerAddress") String address,
+ @Named("SMTPServerPort") int port, @Named("SMTPAuth") boolean auth, @Named("SMTPS") boolean useSSL, IMAPStoreCache cache) {
+ super(preferences, address, port, auth, useSSL,cache);
+ }
+
+ @Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected List getAttachments(SendMessageAction action) throws MessagingException, HupaException {
+ SendReplyMessageAction replyAction = (SendReplyMessageAction)action;
+ List<?> items = new ArrayList();
+ IMAPStore store = cache.get(getUser());
+
+ IMAPFolder folder = (IMAPFolder) store.getFolder(replyAction.getFolder().getFullName());
+ if (folder.isOpen() == false) {
+ folder.open(Folder.READ_ONLY);
+ }
+
+ // Only original inline images have to be added to the list
+ Message msg = folder.getMessageByUID(replyAction.getUid());
+ 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(replyAction));
+
+ return items;
+ }
+
+
+}
Copied: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagService.java (from r1375909, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagService.java?p2=james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagService.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java&r1=1375909&r2=1516164&rev=1516164&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/rpc/Contacts.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagService.java Wed Aug 21 14:08:19 2013
@@ -17,12 +17,13 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.shared.rpc;
+package org.apache.hupa.server.service;
-import java.io.Serializable;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.SetFlagAction;
-import net.customware.gwt.dispatch.shared.Action;
+public interface SetFlagService {
+
+ GenericResult set(SetFlagAction action) throws Exception;
-public class Contacts implements Action<ContactsResult>, Serializable{
- private static final long serialVersionUID = 1l;
}
Added: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagServiceImpl.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagServiceImpl.java?rev=1516164&view=auto
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagServiceImpl.java (added)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/service/SetFlagServiceImpl.java Wed Aug 21 14:08:19 2013
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.service;
+
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+import org.apache.hupa.server.handler.JavamailUtil;
+import org.apache.hupa.shared.data.GenericResultImpl;
+import org.apache.hupa.shared.domain.GenericResult;
+import org.apache.hupa.shared.domain.ImapFolder;
+import org.apache.hupa.shared.domain.SetFlagAction;
+import org.apache.hupa.shared.domain.User;
+
+import com.sun.mail.imap.IMAPStore;
+
+public class SetFlagServiceImpl extends AbstractService implements SetFlagService {
+
+ @Override
+ public GenericResult set(SetFlagAction action) throws Exception {
+ User user = getUser();
+ ImapFolder folder = action.getFolder();
+ List<Long> uids = action.getUids();
+ com.sun.mail.imap.IMAPFolder f = null;
+ try {
+ IMAPStore store = cache.get(user);
+
+ f = (com.sun.mail.imap.IMAPFolder) store.getFolder(folder.getFullName());
+ if (f.isOpen() == false) {
+ f.open(Folder.READ_WRITE);
+ }
+ Message[] msgs = f.getMessagesByUID(toArray(uids));
+ Flag flag = JavamailUtil.convert(action.getFlag());
+ Flags flags = new Flags();
+ flags.add(flag);
+
+ f.setFlags(msgs, flags, action.getValue());
+ return new GenericResultImpl();
+ } catch (MessagingException e) {
+ String errorMsg = "Error while setting flags of messages with uids " + uids + " for user " + user;
+ logger.error(errorMsg, e);
+ throw new Exception(errorMsg, e);
+ } finally {
+ if (f != null && f.isOpen()) {
+ try {
+ f.close(false);
+ } catch (MessagingException e) {
+ // ignore on close
+ }
+ }
+ }
+ }
+
+ private long[] toArray(List<Long> uids) {
+ long[] array = new long[uids.size()];
+ for (int i = 0; i < uids.size(); i++) {
+ array[i] = uids.get(i);
+ }
+ return array;
+ }
+}
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java?rev=1516164&r1=1516163&r2=1516164&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/DownloadAttachmentServlet.java Wed Aug 21 14:08:19 2013
@@ -38,7 +38,7 @@ import org.apache.commons.logging.Log;
import org.apache.hupa.server.IMAPStoreCache;
import org.apache.hupa.server.utils.MessageUtils;
import org.apache.hupa.shared.SConsts;
-import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.domain.User;
import com.google.inject.Inject;
import com.sun.mail.imap.IMAPFolder;
@@ -80,9 +80,10 @@ public class DownloadAttachmentServlet e
String attachmentName = request.getParameter(SConsts.PARAM_NAME);
String folderName = request.getParameter(SConsts.PARAM_FOLDER);
String mode = request.getParameter(SConsts.PARAM_MODE);
- if (!"inline".equals(mode)) {
- response.setHeader("Content-disposition", "attachment; filename="
- + attachmentName + "");
+ boolean inline = "inline".equals(mode);
+ if (!inline) {
+ response.setHeader("Content-disposition", "attachment; filename="
+ + attachmentName + "");
}
InputStream in = null;
OutputStream out = response.getOutputStream();
@@ -105,7 +106,11 @@ public class DownloadAttachmentServlet e
in = part.getInputStream();
if (in != null) {
- response.setContentLength(part.getSize());
+ // FIXME: for some reason Chrome does not display inline images when they have the content-length
+ // it's like the size reported in server is different than the received bytes.
+ if (!inline) {
+ response.setContentLength(part.getSize());
+ }
IOUtils.copy(in, out);
} else {
response.setContentLength(0);
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/MessageSourceServlet.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/MessageSourceServlet.java?rev=1516164&r1=1516163&r2=1516164&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/MessageSourceServlet.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/servlet/MessageSourceServlet.java Wed Aug 21 14:08:19 2013
@@ -33,7 +33,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.hupa.server.IMAPStoreCache;
import org.apache.hupa.shared.SConsts;
-import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.domain.User;
import com.google.inject.Inject;
import com.sun.mail.imap.IMAPFolder;
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=1516164&r1=1516163&r2=1516164&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 Aug 21 14:08:19 2013
@@ -19,7 +19,10 @@
package org.apache.hupa.server.utils;
+import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,17 +34,20 @@ import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Address;
import javax.mail.BodyPart;
+import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.logging.Log;
-import org.apache.hupa.server.handler.AbstractSendMessageHandler;
+import org.apache.hupa.shared.data.MessageAttachmentImpl;
+import org.apache.hupa.shared.domain.MessageAttachment;
@@ -118,6 +124,104 @@ public class MessageUtils {
}
return ret;
}
+
+ /**
+ * Handle the parts of the given message. The method will call itself
+ * recursively to handle all nested parts
+ *
+ * @param message the MimeMessage
+ * @param content the current processing Content
+ * @param sbPlain the StringBuffer to fill with text
+ * @param attachmentList ArrayList with attachments
+ * @throws UnsupportedEncodingException
+ * @throws MessagingException
+ * @throws IOException
+ */
+ public static boolean handleParts(Message message, Object content, StringBuffer sbPlain,
+ ArrayList<MessageAttachment> attachmentList) throws UnsupportedEncodingException, MessagingException,
+ IOException {
+ boolean isHTML = false;
+ if (content instanceof String) {
+ if (message.getContentType().toLowerCase().startsWith("text/html")) {
+ isHTML = true;
+ } else {
+ isHTML = false;
+ }
+ sbPlain.append((String) content);
+
+ } else if (content instanceof Multipart) {
+
+ Multipart mp = (Multipart) content;
+ String multipartContentType = mp.getContentType().toLowerCase();
+
+ String text = null;
+
+ if (multipartContentType.startsWith("multipart/alternative")) {
+ isHTML = handleMultiPartAlternative(mp, sbPlain);
+ } else {
+ for (int i = 0; i < mp.getCount(); i++) {
+ Part part = mp.getBodyPart(i);
+
+ String contentType = part.getContentType().toLowerCase();
+
+ Boolean bodyRead = sbPlain.length() > 0;
+
+ if (!bodyRead && contentType.startsWith("text/plain")) {
+ isHTML = false;
+ text = (String) part.getContent();
+ } else if (!bodyRead && contentType.startsWith("text/html")) {
+ isHTML = true;
+ text = (String) part.getContent();
+ } else if (!bodyRead && contentType.startsWith("message/rfc822")) {
+ // Extract the message and pass it
+ MimeMessage msg = (MimeMessage) part.getDataHandler().getContent();
+ isHTML = handleParts(msg, msg.getContent(), sbPlain, attachmentList);
+ } else {
+ if (part.getFileName() != null) {
+ // Inline images are not added to the attachment
+ // list
+ // TODO: improve the in-line images detection
+ if (part.getHeader("Content-ID") == null) {
+ MessageAttachment attachment = new MessageAttachmentImpl();
+ attachment.setName(MimeUtility.decodeText(part.getFileName()));
+ attachment.setContentType(part.getContentType());
+ attachment.setSize(part.getSize());
+ attachmentList.add(attachment);
+ }
+ } else {
+ isHTML = handleParts(message, part.getContent(), sbPlain, attachmentList);
+ }
+ }
+
+ }
+ if (text != null)
+ sbPlain.append(text);
+ }
+
+ }
+ return isHTML;
+ }
+
+ private static boolean handleMultiPartAlternative(Multipart mp, StringBuffer sbPlain) throws MessagingException, IOException {
+ String text = null;
+ boolean isHTML = false;
+ for (int i = 0; i < mp.getCount(); i++) {
+ Part part = mp.getBodyPart(i);
+
+ String contentType = part.getContentType().toLowerCase();
+
+ // we prefer html
+ if (text == null && contentType.startsWith("text/plain")) {
+ isHTML = false;
+ text = (String) part.getContent();
+ } else if (contentType.startsWith("text/html")) {
+ isHTML = true;
+ text = (String) part.getContent();
+ }
+ }
+ sbPlain.append(text);
+ return isHTML;
+ }
/**
* Loop over MuliPart and write the content to the Outputstream if a
@@ -173,12 +277,65 @@ public class MessageUtils {
*/
public static BodyPart fileitemToBodypart(FileItem item) throws MessagingException {
MimeBodyPart messageBodyPart = new MimeBodyPart();
- DataSource source = new AbstractSendMessageHandler.FileItemDataStore(item);
+ DataSource source = new FileItemDataStore(item);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(source.getName());
return messageBodyPart;
}
-
+
+ /**
+ * DataStore which wrap a FileItem
+ *
+ */
+ public static 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;
+ }
+
+ }
/**
* Decode iso-xxxx strings present in subjects and emails like:
*
Modified: james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/RegexPatterns.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/RegexPatterns.java?rev=1516164&r1=1516163&r2=1516164&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/RegexPatterns.java (original)
+++ james/hupa/trunk/server/src/main/java/org/apache/hupa/server/utils/RegexPatterns.java Wed Aug 21 14:08:19 2013
@@ -48,7 +48,8 @@ public class RegexPatterns {
public static final Pattern regex_inlineImg = Pattern.compile("(?si)(<\\s*img\\s+.*?src=)[\"']?cid:([^\"']+)[\"']?");
public static final String repl_inlineImg = "$1'" + SConsts.HUPA + SConsts.SERVLET_DOWNLOAD
- + "?" + SConsts.PARAM_FOLDER + "=%%FOLDER%%"
+ + "?" + SConsts.PARAM_MODE + "=inline"
+ + "&" + SConsts.PARAM_FOLDER + "=%%FOLDER%%"
+ "&" + SConsts.PARAM_UID + "=%%UID%%"
+ "&" + SConsts.PARAM_NAME + "=$2' name='cid:$2'";
@@ -60,9 +61,9 @@ public class RegexPatterns {
public static final Pattern regex_unneededTags = Pattern.compile("(?si)(</?(html|body)[^>]*?>)");
public static final String repl_unneededTags = "";
-
- public static final String EVENT_ATTR_REGEX = "(?:on[a-z]+)";
- public static final Pattern regex_badAttrs = Pattern.compile("(?si)(<\\w+[^<>]*)(?:[\"']|\\s+)("+ EVENT_ATTR_REGEX + ")=[\"']?([^\\s<>]+?)[\"']?([\\s>])");
+
+ public static final String EVENT_ATTR_REGEX = "(?:on[dbl]*click)|(?:onmouse[a-z]+)|(?:onkey[a-z]+)";
+ public static final Pattern regex_badAttrs = Pattern.compile("(?si)(<\\w+[^<>]*)\\s+("+ EVENT_ATTR_REGEX + ")=[\"']?([^\\s<>]+?)[\"']?([\\s>])");
public static final String repl_badAttrs = "$1$4";
public static final Pattern regex_orphandHttpLinks = Pattern.compile("(?si)(?!.*<a\\s?[^>]*?>.+</a\\s*>.*)(<[^<]*?>[^<>]*)" + HTML_LINK_REGEXP + "([^<>]*<[^>]*?>)");
@@ -99,4 +100,4 @@ public class RegexPatterns {
// s=s.replaceAll("[ \t]+", " ");
-}
\ No newline at end of file
+}
Modified: james/hupa/trunk/server/src/main/webapp/WEB-INF/conf/config.properties
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/webapp/WEB-INF/conf/config.properties?rev=1516164&r1=1516163&r2=1516164&view=diff
==============================================================================
--- james/hupa/trunk/server/src/main/webapp/WEB-INF/conf/config.properties (original)
+++ james/hupa/trunk/server/src/main/webapp/WEB-INF/conf/config.properties Wed Aug 21 14:08:19 2013
@@ -15,6 +15,11 @@
# limitations under the License.
#############################################################################
+# The demo mode should make two lines different
+# 1. IMAPServerAddress=hupa.demo
+# 2. DefaultInboxFolder=Mock-Inbox
+# and then use the credential: demo/demo to login to the webmail through the browser
+
# The IP or domainname of the IMAP server
IMAPServerAddress=imap.gmail.com
# The port of the IMAP server
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org