Author: sgoeschl
Date: Tue Sep  6 21:26:21 2011
New Revision: 1165861

URL: http://svn.apache.org/viewvc?rev=1165861&view=rev
Log:
[EMAIL-107] Added mime.types to META-INF - thanks to Claus Polanka, Michael 
Jakl and the first Austrian Hackergarden.

Added:
    commons/proper/email/trunk/src/resources/
    commons/proper/email/trunk/src/resources/META-INF/
    commons/proper/email/trunk/src/resources/META-INF/mime.types
Modified:
    commons/proper/email/trunk/pom.xml
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java
    
commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java

Modified: commons/proper/email/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/email/trunk/pom.xml?rev=1165861&r1=1165860&r2=1165861&view=diff
==============================================================================
--- commons/proper/email/trunk/pom.xml (original)
+++ commons/proper/email/trunk/pom.xml Tue Sep  6 21:26:21 2011
@@ -258,6 +258,11 @@
 
     <build>
         <sourceDirectory>src/java</sourceDirectory>
+        <resources>
+            <resource>
+                <directory>src/resources</directory>
+            </resource>
+        </resources>
         <testSourceDirectory>src/test</testSourceDirectory>
         <testResources>
             <testResource>

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1165861&r1=1165860&r2=1165861&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Tue Sep  6 21:26:21 2011
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.3" date="as in SVN">
+       <action dev="sgoeschl" type="fix" issue="EMAIL-107" date="2011-09-06" 
due-to="Claus Polanka, Michael Jakl">
+          Added mime.types to META-INF - the definition is actually found in 
activation.jar
+          but did not work.
+      </action>
        <action dev="sgoeschl" type="fix" issue="EMAIL-106" date="2011-09-06" 
due-to="Bruno Harbulot">
           STARTTLS can be used even without authenticator.
       </action>

Added: commons/proper/email/trunk/src/resources/META-INF/mime.types
URL: 
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/resources/META-INF/mime.types?rev=1165861&view=auto
==============================================================================
--- commons/proper/email/trunk/src/resources/META-INF/mime.types (added)
+++ commons/proper/email/trunk/src/resources/META-INF/mime.types Tue Sep  6 
21:26:21 2011
@@ -0,0 +1 @@
+image/png   png PNG

Modified: 
commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java?rev=1165861&r1=1165860&r2=1165861&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java 
(original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailTest.java 
Tue Sep  6 21:26:21 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.mail;
 
+import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
@@ -27,14 +28,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-
 import javax.mail.Authenticator;
 import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 import javax.mail.internet.ParseException;
-
 import org.apache.commons.mail.mocks.MockEmailConcrete;
 
 /**
@@ -355,9 +354,9 @@ public class EmailTest extends BaseEmail
                 "joe....@apache.org",
                 "joe....@apache.org"));
         arrExpected.add(
-            new InternetAddress(
-                "someone_h...@work-address.com.au",
-                "someone_h...@work-address.com.au"));
+                new InternetAddress(
+                        "someone_h...@work-address.com.au",
+                        "someone_h...@work-address.com.au"));
 
         for (int i = 0; i < testEmails.length; i++)
         {
@@ -1320,18 +1319,18 @@ public class EmailTest extends BaseEmail
 
         testInetEmailValid.add(new InternetAddress("m...@home.com", "Name1"));
         testInetEmailValid.add(
-            new InternetAddress(
-                "joe....@apache.org",
-                "joe....@apache.org"));
+                new InternetAddress(
+                        "joe....@apache.org",
+                        "joe....@apache.org"));
         testInetEmailValid.add(
-            new InternetAddress(
-                "someone_h...@work-address.com.au",
-                "someone_h...@work-address.com.au"));
+                new InternetAddress(
+                        "someone_h...@work-address.com.au",
+                        "someone_h...@work-address.com.au"));
 
         this.email.setBcc(testInetEmailValid);
         assertEquals(
-            testInetEmailValid.size(),
-            this.email.getBccAddresses().size());
+                testInetEmailValid.size(),
+                this.email.getBccAddresses().size());
     }
 
     /** */
@@ -1428,4 +1427,21 @@ public class EmailTest extends BaseEmail
         msg.saveChanges();
         assertEquals("application/octet-stream", msg.getContentType());
     }
+
+    public void testCorrectContentTypeForPNG() throws Exception
+    {
+        this.email.setHostName(this.strTestMailServer);
+        this.email.setSmtpPort(this.getMailServerPort());
+        this.email.setFrom("a...@b.com");
+        this.email.addTo("c...@d.com");
+        this.email.setSubject("test mail");
+
+        this.email.setCharset("ISO-8859-1");
+        File png = new 
File("./target/test-classes/images/logos/maven-feather.png");
+        this.email.setContent(png, "image/png");
+        this.email.buildMimeMessage();
+        MimeMessage msg = this.email.getMimeMessage();
+        msg.saveChanges();
+        assertEquals("image/png", msg.getContentType());
+    }
 }

Modified: 
commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java?rev=1165861&r1=1165860&r2=1165861&view=diff
==============================================================================
--- 
commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java 
(original)
+++ 
commons/proper/email/trunk/src/test/org/apache/commons/mail/HtmlEmailTest.java 
Tue Sep  6 21:26:21 2011
@@ -19,11 +19,15 @@ package org.apache.commons.mail;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.List;
 
+import javax.activation.DataSource;
 import javax.activation.FileDataSource;
+import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.mail.mocks.MockHtmlEmailConcrete;
 import org.apache.commons.mail.settings.EmailConfiguration;
+import org.apache.commons.mail.util.MimeMessageParser;
 
 /**
  * JUnit test case for HtmlEmail Class.
@@ -644,5 +648,40 @@ public class HtmlEmailTest extends BaseE
          // back?
          String returnedCid = this.email.embed(file);
          assertEquals("didn't get same CID after embedding same file twice", 
testCid, returnedCid);
-     }     
+     }
+    
+    public void testHtmlMailMimeLayout() throws Exception
+    {
+        assertCorrectContentType("contentTypeTest.gif", "image/gif");
+        assertCorrectContentType("contentTypeTest.jpg", "image/jpeg");
+        assertCorrectContentType("contentTypeTest.png", "image/png");
+    }
+
+    private void assertCorrectContentType(String picture, String contentType) 
throws Exception {
+        HtmlEmail htmlEmail = createDefaultHtmlEmail();
+        String cid = htmlEmail.embed(new File("./src/test/images/" + picture), 
"Apache Logo");
+        String htmlMsg = "<html><img src=\"cid:" + cid + "\"><html>";
+        htmlEmail.setHtmlMsg(htmlMsg);
+        htmlEmail.buildMimeMessage();
+
+        MimeMessage mm = htmlEmail.getMimeMessage();
+        mm.saveChanges();
+        MimeMessageParser mmp = new MimeMessageParser(mm);
+        mmp.parse();
+
+        List attachments = mmp.getAttachmentList();
+        assertEquals("Attachment size", 1, attachments.size());
+
+        DataSource ds = (DataSource) attachments.get(0);
+        assertEquals("Content type", contentType, ds.getContentType());
+    }
+
+    private HtmlEmail createDefaultHtmlEmail() throws EmailException {
+        HtmlEmail htmlEmail = new HtmlEmail();
+        htmlEmail.setHostName(this.strTestMailServer);
+        htmlEmail.setSmtpPort(this.getMailServerPort());
+        htmlEmail.setFrom("a...@b.com");
+        htmlEmail.addTo("c...@d.com");
+        return htmlEmail;
+    }
 }


Reply via email to