Email Server and EmailService in a working state.

- Fixed authentication
 - Fixed I18N
 - Fixed mimetype and encoding issues
Changed 'avm' remote ports and hosts to be 'alfresco.rmi.services' as the 'avm' was starting to creep into non-avm stuff.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7281 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-11-02 13:55:07 +00:00
parent ae37e5c139
commit 488127f5a8
29 changed files with 684 additions and 658 deletions

View File

@@ -39,7 +39,6 @@ import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailMessagePart;
@@ -53,6 +52,15 @@ import org.apache.commons.logging.LogFactory;
*/
public class SubethaEmailMessage implements EmailMessage
{
private static final String ERR_FAILED_TO_CREATE_MIME_MESSAGE = "email.server.err.failed_to_create_mime_message";
private static final String ERR_EXTRACTING_FROM_ADDRESS = "email.server.err.extracting_from_address";
private static final String ERR_NO_FROM_ADDRESS = "email.server.err.no_from_address";
private static final String ERR_EXTRACTING_TO_ADDRESS = "email.server.err.extracting_to_address";
private static final String ERR_NO_TO_ADDRESS = "email.server.err.no_to_address";
private static final String ERR_EXTRACTING_SUBJECT = "email.server.err.extracting_subject";
private static final String ERR_EXTRACTING_SENT_DATE = "email.server.err.extracting_sent_date";
private static final String ERR_PARSE_MESSAGE = "email.server.err.parse_message";
private static final long serialVersionUID = -3735187524926395261L;
private static final Log log = LogFactory.getLog(SubethaEmailMessage.class);
@@ -98,7 +106,7 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (MessagingException e)
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.error-creating-message"), e);
throw new EmailMessageException(ERR_FAILED_TO_CREATE_MIME_MESSAGE, e.getMessage());
}
processMimeMessage(mimeMessage);
@@ -115,11 +123,11 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (MessagingException e)
{
throw new EmailMessageException("Error extract from.", e);
throw new EmailMessageException(ERR_EXTRACTING_FROM_ADDRESS, e.getMessage());
}
if (addresses == null || addresses.length == 0)
{
throw new EmailMessageException("There is no one from.");
throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
}
from = addresses[0].toString();
}
@@ -133,11 +141,11 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (MessagingException e)
{
throw new EmailMessageException("Error extract recepient.", e);
throw new EmailMessageException(ERR_EXTRACTING_TO_ADDRESS, e.getMessage());
}
if (addresses == null || addresses.length == 0)
{
throw new EmailMessageException("There is no one recepient.");
throw new EmailMessageException(ERR_NO_TO_ADDRESS);
}
to = addresses[0].toString();
}
@@ -148,7 +156,7 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (MessagingException e)
{
throw new EmailMessageException("Error extract subject.", e);
throw new EmailMessageException(ERR_EXTRACTING_SUBJECT, e.getMessage());
}
if (subject == null)
{
@@ -161,7 +169,7 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (MessagingException e)
{
throw new EmailMessageException("Error extract sentDate.", e);
throw new EmailMessageException(ERR_EXTRACTING_SENT_DATE, e.getMessage());
}
if (sentDate == null)
{
@@ -261,11 +269,11 @@ public class SubethaEmailMessage implements EmailMessage
}
catch (IOException e)
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.error-parse-message"), e);
throw new EmailMessageException(ERR_PARSE_MESSAGE, e.getMessage());
}
catch (MessagingException e)
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.error-parse-message"), e);
throw new EmailMessageException(ERR_PARSE_MESSAGE, e.getMessage());
}
}

View File

@@ -35,9 +35,9 @@ import java.util.regex.Pattern;
import javax.mail.MessagingException;
import javax.mail.Part;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailMessagePart;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.remote.RemotableInputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,6 +47,10 @@ import org.apache.commons.logging.LogFactory;
*/
public class SubethaEmailMessagePart implements EmailMessagePart
{
private static final String ERR_UNSUPPORTED_ENCODING = "email.server.err.usupported_encoding";
private static final String ERR_FAILED_TO_READ_CONTENT_STREAM = "email.server.err.failed_to_read_content_stream";
private static final String ERR_INCORRECT_MESSAGE_PART = "email.server.err.incorrect_message_part";
private static final long serialVersionUID = -8530238872199733096L;
static final Log log = LogFactory.getLog(SubethaEmailMessagePart.class);
@@ -74,8 +78,7 @@ public class SubethaEmailMessagePart implements EmailMessagePart
*/
public SubethaEmailMessagePart(Part messagePart)
{
if (messagePart == null)
throw new IllegalArgumentException("messagePart");
ParameterCheck.mandatory("messagePart", messagePart);
try
{
@@ -89,7 +92,7 @@ public class SubethaEmailMessagePart implements EmailMessagePart
encoding = matcher.group(1);
if (!Charset.isSupported(encoding))
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.usupported-encoding", encoding));
throw new EmailMessageException(ERR_UNSUPPORTED_ENCODING, encoding);
}
}
@@ -99,12 +102,12 @@ public class SubethaEmailMessagePart implements EmailMessagePart
}
catch (Exception ex)
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.error-getting-content-stream"), ex);
throw new EmailMessageException(ERR_FAILED_TO_READ_CONTENT_STREAM, ex.getMessage());
}
}
catch (MessagingException e)
{
throw new EmailMessageException(I18NUtil.getMessage("email.server.incorrect-message-part"), e);
throw new EmailMessageException(ERR_INCORRECT_MESSAGE_PART, e.getMessage());
}
}

View File

@@ -31,7 +31,6 @@ import java.util.LinkedList;
import java.util.List;
import org.alfresco.email.server.EmailServer;
import org.alfresco.email.server.EmailServerConfiguration;
import org.alfresco.service.cmr.email.EmailMessage;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.apache.commons.logging.Log;
@@ -53,17 +52,17 @@ public class SubethaEmailServer extends EmailServer
private SMTPServer serverImpl;
protected SubethaEmailServer(EmailServerConfiguration serverConfiguration)
protected SubethaEmailServer()
{
super(serverConfiguration);
serverImpl = new SMTPServer(new HandlerFactory());
serverImpl.setPort(serverConfiguration.getPort());
serverImpl.setHostName(serverConfiguration.getDomain());
super();
}
@Override
public void startup()
{
serverImpl = new SMTPServer(new HandlerFactory());
serverImpl.setPort(getPort());
serverImpl.setHostName(getDomain());
serverImpl.start();
log.info("Email Server has started successfully");
}
@@ -112,7 +111,7 @@ public class SubethaEmailServer extends EmailServer
this.from = from;
try
{
blackAndWhiteListFiltering(from);
filterSender(from);
}
catch (EmailMessageException e)
{
@@ -168,12 +167,17 @@ public class SubethaEmailServer extends EmailServer
try
{
emailMessage = new SubethaEmailMessage(from, delivery.getRecipient(), data);
configuration.getEmailService().importMessage(emailMessage);
getEmailService().importMessage(emailMessage);
}
catch (EmailMessageException e)
{
throw new RejectException(554, e.getMessage());
}
catch (Throwable e)
{
log.error(e.getMessage(), e);
throw new RejectException(554, "An internal error prevented mail delivery.");
}
}
public List<String> getAuthenticationMechanisms()