You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/02/22 11:40:34 UTC

svn commit: r1448981 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/ main/java/org/apache/commons/mail/resolver/ test/java/org/apache/commons/mail/

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.chalmers@maxware.nl">Colin Chalmers</a>
  * @author <a href="mailto:jon@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;
+    }
+
+    /**
      * 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);
 



Re: svn commit: r1448981 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/ main/java/org/apache/commons/mail/resolver/ test/java/org/apache/commons/mail/

Posted by Benedikt Ritter <br...@apache.org>.
Hi Thomas


2013/2/22 Thomas Neidhart <th...@gmail.com>

> On 02/22/2013 01:50 PM, Thomas Neidhart wrote:
> > On 02/22/2013 01:36 PM, Benedikt Ritter wrote:
> >> Hi Thomas,
> >>
> >>
> >> 2013/2/22 <tn...@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.chalmers@maxware.nl">Colin
> Chalmers</a>
> >>>   * @author <a href="mailto:jon@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".
> >
> > you just copied the part of the sentence that make it appear as a
> > mandatory requirement. The full sentence is:
> >
> >> A point release typically involves simple bug fixes or optimizations >
> > that do not introduce new features. Developers may perform a point
> >> release if the release is at least interface-compatible with the
> >> previous release.
> >
> > The interface is compatible with a previous release, just a new method
> > has been added which was necessary to fix the bug in a clean way.
> >
> > Additionally, to keep backwards compatibility, I added a sanity check,
> > if the name of the DataSource is not set, and default it to the resource
> > location in that case (although this should not happen in any case as
> > the DataSource is created by email itself).
>
> btw. take a look here:
>
> http://commons.apache.org/beanutils/clirr-report.html


Thanks for the clarification!


>
>
> Thomas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


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

Re: svn commit: r1448981 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/ main/java/org/apache/commons/mail/resolver/ test/java/org/apache/commons/mail/

Posted by Thomas Neidhart <th...@gmail.com>.
On 02/22/2013 01:50 PM, Thomas Neidhart wrote:
> On 02/22/2013 01:36 PM, Benedikt Ritter wrote:
>> Hi Thomas,
>>
>>
>> 2013/2/22 <tn...@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.chalmers@maxware.nl">Colin Chalmers</a>
>>>   * @author <a href="mailto:jon@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".
> 
> you just copied the part of the sentence that make it appear as a
> mandatory requirement. The full sentence is:
> 
>> A point release typically involves simple bug fixes or optimizations >
> that do not introduce new features. Developers may perform a point
>> release if the release is at least interface-compatible with the
>> previous release.
> 
> The interface is compatible with a previous release, just a new method
> has been added which was necessary to fix the bug in a clean way.
> 
> Additionally, to keep backwards compatibility, I added a sanity check,
> if the name of the DataSource is not set, and default it to the resource
> location in that case (although this should not happen in any case as
> the DataSource is created by email itself).

btw. take a look here:

http://commons.apache.org/beanutils/clirr-report.html

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1448981 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/ main/java/org/apache/commons/mail/resolver/ test/java/org/apache/commons/mail/

Posted by Thomas Neidhart <th...@gmail.com>.
On 02/22/2013 01:36 PM, Benedikt Ritter wrote:
> Hi Thomas,
> 
> 
> 2013/2/22 <tn...@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.chalmers@maxware.nl">Colin Chalmers</a>
>>   * @author <a href="mailto:jon@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".

you just copied the part of the sentence that make it appear as a
mandatory requirement. The full sentence is:

> A point release typically involves simple bug fixes or optimizations >
that do not introduce new features. Developers may perform a point
> release if the release is at least interface-compatible with the
> previous release.

The interface is compatible with a previous release, just a new method
has been added which was necessary to fix the bug in a clean way.

Additionally, to keep backwards compatibility, I added a sanity check,
if the name of the DataSource is not set, and default it to the resource
location in that case (although this should not happen in any case as
the DataSource is created by email itself).

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1448981 - in /commons/proper/email/trunk/src: main/java/org/apache/commons/mail/ main/java/org/apache/commons/mail/resolver/ test/java/org/apache/commons/mail/

Posted by Benedikt Ritter <br...@apache.org>.
Hi Thomas,


2013/2/22 <tn...@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.chalmers@maxware.nl">Colin Chalmers</a>
>   * @author <a href="mailto:jon@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