ACS-9199 Bump subethasmtp version to 7.1.3 (#3207)

* ACS-9199 Bump subethasmtp to 7.1.3

* ACS-9199 Bump subethasmtp to 7.1.3

* ACS-9199 Use org.eclipse.angus

* ACS-9199 Update notice.txt

* ACS-9199 Remove provided scope for jakarta.mail:mail-api

* ACS-9199 Fix ags

* ACS-9199 Remove verbose
This commit is contained in:
Damian Ujma
2025-02-19 15:42:14 +01:00
committed by GitHub
parent 85c0d7896e
commit 1adddb0f7f
8 changed files with 2069 additions and 2108 deletions

View File

@@ -1377,7 +1377,7 @@
"filename": "repository/src/test/java/org/alfresco/repo/imap/ImapMessageTest.java",
"hashed_secret": "d033e22ae348aeb5660fc2140aec35850c4da997",
"is_verified": false,
"line_number": 118,
"line_number": 116,
"is_secret": false
}
],
@@ -1868,5 +1868,5 @@
}
]
},
"generated_at": "2025-02-11T13:28:51Z"
"generated_at": "2025-02-18T15:50:35Z"
}

View File

@@ -63,10 +63,6 @@
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
</dependency>
<dependency>
<groupId>org.alfresco.surf</groupId>
<artifactId>spring-webscripts</artifactId>

View File

@@ -180,13 +180,13 @@ Lightbox JS http://lokeshdhakar.com/projects/lightbox/
=== Eclipse Public License 1.0 ===
Angus Mail Provider https://eclipse-ee4j.github.io/angus-mail/
AspectJ http://eclipse.org/aspectj/
Bliki http://code.google.com/p/gwtwiki/
JUnit http://junit.org/
TrueLicense http://truelicense.java.net/
truezip http://truezip.java.net/
=== ICU License ===
icu4j http://icu-project.org/

View File

@@ -57,8 +57,8 @@
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
</dependency>
<dependency>

10
pom.xml
View File

