Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

93668: ALF-21099 - MailActionExecutor.java doesn't support sending email by doing CC/BCC


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94991 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 12:31:16 +00:00
parent 1b9e432553
commit c9ca04c8dc
2 changed files with 79 additions and 0 deletions

View File

@@ -124,6 +124,8 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
public static final String NAME = "mail";
public static final String PARAM_LOCALE = "locale";
public static final String PARAM_TO = "to";
public static final String PARAM_CC = "cc";
public static final String PARAM_BCC = "bcc";
public static final String PARAM_TO_MANY = "to_many";
public static final String PARAM_SUBJECT = "subject";
public static final String PARAM_SUBJECT_PARAMS = "subjectParams";
@@ -612,6 +614,53 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
// Note: there is no validation on the username to check that it actually is an email address.
// TODO Fix this.
Serializable ccValue = (String)ruleAction.getParameterValue(PARAM_CC);
if(ccValue != null)
{
if (ccValue instanceof String)
{
String cc = (String)ccValue;
if(cc.length() > 0)
{
messageRef[0].setCc(cc);
}
}
else if (ccValue instanceof List<?>)
{
List<String>s = (List<String>)ccValue;
messageRef[0].setCc((String[])s.toArray());
}
else if (ccValue.getClass().isArray())
{
messageRef[0].setCc((String[])ccValue);
}
}
Serializable bccValue = (String)ruleAction.getParameterValue(PARAM_BCC);
if(bccValue != null)
{
if (bccValue instanceof String)
{
String bcc = (String)bccValue;
if(bcc.length() > 0)
{
messageRef[0].setBcc(bcc);
}
}
else if (bccValue instanceof List<?>)
{
List<String>s = (List<String>)bccValue;
messageRef[0].setBcc((String[])s.toArray());
}
else if (bccValue.getClass().isArray())
{
messageRef[0].setCc((String[])bccValue);
}
}
}
else
{
@@ -1491,6 +1540,8 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_TO)));
paramList.add(new ParameterDefinitionImpl(PARAM_CC, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CC)));
paramList.add(new ParameterDefinitionImpl(PARAM_BCC, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_BCC)));
paramList.add(new ParameterDefinitionImpl(PARAM_TO_MANY, DataTypeDefinition.ANY, false, getParamDisplayLabel(PARAM_TO_MANY), true));
paramList.add(new ParameterDefinitionImpl(PARAM_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_TEXT)));

View File

@@ -494,6 +494,34 @@ public abstract class AbstractMailActionExecuterTest
}
}
/**
* Test for CC / BCC
* @throws Exception
*/
@Test
public void testSendingToCarbonCopy() throws IOException, MessagingException
{
// PARAM_TO variant
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "some.bodyelse@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_CC, "some.carbon@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
ACTION_SERVICE.executeAction(mailAction, null);
MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Assert.assertEquals("Hello Jan 1, 1970", (String) message.getContent());
Assert.assertEquals("recipents too short", (message.getAllRecipients()).length, 3);
}
/**
* Test for MNT-11079
*/