commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1665692 - in /commons/proper/email/trunk/src: changes/changes.xml main/java/org/apache/commons/mail/ImageHtmlEmail.java test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
Date Tue, 10 Mar 2015 20:59:29 GMT
Author: tn
Date: Tue Mar 10 20:59:29 2015
New Revision: 1665692

URL: http://svn.apache.org/r1665692
Log:
[EMAIL-151] ImageHtmlEmail failed to embed attachments without a data source name. Thanks
to Andreas Kohn.

Modified:
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java
    commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1665692&r1=1665691&r2=1665692&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Tue Mar 10 20:59:29 2015
@@ -23,6 +23,9 @@
 
   <body>
     <release version="1.4.0" date="2014-??-??">
+      <action dev="tn" type="fix" issue="EMAIL-151" date="2015-03-10" due-to="Andreas
Kohn">
+        "ImageHtmlEmail" failed to embed attachments if their data source name was null.
+      </action>
       <action dev="tn" type="fix" issue="EMAIL-147" date="2014-12-26" due-to="Can Eskikaya">
         Html emails did not have the correct content-type set when using the Apache Geronimo
         JavaMail implementation v1.8.x.

Modified: commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java?rev=1665692&r1=1665691&r2=1665692&view=diff
==============================================================================
--- commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java (original)
+++ commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java Tue
Mar 10 20:59:29 2015
@@ -172,7 +172,7 @@ public class ImageHtmlEmail extends Html
 
                 if (cid == null)
                 {
-                    cid = embed(dataSource, dataSource.getName());
+                    cid = embed(dataSource, name);
                     cidCache.put(name, cid);
                 }
 

Modified: commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java?rev=1665692&r1=1665691&r2=1665692&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
(original)
+++ commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
Tue Mar 10 20:59:29 2015
@@ -29,7 +29,9 @@ import org.apache.commons.mail.util.Mime
 import org.junit.Before;
 import org.junit.Test;
 
+import javax.activation.DataSource;
 import javax.mail.internet.MimeMessage;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -241,6 +243,46 @@ public class ImageHtmlEmailTest extends
     }
 
     @Test
+    public void testSendClassPathFileWithNullName() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        getMailServer();
+
+        final String strSubject = "Test HTML Send default";
+
+        email = new MockImageHtmlEmailConcrete();
+        email.setDataSourceResolver(new MockDataSourceClassPathResolver("/", TEST_IS_LENIENT));
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+
+        final String html = loadUrlContent(TEST2_HTML_URL);
+
+        // set the html message
+        email.setHtmlMsg(html);
+
+        // set the alternative message
+        email.setTextMsg("Your email client does not support HTML messages");
+
+        // send the email
+        email.send();
+
+        fakeMailServer.stop();
+
+        assertEquals(1, fakeMailServer.getMessages().size());
+        final MimeMessage mimeMessage = fakeMailServer.getMessages().get(0).getMimeMessage();
+        MimeMessageUtils.writeMimeMessage(mimeMessage,
+                new File("./target/test-emails/testSendClassPathFileWithNullName.eml"));
+
+        final MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse();
+        assertTrue(mimeMessageParser.getHtmlContent().contains("\"cid:"));
+        assertTrue(mimeMessageParser.getAttachmentList().size() == 1);
+    }
+
+    @Test
     public void testSendHTMLAutoResolveFile() throws Exception {
         Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
 
@@ -448,4 +490,20 @@ public class ImageHtmlEmailTest extends
         }
         return html.toString();
     }
+    
+    private static final class MockDataSourceClassPathResolver extends DataSourceClassPathResolver
{
+
+        public MockDataSourceClassPathResolver(final String classPathBase, final boolean
lenient) {
+            super(classPathBase, lenient);
+        }
+
+        @Override
+        public DataSource resolve(String resourceLocation, boolean isLenient) throws IOException
{
+            javax.mail.util.ByteArrayDataSource ds =
+                    (javax.mail.util.ByteArrayDataSource) super.resolve(resourceLocation,
isLenient);
+            ds.setName(null);
+            return ds;
+        }
+        
+    }
 }



Mime
View raw message