Hi Thomas,

2013/2/22 <t...@apache.org>

> Author: tn
> Date: Fri Feb 22 10:40:34 2013
> New Revision: 1448981
>
> URL: http://svn.apache.org/r1448981
> Log:
> [EMAIL-125] Add datasource name for ByteArrayDataSource, fixes embedding
> multiple resources loaded from a ClassPath resolver.
>
> Modified:
>
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
>
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ImageHtmlEmail.java
>
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
>
> commons/proper/email/trunk/src/test/java/org/apache/commons/mail/ImageHtmlEmailTest.java
>
> Modified:
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java?rev=1448981&r1=1448980&r2=1448981&view=diff
>
> ==============================================================================
> ---
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
> (original)
> +++
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
> Fri Feb 22 10:40:34 2013
> @@ -34,6 +34,10 @@ import javax.activation.DataSource;
>   * - a byte array<br>
>   * - a String<br>
>   *
> + * <p>
> + * From version 1.3.1, it is possible to set a name for this DataSource,
> + * and it is recommended to do so.
> + *
>   * @since 1.0
>   * @author <a href="mailto:colin.chalm...@maxware.nl";>Colin Chalmers</a>
>   * @author <a href="mailto:j...@latchkey.com";>Jon S. Stevens</a>
> @@ -52,6 +56,13 @@ public class ByteArrayDataSource impleme
>      private final String type; // = "application/octet-stream";
>
>      /**
> +     * The name associated with this data source.
> +     * By default, the name is an empty string, similar to
> javax.mail.util.ByteArrayDataSource.
> +     * @since 1.3.1
> +     */
> +    private String name = "";
> +
> +    /**
>       * Create a datasource from a byte array.
>       *
>       * @param data A byte[].
> @@ -203,6 +214,17 @@ public class ByteArrayDataSource impleme
>      }
>
>      /**
> +     * Sets the name for this DataSource.
> +     *
> +     * @param name The name.
> +     * @since 1.3.1
> +     */
> +    public void setName(String name)
> +    {
> +        this.name = name;
> +    }
>

Is it possible to do this in 1.3.1? This is a change of the external API. I
always thought that this would cause the <minor>-segment of the version to
change. According to the versioning guidelines [1] a point release is only
possible if it only " involves simple bug fixes or optimizations that do
not introduce new features."
To me it is not clear what exactly is a "new feature".

Benedikt

[1] http://commons.apache.org/releases/versioning.html



> +
> +    /**
>       * Get the name.
>       *
>       * @return A String.
> @@ -210,7 +232,7 @@ public class ByteArrayDataSource impleme
>       */
>      public String getName()
>      {
> -        return "ByteArrayDataSource";
> +        return name;
>      }
>
>      /**
>
> 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=1448981&r1=1448980&r2=1448981&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
> Fri Feb 22 10:40:34 2013
> @@ -161,6 +161,11 @@ public class ImageHtmlEmail extends Html
>              if (dataSource != null)
>              {
>                  String name = dataSource.getName();
> +                if (EmailUtils.isEmpty(name))
> +                {
> +                    name = resourceLocation;
> +                }
> +
>                  String cid = cidCache.get(name);
>
>                  if (cid == null)
>
> Modified:
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/email/trunk/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java?rev=1448981&r1=1448980&r2=1448981&view=diff
>
> ==============================================================================
> ---
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
> (original)
> +++
> commons/proper/email/trunk/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
> Fri Feb 22 10:40:34 2013
> @@ -93,7 +93,11 @@ public class DataSourceClassPathResolver
>
>                  if (is != null)
>                  {
> -                    result = new ByteArrayDataSource(is, mimeType);
> +                    ByteArrayDataSource ds = new ByteArrayDataSource(is,
> mimeType);
> +                    // EMAIL-125: set the name of the DataSource to the
> normalized resource URL
> +                    // similar to other DataSource implementations, e.g.
> FileDataSource, URLDataSource
> +
>  
> ds.setName(DataSourceClassPathResolver.class.getResource(resourceName).toString());
> +                    result = ds;
>                  }
>                  else
>                  {
>
> 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=1448981&r1=1448980&r2=1448981&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
> Fri Feb 22 10:40:34 2013
> @@ -278,6 +278,48 @@ public class ImageHtmlEmailTest extends
>          assertTrue(mimeMessageParser.getAttachmentList().size() == 1);
>      }
>
> +    public void testSendHTMLAutoResolveMultipleFiles() throws Exception {
> +
>  Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
> +
> +        // Create the email message
> +        getMailServer();
> +
> +        String strSubject = "Test HTML Send default";
> +
> +        email = new MockImageHtmlEmailConcrete();
> +        DataSourceResolver dataSourceResolver = new
> DataSourceClassPathResolver("/", true);
> +
> +        email.setDataSourceResolver(dataSourceResolver);
> +        email.setHostName(strTestMailServer);
> +        email.setSmtpPort(getMailServerPort());
> +        email.setFrom(strTestMailFrom);
> +        email.addTo(strTestMailTo);
> +        email.setSubject(strSubject);
> +
> +        String html = "<p>First image  <img
> src=\"images/contentTypeTest.gif\"/></p>" +
> +                      "<p>Second image <img
> src=\"images/contentTypeTest.jpg\"/></p>" +
> +                      "<p>Third image  <img
> src=\"images/contentTypeTest.png\"/></p>";
> +
> +        // 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());
> +        MimeMessage mimeMessage =
> fakeMailServer.getMessages().get(0).getMimeMessage();
> +        MimeMessageUtils.writeMimeMessage(mimeMessage, new
> File("./target/test-emails/testSendHTMLAutoMultipleFiles.eml"));
> +
> +        MimeMessageParser mimeMessageParser = new
> MimeMessageParser(mimeMessage).parse();
> +        assertTrue(mimeMessageParser.getHtmlContent().indexOf("\"cid:")
> >= 0);
> +        assertTrue(mimeMessageParser.getAttachmentList().size() == 3);
> +    }
> +
>      public void testRegex() {
>          Pattern pattern = Pattern.compile(ImageHtmlEmail.REGEX_IMG_SRC);
>
>
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Reply via email to