+ * This code is based on a class of the same name originally implemented in alfresco-repository. + *
+ * * @author Neil Mc Erlean * @author eknizat * @since 4.0 diff --git a/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/EMLTransformer.java b/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/EMLTransformer.java new file mode 100644 index 00000000..0710635e --- /dev/null +++ b/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/EMLTransformer.java @@ -0,0 +1,245 @@ +/* + * #%L + * Alfresco Transform Core + * %% + * Copyright (C) 2005 - 2019 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see+ * This code is based on a class of the same name originally implemented in alfresco-repository. + *
+ * + */ +public class EMLTransformer implements SelectableTransformer + +{ + private static final Logger logger = LoggerFactory.getLogger( EMLTransformer.class); + + private static final String CHARSET = "charset"; + private static final String DEFAULT_ENCODING = "UTF-8"; + + @Override + public boolean isTransformable(String sourceMimetype, String targetMimetype, Map+ * This code is based on a class of the same name originally implemented in alfresco-repository. + *
+ * * @author Nick Burch * @author eknizat */ diff --git a/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectingTransformer.java b/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectingTransformer.java index 4abd8629..0e03f375 100644 --- a/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectingTransformer.java +++ b/alfresco-docker-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectingTransformer.java @@ -61,7 +61,8 @@ public class SelectingTransformer new AppleIWorksContentTransformer(), new HtmlParserContentTransformer(), new StringExtractingContentTransformer(), - new TextToPdfContentTransformer() + new TextToPdfContentTransformer(), + new EMLTransformer() // new OOXMLThumbnailContentTransformer()); // Doesn't work with java 11, transformer and test disabled ); } diff --git a/alfresco-docker-transform-misc/src/main/resources/engine_config.json b/alfresco-docker-transform-misc/src/main/resources/engine_config.json index a12997d2..f2b7a485 100644 --- a/alfresco-docker-transform-misc/src/main/resources/engine_config.json +++ b/alfresco-docker-transform-misc/src/main/resources/engine_config.json @@ -60,6 +60,14 @@ "transformOptions": [ "textToPdfOptions" ] + }, + { + "transformerName": "rfc822", + "supportedSourceAndTargetList": [ + {"sourceMediaType": "message/rfc822", "targetMediaType": "text/plain"} + ], + "transformOptions": [ + ] } ] } \ No newline at end of file diff --git a/alfresco-docker-transform-misc/src/test/java/org/alfresco/transformer/MiscControllerTest.java b/alfresco-docker-transform-misc/src/test/java/org/alfresco/transformer/MiscControllerTest.java index cbb8a19c..7830a804 100644 --- a/alfresco-docker-transform-misc/src/test/java/org/alfresco/transformer/MiscControllerTest.java +++ b/alfresco-docker-transform-misc/src/test/java/org/alfresco/transformer/MiscControllerTest.java @@ -31,11 +31,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_JPEG; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IWORK_KEYNOTE; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IWORK_NUMBERS; -import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IWORK_PAGES; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN; +import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.springframework.http.HttpStatus.OK; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; @@ -105,7 +106,6 @@ public class MiscControllerTest extends AbstractTransformerControllerTest } @Override - // Add extra required parameters to the request. protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile, String... params) { @@ -124,6 +124,116 @@ public class MiscControllerTest extends AbstractTransformerControllerTest // It is the mock that returns a zero length file for other transformers, when we supply an invalid targetExtension. } + /** + * Test transforming a valid eml file to text + */ + @Test + public void testRFC822ToText() throws Exception + { + String expected = "Gym class featuring a brown fox and lazy dog"; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("eml")); + assertTrue("Content from eml transform didn't contain expected value. ", + result.getResponse().getContentAsString().contains(expected)); + } + + /** + * Test transforming a non-ascii eml file to text + */ + @Test + public void testNonAsciiRFC822ToText() throws Exception + { + String expected = "El r\u00E1pido zorro marr\u00F3n salta sobre el perro perezoso"; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("spanish.eml")); + + String contentResult = new String(result.getResponse().getContentAsByteArray(), "UTF-8"); + assertTrue("Content from eml transform didn't contain expected value. ", contentResult.contains(expected)); + } + + /** + * Test transforming a valid eml with an attachment to text; attachment should be ignored + */ + @Test + public void testRFC822WithAttachmentToText() throws Exception + { + String expected = "Mail with attachment content"; + String notExpected = "File attachment content"; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("attachment.eml")); + assertTrue("Content from eml transform didn't contain expected value. ", + result.getResponse().getContentAsString().contains(expected)); + assertFalse(result.getResponse().getContentAsString().contains(notExpected)); + } + + /** + * Test transforming a valid eml with minetype multipart/alternative to text + */ + @Test + public void testRFC822AlternativeToText() throws Exception + { + String expected = "alternative plain text"; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("alternative.eml")); + assertTrue("Content from eml transform didn't contain expected value. ", + result.getResponse().getContentAsString().contains(expected)); + } + + /** + * Test transforming a valid eml with nested mimetype multipart/alternative to text + */ + @Test + public void testRFC822NestedAlternativeToText() throws Exception + { + String expected = "nested alternative plain text"; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("nested.alternative.eml")); + assertTrue("Content from eml transform didn't contain expected value. ", + result.getResponse().getContentAsString().contains(expected)); + } + + /** + * Test transforming a valid eml with a html part containing html special characters to text + */ + @Test + public void testHtmlSpecialCharsToText() throws Exception + { + String expected = " "; + MvcResult result = sendRequest("eml", + null, + MIMETYPE_RFC822, + "txt", + MIMETYPE_TEXT_PLAIN, + null, + readTestFile("htmlChars.eml")); + assertFalse(result.getResponse().getContentAsString().contains(expected)); + } + @Test public void testHTMLtoString() throws Exception { @@ -139,7 +249,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest String partC = "