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:
Mark Rogers
2012-01-03 11:45:05 +00:00
parent a56372d469
commit 183774a2ea
7 changed files with 124 additions and 40 deletions

View File

@@ -131,17 +131,19 @@ public class SubethaEmailMessage implements EmailMessage
}
if (addresses == null || addresses.length == 0)
{
throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
}
if(addresses[0] instanceof InternetAddress)
{
from = ((InternetAddress)addresses[0]).getAddress();
//throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
}
else
{
from = addresses[0].toString();
}
if(addresses[0] instanceof InternetAddress)
{
from = ((InternetAddress)addresses[0]).getAddress();
}
else
{
from = addresses[0].toString();
}
}
}
if (to == null)
@@ -157,18 +159,19 @@ public class SubethaEmailMessage implements EmailMessage
}
if (addresses == null || addresses.length == 0)
{
throw new EmailMessageException(ERR_NO_TO_ADDRESS);
}
if(addresses[0] instanceof InternetAddress)
{
to = ((InternetAddress)addresses[0]).getAddress();
//throw new EmailMessageException(ERR_NO_TO_ADDRESS);
}
else
{
to = addresses[0].toString();
}
to = addresses[0].toString();
if(addresses[0] instanceof InternetAddress)
{
to = ((InternetAddress)addresses[0]).getAddress();
}
else
{
to = addresses[0].toString();
}
}
}
if (cc == null)

View File

@@ -33,11 +33,17 @@ import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.apache.commons.logging.Log;
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.MessageHandler;
import org.subethamail.smtp.MessageHandlerFactory;
import org.subethamail.smtp.RejectException;
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;
/**
@@ -66,6 +72,12 @@ public class SubethaEmailServer extends EmailServer
serverImpl.setEnableTLS(isEnableTLS());
serverImpl.setRequireTLS(isRequireTLS());
if(isAuthenticate())
{
AuthenticationHandlerFactory authenticationHandler = new EasyAuthenticationHandlerFactory(new AlfrescoLoginUsernamePasswordValidator());
serverImpl.setAuthenticationHandlerFactory(authenticationHandler);
}
serverImpl.start();
log.info("Inbound SMTP Email Server has started successfully, on hostName:" + getDomain() + "port:" + getPort());
}
@@ -76,7 +88,20 @@ public class SubethaEmailServer extends EmailServer
serverImpl.stop();
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
{
public MessageHandler create(MessageContext messageContext)
@@ -139,7 +164,9 @@ public class SubethaEmailServer extends EmailServer
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
@@ -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
public void done()
{