mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-11837 - Alfresco 4.0 SMTP Inbound does not work with messages without From and To Headers.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33015 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -42,9 +42,15 @@
|
|||||||
<property name="requireTLS">
|
<property name="requireTLS">
|
||||||
<value>${email.server.requireTLS}</value>
|
<value>${email.server.requireTLS}</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="authenticate">
|
||||||
|
<value>${email.server.auth.enabled}</value>
|
||||||
|
</property>
|
||||||
<property name="emailService">
|
<property name="emailService">
|
||||||
<ref bean="EmailService" />
|
<ref bean="EmailService" />
|
||||||
</property>
|
</property>
|
||||||
|
<property name="authenticationComponent">
|
||||||
|
<ref bean="authenticationComponent" />
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -24,5 +24,8 @@ email.server.enableTLS=true
|
|||||||
# Set this to true to require TLS
|
# Set this to true to require TLS
|
||||||
email.server.requireTLS=false
|
email.server.requireTLS=false
|
||||||
|
|
||||||
|
# Is the user required to authenticate to use the smtp server?
|
||||||
|
email.server.auth.enabled=false
|
||||||
|
|
||||||
# Should duplicate messages to a folder overwrite each other or be named with a (number)
|
# Should duplicate messages to a folder overwrite each other or be named with a (number)
|
||||||
email.handler.folder.overwriteDuplicates=true
|
email.handler.folder.overwriteDuplicates=true
|
@@ -24,6 +24,8 @@ import java.util.Set;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||||
import org.alfresco.service.cmr.email.EmailService;
|
import org.alfresco.service.cmr.email.EmailService;
|
||||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||||
@@ -50,9 +52,10 @@ public abstract class EmailServer extends AbstractLifecycleBean
|
|||||||
private boolean hideTLS = false;
|
private boolean hideTLS = false;
|
||||||
private boolean enableTLS = true;
|
private boolean enableTLS = true;
|
||||||
private boolean requireTLS = false;
|
private boolean requireTLS = false;
|
||||||
|
private boolean authenticate = false;
|
||||||
|
|
||||||
private EmailService emailService;
|
private EmailService emailService;
|
||||||
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param serverConfiguration Server configuration
|
* @param serverConfiguration Server configuration
|
||||||
@@ -329,6 +332,19 @@ public abstract class EmailServer extends AbstractLifecycleBean
|
|||||||
System.err.println("\t configLocation - spring xml configs with EmailServer related beans (emailServer, emailServerConfiguration, emailService)");
|
System.err.println("\t configLocation - spring xml configs with EmailServer related beans (emailServer, emailServerConfiguration, emailService)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean authenticateUserNamePassword(String userName, char[] password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getAuthenticationComponent().authenticate(userName, password);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (AuthenticationException e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Hide the TLS (Trusted Login Session) option
|
/** Hide the TLS (Trusted Login Session) option
|
||||||
*
|
*
|
||||||
* @param hideTLS
|
* @param hideTLS
|
||||||
@@ -363,4 +379,24 @@ public abstract class EmailServer extends AbstractLifecycleBean
|
|||||||
return requireTLS;
|
return requireTLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAuthenticate(boolean enableAuthentication)
|
||||||
|
{
|
||||||
|
this.authenticate = enableAuthentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthenticate()
|
||||||
|
{
|
||||||
|
return authenticate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||||
|
{
|
||||||
|
this.authenticationComponent = authenticationComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthenticationComponent getAuthenticationComponent()
|
||||||
|
{
|
||||||
|
return authenticationComponent;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -229,8 +229,6 @@ public class EmailServiceImpl implements EmailService
|
|||||||
}
|
}
|
||||||
|
|
||||||
return userName;
|
return userName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RunAsWork<String> getUsernameRunAsWork = new RunAsWork<String>()
|
RunAsWork<String> getUsernameRunAsWork = new RunAsWork<String>()
|
||||||
@@ -240,7 +238,20 @@ public class EmailServiceImpl implements EmailService
|
|||||||
return retryingTransactionHelper.doInTransaction(getUsernameCallback, false);
|
return retryingTransactionHelper.doInTransaction(getUsernameCallback, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String username = AuthenticationUtil.runAs(getUsernameRunAsWork, AuthenticationUtil.SYSTEM_USER_NAME);
|
|
||||||
|
|
||||||
|
String username;
|
||||||
|
if(delivery.getAuth() != null)
|
||||||
|
{
|
||||||
|
// The user has authenticated.
|
||||||
|
username = delivery.getAuth();
|
||||||
|
logger.debug("user has already authenticated as:" + username);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Need to faff with old message stuff.
|
||||||
|
username = AuthenticationUtil.runAs(getUsernameRunAsWork, AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
// Process the message using the username's account
|
// Process the message using the username's account
|
||||||
final RetryingTransactionCallback<Object> processMessageCallback = new RetryingTransactionCallback<Object>()
|
final RetryingTransactionCallback<Object> processMessageCallback = new RetryingTransactionCallback<Object>()
|
||||||
@@ -279,7 +290,7 @@ public class EmailServiceImpl implements EmailService
|
|||||||
}
|
}
|
||||||
catch (AccessDeniedException e)
|
catch (AccessDeniedException e)
|
||||||
{
|
{
|
||||||
throw new EmailMessageException(ERR_ACCESS_DENIED, message.getFrom(), message.getTo());
|
throw new EmailMessageException(ERR_ACCESS_DENIED, delivery.getFrom(), delivery.getRecipient());
|
||||||
}
|
}
|
||||||
catch (IntegrityException e)
|
catch (IntegrityException e)
|
||||||
{
|
{
|
||||||
@@ -379,6 +390,12 @@ public class EmailServiceImpl implements EmailService
|
|||||||
private String getUsername(String from)
|
private String getUsername(String from)
|
||||||
{
|
{
|
||||||
String userName = null;
|
String userName = null;
|
||||||
|
|
||||||
|
if(from == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
||||||
String query = "TYPE:cm\\:person +@cm\\:email:\"" + from + "\"";
|
String query = "TYPE:cm\\:person +@cm\\:email:\"" + from + "\"";
|
||||||
|
|
||||||
|
@@ -108,11 +108,17 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
|||||||
messageSubject = I18NUtil.getMessage(MSG_DEFAULT_SUBJECT, new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now));
|
messageSubject = I18NUtil.getMessage(MSG_DEFAULT_SUBJECT, new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String messageFrom = message.getFrom();
|
||||||
|
if(messageFrom == null)
|
||||||
|
{
|
||||||
|
messageFrom = "";
|
||||||
|
}
|
||||||
|
|
||||||
// Create main content node
|
// Create main content node
|
||||||
NodeRef contentNodeRef;
|
NodeRef contentNodeRef;
|
||||||
contentNodeRef = addContentNode(getNodeService(), spaceNodeRef, messageSubject, overwriteDuplicates);
|
contentNodeRef = addContentNode(getNodeService(), spaceNodeRef, messageSubject, overwriteDuplicates);
|
||||||
// Add titled aspect
|
// Add titled aspect
|
||||||
addTitledAspect(contentNodeRef, messageSubject, message.getFrom());
|
addTitledAspect(contentNodeRef, messageSubject, messageFrom);
|
||||||
// Add emailed aspect
|
// Add emailed aspect
|
||||||
addEmailedAspect(contentNodeRef, message);
|
addEmailedAspect(contentNodeRef, message);
|
||||||
// Write the message content
|
// Write the message content
|
||||||
|
@@ -131,8 +131,10 @@ public class SubethaEmailMessage implements EmailMessage
|
|||||||
}
|
}
|
||||||
if (addresses == null || addresses.length == 0)
|
if (addresses == null || addresses.length == 0)
|
||||||
{
|
{
|
||||||
throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
|
//throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if(addresses[0] instanceof InternetAddress)
|
if(addresses[0] instanceof InternetAddress)
|
||||||
{
|
{
|
||||||
from = ((InternetAddress)addresses[0]).getAddress();
|
from = ((InternetAddress)addresses[0]).getAddress();
|
||||||
@@ -141,7 +143,7 @@ public class SubethaEmailMessage implements EmailMessage
|
|||||||
{
|
{
|
||||||
from = addresses[0].toString();
|
from = addresses[0].toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (to == null)
|
if (to == null)
|
||||||
@@ -157,8 +159,10 @@ public class SubethaEmailMessage implements EmailMessage
|
|||||||
}
|
}
|
||||||
if (addresses == null || addresses.length == 0)
|
if (addresses == null || addresses.length == 0)
|
||||||
{
|
{
|
||||||
throw new EmailMessageException(ERR_NO_TO_ADDRESS);
|
//throw new EmailMessageException(ERR_NO_TO_ADDRESS);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if(addresses[0] instanceof InternetAddress)
|
if(addresses[0] instanceof InternetAddress)
|
||||||
{
|
{
|
||||||
to = ((InternetAddress)addresses[0]).getAddress();
|
to = ((InternetAddress)addresses[0]).getAddress();
|
||||||
@@ -167,8 +171,7 @@ public class SubethaEmailMessage implements EmailMessage
|
|||||||
{
|
{
|
||||||
to = addresses[0].toString();
|
to = addresses[0].toString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
to = addresses[0].toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc == null)
|
if (cc == null)
|
||||||
|
@@ -33,11 +33,17 @@ import org.alfresco.service.cmr.email.EmailMessage;
|
|||||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.subethamail.smtp.AuthenticationHandler;
|
||||||
|
import org.subethamail.smtp.AuthenticationHandlerFactory;
|
||||||
import org.subethamail.smtp.MessageContext;
|
import org.subethamail.smtp.MessageContext;
|
||||||
import org.subethamail.smtp.MessageHandler;
|
import org.subethamail.smtp.MessageHandler;
|
||||||
import org.subethamail.smtp.MessageHandlerFactory;
|
import org.subethamail.smtp.MessageHandlerFactory;
|
||||||
import org.subethamail.smtp.RejectException;
|
import org.subethamail.smtp.RejectException;
|
||||||
import org.subethamail.smtp.TooMuchDataException;
|
import org.subethamail.smtp.TooMuchDataException;
|
||||||
|
import org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory;
|
||||||
|
import org.subethamail.smtp.auth.LoginFailedException;
|
||||||
|
import org.subethamail.smtp.auth.MultipleAuthenticationHandlerFactory;
|
||||||
|
import org.subethamail.smtp.auth.UsernamePasswordValidator;
|
||||||
import org.subethamail.smtp.server.SMTPServer;
|
import org.subethamail.smtp.server.SMTPServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,6 +72,12 @@ public class SubethaEmailServer extends EmailServer
|
|||||||
serverImpl.setEnableTLS(isEnableTLS());
|
serverImpl.setEnableTLS(isEnableTLS());
|
||||||
serverImpl.setRequireTLS(isRequireTLS());
|
serverImpl.setRequireTLS(isRequireTLS());
|
||||||
|
|
||||||
|
if(isAuthenticate())
|
||||||
|
{
|
||||||
|
AuthenticationHandlerFactory authenticationHandler = new EasyAuthenticationHandlerFactory(new AlfrescoLoginUsernamePasswordValidator());
|
||||||
|
serverImpl.setAuthenticationHandlerFactory(authenticationHandler);
|
||||||
|
}
|
||||||
|
|
||||||
serverImpl.start();
|
serverImpl.start();
|
||||||
log.info("Inbound SMTP Email Server has started successfully, on hostName:" + getDomain() + "port:" + getPort());
|
log.info("Inbound SMTP Email Server has started successfully, on hostName:" + getDomain() + "port:" + getPort());
|
||||||
}
|
}
|
||||||
@@ -77,6 +89,19 @@ public class SubethaEmailServer extends EmailServer
|
|||||||
log.info("Inbound SMTP Email Server has stopped successfully");
|
log.info("Inbound SMTP Email Server has stopped successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AlfrescoLoginUsernamePasswordValidator implements UsernamePasswordValidator
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void login(String username, String password)
|
||||||
|
throws LoginFailedException
|
||||||
|
{
|
||||||
|
if(authenticateUserNamePassword(username, password.toCharArray()))
|
||||||
|
{
|
||||||
|
throw new LoginFailedException("unable to log on");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class HandlerFactory implements MessageHandlerFactory
|
class HandlerFactory implements MessageHandlerFactory
|
||||||
{
|
{
|
||||||
public MessageHandler create(MessageContext messageContext)
|
public MessageHandler create(MessageContext messageContext)
|
||||||
@@ -139,7 +164,9 @@ public class SubethaEmailServer extends EmailServer
|
|||||||
|
|
||||||
public void recipient(String recipient) throws RejectException
|
public void recipient(String recipient) throws RejectException
|
||||||
{
|
{
|
||||||
deliveries.add(new EmailDelivery(recipient, from, null));
|
AuthenticationHandler auth = messageContext.getAuthenticationHandler();
|
||||||
|
|
||||||
|
deliveries.add(new EmailDelivery(recipient, from, auth != null ? (String)auth.getIdentity(): null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void data(InputStream data) throws TooMuchDataException, IOException, RejectException
|
public void data(InputStream data) throws TooMuchDataException, IOException, RejectException
|
||||||
@@ -171,20 +198,6 @@ public class SubethaEmailServer extends EmailServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public List<String> getAuthenticationMechanisms()
|
|
||||||
// {
|
|
||||||
// return EMPTY_LIST;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public boolean auth(String clientInput, StringBuffer response) throws RejectException
|
|
||||||
// {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void resetState()
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
@Override
|
@Override
|
||||||
public void done()
|
public void done()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user