This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 49a8fd2  add test for multiple text attachments but different charsets 
(#6940)
49a8fd2 is described below

commit 49a8fd210f494588d22097efb00206ead7d23a55
Author: Yasser Zamani <[email protected]>
AuthorDate: Mon Feb 14 10:53:40 2022 +0330

    add test for multiple text attachments but different charsets (#6940)
    
    * add test for multiple text attachments but different charsets
    
    * unicode escape of German 'a umlaut' character
---
 .../multipart/MimeMultipartDataFormatTest.java     | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
index 61f3ce0..ce9558e 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/dataformat/mime/multipart/MimeMultipartDataFormatTest.java
@@ -147,6 +147,62 @@ public class MimeMultipartDataFormatTest extends 
CamelTestSupport {
     }
 
     @Test
+    public void roundtripWithMultipleTextAttachmentsButDifferentCharsets() 
throws IOException {
+        String att1ContentType = "text/plain; charset=ISO-8859-1";
+        String att1Text = new String("empf\u00e4nger1".getBytes("ISO-8859-1"), 
"ISO-8859-1");
+        String att1FileName = "empf\u00e4nger1";
+        String att2ContentType = "text/plain; charset=ISO-8859-15";
+        String att2Text = new 
String("empf\u00e4nger15".getBytes("ISO-8859-15"), "ISO-8859-15");
+        String att2FileName = "empf\u00e4nger15";
+        String att3ContentType = "text/plain; charset=UTF-8";
+        String att3Text = new String("empf\u00e4nger8".getBytes("UTF-8"), 
"UTF-8");
+        String att3FileName = "empf\u00e4nger8";
+        addAttachment(att1ContentType, att1Text, att1FileName);
+        addAttachment(att2ContentType, att2Text, att2FileName);
+        addAttachment(att3ContentType, att3Text, att3FileName);
+
+        in.setBody(new String("empf\u00e4nger15".getBytes("ISO-8859-15"), 
"ISO-8859-15"));
+        in.setHeader(Exchange.CONTENT_TYPE, "text/plain; charset=ISO-8859-15");
+        in.setHeader(Exchange.CONTENT_ENCODING, "ISO-8859-15");
+
+        Exchange result = template.send("direct:roundtrip", exchange);
+        AttachmentMessage out = result.getMessage(AttachmentMessage.class);
+
+        assertEquals(att2Text, out.getBody(String.class));
+        assertTrue(out.getHeader(Exchange.CONTENT_TYPE, 
String.class).startsWith("text/plain"));
+        assertEquals("ISO-8859-15", out.getHeader(Exchange.CONTENT_ENCODING));
+        assertTrue(out.hasAttachments());
+        assertEquals(3, out.getAttachmentNames().size());
+
+        assertTrue(out.getAttachmentNames().contains(att1FileName));
+        DataHandler dh = out.getAttachment(att1FileName);
+        assertNotNull(dh);
+        assertEquals(att1ContentType, dh.getContentType());
+        InputStream is = dh.getInputStream();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os);
+        assertEquals(att1Text, new String(os.toByteArray(), "ISO-8859-1"));
+
+        assertTrue(out.getAttachmentNames().contains(att2FileName));
+        dh = out.getAttachment(att2FileName);
+        assertNotNull(dh);
+        assertEquals(att2ContentType, dh.getContentType());
+        is = dh.getInputStream();
+        os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os);
+        assertEquals(att2Text, new String(os.toByteArray(), "ISO-8859-15"));
+
+        assertTrue(out.getAttachmentNames().contains(att3FileName));
+        dh = out.getAttachment(att3FileName);
+        assertNotNull(dh);
+        assertEquals(att3ContentType, dh.getContentType());
+        is = dh.getInputStream();
+        os = new ByteArrayOutputStream();
+        IOHelper.copyAndCloseInput(is, os);
+        assertEquals(att3Text, new String(os.toByteArray(), "UTF-8"));
+    }
+
+    @Test
     public void roundtripWithTextAttachmentsAndBinaryContent() throws 
IOException {
         String attContentType = "text/plain";
         String attText = "Attachment Text";

Reply via email to