@@ -97,6 +97,7 @@
<dependency.jdom2.version>2.0.6.1</dependency.jdom2.version>
<dependency.pooled-jms.version>3.1.6</dependency.pooled-jms.version>
<dependency.kxml2.version>2.3.0</dependency.kxml2.version>
<dependency.angus-mail.version>2.0.3</dependency.angus-mail.version>
<dependency.jakarta-ee-jaxb-api.version>4.0.2</dependency.jakarta-ee-jaxb-api.version>
<dependency.jakarta-ee-jaxb-impl.version>4.0.5</dependency.jakarta-ee-jaxb-impl.version>
@@ -105,7 +106,7 @@
<dependency.jakarta-annotation-api.version>3.0.0</dependency.jakarta-annotation-api.version>
<dependency.jakarta-transaction-api.version>2.0.1</dependency.jakarta-transaction-api.version>
<dependency.jakarta-jws-api.version>3.0.0</dependency.jakarta-jws-api.version>
<dependency.jakarta-ee-mail.version>2.0.1</dependency.jakarta-ee-mail.version>
<dependency.jakarta-ee-mail.version>2.1.3</dependency.jakarta-ee-mail.version>
<dependency.jakarta-ee-activation.version>2.0.1</dependency.jakarta-ee-activation.version>
<dependency.jakarta-ee-jms.version>3.1.0</dependency.jakarta-ee-jms.version>
<dependency.java-ee-activation.version>1.2.0</dependency.java-ee-activation.version>
@@ -219,15 +220,14 @@
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>${dependency.jakarta-ee-mail.version}</version>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
<version>${dependency.angus-mail.version}</version>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>${dependency.jakarta-ee-mail.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>

View File

@@ -56,8 +56,8 @@
<artifactId>jakarta.mail-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
</dependency>
<dependency>
@@ -190,7 +190,7 @@
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>subethasmtp</artifactId>
<version>6.0.6</version>
<version>7.1.3</version>
<exclusions>
<!-- Duplicate classes from com.sun.mail:jakarta.mail -->
<exclusion>

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -35,12 +35,17 @@ import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import jakarta.mail.Message;
import jakarta.mail.Session;
import jakarta.mail.internet.InternetAddress;
import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.angus.mail.smtp.SMTPMessage;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.alfresco.email.server.handler.FolderEmailMessageHandler;
import org.alfresco.email.server.impl.subetha.SubethaEmailMessage;
@@ -48,8 +53,8 @@ import org.alfresco.model.ContentModel;
import org.alfresco.model.ForumModel;
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transfer.TransferModel;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transfer.TransferModel;
import org.alfresco.service.cmr.email.EmailDelivery;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailService;
@@ -65,17 +70,10 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.testing.category.LuceneTests;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import com.sun.mail.smtp.SMTPMessage;
/**
* Unit test of EmailServiceImplTest
*
* @author mrogers
*
*/
@@ -98,26 +96,26 @@ public class EmailServiceImplTest extends TestCase
private FolderEmailMessageHandler folderEmailMessageHandler;
private RetryingTransactionHelper transactionHelper;
String TEST_USER="EmailServiceImplTestUser";
String TEST_USER = "EmailServiceImplTestUser";
@Override
public void setUp() throws Exception
{
AuthenticationUtil.setRunAsUserSystem();
nodeService = (NodeService)ctx.getBean("NodeService");
nodeService = (NodeService) ctx.getBean("NodeService");
assertNotNull("nodeService", nodeService);
authorityService = (AuthorityService)ctx.getBean("AuthorityService");
authorityService = (AuthorityService) ctx.getBean("AuthorityService");
assertNotNull("authorityService", authorityService);
ChildApplicationContextFactory emailSubsystem = (ChildApplicationContextFactory) ctx.getBean("InboundSMTP");
assertNotNull("emailSubsystem", emailSubsystem);
ApplicationContext emailCtx = emailSubsystem.getApplicationContext();
emailService = (EmailService)emailCtx.getBean("emailService");
emailService = (EmailService) emailCtx.getBean("emailService");
assertNotNull("emailService", emailService);
personService = (PersonService)emailCtx.getBean("PersonService");
personService = (PersonService) emailCtx.getBean("PersonService");
assertNotNull("personService", personService);
namespaceService = (NamespaceService)emailCtx.getBean("NamespaceService");
namespaceService = (NamespaceService) emailCtx.getBean("NamespaceService");
assertNotNull("namespaceService", namespaceService);
searchService = (SearchService)emailCtx.getBean("SearchService");
searchService = (SearchService) emailCtx.getBean("SearchService");
assertNotNull("searchService", searchService);
folderEmailMessageHandler = (FolderEmailMessageHandler) emailCtx.getBean("folderEmailMessageHandler");
assertNotNull("folderEmailMessageHandler", folderEmailMessageHandler);
@@ -133,19 +131,15 @@ public class EmailServiceImplTest extends TestCase
personService.deletePerson(TEST_USER);
}
catch (Exception e)
{
}
{}
}
/**
* Test the from name.
*
* Step 1:
* User admin will map to the "unknownUser" which out of the box is "anonymous"
* Sending email From "admin" will fail.
* Step 1: User admin will map to the "unknownUser" which out of the box is "anonymous" Sending email From "admin" will fail.
*
* Step 2:
* Send from the test user to the test' user's home folder.
* Step 2: Send from the test user to the test' user's home folder.
*/
public void testFromName() throws Exception
{
@@ -154,11 +148,11 @@ public class EmailServiceImplTest extends TestCase
logger.debug("Start testFromName");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -169,7 +163,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -182,16 +176,14 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long) nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
/**
* Step 1
* Negative test - send from "Bert" who does not exist.
* User will be mapped to anonymous who is not an email contributor.
* Step 1 Negative test - send from "Bert" who does not exist. User will be mapped to anonymous who is not an email contributor.
*/
try
{
@@ -202,7 +194,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress("Bert"));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -243,7 +235,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -266,8 +258,7 @@ public class EmailServiceImplTest extends TestCase
/**
* Step 3
*
* message.from From with "name" < name@ domain > format
* SMTP.FROM="dummy"
* message.from From with "name" < name@ domain > format SMTP.FROM="dummy"
*
* Send From the test user <TEST_EMAIL> to the test user's home
*/
@@ -281,7 +272,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -299,7 +290,7 @@ public class EmailServiceImplTest extends TestCase
EmailDelivery delivery = new EmailDelivery(to, "dummy", null);
emailService.importMessage(delivery,m);
emailService.importMessage(delivery, m);
}
/**
@@ -319,7 +310,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -340,52 +331,50 @@ public class EmailServiceImplTest extends TestCase
EmailDelivery delivery = new EmailDelivery(to, x, null);
emailService.importMessage(delivery,m);
emailService.importMessage(delivery, m);
}
// /**
// * Step 5
// *
// * From with <e=name@domain> format
// *
// * RFC3696
// *
// * Send From the test user <TEST_EMAIL> to the test user's home
// */
// {
// logger.debug("Step 4 <local tag=name@ domain > format");
//
// String from = "\"Joe Bloggs\" <e=" + TEST_EMAIL + ">";
// String to = testUserHomeDBID;
// String content = "hello world";
//
// Session sess = Session.getDefaultInstance(new Properties());
// assertNotNull("sess is null", sess);
// SMTPMessage msg = new SMTPMessage(sess);
// InternetAddress[] toa = { new InternetAddress(to) };
//
// msg.setFrom(new InternetAddress(from));
// msg.setRecipients(Message.RecipientType.TO, toa);
// msg.setSubject("JavaMail APIs transport.java Test");
// msg.setContent(content, "text/plain");
//
// StringBuffer sb = new StringBuffer();
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// msg.writeTo(System.out);
// msg.writeTo(bos);
// InputStream is = IOUtils.toInputStream(bos.toString());
// assertNotNull("is is null", is);
//
// SubethaEmailMessage m = new SubethaEmailMessage(is);
//
// emailService.importMessage(m);
// }
// /**
// * Step 5
// *
// * From with <e=name@domain> format
// *
// * RFC3696
// *
// * Send From the test user <TEST_EMAIL> to the test user's home
// */
// {
// logger.debug("Step 4 <local tag=name@ domain > format");
//
// String from = "\"Joe Bloggs\" <e=" + TEST_EMAIL + ">";
// String to = testUserHomeDBID;
// String content = "hello world";
//
// Session sess = Session.getDefaultInstance(new Properties());
// assertNotNull("sess is null", sess);
// SMTPMessage msg = new SMTPMessage(sess);
// InternetAddress[] toa = { new InternetAddress(to) };
//
// msg.setFrom(new InternetAddress(from));
// msg.setRecipients(Message.RecipientType.TO, toa);
// msg.setSubject("JavaMail APIs transport.java Test");
// msg.setContent(content, "text/plain");
//
// StringBuffer sb = new StringBuffer();
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// msg.writeTo(System.out);
// msg.writeTo(bos);
// InputStream is = IOUtils.toInputStream(bos.toString());
// assertNotNull("is is null", is);
//
// SubethaEmailMessage m = new SubethaEmailMessage(is);
//
// emailService.importMessage(m);
// }
}
/**
* ALF-9544
* ALF-751
* ALF-9544 ALF-751
*
* Inbound email to a folder restricts file name to 86 characters or less.
*
@@ -395,13 +384,13 @@ public class EmailServiceImplTest extends TestCase
{
logger.debug("Start testFromName");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
folderEmailMessageHandler.setOverwriteDuplicates(true);
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -412,7 +401,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -425,11 +414,11 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long) nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
/**
* Send From the test user TEST_EMAIL to the test user's home
@@ -442,7 +431,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -466,7 +455,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -490,11 +479,11 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
//msg.setSubject();
// msg.setSubject();
msg.setContent(content, "text/plain");
StringBuffer sb = new StringBuffer();
@@ -509,13 +498,12 @@ public class EmailServiceImplTest extends TestCase
emailService.importMessage(delivery, m);
}
// ALF-751 Email ends with period
{
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -539,7 +527,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -563,7 +551,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -587,7 +575,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -617,16 +605,15 @@ public class EmailServiceImplTest extends TestCase
{
logger.debug("Start testFromName");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
String TEST_SUBJECT="Practical Bee Keeping";
String TEST_SUBJECT = "Practical Bee Keeping";
String TEST_LONG_SUBJECT = "This is a very very long name in particular it is greater than eitghty six characters which was a problem explored in ALF-9544";
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -637,7 +624,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -650,15 +637,15 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long) nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// Clean up old messages in test folder
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for(ChildAssociationRef assoc : assocs)
for (ChildAssociationRef assoc : assocs)
{
nodeService.deleteNode(assoc.getChildRef());
}
@@ -673,7 +660,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -735,8 +722,7 @@ public class EmailServiceImplTest extends TestCase
assertEquals("assocs not 5", 5, assocs.size());
/**
* Check assoc rename with long names and an extension. So truncation and rename need to
* work together and not muck up a .extension.
* Check assoc rename with long names and an extension. So truncation and rename need to work together and not muck up a .extension.
*/
logger.debug("Step 4: turn off Overwite Duplicates with long subject name with extension");
String EXT_NAME = "Blob.xls";
@@ -754,7 +740,7 @@ public class EmailServiceImplTest extends TestCase
assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
List<QName> assocNames = new Vector<QName>();
for(ChildAssociationRef assoc : assocs)
for (ChildAssociationRef assoc : assocs)
{
logger.debug("assocName: " + assoc.getQName());
System.out.println(assoc.getQName());
@@ -764,7 +750,7 @@ public class EmailServiceImplTest extends TestCase
assertTrue("Blob(1).xls not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Blob(1).xls")));
assertTrue("Blob(2).xls not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Blob(2).xls")));
assertTrue(TEST_SUBJECT + "not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, TEST_SUBJECT)));
assertTrue(TEST_SUBJECT+"(1) not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Practical Bee Keeping(1)")));
assertTrue(TEST_SUBJECT + "(1) not found", assocNames.contains(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "Practical Bee Keeping(1)")));
/**
* Check concurrent deliver of the same message. Reuse message from the previous test.
@@ -785,13 +771,13 @@ public class EmailServiceImplTest extends TestCase
class ConcurrentMessageImporter implements Runnable
{
private Throwable throwable;
@Override
public void run()
{
try
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
cdl.countDown();
@@ -808,8 +794,7 @@ public class EmailServiceImplTest extends TestCase
}
ConcurrentMessageImporter messageImporter = new ConcurrentMessageImporter();
final Thread messageImporterThread = new Thread(messageImporter);
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable
{
emailService.importMessage(delivery, m);
@@ -834,9 +819,9 @@ public class EmailServiceImplTest extends TestCase
public void testCaseSensitivity() throws Exception
{
NodeRef person = personService.getPerson(TEST_USER);
String TEST_EMAIL="buffy@sunnydale.high";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
if(person == null)
String TEST_EMAIL = "buffy@sunnydale.high";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -848,7 +833,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -863,7 +848,7 @@ public class EmailServiceImplTest extends TestCase
assertNotNull("company home is null", companyHomeNodeRef);
String TEST_CASE_SENSITIVITY_SUBJECT = "Test (Mail)";
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String from = TEST_EMAIL;
String to = testUserHomeDBID;
@@ -872,7 +857,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
EmailDelivery delivery = new EmailDelivery(to, from, null);
@@ -907,7 +892,6 @@ public class EmailServiceImplTest extends TestCase
assertEquals(1, assocs.size());
}
/**
* ALF-12297
*
@@ -917,16 +901,15 @@ public class EmailServiceImplTest extends TestCase
{
logger.debug("Start testMessagesToDocument");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
String TEST_SUBJECT="Practical Bee Keeping";
String TEST_SUBJECT = "Practical Bee Keeping";
String TEST_LONG_SUBJECT = "This is a very very long name in particular it is greater than eitghty six characters which was a problem explored in ALF-9544";
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -937,7 +920,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -950,27 +933,26 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
// String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// Clean up old messages in test folder
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for(ChildAssociationRef assoc : assocs)
for (ChildAssociationRef assoc : assocs)
{
nodeService.deleteNode(assoc.getChildRef());
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_NAME, "bees");
properties.put(ContentModel.PROP_DESCRIPTION, "bees - test doc for email tests");
ChildAssociationRef testDoc = nodeService.createNode(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "bees"), ContentModel.TYPE_CONTENT, properties);
NodeRef testDocNodeRef = testDoc.getChildRef();
String testDocDBID = ((Long)nodeService.getProperty(testDocNodeRef, ContentModel.PROP_NODE_DBID)).toString();
String testDocDBID = ((Long) nodeService.getProperty(testDocNodeRef, ContentModel.PROP_NODE_DBID)).toString();
/**
* Send From the test user TEST_EMAIL to the test user's home
@@ -982,7 +964,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -1007,11 +989,8 @@ public class EmailServiceImplTest extends TestCase
assertTrue(nodeService.hasAspect(testDocNodeRef, ForumModel.ASPECT_DISCUSSABLE));
} // end of test sending to cm:content node
/**
* ENH-560 - Inbound email server not working with custom types
*/
@@ -1019,16 +998,15 @@ public class EmailServiceImplTest extends TestCase
{
logger.debug("Start testMessagesToSubTypesOfDocument");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
String TEST_SUBJECT="Practical Bee Keeping";
String TEST_SUBJECT = "Practical Bee Keeping";
String TEST_LONG_SUBJECT = "This is a very very long name in particular it is greater than eitghty six characters which was a problem explored in ALF-9544";
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -1039,7 +1017,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(!auths.contains(TEST_USER))
if (!auths.contains(TEST_USER))
{
authorityService.addAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -1052,20 +1030,19 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
// String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
// Clean up old messages in test folder
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for(ChildAssociationRef assoc : assocs)
for (ChildAssociationRef assoc : assocs)
{
nodeService.deleteNode(assoc.getChildRef());
}
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(ContentModel.PROP_NAME, "hamster");
properties.put(ContentModel.PROP_DESCRIPTION, "syrian hamsters - test doc for email tests, sending to a subtype of cm:content");
@@ -1074,7 +1051,7 @@ public class EmailServiceImplTest extends TestCase
ChildAssociationRef testDoc = nodeService.createNode(testUserHomeFolder, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "bees"), TransferModel.TYPE_TRANSFER_REPORT, properties);
NodeRef testDocNodeRef = testDoc.getChildRef();
String testDocDBID = ((Long)nodeService.getProperty(testDocNodeRef, ContentModel.PROP_NODE_DBID)).toString();
String testDocDBID = ((Long) nodeService.getProperty(testDocNodeRef, ContentModel.PROP_NODE_DBID)).toString();
/**
* Send From the test user TEST_EMAIL to the test user's home
@@ -1086,7 +1063,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -1111,10 +1088,6 @@ public class EmailServiceImplTest extends TestCase
} // end of test sending to trx:transferReport
/**
* The Email contributors authority controls who can add email.
*
@@ -1122,17 +1095,17 @@ public class EmailServiceImplTest extends TestCase
*/
public void testEmailContributorsAuthority() throws Exception
{
EmailServiceImpl emailServiceImpl = (EmailServiceImpl)emailService;
EmailServiceImpl emailServiceImpl = (EmailServiceImpl) emailService;
folderEmailMessageHandler.setOverwriteDuplicates(true);
logger.debug("Start testEmailContributorsAuthority");
String TEST_EMAIL="buffy@sunnydale.high";
String TEST_EMAIL = "buffy@sunnydale.high";
// TODO Investigate why setting PROP_EMAIL on createPerson does not work.
NodeRef person = personService.getPerson(TEST_USER);
if(person == null)
if (person == null)
{
logger.debug("new person created");
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
@@ -1143,7 +1116,7 @@ public class EmailServiceImplTest extends TestCase
nodeService.setProperty(person, ContentModel.PROP_EMAIL, TEST_EMAIL);
Set<String> auths = authorityService.getContainedAuthorities(null, "GROUP_EMAIL_CONTRIBUTORS", true);
if(auths.contains(TEST_USER))
if (auths.contains(TEST_USER))
{
authorityService.removeAuthority("GROUP_EMAIL_CONTRIBUTORS", TEST_USER);
}
@@ -1156,18 +1129,16 @@ public class EmailServiceImplTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
assertNotNull("company home is null", companyHomeNodeRef);
String companyHomeDBID = ((Long)nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long)nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
String companyHomeDBID = ((Long) nodeService.getProperty(companyHomeNodeRef, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserDBID = ((Long) nodeService.getProperty(person, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
NodeRef testUserHomeFolder = (NodeRef) nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
assertNotNull("testUserHomeFolder is null", testUserHomeFolder);
String testUserHomeDBID = ((Long)nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
String testUserHomeDBID = ((Long) nodeService.getProperty(testUserHomeFolder, ContentModel.PROP_NODE_DBID)).toString() + "@Alfresco.com";
/**
* Step 1
* Set the email contributors authority to EVERYONE
* Step 1 Set the email contributors authority to EVERYONE
*
* Test that TEST_USER is allowed to send email - so even though TEST_USER is not
* a contributor
* Test that TEST_USER is allowed to send email - so even though TEST_USER is not a contributor
*/
emailServiceImpl.setEmailContributorsAuthority("EVERYONE");
@@ -1178,7 +1149,7 @@ public class EmailServiceImplTest extends TestCase
Session sess = Session.getDefaultInstance(new Properties());
assertNotNull("sess is null", sess);
SMTPMessage msg = new SMTPMessage(sess);
InternetAddress[] toa = { new InternetAddress(to) };
InternetAddress[] toa = {new InternetAddress(to)};
msg.setFrom(new InternetAddress(TEST_EMAIL));
msg.setRecipients(Message.RecipientType.TO, toa);
@@ -1198,8 +1169,7 @@ public class EmailServiceImplTest extends TestCase
emailService.importMessage(delivery, m);
/**
* Step 2
* Negative test
* Step 2 Negative test
*
* Send From the test user TEST_EMAIL to the test user's home
*/

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -25,6 +25,8 @@
*/
package org.alfresco.repo.imap;
import static org.alfresco.model.ContentModel.PROP_MODIFIED;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
@@ -37,7 +39,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import jakarta.mail.Address;
import jakarta.mail.Folder;
import jakarta.mail.Message;
@@ -51,6 +52,23 @@ import jakarta.mail.internet.MimeUtility;
import jakarta.transaction.UserTransaction;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.angus.mail.iap.ProtocolException;
import org.eclipse.angus.mail.iap.Response;
import org.eclipse.angus.mail.imap.IMAPFolder;
import org.eclipse.angus.mail.imap.protocol.BODY;
import org.eclipse.angus.mail.imap.protocol.FetchResponse;
import org.eclipse.angus.mail.imap.protocol.IMAPProtocol;
import org.eclipse.angus.mail.imap.protocol.IMAPResponse;
import org.eclipse.angus.mail.imap.protocol.RFC822DATA;
import org.eclipse.angus.mail.imap.protocol.UID;
import org.eclipse.angus.mail.util.ASCIIUtility;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.alfresco.model.ContentModel;
import org.alfresco.model.ImapModel;
@@ -83,26 +101,6 @@ import org.alfresco.util.PropertyMap;
import org.alfresco.util.config.RepositoryFolderConfigBean;
import org.alfresco.util.testing.category.LuceneTests;
import org.alfresco.util.testing.category.RedundantTests;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.MimeMessageHelper;
import com.sun.mail.iap.ProtocolException;
import com.sun.mail.iap.Response;
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.protocol.BODY;
import com.sun.mail.imap.protocol.FetchResponse;
import com.sun.mail.imap.protocol.IMAPProtocol;
import com.sun.mail.imap.protocol.IMAPResponse;
import com.sun.mail.imap.protocol.RFC822DATA;
import com.sun.mail.imap.protocol.UID;
import com.sun.mail.util.ASCIIUtility;
import static org.alfresco.model.ContentModel.PROP_MODIFIED;
@Category({OwnJVMTestsCategory.class, LuceneTests.class})
public class ImapMessageTest extends TestCase
@@ -159,7 +157,6 @@ public class ImapMessageTest extends TestCase
namespaceService = serviceRegistry.getNamespaceService();
fileFolderService = serviceRegistry.getFileFolderService();
// start the transaction
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
@@ -200,7 +197,7 @@ public class ImapMessageTest extends TestCase
ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService");
imapServer = (AlfrescoImapServer) imapCtx.getBean("imapServer");
if(!imapServer.isImapServerEnabled())
if (!imapServer.isImapServerEnabled())
{
imapServer.setImapServerEnabled(true);
imapServer.setHost(HOST);
@@ -220,7 +217,6 @@ public class ImapMessageTest extends TestCase
imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + IMAP_FOLDER_NAME);
imapServiceImpl.setImapHome(imapHome);
// Starting IMAP
imapServiceImpl.startupInTxn(true);
@@ -228,10 +224,7 @@ public class ImapMessageTest extends TestCase
namespaceService, false);
testImapFolderNodeRef = nodeRefs.get(0);
/*
* Importing test folders: Test folder contains: "___-___folder_a" "___-___folder_a" contains: "___-___folder_a_a", "___-___file_a", "Message_485.eml" (this is IMAP
* Message) "___-___folder_a_a" contains: "____-____file_a_a"
*/
/* Importing test folders: Test folder contains: "___-___folder_a" "___-___folder_a" contains: "___-___folder_a_a", "___-___file_a", "Message_485.eml" (this is IMAP Message) "___-___folder_a_a" contains: "____-____file_a_a" */
importInternal("imap/imapservice_test_folder_a.acp", testImapFolderNodeRef);
txn.commit();
@@ -243,7 +236,7 @@ public class ImapMessageTest extends TestCase
// Get the store
this.store = session.getStore(PROTOCOL);
//this.store.connect(HOST, PORT, anotherUserName, anotherUserName);
// this.store.connect(HOST, PORT, anotherUserName, anotherUserName);
this.store.connect(imapServer.getHost(), imapServer.getPort(), anotherUserName, anotherUserName);
// Get folder
@@ -349,8 +342,7 @@ public class ImapMessageTest extends TestCase
fail("Should raise an IOException");
}
catch (IOException e)
{
}
{}
}
public void dontTestMessageCache() throws Exception
@@ -411,8 +403,7 @@ public class ImapMessageTest extends TestCase
{
Locale.setDefault(Locale.FRENCH);
String dateStr = "12-Jul-2020";
final IMAPFolder.ProtocolCommand uid_search_since = new IMAPFolder.ProtocolCommand()
{
final IMAPFolder.ProtocolCommand uid_search_since = new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol)
{
@@ -445,8 +436,7 @@ public class ImapMessageTest extends TestCase
Locale.setDefault(Locale.FRENCH);
String dateStr = "12-juil.-2020";
final IMAPFolder.ProtocolCommand uid_search_since = new IMAPFolder.ProtocolCommand()
{
final IMAPFolder.ProtocolCommand uid_search_since = new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol)
{
@@ -512,7 +502,7 @@ public class ImapMessageTest extends TestCase
// InternetAddress.toString(new Address[] {address}) - is used in the RFC822MetadataExtracter
// So, compare with that
assertFalse("Non ASCII characters in the address should be encoded", decodedAddress.equals(InternetAddress.toString(new Address[] {address})));
assertFalse("Non ASCII characters in the address should be encoded", decodedAddress.equals(InternetAddress.toString(new Address[]{address})));
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()));
@@ -540,7 +530,7 @@ public class ImapMessageTest extends TestCase
// triggers a metadata extract to take place in a post commit method. Previously this would have been a
// synchronous process. This is no longer true as it may now take place in a T-Engine. So, we need to wait
// for the extract to take place. There does not
long end = System.currentTimeMillis()+10000;
long end = System.currentTimeMillis() + 10000;
while (System.currentTimeMillis() <= end && origModified.equals(getModified(nodeRef)))
{
Thread.currentThread().sleep(1000);
@@ -607,8 +597,6 @@ public class ImapMessageTest extends TestCase
lfolder.appendMessages(messages);
// The search is not implemented.
// SearchTerm term = new HeaderTerm("X-Alfresco-Unique", "test8bit");
// messages = folder.search(term);
@@ -626,7 +614,6 @@ public class ImapMessageTest extends TestCase
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, messageXPath, params, namespaceService, true);
// does the message exist
assertEquals(1, nodeRefs.size());
@@ -646,8 +633,10 @@ public class ImapMessageTest extends TestCase
}
finally
{
if (messageFileInputStream1 != null) messageFileInputStream1.close();
if (messageFileInputStream2 != null) messageFileInputStream2.close();
if (messageFileInputStream1 != null)
messageFileInputStream1.close();
if (messageFileInputStream2 != null)
messageFileInputStream2.close();
}
// close connection
@@ -656,11 +645,9 @@ public class ImapMessageTest extends TestCase
}
private static RFC822DATA getRFC822Message(final IMAPFolder folder, final long uid) throws MessagingException
{
return (RFC822DATA) folder.doCommand(new IMAPFolder.ProtocolCommand()
{
return (RFC822DATA) folder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException
{
Response[] r = p.command("UID FETCH " + uid + " (RFC822)", null);
@@ -681,17 +668,20 @@ public class ImapMessageTest extends TestCase
/**
* Returns BODY object containing desired message fragment
*
* @param folder Folder containing the message
* @param uid Message UID
* @param from starting byte
* @param count bytes to read
* @param folder
* Folder containing the message
* @param uid
* Message UID
* @param from
* starting byte
* @param count
* bytes to read
* @return BODY containing desired message fragment
* @throws MessagingException
*/
private static BODY getMessageBodyPart(IMAPFolder folder, final Long uid, final Integer from, final Integer count) throws MessagingException
{
return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand()
{
return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException
{
Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[]<" + from + "." + count + ">)", null);
@@ -705,7 +695,7 @@ public class ImapMessageTest extends TestCase
}
FetchResponse fetchResponse = (FetchResponse) r[0];
BODY body = (BODY) fetchResponse.getItem(com.sun.mail.imap.protocol.BODY.class);
BODY body = (BODY) fetchResponse.getItem(BODY.class);
return body;
}
});
@@ -715,7 +705,8 @@ public class ImapMessageTest extends TestCase
/**
* Finds node by its path
*
* @param path String
* @param path
* String
* @return NodeRef
*/
private NodeRef findNode(String path)
@@ -727,15 +718,16 @@ public class ImapMessageTest extends TestCase
/**
* Returns the UID of the first message in folder
*
* @param folder Folder containing the message
* @param msn message sequence number
* @param folder
* Folder containing the message
* @param msn
* message sequence number
* @return UID of the first message
* @throws MessagingException
*/
private static Long getMessageUid(IMAPFolder folder, final int msn) throws MessagingException
{
return (Long) folder.doCommand(new IMAPFolder.ProtocolCommand()
{
return (Long) folder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException
{
String command = "FETCH " + msn + " (UID)";
@@ -749,38 +741,37 @@ public class ImapMessageTest extends TestCase
throw new ProtocolException("Unable to retrieve message UID");
}
for(int i = 0 ; i < r.length; i++)
for (int i = 0; i < r.length; i++)
{
if(r[i] instanceof FetchResponse)
if (r[i] instanceof FetchResponse)
{
FetchResponse fetchResponse = (FetchResponse) r[0];
UID uid = (UID) fetchResponse.getItem(UID.class);
logger.debug("SECNUM=" + uid.seqnum + ", UID="+uid.uid);
logger.debug("SECNUM=" + uid.seqnum + ", UID=" + uid.uid);
return uid.uid;
}
}
/**
* Uh-oh - this is where we would intermittently fall over with a class cast exception.
* The following code probes why we don't have a FetchResponse
* Uh-oh - this is where we would intermittently fall over with a class cast exception. The following code probes why we don't have a FetchResponse
*/
StringBuffer sb = new StringBuffer();
sb.append("command="+command);
sb.append("command=" + command);
sb.append('\n');
sb.append("resp length=" + r.length);
sb.append('\n');
for(int i = 0 ; i < r.length; i++)
for (int i = 0; i < r.length; i++)
{
logger.error(r[i]);
sb.append("class=" + r[i].getClass().getName());
IMAPResponse unexpected = (IMAPResponse)r[i];
IMAPResponse unexpected = (IMAPResponse) r[i];
sb.append("key=" + unexpected.getKey());
sb.append("number=" + unexpected.getNumber());
sb.append("rest=" + unexpected.getRest());
sb.append("r[" + i + "]=" + r[i] + '\n');
}
throw new ProtocolException("getMessageUid: "+ sb.toString());
throw new ProtocolException("getMessageUid: " + sb.toString());
}
});
}
@@ -788,8 +779,10 @@ public class ImapMessageTest extends TestCase
/**
* Returns size of the message
*
* @param folder Folder containing the message
* @param uid Message UID
* @param folder
* Folder containing the message
* @param uid
* Message UID
* @return Returns size of the message
* @throws MessagingException
*/
@@ -801,15 +794,16 @@ public class ImapMessageTest extends TestCase
/**
* Returns a full message body
*
* @param folder Folder containing the message
* @param uid Message UID
* @param folder
* Folder containing the message
* @param uid
* Message UID
* @return Returns size of the message
* @throws MessagingException
*/
private static BODY getMessageBody(IMAPFolder folder, final Long uid) throws MessagingException
{
return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand()
{
return (BODY) folder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException
{
Response[] r = p.command("UID FETCH " + uid + " (FLAGS BODY.PEEK[])", null);
@@ -831,7 +825,8 @@ public class ImapMessageTest extends TestCase
/**
* Simple util for logging response
*
* @param r response
* @param r
* response
*/
private static void logResponse(Response[] r)
{