mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)
73354: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 73241: MNT-11079: Merged DEV to V4.2-BUG-FIX (4.2.3) 67748: MNT-11079: "Start Workflow" email notification is not sent out if the recipient's User Name contians "@" - During defining mail recipients first check email field and only then check if the username is the valid email address. Fix formatting and cleanup for other MailActionExecuterTest tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74772 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1169,19 +1169,19 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
{
|
{
|
||||||
if (personExists(authority))
|
if (personExists(authority))
|
||||||
{
|
{
|
||||||
EmailValidator emailValidator = EmailValidator.getInstance(true);
|
String address = getPersonEmail(authority);
|
||||||
if (validateAddresses && emailValidator.isValid(authority))
|
if (address != null && address.length() != 0 && validateAddress(address))
|
||||||
{
|
{
|
||||||
Locale locale = getLocaleForUser(authority);
|
Locale locale = getLocaleForUser(authority);
|
||||||
recipients.add(new Pair<String, Locale>(authority, locale));
|
recipients.add(new Pair<String, Locale>(address, locale));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String address = getPersonEmail(authority);
|
EmailValidator emailValidator = EmailValidator.getInstance(true);
|
||||||
if (address != null && address.length() != 0 && validateAddress(address))
|
if (validateAddresses && emailValidator.isValid(authority))
|
||||||
{
|
{
|
||||||
Locale locale = getLocaleForUser(authority);
|
Locale locale = getLocaleForUser(authority);
|
||||||
recipients.add(new Pair<String, Locale>(address, locale));
|
recipients.add(new Pair<String, Locale>(authority, locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1211,22 +1211,22 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
// Check the user name to be a valid email and we don't need to log an error in this case
|
// Check the user name to be a valid email and we don't need to log an error in this case
|
||||||
// ALF-19231
|
// ALF-19231
|
||||||
// Validate the email, allowing for local email addresses
|
// Validate the email, allowing for local email addresses
|
||||||
EmailValidator emailValidator = EmailValidator.getInstance(true);
|
String address = getPersonEmail(userAuth);
|
||||||
if (validateAddresses && emailValidator.isValid(userAuth))
|
if (address != null && address.length() != 0 && validateAddress(address))
|
||||||
{
|
{
|
||||||
if (userAuth != null && userAuth.length() != 0)
|
Locale locale = getLocaleForUser(userAuth);
|
||||||
{
|
recipients.add(new Pair<String, Locale>(address, locale));
|
||||||
Locale locale = getLocaleForUser(userAuth);
|
|
||||||
recipients.add(new Pair<String, Locale>(userAuth, locale));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String address = getPersonEmail(userAuth);
|
EmailValidator emailValidator = EmailValidator.getInstance(true);
|
||||||
if (address != null && address.length() != 0 && validateAddress(address))
|
if (validateAddresses && emailValidator.isValid(userAuth))
|
||||||
{
|
{
|
||||||
Locale locale = getLocaleForUser(userAuth);
|
if (userAuth != null && userAuth.length() != 0)
|
||||||
recipients.add(new Pair<String, Locale>(address, locale));
|
{
|
||||||
|
Locale locale = getLocaleForUser(userAuth);
|
||||||
|
recipients.add(new Pair<String, Locale>(userAuth, locale));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -335,10 +335,10 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
public void testPrepareEmailForDisabledUsers() throws MessagingException
|
public void testPrepareEmailForDisabledUsers() throws MessagingException
|
||||||
{
|
{
|
||||||
String groupName = null;
|
String groupName = null;
|
||||||
|
final String USER1 = "test_user1";
|
||||||
|
final String USER2 = "test_user2";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final String USER1 = "test_user1";
|
|
||||||
final String USER2 = "test_user2";
|
|
||||||
createUser(USER1, null);
|
createUser(USER1, null);
|
||||||
NodeRef userNode = createUser(USER2, null);
|
NodeRef userNode = createUser(USER2, null);
|
||||||
groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
|
groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
|
||||||
@@ -373,6 +373,8 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
{
|
{
|
||||||
AUTHORITY_SERVICE.deleteAuthority(groupName, true);
|
AUTHORITY_SERVICE.deleteAuthority(groupName, true);
|
||||||
}
|
}
|
||||||
|
PERSON_SERVICE.deletePerson(USER1);
|
||||||
|
PERSON_SERVICE.deletePerson(USER2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,26 +412,35 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
{
|
{
|
||||||
final String USER_WITH_NON_EXISTING_TENANT = "test_user_non_tenant@non_existing_tenant.com";
|
final String USER_WITH_NON_EXISTING_TENANT = "test_user_non_tenant@non_existing_tenant.com";
|
||||||
|
|
||||||
createUser(USER_WITH_NON_EXISTING_TENANT, USER_WITH_NON_EXISTING_TENANT);
|
try
|
||||||
|
|
||||||
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
|
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, USER_WITH_NON_EXISTING_TENANT);
|
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
|
|
||||||
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "This is a test message.");
|
|
||||||
|
|
||||||
// run as non admin and non system
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(BRITISH_USER.getUsername());
|
|
||||||
TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
|
||||||
{
|
{
|
||||||
@Override
|
createUser(USER_WITH_NON_EXISTING_TENANT, USER_WITH_NON_EXISTING_TENANT);
|
||||||
public Void execute() throws Throwable
|
|
||||||
{
|
|
||||||
ACTION_EXECUTER.executeImpl(mailAction, null);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AuthenticationUtil.clearCurrentSecurityContext();
|
final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
|
||||||
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, USER_WITH_NON_EXISTING_TENANT);
|
||||||
|
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
|
||||||
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "This is a test message.");
|
||||||
|
|
||||||
|
// run as non admin and non system
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(BRITISH_USER.getUsername());
|
||||||
|
TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
ACTION_EXECUTER.executeImpl(mailAction, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// restore system user as current user
|
||||||
|
AuthenticationUtil.setRunAsUserSystem();
|
||||||
|
// tidy up
|
||||||
|
PERSON_SERVICE.deletePerson(USER_WITH_NON_EXISTING_TENANT);
|
||||||
|
AuthenticationUtil.clearCurrentSecurityContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -478,4 +489,42 @@ public abstract class AbstractMailActionExecuterTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for MNT-11079
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSendingToUserWithMailAlikeName() throws IOException, MessagingException
|
||||||
|
{
|
||||||
|
final String USER_1 = "user1@namelookslikeemail";
|
||||||
|
final String USER_1_EMAIL = "user1@trueemail.com";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
createUser(USER_1, USER_1_EMAIL);
|
||||||
|
|
||||||
|
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
|
||||||
|
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
|
||||||
|
mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, USER_1);
|
||||||
|
|
||||||
|
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(1, message.getAllRecipients().length);
|
||||||
|
javax.mail.internet.InternetAddress address = (InternetAddress) message.getAllRecipients()[0];
|
||||||
|
Assert.assertEquals(USER_1_EMAIL, address.getAddress());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// tidy up
|
||||||
|
PERSON_SERVICE.deletePerson(USER_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user